aboutsummaryrefslogtreecommitdiff
path: root/weed/filesys/file.go
diff options
context:
space:
mode:
authorKonstantin Lebedev <lebedev_k@tochka.com>2020-11-19 18:16:44 +0500
committerKonstantin Lebedev <lebedev_k@tochka.com>2020-11-19 18:16:44 +0500
commit27e73de7975ff9f097bbfd8d2717aa27931f25b5 (patch)
tree802f8cf0f7cc6834e03a24700a8d07a218f5bd86 /weed/filesys/file.go
parente1190b3224638616cf4e1318ddcba0b1575f2130 (diff)
parentda04bb3d1bb60d92fdacfb2edd8c8bdba2643038 (diff)
downloadseaweedfs-27e73de7975ff9f097bbfd8d2717aa27931f25b5.tar.xz
seaweedfs-27e73de7975ff9f097bbfd8d2717aa27931f25b5.zip
Merge branch 'upstream_master' into store_s3cred
# Conflicts: # weed/s3api/filer_util.go
Diffstat (limited to 'weed/filesys/file.go')
-rw-r--r--weed/filesys/file.go34
1 files changed, 28 insertions, 6 deletions
diff --git a/weed/filesys/file.go b/weed/filesys/file.go
index 4662c23db..3bffa156e 100644
--- a/weed/filesys/file.go
+++ b/weed/filesys/file.go
@@ -144,7 +144,7 @@ func (file *File) Setattr(ctx context.Context, req *fuse.SetattrRequest, resp *f
}
}
file.entry.Chunks = chunks
- file.entryViewCache = nil
+ file.entryViewCache, _ = filer.NonOverlappingVisibleIntervals(filer.LookupFn(file.wfs), chunks)
file.reader = nil
file.wfs.deleteFileChunks(truncatedChunks)
}
@@ -282,15 +282,37 @@ func (file *File) maybeLoadEntry(ctx context.Context) (entry *filer_pb.Entry, er
return entry, nil
}
+func lessThan(a, b *filer_pb.FileChunk) bool {
+ if a.Mtime == b.Mtime {
+ return a.Fid.FileKey < b.Fid.FileKey
+ }
+ return a.Mtime < b.Mtime
+}
+
func (file *File) addChunks(chunks []*filer_pb.FileChunk) {
- sort.Slice(chunks, func(i, j int) bool {
- if chunks[i].Mtime == chunks[j].Mtime {
- return chunks[i].Fid.FileKey < chunks[j].Fid.FileKey
+ // find the earliest incoming chunk
+ newChunks := chunks
+ earliestChunk := newChunks[0]
+ for i := 1; i < len(newChunks); i++ {
+ if lessThan(earliestChunk, newChunks[i]) {
+ earliestChunk = newChunks[i]
+ }
+ }
+
+ // pick out-of-order chunks from existing chunks
+ for _, chunk := range file.entry.Chunks {
+ if lessThan(earliestChunk, chunk) {
+ chunks = append(chunks, chunk)
}
- return chunks[i].Mtime < chunks[j].Mtime
+ }
+
+ // sort incoming chunks
+ sort.Slice(chunks, func(i, j int) bool {
+ return lessThan(chunks[i], chunks[j])
})
+ // add to entry view cache
for _, chunk := range chunks {
file.entryViewCache = filer.MergeIntoVisibles(file.entryViewCache, chunk)
}
@@ -299,7 +321,7 @@ func (file *File) addChunks(chunks []*filer_pb.FileChunk) {
glog.V(4).Infof("%s existing %d chunks adds %d more", file.fullpath(), len(file.entry.Chunks), len(chunks))
- file.entry.Chunks = append(file.entry.Chunks, chunks...)
+ file.entry.Chunks = append(file.entry.Chunks, newChunks...)
}
func (file *File) setEntry(entry *filer_pb.Entry) {