From db87abd49640059998f87335da6e82cb7f64ab8c Mon Sep 17 00:00:00 2001 From: chrislu Date: Thu, 20 Nov 2025 17:55:51 -0800 Subject: [PATCH] fix: rename vicCacheLock to vidCacheLock for consistency MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fixed typo in variable name for better code consistency and readability. Problem: vidCache := make(map[string]*filer_pb.Locations) var vicCacheLock sync.RWMutex // Typo: vic instead of vid vicCacheLock.RLock() locations, found := vidCache[vid] vicCacheLock.RUnlock() The variable name 'vicCacheLock' is inconsistent with 'vidCache'. Both should use 'vid' prefix (volume ID) not 'vic'. Fix: Renamed all 5 occurrences: - var vicCacheLock → var vidCacheLock (line 56) - vicCacheLock.RLock() → vidCacheLock.RLock() (line 62) - vicCacheLock.RUnlock() → vidCacheLock.RUnlock() (line 64) - vicCacheLock.Lock() → vidCacheLock.Lock() (line 81) - vicCacheLock.Unlock() → vidCacheLock.Unlock() (line 91) Benefits: ✓ Consistent variable naming convention ✓ Clearer intent (volume ID cache lock) ✓ Better code readability ✓ Easier code navigation --- weed/filer/reader_at.go | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/weed/filer/reader_at.go b/weed/filer/reader_at.go index 9027d3aa9..aeac9b34a 100644 --- a/weed/filer/reader_at.go +++ b/weed/filer/reader_at.go @@ -53,15 +53,15 @@ var _ = io.Closer(&ChunkReadAt{}) func LookupFn(filerClient filer_pb.FilerClient) wdclient.LookupFileIdFunctionType { vidCache := make(map[string]*filer_pb.Locations) - var vicCacheLock sync.RWMutex + var vidCacheLock sync.RWMutex cacheSize := 0 const maxCacheSize = 10000 // Simple bound to prevent unbounded growth return func(ctx context.Context, fileId string) (targetUrls []string, err error) { vid := VolumeId(fileId) - vicCacheLock.RLock() + vidCacheLock.RLock() locations, found := vidCache[vid] - vicCacheLock.RUnlock() + vidCacheLock.RUnlock() if !found { util.Retry("lookup volume "+vid, func() error { @@ -78,7 +78,7 @@ func LookupFn(filerClient filer_pb.FilerClient) wdclient.LookupFileIdFunctionTyp glog.V(0).InfofCtx(ctx, "failed to locate %s", fileId) return fmt.Errorf("failed to locate %s", fileId) } - vicCacheLock.Lock() + vidCacheLock.Lock() // Simple size limit to prevent unbounded growth // For proper cache management, use wdclient.FilerClient instead if cacheSize < maxCacheSize { @@ -88,7 +88,7 @@ func LookupFn(filerClient filer_pb.FilerClient) wdclient.LookupFileIdFunctionTyp glog.Warningf("filer.LookupFn cache reached limit of %d volumes, not caching new entries. Consider migrating to wdclient.FilerClient for bounded cache management.", maxCacheSize) cacheSize++ // Only log once } - vicCacheLock.Unlock() + vidCacheLock.Unlock() return nil })