|
@ -121,14 +121,13 @@ func (fs *FilerSink) CreateEntry(key string, entry *filer_pb.Entry) error { |
|
|
}) |
|
|
}) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
func (fs *FilerSink) UpdateEntry(key string, oldEntry, newEntry *filer_pb.Entry, deleteIncludeChunks bool) (err error) { |
|
|
|
|
|
|
|
|
func (fs *FilerSink) LookupEntry(key string) (entry *filer_pb.Entry, err error) { |
|
|
|
|
|
|
|
|
ctx := context.Background() |
|
|
ctx := context.Background() |
|
|
|
|
|
|
|
|
dir, name := filer2.FullPath(key).DirAndName() |
|
|
dir, name := filer2.FullPath(key).DirAndName() |
|
|
|
|
|
|
|
|
// read existing entry
|
|
|
// read existing entry
|
|
|
var entry *filer_pb.Entry |
|
|
|
|
|
err = fs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error { |
|
|
err = fs.withFilerClient(func(client filer_pb.SeaweedFilerClient) error { |
|
|
|
|
|
|
|
|
request := &filer_pb.LookupDirectoryEntryRequest{ |
|
|
request := &filer_pb.LookupDirectoryEntryRequest{ |
|
@ -136,7 +135,7 @@ func (fs *FilerSink) UpdateEntry(key string, oldEntry, newEntry *filer_pb.Entry, |
|
|
Name: name, |
|
|
Name: name, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
glog.V(4).Infof("lookup directory entry: %v", request) |
|
|
|
|
|
|
|
|
glog.V(4).Infof("lookup entry: %v", request) |
|
|
resp, err := client.LookupDirectoryEntry(ctx, request) |
|
|
resp, err := client.LookupDirectoryEntry(ctx, request) |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
glog.V(0).Infof("lookup %s: %v", key, err) |
|
|
glog.V(0).Infof("lookup %s: %v", key, err) |
|
@ -149,10 +148,21 @@ func (fs *FilerSink) UpdateEntry(key string, oldEntry, newEntry *filer_pb.Entry, |
|
|
}) |
|
|
}) |
|
|
|
|
|
|
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return fmt.Errorf("lookup when updating %s: %v", key, err) |
|
|
|
|
|
|
|
|
return nil, fmt.Errorf("lookup %s: %v", key, err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if filer2.ETag(newEntry.Chunks) == filer2.ETag(entry.Chunks) { |
|
|
|
|
|
|
|
|
return entry, nil |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
func (fs *FilerSink) UpdateEntry(key string, oldEntry, newEntry, existingEntry *filer_pb.Entry, deleteIncludeChunks bool) (err error) { |
|
|
|
|
|
|
|
|
|
|
|
ctx := context.Background() |
|
|
|
|
|
|
|
|
|
|
|
dir, _ := filer2.FullPath(key).DirAndName() |
|
|
|
|
|
|
|
|
|
|
|
glog.V(0).Infof("oldEntry %+v, newEntry %+v, existingEntry: %+v", oldEntry, newEntry, existingEntry) |
|
|
|
|
|
|
|
|
|
|
|
if filer2.ETag(newEntry.Chunks) == filer2.ETag(existingEntry.Chunks) { |
|
|
// skip if no change
|
|
|
// skip if no change
|
|
|
// this usually happens when retrying the replication
|
|
|
// this usually happens when retrying the replication
|
|
|
glog.V(0).Infof("already replicated %s", key) |
|
|
glog.V(0).Infof("already replicated %s", key) |
|
@ -163,7 +173,7 @@ func (fs *FilerSink) UpdateEntry(key string, oldEntry, newEntry *filer_pb.Entry, |
|
|
// delete the chunks that are deleted from the source
|
|
|
// delete the chunks that are deleted from the source
|
|
|
if deleteIncludeChunks { |
|
|
if deleteIncludeChunks { |
|
|
// remove the deleted chunks. Actual data deletion happens in filer UpdateEntry FindUnusedFileChunks
|
|
|
// remove the deleted chunks. Actual data deletion happens in filer UpdateEntry FindUnusedFileChunks
|
|
|
entry.Chunks = minusChunks(entry.Chunks, deletedChunks) |
|
|
|
|
|
|
|
|
existingEntry.Chunks = minusChunks(existingEntry.Chunks, deletedChunks) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// replicate the chunks that are new in the source
|
|
|
// replicate the chunks that are new in the source
|
|
@ -171,7 +181,7 @@ func (fs *FilerSink) UpdateEntry(key string, oldEntry, newEntry *filer_pb.Entry, |
|
|
if err != nil { |
|
|
if err != nil { |
|
|
return fmt.Errorf("replicte %s chunks error: %v", key, err) |
|
|
return fmt.Errorf("replicte %s chunks error: %v", key, err) |
|
|
} |
|
|
} |
|
|
entry.Chunks = append(entry.Chunks, replicatedChunks...) |
|
|
|
|
|
|
|
|
existingEntry.Chunks = append(existingEntry.Chunks, replicatedChunks...) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
// save updated meta data
|
|
|
// save updated meta data
|
|
@ -179,11 +189,11 @@ func (fs *FilerSink) UpdateEntry(key string, oldEntry, newEntry *filer_pb.Entry, |
|
|
|
|
|
|
|
|
request := &filer_pb.UpdateEntryRequest{ |
|
|
request := &filer_pb.UpdateEntryRequest{ |
|
|
Directory: dir, |
|
|
Directory: dir, |
|
|
Entry: entry, |
|
|
|
|
|
|
|
|
Entry: existingEntry, |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
if _, err := client.UpdateEntry(ctx, request); err != nil { |
|
|
if _, err := client.UpdateEntry(ctx, request); err != nil { |
|
|
return fmt.Errorf("update entry %s: %v", key, err) |
|
|
|
|
|
|
|
|
return fmt.Errorf("update existingEntry %s: %v", key, err) |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
return nil |
|
|
return nil |
|
|