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
Fix dead lock (#5815)
Chris Lu952afd810c20
diff --git a/weed/mount/filehandle.go b/weed/mount/filehandle.goindex 2e08432c01..f47d4a877e 100644--- a/weed/mount/filehandle.go+++ b/weed/mount/filehandle.go@@ -66,8 +66,8 @@ func (fh *FileHandle) FullPath() util.FullPath {return fp}-func (fh *FileHandle) GetEntry() *filer_pb.Entry {- return fh.entry.GetEntry()+func (fh *FileHandle) GetEntry() *LockedEntry {+ return fh.entry}func (fh *FileHandle) SetEntry(entry *filer_pb.Entry) {@@ -90,13 +90,6 @@ func (fh *FileHandle) UpdateEntry(fn func(entry *filer_pb.Entry)) *filer_pb.Entr}func (fh *FileHandle) AddChunks(chunks []*filer_pb.FileChunk) {- fh.entryLock.Lock()- defer fh.entryLock.Unlock()-- if fh.entry == nil {- return- }-fh.entry.AppendChunks(chunks)}@@ -105,9 +98,6 @@ func (fh *FileHandle) ReleaseHandle() {fhActiveLock := fh.wfs.fhLockTable.AcquireLock("ReleaseHandle", fh.fh, util.ExclusiveLock)defer fh.wfs.fhLockTable.ReleaseLock(fh.fh, fhActiveLock)- fh.entryLock.Lock()- defer fh.entryLock.Unlock()-fh.dirtyPages.Destroy()if IsDebugFileReadWrite {fh.mirrorFile.Close()diff --git a/weed/mount/filehandle_map.go b/weed/mount/filehandle_map.goindex f0051f0614..bb78d0b144 100644--- a/weed/mount/filehandle_map.go+++ b/weed/mount/filehandle_map.go@@ -50,7 +50,7 @@ func (i *FileHandleToInode) AcquireFileHandle(wfs *WFS, inode uint64, entry *fil} else {fh.counter++}- if fh.GetEntry() != entry {+ if fh.GetEntry().GetEntry() != entry {fh.SetEntry(entry)}return fhdiff --git a/weed/mount/filehandle_read.go b/weed/mount/filehandle_read.goindex 7b2629c131..3c315b1c4b 100644--- a/weed/mount/filehandle_read.go+++ b/weed/mount/filehandle_read.go@@ -29,23 +29,19 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, int64, efileFullPath := fh.FullPath()entry := fh.GetEntry()- if entry == nil {- return 0, 0, io.EOF- }if entry.IsInRemoteOnly() {glog.V(4).Infof("download remote entry %s", fileFullPath)- newEntry, err := fh.downloadRemoteEntry(entry)+ err := fh.downloadRemoteEntry(entry)if err != nil {glog.V(1).Infof("download remote entry %s: %v", fileFullPath, err)return 0, 0, err}- entry = newEntry}fileSize := int64(entry.Attributes.FileSize)if fileSize == 0 {- fileSize = int64(filer.FileSize(entry))+ fileSize = int64(filer.FileSize(entry.GetEntry()))}if fileSize == 0 {@@ -70,7 +66,7 @@ func (fh *FileHandle) readFromChunks(buff []byte, offset int64) (int64, int64, ereturn int64(totalRead), ts, err}-func (fh *FileHandle) downloadRemoteEntry(entry *filer_pb.Entry) (*filer_pb.Entry, error) {+func (fh *FileHandle) downloadRemoteEntry(entry *LockedEntry) (error) {fileFullPath := fh.FullPath()dir, _ := fileFullPath.DirAndName()@@ -88,12 +84,12 @@ func (fh *FileHandle) downloadRemoteEntry(entry *filer_pb.Entry) (*filer_pb.Entrreturn fmt.Errorf("CacheRemoteObjectToLocalCluster file %s: %v", fileFullPath, err)}- entry = resp.Entry+ entry.SetEntry(resp.Entry)fh.wfs.metaCache.InsertEntry(context.Background(), filer.FromPbEntry(request.Directory, resp.Entry))return nil})- return entry, err+ return err}diff --git a/weed/mount/locked_entry.go b/weed/mount/locked_entry.goindex f3b4bf484f..c5fbaee91a 100644--- a/weed/mount/locked_entry.go+++ b/weed/mount/locked_entry.go@@ -16,6 +16,8 @@ func (le *LockedEntry) GetEntry() *filer_pb.Entry {return le.Entry}+// SetEntry sets the entry of the LockedEntry+// entry should never be nilfunc (le *LockedEntry) SetEntry(entry *filer_pb.Entry) {le.Lock()defer le.Unlock()diff --git a/weed/mount/weedfs.go b/weed/mount/weedfs.goindex c5a1d2755a..a9fbd93804 100644--- a/weed/mount/weedfs.go+++ b/weed/mount/weedfs.go@@ -112,9 +112,6 @@ func NewSeaweedFileSystem(option *Option) *WFS {fhActiveLock := fh.wfs.fhLockTable.AcquireLock("invalidateFunc", fh.fh, util.ExclusiveLock)defer fh.wfs.fhLockTable.ReleaseLock(fh.fh, fhActiveLock)- fh.entryLock.Lock()- defer fh.entryLock.Unlock()-// Recreate dirty pagesfh.dirtyPages.Destroy()fh.dirtyPages = newPageWriter(fh, wfs.option.ChunkSizeLimit)@@ -122,7 +119,7 @@ func NewSeaweedFileSystem(option *Option) *WFS {// Update handle entrynewentry, status := wfs.maybeLoadEntry(filePath)if status == fuse.OK {- if fh.GetEntry() != newentry {+ if fh.GetEntry().GetEntry() != newentry {fh.SetEntry(newentry)}}diff --git a/weed/mount/weedfs_dir_lookup.go b/weed/mount/weedfs_dir_lookup.goindex e646b06a96..f3ba0cc856 100644--- a/weed/mount/weedfs_dir_lookup.go+++ b/weed/mount/weedfs_dir_lookup.go@@ -59,7 +59,7 @@ func (wfs *WFS) Lookup(cancel <-chan struct{}, header *fuse.InHeader, name strinif fh, found := wfs.fhmap.FindFileHandle(inode); found {fh.entryLock.RLock()- if entry := fh.GetEntry(); entry != nil {+ if entry := fh.GetEntry().GetEntry(); entry != nil {glog.V(4).Infof("lookup opened file %s size %d", dirPath.Child(localEntry.Name()), filer.FileSize(entry))localEntry = filer.FromPbEntry(string(dirPath), entry)}diff --git a/weed/mount/weedfs_dir_read.go b/weed/mount/weedfs_dir_read.goindex f140fd86f8..02ed72431b 100644--- a/weed/mount/weedfs_dir_read.go+++ b/weed/mount/weedfs_dir_read.go@@ -173,7 +173,7 @@ func (wfs *WFS) doReadDirectory(input *fuse.ReadIn, out *fuse.DirEntryList, isPl}if fh, found := wfs.fhmap.FindFileHandle(inode); found {glog.V(4).Infof("readdir opened file %s", dirPath.Child(dirEntry.Name))- entry = filer.FromPbEntry(string(dirPath), fh.GetEntry())+ entry = filer.FromPbEntry(string(dirPath), fh.GetEntry().GetEntry())}wfs.outputFilerEntry(entryOut, inode, entry)}diff --git a/weed/mount/weedfs_file_lseek.go b/weed/mount/weedfs_file_lseek.goindex 35157d9937..0cf7ef43b1 100644--- a/weed/mount/weedfs_file_lseek.go+++ b/weed/mount/weedfs_file_lseek.go@@ -38,10 +38,8 @@ func (wfs *WFS) Lseek(cancel <-chan struct{}, in *fuse.LseekIn, out *fuse.LseekO// lock the file until the proper offset was calculatedfhActiveLock := fh.wfs.fhLockTable.AcquireLock("Lseek", fh.fh, util.SharedLock)defer fh.wfs.fhLockTable.ReleaseLock(fh.fh, fhActiveLock)- fh.entryLock.RLock()- defer fh.entryLock.RUnlock()- fileSize := int64(filer.FileSize(fh.GetEntry()))+ fileSize := int64(filer.FileSize(fh.GetEntry().GetEntry()))offset := max(int64(in.Offset), 0)glog.V(4).Infof(diff --git a/weed/mount/weedfs_file_sync.go b/weed/mount/weedfs_file_sync.goindex 762a9b8deb..d857606bdd 100644--- a/weed/mount/weedfs_file_sync.go+++ b/weed/mount/weedfs_file_sync.go@@ -116,13 +116,8 @@ func (wfs *WFS) doFlush(fh *FileHandle, uid, gid uint32) fuse.Status {defer fh.wfs.fhLockTable.ReleaseLock(fh.fh, fhActiveLock)err := wfs.WithFilerClient(false, func(client filer_pb.SeaweedFilerClient) error {- fh.entryLock.Lock()- defer fh.entryLock.Unlock()entry := fh.GetEntry()- if entry == nil {- return nil- }entry.Name = name // this flush may be just after a rename operationif entry.Attributes != nil {@@ -141,7 +136,7 @@ func (wfs *WFS) doFlush(fh *FileHandle, uid, gid uint32) fuse.Status {request := &filer_pb.CreateEntryRequest{Directory: string(dir),- Entry: entry,+ Entry: entry.GetEntry(),Signatures: []int32{wfs.signature},SkipCheckParentDirectory: true,}