Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

refactoring

Chris Lud9f9aca45301
diff --git a/weed/filesys/file.go b/weed/filesys/file.go
index ce9ef3a804..e27cdd42e0 100644
--- a/weed/filesys/file.go
+++ b/weed/filesys/file.go
@@ -173,3 +173,18 @@ func (file *File) maybeLoadAttributes(ctx context.Context) error {
}
return nil
}
+
+func (file *File) addChunk(chunk *filer_pb.FileChunk) {
+ if chunk != nil {
+ file.addChunks([]*filer_pb.FileChunk{chunk})
+ }
+}
+
+func (file *File) addChunks(chunks []*filer_pb.FileChunk) {
+ for _, chunk := range chunks {
+ file.entry.Chunks = append(file.entry.Chunks, chunk)
+ file.entryViewCache = nil
+ glog.V(4).Infof("uploaded %s/%s to %s [%d,%d)", file.dir.Path, file.Name, chunk.FileId, chunk.Offset, chunk.Offset+int64(chunk.Size))
+ }
+ file.entryViewCache = filer2.NonOverlappingVisibleIntervals(file.entry.Chunks)
+}
diff --git a/weed/filesys/filehandle.go b/weed/filesys/filehandle.go
index 8909da52af..23741a0520 100644
--- a/weed/filesys/filehandle.go
+++ b/weed/filesys/filehandle.go
@@ -157,10 +157,9 @@ func (fh *FileHandle) Write(ctx context.Context, req *fuse.WriteRequest, resp *f
fh.dirtyMetadata = true
}
- for _, chunk := range chunks {
- fh.f.entry.Chunks = append(fh.f.entry.Chunks, chunk)
- fh.f.entryViewCache = nil
- glog.V(4).Infof("uploaded %s/%s to %s [%d,%d)", fh.f.dir.Path, fh.f.Name, chunk.FileId, chunk.Offset, chunk.Offset+int64(chunk.Size))
+ fh.f.addChunks(chunks)
+
+ if len(chunks) > 0 {
fh.dirtyMetadata = true
}
@@ -190,10 +189,8 @@ func (fh *FileHandle) Flush(ctx context.Context, req *fuse.FlushRequest) error {
glog.Errorf("flush %s/%s: %v", fh.f.dir.Path, fh.f.Name, err)
return fmt.Errorf("flush %s/%s: %v", fh.f.dir.Path, fh.f.Name, err)
}
- if chunk != nil {
- fh.f.entry.Chunks = append(fh.f.entry.Chunks, chunk)
- fh.f.entryViewCache = nil
- }
+
+ fh.f.addChunk(chunk)
if !fh.dirtyMetadata {
return nil
@@ -222,7 +219,7 @@ func (fh *FileHandle) Flush(ctx context.Context, req *fuse.FlushRequest) error {
chunks, garbages := filer2.CompactFileChunks(fh.f.entry.Chunks)
fh.f.entry.Chunks = chunks
- fh.f.entryViewCache = nil
+ // fh.f.entryViewCache = nil
fh.f.wfs.asyncDeleteFileChunks(garbages)
if _, err := client.CreateEntry(ctx, request); err != nil {