From 04fff7b0023d424eb69d2ee057d425942ae3efcb Mon Sep 17 00:00:00 2001 From: Boofdev Date: Sun, 29 Mar 2026 17:37:34 +0200 Subject: [PATCH] address gemini code review's suggested changes --- weed/mount/meta_cache/meta_cache.go | 45 +++++++++---------- .../mount/meta_cache/meta_cache_apply_test.go | 1 + weed/mount/weedfs.go | 2 +- weed/mount/weedfs_file_copy_range_test.go | 1 + weed/mount/weedfs_file_mkrm_test.go | 1 + weed/mount/weedfs_rename_test.go | 1 + 6 files changed, 26 insertions(+), 25 deletions(-) diff --git a/weed/mount/meta_cache/meta_cache.go b/weed/mount/meta_cache/meta_cache.go index 0776984f7..d2004c079 100644 --- a/weed/mount/meta_cache/meta_cache.go +++ b/weed/mount/meta_cache/meta_cache.go @@ -27,18 +27,18 @@ type MetaCache struct { localStore filer.VirtualFilerStore leveldbStore *leveldb.LevelDBStore // direct reference for batch operations sync.RWMutex - uidGidMapper *UidGidMapper - markCachedFn func(fullpath util.FullPath) - isCachedFn func(fullpath util.FullPath) bool - invalidateFunc func(fullpath util.FullPath, entry *filer_pb.Entry) - onDirectoryUpdate func(dir util.FullPath) - visitGroup singleflight.Group // deduplicates concurrent EnsureVisited calls for the same path - applyCh chan metadataApplyRequest - applyDone chan struct{} - applyStateMu sync.Mutex - applyClosed bool - buildingDirs map[util.FullPath]*directoryBuildState - dedupRing dedupRingBuffer + uidGidMapper *UidGidMapper + markCachedFn func(fullpath util.FullPath) + isCachedFn func(fullpath util.FullPath) bool + invalidateFunc func(fullpath util.FullPath, entry *filer_pb.Entry) + onDirectoryUpdate func(dir util.FullPath) + visitGroup singleflight.Group // deduplicates concurrent EnsureVisited calls for the same path + applyCh chan metadataApplyRequest + applyDone chan struct{} + applyStateMu sync.Mutex + applyClosed bool + buildingDirs map[util.FullPath]*directoryBuildState + dedupRing dedupRingBuffer includeSystemEntries bool } @@ -85,17 +85,18 @@ type metadataApplyRequest struct { done chan error } -func NewMetaCache(dbFolder string, uidGidMapper *UidGidMapper, root util.FullPath, +func NewMetaCache(dbFolder string, uidGidMapper *UidGidMapper, root util.FullPath, includeSystemEntries bool, markCachedFn func(path util.FullPath), isCachedFn func(path util.FullPath) bool, invalidateFunc func(util.FullPath, *filer_pb.Entry), onDirectoryUpdate func(dir util.FullPath)) *MetaCache { leveldbStore, virtualStore := openMetaStore(dbFolder) mc := &MetaCache{ - root: root, - localStore: virtualStore, - leveldbStore: leveldbStore, - markCachedFn: markCachedFn, - isCachedFn: isCachedFn, - uidGidMapper: uidGidMapper, - onDirectoryUpdate: onDirectoryUpdate, + root: root, + localStore: virtualStore, + leveldbStore: leveldbStore, + markCachedFn: markCachedFn, + isCachedFn: isCachedFn, + uidGidMapper: uidGidMapper, + onDirectoryUpdate: onDirectoryUpdate, + includeSystemEntries: includeSystemEntries, invalidateFunc: func(fullpath util.FullPath, entry *filer_pb.Entry) { invalidateFunc(fullpath, entry) }, @@ -108,10 +109,6 @@ func NewMetaCache(dbFolder string, uidGidMapper *UidGidMapper, root util.FullPat return mc } -func (mc *MetaCache) SetIncludeSystemEntries(include bool) { - mc.includeSystemEntries = include -} - func openMetaStore(dbFolder string) (*leveldb.LevelDBStore, filer.VirtualFilerStore) { os.RemoveAll(dbFolder) diff --git a/weed/mount/meta_cache/meta_cache_apply_test.go b/weed/mount/meta_cache/meta_cache_apply_test.go index d30fab90d..9292a00c5 100644 --- a/weed/mount/meta_cache/meta_cache_apply_test.go +++ b/weed/mount/meta_cache/meta_cache_apply_test.go @@ -312,6 +312,7 @@ func newTestMetaCache(t *testing.T, cached map[util.FullPath]bool) (*MetaCache, filepath.Join(t.TempDir(), "meta"), mapper, util.FullPath("/"), + false, func(path util.FullPath) { cachedMu.Lock() defer cachedMu.Unlock() diff --git a/weed/mount/weedfs.go b/weed/mount/weedfs.go index cb12522ec..a1514d686 100644 --- a/weed/mount/weedfs.go +++ b/weed/mount/weedfs.go @@ -204,6 +204,7 @@ func NewSeaweedFileSystem(option *Option) *WFS { wfs.metaCache = meta_cache.NewMetaCache(path.Join(option.getUniqueCacheDirForRead(), "meta"), option.UidGidMapper, util.FullPath(option.FilerMountRootPath), + option.ShowSystemEntries, func(path util.FullPath) { wfs.inodeToPath.MarkChildrenCached(path) }, func(path util.FullPath) bool { @@ -234,7 +235,6 @@ func NewSeaweedFileSystem(option *Option) *WFS { wfs.markDirectoryReadThrough(dirPath) } }) - wfs.metaCache.SetIncludeSystemEntries(option.ShowSystemEntries) grace.OnInterrupt(func() { // grace calls os.Exit(0) after all hooks, so WaitForAsyncFlush // after server.Serve() would never execute. Drain here first. diff --git a/weed/mount/weedfs_file_copy_range_test.go b/weed/mount/weedfs_file_copy_range_test.go index a596eadf8..5142f3f50 100644 --- a/weed/mount/weedfs_file_copy_range_test.go +++ b/weed/mount/weedfs_file_copy_range_test.go @@ -338,6 +338,7 @@ func newCopyRangeTestWFSWithMetaCache(t *testing.T) *WFS { filepath.Join(t.TempDir(), "meta"), uidGidMapper, root, + false, func(path util.FullPath) { wfs.inodeToPath.MarkChildrenCached(path) }, diff --git a/weed/mount/weedfs_file_mkrm_test.go b/weed/mount/weedfs_file_mkrm_test.go index 03506b48f..abfb93d20 100644 --- a/weed/mount/weedfs_file_mkrm_test.go +++ b/weed/mount/weedfs_file_mkrm_test.go @@ -120,6 +120,7 @@ func newCreateTestWFS(t *testing.T) (*WFS, *createEntryTestServer) { filepath.Join(t.TempDir(), "meta"), uidGidMapper, root, + false, func(path util.FullPath) { wfs.inodeToPath.MarkChildrenCached(path) }, diff --git a/weed/mount/weedfs_rename_test.go b/weed/mount/weedfs_rename_test.go index 4b79cc709..75b1e19eb 100644 --- a/weed/mount/weedfs_rename_test.go +++ b/weed/mount/weedfs_rename_test.go @@ -23,6 +23,7 @@ func TestHandleRenameResponseLeavesUncachedTargetOutOfCache(t *testing.T) { filepath.Join(t.TempDir(), "meta"), uidGidMapper, root, + false, func(path util.FullPath) { inodeToPath.MarkChildrenCached(path) },