From 94bd8b39cf8bca8d2c1f2166c894006bcb270919 Mon Sep 17 00:00:00 2001 From: chrislu Date: Wed, 19 Mar 2025 21:01:47 -0700 Subject: [PATCH] refactor --- weed/mount/filehandle_map.go | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/weed/mount/filehandle_map.go b/weed/mount/filehandle_map.go index 852ef9e35..4441de0be 100644 --- a/weed/mount/filehandle_map.go +++ b/weed/mount/filehandle_map.go @@ -1,9 +1,10 @@ package mount import ( - "github.com/seaweedfs/seaweedfs/weed/util" "sync" + "github.com/seaweedfs/seaweedfs/weed/util" + "github.com/seaweedfs/seaweedfs/weed/pb/filer_pb" ) @@ -67,22 +68,26 @@ func (i *FileHandleToInode) ReleaseByInode(inode uint64) { } } } + func (i *FileHandleToInode) ReleaseByHandle(fh FileHandleId) { i.Lock() defer i.Unlock() - inode, found := i.fh2inode[fh] - if found { - fhHandle, fhFound := i.inode2fh[inode] - if !fhFound { - delete(i.fh2inode, fh) - } else { - fhHandle.counter-- - if fhHandle.counter <= 0 { - delete(i.inode2fh, inode) - delete(i.fh2inode, fhHandle.fh) - fhHandle.ReleaseHandle() - } - } + inode, found := i.fh2inode[fh] + if !found { + return // Handle already released or invalid + } + + fhHandle, fhFound := i.inode2fh[inode] + if !fhFound { + delete(i.fh2inode, fh) + return + } + + fhHandle.counter-- + if fhHandle.counter <= 0 { + delete(i.inode2fh, inode) + delete(i.fh2inode, fhHandle.fh) + fhHandle.ReleaseHandle() } }