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.
Go blob-storagecloud-drivedistributed-file-systemdistributed-storageerasure-codingfusehadoop-hdfshdfskuberneteslancelancedbobject-storageposixs3s3-storageseaweedfstiered-file-systemvector-search
mount: file handle locks entry better
chrislud65bb2c6df1a
diff --git a/weed/mount/dirty_pages_chunked.go b/weed/mount/dirty_pages_chunked.goindex e0d7640707..52308e0e5c 100644--- a/weed/mount/dirty_pages_chunked.go+++ b/weed/mount/dirty_pages_chunked.go@@ -84,7 +84,7 @@ func (pages *ChunkedDirtyPages) saveChunkedFileIntevalToStorage(reader io.Reader}chunk.Mtime = mtimepages.collection, pages.replication = collection, replication- pages.fh.addChunks([]*filer_pb.FileChunk{chunk})+ pages.fh.AddChunks([]*filer_pb.FileChunk{chunk})pages.fh.entryViewCache = nilglog.V(3).Infof("%v saveToStorage %s [%d,%d)", fileFullPath, chunk.FileId, offset, offset+size)diff --git a/weed/mount/filehandle.go b/weed/mount/filehandle.goindex 8ce31a078b..49918c104f 100644--- a/weed/mount/filehandle.go+++ b/weed/mount/filehandle.go@@ -13,12 +13,12 @@ import (type FileHandleId uint64type FileHandle struct {- fh FileHandleId- counter int64- entry *filer_pb.Entry- chunkAddLock sync.Mutex- inode uint64- wfs *WFS+ fh FileHandleId+ counter int64+ entry *filer_pb.Entry+ entryLock sync.Mutex+ inode uint64+ wfs *WFS// cache file has been written todirtyMetadata bool@@ -53,7 +53,20 @@ func (fh *FileHandle) FullPath() util.FullPath {return fp}-func (fh *FileHandle) addChunks(chunks []*filer_pb.FileChunk) {+func (fh *FileHandle) GetEntry() *filer_pb.Entry {+ fh.entryLock.Lock()+ defer fh.entryLock.Unlock()+ return fh.entry+}+func (fh *FileHandle) SetEntry(entry *filer_pb.Entry) {+ fh.entryLock.Lock()+ defer fh.entryLock.Unlock()+ fh.entry = entry+}++func (fh *FileHandle) AddChunks(chunks []*filer_pb.FileChunk) {+ fh.entryLock.Lock()+ defer fh.entryLock.Unlock()// find the earliest incoming chunknewChunks := chunks@@ -82,10 +95,8 @@ func (fh *FileHandle) addChunks(chunks []*filer_pb.FileChunk) {glog.V(4).Infof("%s existing %d chunks adds %d more", fh.FullPath(), len(fh.entry.Chunks), len(chunks))- fh.chunkAddLock.Lock()fh.entry.Chunks = append(fh.entry.Chunks, newChunks...)fh.entryViewCache = nil- fh.chunkAddLock.Unlock()}func (fh *FileHandle) Release() {diff --git a/weed/mount/filehandle_read.go b/weed/mount/filehandle_read.goindex 5439b8bfd5..88ab8612c1 100644--- a/weed/mount/filehandle_read.go+++ b/weed/mount/filehandle_read.go@@ -25,6 +25,9 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, error) {fileFullPath := fh.FullPath()+ fh.entryLock.Lock()+ defer fh.entryLock.Unlock()+entry := fh.entryif entry == nil {return 0, io.EOFdiff --git a/weed/mount/weedfs.go b/weed/mount/weedfs.goindex 2ab82b3ed3..6437499bf9 100644--- a/weed/mount/weedfs.go+++ b/weed/mount/weedfs.go@@ -131,10 +131,11 @@ func (wfs *WFS) maybeReadEntry(inode uint64) (path util.FullPath, fh *FileHandle}var found boolif fh, found = wfs.fhmap.FindFileHandle(inode); found {- if fh.entry.Attributes == nil {- fh.entry.Attributes = &filer_pb.FuseAttributes{}+ entry = fh.GetEntry()+ if entry != nil && fh.entry.Attributes == nil {+ entry.Attributes = &filer_pb.FuseAttributes{}}- return path, fh, fh.entry, fuse.OK+ return path, fh, entry, fuse.OK}entry, status = wfs.maybeLoadEntry(path)returndiff --git a/weed/mount/weedfs_attr.go b/weed/mount/weedfs_attr.goindex cb935d0e45..be504f5e20 100644--- a/weed/mount/weedfs_attr.go+++ b/weed/mount/weedfs_attr.go@@ -43,6 +43,10 @@ func (wfs *WFS) SetAttr(cancel <-chan struct{}, input *fuse.SetAttrIn, out *fuseif status != fuse.OK {return status}+ if fh != nil {+ fh.entryLock.Lock()+ defer fh.entryLock.Unlock()+ }if size, ok := input.GetSize(); ok {glog.V(4).Infof("%v setattr set size=%v chunks=%d", path, size, len(entry.Chunks))diff --git a/weed/mount/weedfs_file_sync.go b/weed/mount/weedfs_file_sync.goindex 1c80329c21..f3536ddcee 100644--- a/weed/mount/weedfs_file_sync.go+++ b/weed/mount/weedfs_file_sync.go@@ -118,6 +118,9 @@ func (wfs *WFS) doFlush(fh *FileHandle, uid, gid uint32) fuse.Status {err := wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {+ fh.entryLock.Lock()+ defer fh.entryLock.Unlock()+entry := fh.entryif entry == nil {return nildiff --git a/weed/mount/weedfs_xattr.go b/weed/mount/weedfs_xattr.goindex c85a1b3a1e..2fb2b07418 100644--- a/weed/mount/weedfs_xattr.go+++ b/weed/mount/weedfs_xattr.go@@ -94,10 +94,15 @@ func (wfs *WFS) SetXAttr(cancel <-chan struct{}, input *fuse.SetXAttrIn, attr st}}- path, _, entry, status := wfs.maybeReadEntry(input.NodeId)+ path, fh, entry, status := wfs.maybeReadEntry(input.NodeId)if status != fuse.OK {return status}+ if fh != nil {+ fh.entryLock.Lock()+ defer fh.entryLock.Unlock()+ }+if entry.Extended == nil {entry.Extended = make(map[string][]byte)}@@ -154,10 +159,15 @@ func (wfs *WFS) RemoveXAttr(cancel <-chan struct{}, header *fuse.InHeader, attrif len(attr) == 0 {return fuse.EINVAL}- path, _, entry, status := wfs.maybeReadEntry(header.NodeId)+ path, fh, entry, status := wfs.maybeReadEntry(header.NodeId)if status != fuse.OK {return status}+ if fh != nil {+ fh.entryLock.Lock()+ defer fh.entryLock.Unlock()+ }+if entry.Extended == nil {return fuse.ENOATTR}