diff options
Diffstat (limited to 'weed/replication/replicator.go')
| -rw-r--r-- | weed/replication/replicator.go | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/weed/replication/replicator.go b/weed/replication/replicator.go new file mode 100644 index 000000000..c223021c2 --- /dev/null +++ b/weed/replication/replicator.go @@ -0,0 +1,31 @@ +package replication + +import ( + "github.com/chrislusf/seaweedfs/weed/replication/sink" + "github.com/chrislusf/seaweedfs/weed/util" + "github.com/chrislusf/seaweedfs/weed/pb/filer_pb" +) + +type Replicator struct { + sink *sink.FilerSink +} + +func NewReplicator(config util.Configuration) *Replicator { + + sink := &sink.FilerSink{} + sink.Initialize(config) + + return &Replicator{ + sink: sink, + } +} + +func (r *Replicator) Replicate(key string, message *filer_pb.EventNotification) error { + if message.OldEntry != nil && message.NewEntry == nil { + return r.sink.DeleteEntry(message.OldEntry, message.DeleteChunks) + } + if message.OldEntry == nil && message.NewEntry != nil { + return r.sink.CreateEntry(message.NewEntry) + } + return r.sink.UpdateEntry(message.OldEntry, message.NewEntry, message.DeleteChunks) +} |
