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.

refactor

chrislua9c9e1bcb338
diff --git a/weed/mount/weedfs.go b/weed/mount/weedfs.go
index 3ad938699b..6a1081113f 100644
--- a/weed/mount/weedfs.go
+++ b/weed/mount/weedfs.go
@@ -2,6 +2,7 @@ package mount
import (
"context"
+ "errors"
"math/rand"
"os"
"path"
@@ -76,8 +77,8 @@ type WFS struct {
signature int32
concurrentWriters *util.LimitedConcurrentExecutor
inodeToPath *InodeToPath
- fhmap *FileHandleToInode
- dhmap *DirectoryHandleToInode
+ fhMap *FileHandleToInode
+ dhMap *DirectoryHandleToInode
fuseServer *fuse.Server
IsOverQuota bool
fhLockTable *util.LockTable[FileHandleId]
@@ -89,8 +90,8 @@ func NewSeaweedFileSystem(option *Option) *WFS {
option: option,
signature: util.RandomInt32(),
inodeToPath: NewInodeToPath(util.FullPath(option.FilerMountRootPath)),
- fhmap: NewFileHandleToInode(),
- dhmap: NewDirectoryHandleToInode(),
+ fhMap: NewFileHandleToInode(),
+ dhMap: NewDirectoryHandleToInode(),
fhLockTable: util.NewLockTable[FileHandleId](),
}
@@ -108,9 +109,9 @@ func NewSeaweedFileSystem(option *Option) *WFS {
return wfs.inodeToPath.IsChildrenCached(path)
}, func(filePath util.FullPath, entry *filer_pb.Entry) {
// Find inode if it is not a deleted path
- if inode, inode_found := wfs.inodeToPath.GetInode(filePath); inode_found {
+ if inode, inodeFound := wfs.inodeToPath.GetInode(filePath); inodeFound {
// Find open file handle
- if fh, fh_found := wfs.fhmap.FindFileHandle(inode); fh_found {
+ if fh, fhFound := wfs.fhMap.FindFileHandle(inode); fhFound {
fhActiveLock := fh.wfs.fhLockTable.AcquireLock("invalidateFunc", fh.fh, util.ExclusiveLock)
defer fh.wfs.fhLockTable.ReleaseLock(fh.fh, fhActiveLock)
@@ -119,10 +120,10 @@ func NewSeaweedFileSystem(option *Option) *WFS {
fh.dirtyPages = newPageWriter(fh, wfs.option.ChunkSizeLimit)
// Update handle entry
- newentry, status := wfs.maybeLoadEntry(filePath)
+ newEntry, status := wfs.maybeLoadEntry(filePath)
if status == fuse.OK {
- if fh.GetEntry().GetEntry() != newentry {
- fh.SetEntry(newentry)
+ if fh.GetEntry().GetEntry() != newEntry {
+ fh.SetEntry(newEntry)
}
}
}
@@ -160,7 +161,7 @@ func (wfs *WFS) maybeReadEntry(inode uint64) (path util.FullPath, fh *FileHandle
return
}
var found bool
- if fh, found = wfs.fhmap.FindFileHandle(inode); found {
+ if fh, found = wfs.fhMap.FindFileHandle(inode); found {
entry = fh.UpdateEntry(func(entry *filer_pb.Entry) {
if entry != nil && fh.entry.Attributes == nil {
entry.Attributes = &filer_pb.FuseAttributes{}
@@ -195,7 +196,7 @@ func (wfs *WFS) maybeLoadEntry(fullpath util.FullPath) (*filer_pb.Entry, fuse.St
// read from async meta cache
meta_cache.EnsureVisited(wfs.metaCache, wfs, util.FullPath(dir))
cachedEntry, cacheErr := wfs.metaCache.FindEntry(context.Background(), fullpath)
- if cacheErr == filer_pb.ErrNotFound {
+ if errors.Is(cacheErr, filer_pb.ErrNotFound) {
return nil, fuse.ENOENT
}
return cachedEntry.ToProtoEntry(), fuse.OK
diff --git a/weed/mount/weedfs_attr.go b/weed/mount/weedfs_attr.go
index c389e0627d..24da292d6d 100644
--- a/weed/mount/weedfs_attr.go
+++ b/weed/mount/weedfs_attr.go
@@ -23,7 +23,7 @@ func (wfs *WFS) GetAttr(cancel <-chan struct{}, input *fuse.GetAttrIn, out *fuse
wfs.setAttrByPbEntry(&out.Attr, inode, entry, true)
return status
} else {
- if fh, found := wfs.fhmap.FindFileHandle(inode); found {
+ if fh, found := wfs.fhMap.FindFileHandle(inode); found {
out.AttrValid = 1
wfs.setAttrByPbEntry(&out.Attr, inode, fh.entry.GetEntry(), true)
out.Nlink = 0
diff --git a/weed/mount/weedfs_dir_lookup.go b/weed/mount/weedfs_dir_lookup.go
index f3ba0cc856..7fc10ef28f 100644
--- a/weed/mount/weedfs_dir_lookup.go
+++ b/weed/mount/weedfs_dir_lookup.go
@@ -57,7 +57,7 @@ func (wfs *WFS) Lookup(cancel <-chan struct{}, header *fuse.InHeader, name strin
inode := wfs.inodeToPath.Lookup(fullFilePath, localEntry.Crtime.Unix(), localEntry.IsDirectory(), len(localEntry.HardLinkId) > 0, localEntry.Inode, true)
- if fh, found := wfs.fhmap.FindFileHandle(inode); found {
+ if fh, found := wfs.fhMap.FindFileHandle(inode); found {
fh.entryLock.RLock()
if entry := fh.GetEntry().GetEntry(); entry != nil {
glog.V(4).Infof("lookup opened file %s size %d", dirPath.Child(localEntry.Name()), filer.FileSize(entry))
diff --git a/weed/mount/weedfs_dir_read.go b/weed/mount/weedfs_dir_read.go
index c80ecce9e3..6e18b50e80 100644
--- a/weed/mount/weedfs_dir_read.go
+++ b/weed/mount/weedfs_dir_read.go
@@ -46,30 +46,30 @@ func NewDirectoryHandleToInode() *DirectoryHandleToInode {
func (wfs *WFS) AcquireDirectoryHandle() (DirectoryHandleId, *DirectoryHandle) {
fh := FileHandleId(util.RandomUint64())
- wfs.dhmap.Lock()
- defer wfs.dhmap.Unlock()
+ wfs.dhMap.Lock()
+ defer wfs.dhMap.Unlock()
dh := new(DirectoryHandle)
dh.reset()
- wfs.dhmap.dir2inode[DirectoryHandleId(fh)] = dh
+ wfs.dhMap.dir2inode[DirectoryHandleId(fh)] = dh
return DirectoryHandleId(fh), dh
}
func (wfs *WFS) GetDirectoryHandle(dhid DirectoryHandleId) *DirectoryHandle {
- wfs.dhmap.Lock()
- defer wfs.dhmap.Unlock()
- if dh, found := wfs.dhmap.dir2inode[dhid]; found {
+ wfs.dhMap.Lock()
+ defer wfs.dhMap.Unlock()
+ if dh, found := wfs.dhMap.dir2inode[dhid]; found {
return dh
}
dh := new(DirectoryHandle)
dh.reset()
- wfs.dhmap.dir2inode[dhid] = dh
+ wfs.dhMap.dir2inode[dhid] = dh
return dh
}
func (wfs *WFS) ReleaseDirectoryHandle(dhid DirectoryHandleId) {
- wfs.dhmap.Lock()
- defer wfs.dhmap.Unlock()
- delete(wfs.dhmap.dir2inode, dhid)
+ wfs.dhMap.Lock()
+ defer wfs.dhMap.Unlock()
+ delete(wfs.dhMap.dir2inode, dhid)
}
// Directory handling
@@ -169,7 +169,7 @@ func (wfs *WFS) doReadDirectory(input *fuse.ReadIn, out *fuse.DirEntryList, isPl
isEarlyTerminated = true
return false
}
- if fh, found := wfs.fhmap.FindFileHandle(inode); found {
+ 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().GetEntry())
}
diff --git a/weed/mount/weedfs_filehandle.go b/weed/mount/weedfs_filehandle.go
index 99b54850a0..e0149aee9a 100644
--- a/weed/mount/weedfs_filehandle.go
+++ b/weed/mount/weedfs_filehandle.go
@@ -18,15 +18,15 @@ func (wfs *WFS) AcquireHandle(inode uint64, flags, uid, gid uint32) (fileHandle
}
}
// need to AcquireFileHandle again to ensure correct handle counter
- fileHandle = wfs.fhmap.AcquireFileHandle(wfs, inode, entry)
+ fileHandle = wfs.fhMap.AcquireFileHandle(wfs, inode, entry)
}
return
}
func (wfs *WFS) ReleaseHandle(handleId FileHandleId) {
- wfs.fhmap.ReleaseByHandle(handleId)
+ wfs.fhMap.ReleaseByHandle(handleId)
}
func (wfs *WFS) GetHandle(handleId FileHandleId) *FileHandle {
- return wfs.fhmap.GetFileHandle(handleId)
+ return wfs.fhMap.GetFileHandle(handleId)
}
diff --git a/weed/mount/weedfs_forget.go b/weed/mount/weedfs_forget.go
index 2f9cff7e69..0a45aba6b7 100644
--- a/weed/mount/weedfs_forget.go
+++ b/weed/mount/weedfs_forget.go
@@ -65,5 +65,5 @@ func (wfs *WFS) Forget(nodeid, nlookup uint64) {
wfs.inodeToPath.Forget(nodeid, nlookup, func(dir util.FullPath) {
wfs.metaCache.DeleteFolderChildren(context.Background(), dir)
})
- wfs.fhmap.ReleaseByInode(nodeid)
+ wfs.fhMap.ReleaseByInode(nodeid)
}
diff --git a/weed/mount/weedfs_rename.go b/weed/mount/weedfs_rename.go
index 58c60aa289..f9fc85b3f1 100644
--- a/weed/mount/weedfs_rename.go
+++ b/weed/mount/weedfs_rename.go
@@ -235,7 +235,7 @@ func (wfs *WFS) handleRenameResponse(ctx context.Context, resp *filer_pb.StreamR
sourceInode, targetInode := wfs.inodeToPath.MovePath(oldPath, newPath)
if sourceInode != 0 {
- fh, foundFh := wfs.fhmap.FindFileHandle(sourceInode)
+ fh, foundFh := wfs.fhMap.FindFileHandle(sourceInode)
if foundFh {
if entry := fh.GetEntry(); entry != nil {
entry.Name = newName