From 23ef0a816a75a9045e96ff6d925611ae75f5de05 Mon Sep 17 00:00:00 2001 From: Chris Lu Date: Fri, 7 Aug 2026 14:14:58 -0700 Subject: [PATCH] mount: size the listing cache through NewMetaCache rather than a second constructor A NewXWithY alongside NewX is two names for one thing, and the one that takes the argument is the only one that ever needed to exist. Callers pass the default explicitly. --- weed/mount/filehandle_read_remote_test.go | 1 + weed/mount/meta_cache/listing_cache_test.go | 2 +- weed/mount/meta_cache/meta_cache.go | 7 +------ weed/mount/meta_cache/meta_cache_apply_test.go | 1 + weed/mount/meta_cache/meta_cache_deadlock_test.go | 1 + weed/mount/weedfs.go | 2 +- weed/mount/weedfs_dir_read_bench_test.go | 1 + weed/mount/weedfs_dir_read_pagination_test.go | 1 + weed/mount/weedfs_file_copy_range_test.go | 1 + weed/mount/weedfs_file_mkrm_test.go | 1 + weed/mount/weedfs_invalidate_open_handle_test.go | 1 + weed/mount/weedfs_rename_test.go | 1 + 12 files changed, 12 insertions(+), 8 deletions(-) diff --git a/weed/mount/filehandle_read_remote_test.go b/weed/mount/filehandle_read_remote_test.go index 70d353b2e..3afa908e9 100644 --- a/weed/mount/filehandle_read_remote_test.go +++ b/weed/mount/filehandle_read_remote_test.go @@ -111,6 +111,7 @@ func TestReadUncachedRemoteEntryDoesNotDeadlock(t *testing.T) { wfs.fhLockTable.ReleaseLock(fh.fh, lock) }, nil, + meta_cache.DefaultListingCacheEntries, ) wfs.inodeToPath.MarkChildrenCached(root) wfs.inodeToPath.Lookup(util.FullPath("/dir"), time.Now().Unix(), true, false, 0, false) diff --git a/weed/mount/meta_cache/listing_cache_test.go b/weed/mount/meta_cache/listing_cache_test.go index 1582aa6c8..3ad537592 100644 --- a/weed/mount/meta_cache/listing_cache_test.go +++ b/weed/mount/meta_cache/listing_cache_test.go @@ -19,7 +19,7 @@ func newListingTestCache(t *testing.T, maxEntries int) *MetaCache { t.Fatalf("uid/gid mapper: %v", err) } cached := map[util.FullPath]bool{} - mc := NewMetaCacheWithListingCache(t.TempDir(), uidGidMapper, util.FullPath("/"), false, + mc := NewMetaCache(t.TempDir(), uidGidMapper, util.FullPath("/"), false, func(p util.FullPath) { cached[p] = true }, func(p util.FullPath) bool { return cached[p] }, func(EntryInvalidation) {}, nil, maxEntries) diff --git a/weed/mount/meta_cache/meta_cache.go b/weed/mount/meta_cache/meta_cache.go index 9bd04e7b0..aae066ce9 100644 --- a/weed/mount/meta_cache/meta_cache.go +++ b/weed/mount/meta_cache/meta_cache.go @@ -107,13 +107,8 @@ type metadataApplyRequest struct { done chan error } +// listingCacheEntries sizes the directory listing cache; zero disables it. func NewMetaCache(dbFolder string, uidGidMapper *UidGidMapper, root util.FullPath, includeSystemEntries bool, - markCachedFn func(path util.FullPath), isCachedFn func(path util.FullPath) bool, invalidateFunc func(EntryInvalidation), onDirectoryUpdate func(dir util.FullPath)) *MetaCache { - return NewMetaCacheWithListingCache(dbFolder, uidGidMapper, root, includeSystemEntries, markCachedFn, isCachedFn, invalidateFunc, onDirectoryUpdate, DefaultListingCacheEntries) -} - -// NewMetaCacheWithListingCache sizes the directory listing cache; zero disables it. -func NewMetaCacheWithListingCache(dbFolder string, uidGidMapper *UidGidMapper, root util.FullPath, includeSystemEntries bool, markCachedFn func(path util.FullPath), isCachedFn func(path util.FullPath) bool, invalidateFunc func(EntryInvalidation), onDirectoryUpdate func(dir util.FullPath), listingCacheEntries int) *MetaCache { leveldbStore, virtualStore := openMetaStore(dbFolder) diff --git a/weed/mount/meta_cache/meta_cache_apply_test.go b/weed/mount/meta_cache/meta_cache_apply_test.go index 9d830d881..20677000d 100644 --- a/weed/mount/meta_cache/meta_cache_apply_test.go +++ b/weed/mount/meta_cache/meta_cache_apply_test.go @@ -506,6 +506,7 @@ func newTestMetaCache(t *testing.T, cached map[util.FullPath]bool) (*MetaCache, func(dir util.FullPath) { notifications.record(dir) }, + DefaultListingCacheEntries, ) return mc, cached, notifications, invalidations diff --git a/weed/mount/meta_cache/meta_cache_deadlock_test.go b/weed/mount/meta_cache/meta_cache_deadlock_test.go index 8f688e970..5dbe0750f 100644 --- a/weed/mount/meta_cache/meta_cache_deadlock_test.go +++ b/weed/mount/meta_cache/meta_cache_deadlock_test.go @@ -66,6 +66,7 @@ func TestApplyLoopInvalidateDoesNotDeadlockWithLockHoldingEnqueuer(t *testing.T) fhLockTable.ReleaseLock(fhKey, lock) }, func(dir util.FullPath) {}, + DefaultListingCacheEntries, ) defer func() { // Only safe to shut down once the apply loop is unwedged. diff --git a/weed/mount/weedfs.go b/weed/mount/weedfs.go index 16141620a..1e77f3776 100644 --- a/weed/mount/weedfs.go +++ b/weed/mount/weedfs.go @@ -304,7 +304,7 @@ func NewSeaweedFileSystem(option *Option) *WFS { wfs.writeBufferAccountant.SetEvictor(wfs.evictOneWritableChunk) } - wfs.metaCache = meta_cache.NewMetaCacheWithListingCache(path.Join(option.getUniqueCacheDirForRead(), "meta"), option.UidGidMapper, + wfs.metaCache = meta_cache.NewMetaCache(path.Join(option.getUniqueCacheDirForRead(), "meta"), option.UidGidMapper, util.FullPath(option.FilerMountRootPath), option.IncludeSystemEntries, func(path util.FullPath) { diff --git a/weed/mount/weedfs_dir_read_bench_test.go b/weed/mount/weedfs_dir_read_bench_test.go index a78da820d..d09753781 100644 --- a/weed/mount/weedfs_dir_read_bench_test.go +++ b/weed/mount/weedfs_dir_read_bench_test.go @@ -110,6 +110,7 @@ func newBenchWFS(tb testing.TB, dir util.FullPath, n int) *WFS { func(path util.FullPath) bool { return wfs.inodeToPath.IsChildrenCached(path) }, func(meta_cache.EntryInvalidation) {}, nil, + meta_cache.DefaultListingCacheEntries, ) tb.Cleanup(wfs.metaCache.Shutdown) diff --git a/weed/mount/weedfs_dir_read_pagination_test.go b/weed/mount/weedfs_dir_read_pagination_test.go index 00e07d7e1..7869b229c 100644 --- a/weed/mount/weedfs_dir_read_pagination_test.go +++ b/weed/mount/weedfs_dir_read_pagination_test.go @@ -63,6 +63,7 @@ func newPagingWFS(tb testing.TB, dir util.FullPath, names []string, ttlSec int32 func(p util.FullPath) { wfs.inodeToPath.MarkChildrenCached(p) }, func(p util.FullPath) bool { return wfs.inodeToPath.IsChildrenCached(p) }, func(meta_cache.EntryInvalidation) {}, nil, + meta_cache.DefaultListingCacheEntries, ) tb.Cleanup(wfs.metaCache.Shutdown) diff --git a/weed/mount/weedfs_file_copy_range_test.go b/weed/mount/weedfs_file_copy_range_test.go index 4bca12e94..7238fe55d 100644 --- a/weed/mount/weedfs_file_copy_range_test.go +++ b/weed/mount/weedfs_file_copy_range_test.go @@ -348,6 +348,7 @@ func newCopyRangeTestWFSWithMetaCache(t *testing.T) *WFS { }, func(meta_cache.EntryInvalidation) {}, nil, + meta_cache.DefaultListingCacheEntries, ) t.Cleanup(func() { wfs.metaCache.Shutdown() diff --git a/weed/mount/weedfs_file_mkrm_test.go b/weed/mount/weedfs_file_mkrm_test.go index 6a8b34312..581e12a74 100644 --- a/weed/mount/weedfs_file_mkrm_test.go +++ b/weed/mount/weedfs_file_mkrm_test.go @@ -130,6 +130,7 @@ func newCreateTestWFS(t *testing.T) (*WFS, *createEntryTestServer) { }, func(meta_cache.EntryInvalidation) {}, nil, + meta_cache.DefaultListingCacheEntries, ) wfs.inodeToPath.MarkChildrenCached(root) t.Cleanup(func() { diff --git a/weed/mount/weedfs_invalidate_open_handle_test.go b/weed/mount/weedfs_invalidate_open_handle_test.go index af991e10c..377a075a7 100644 --- a/weed/mount/weedfs_invalidate_open_handle_test.go +++ b/weed/mount/weedfs_invalidate_open_handle_test.go @@ -62,6 +62,7 @@ func newInvalidateTestWFS(t *testing.T) *WFS { func(path util.FullPath) bool { return wfs.inodeToPath.IsChildrenCached(path) }, wfs.invalidateOpenFileHandle, nil, + meta_cache.DefaultListingCacheEntries, ) t.Cleanup(wfs.metaCache.Shutdown) diff --git a/weed/mount/weedfs_rename_test.go b/weed/mount/weedfs_rename_test.go index 406a093c3..1cb74558e 100644 --- a/weed/mount/weedfs_rename_test.go +++ b/weed/mount/weedfs_rename_test.go @@ -32,6 +32,7 @@ func TestHandleRenameResponseLeavesUncachedTargetOutOfCache(t *testing.T) { }, func(meta_cache.EntryInvalidation) {}, nil, + meta_cache.DefaultListingCacheEntries, ) defer mc.Shutdown()