aboutsummaryrefslogtreecommitdiff
path: root/weed/replication/replicator.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2018-09-25 09:27:03 -0700
committerChris Lu <chris.lu@gmail.com>2018-09-25 09:27:03 -0700
commit31ed352ab638027e940ff92af55c0c6db0dc3309 (patch)
tree71d3db47c17195fb764425ba9b235287bdf437e7 /weed/replication/replicator.go
parent60c1ada4c170297f1470ad78df3b1f0520769632 (diff)
downloadseaweedfs-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.go16
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)
}