diff options
| author | Chris Lu <chris.lu@gmail.com> | 2018-09-25 09:27:03 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2018-09-25 09:27:03 -0700 |
| commit | 31ed352ab638027e940ff92af55c0c6db0dc3309 (patch) | |
| tree | 71d3db47c17195fb764425ba9b235287bdf437e7 /weed/replication/replicator.go | |
| parent | 60c1ada4c170297f1470ad78df3b1f0520769632 (diff) | |
| download | seaweedfs-31ed352ab638027e940ff92af55c0c6db0dc3309.tar.xz seaweedfs-31ed352ab638027e940ff92af55c0c6db0dc3309.zip | |
replication handle cases when entry already exists
Diffstat (limited to 'weed/replication/replicator.go')
| -rw-r--r-- | weed/replication/replicator.go | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/weed/replication/replicator.go b/weed/replication/replicator.go index 215be5992..834da6217 100644 --- a/weed/replication/replicator.go +++ b/weed/replication/replicator.go @@ -9,6 +9,7 @@ import ( "github.com/chrislusf/seaweedfs/weed/replication/sink/filersink" "github.com/chrislusf/seaweedfs/weed/replication/source" "github.com/chrislusf/seaweedfs/weed/util" + "github.com/chrislusf/seaweedfs/weed/glog" ) type Replicator struct { @@ -43,5 +44,18 @@ func (r *Replicator) Replicate(key string, message *filer_pb.EventNotification) if message.OldEntry == nil && message.NewEntry != nil { return r.sink.CreateEntry(key, message.NewEntry) } - return r.sink.UpdateEntry(key, message.OldEntry, message.NewEntry, message.DeleteChunks) + if existingEntry, err := r.sink.LookupEntry(key); err == nil { + if message.OldEntry == nil && message.NewEntry == nil { + glog.V(0).Infof("message %+v existingEntry: %+v", message, existingEntry) + return r.sink.DeleteEntry(key, existingEntry, true) + } + return r.sink.UpdateEntry(key, message.OldEntry, message.NewEntry, existingEntry, message.DeleteChunks) + } + + glog.V(0).Infof("key:%s, message %+v", key, message) + if message.OldEntry == nil && message.NewEntry == nil { + return nil + } + + return r.sink.CreateEntry(key, message.NewEntry) } |
