You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

31 lines
798 B

  1. package replication
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/replication/sink"
  4. "github.com/chrislusf/seaweedfs/weed/util"
  5. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  6. )
  7. type Replicator struct {
  8. sink *sink.FilerSink
  9. }
  10. func NewReplicator(config util.Configuration) *Replicator {
  11. sink := &sink.FilerSink{}
  12. sink.Initialize(config)
  13. return &Replicator{
  14. sink: sink,
  15. }
  16. }
  17. func (r *Replicator) Replicate(key string, message *filer_pb.EventNotification) error {
  18. if message.OldEntry != nil && message.NewEntry == nil {
  19. return r.sink.DeleteEntry(message.OldEntry, message.DeleteChunks)
  20. }
  21. if message.OldEntry == nil && message.NewEntry != nil {
  22. return r.sink.CreateEntry(message.NewEntry)
  23. }
  24. return r.sink.UpdateEntry(message.OldEntry, message.NewEntry, message.DeleteChunks)
  25. }