diff options
| author | Chris Lu <chris.lu@gmail.com> | 2020-10-21 19:28:59 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2020-10-21 19:28:59 -0700 |
| commit | bd103c143a8db12687d2d60829aac6bb6d42d74c (patch) | |
| tree | 055bd351d7fa161643ac5787a614d421e771da26 | |
| parent | 81cf8d04dfcbb84093044de4f10a8a92d9c8bd1c (diff) | |
| download | seaweedfs-bd103c143a8db12687d2d60829aac6bb6d42d74c.tar.xz seaweedfs-bd103c143a8db12687d2d60829aac6bb6d42d74c.zip | |
add lock for vidCache
| -rw-r--r-- | weed/filer/reader_at.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/weed/filer/reader_at.go b/weed/filer/reader_at.go index f73f72429..04c64d449 100644 --- a/weed/filer/reader_at.go +++ b/weed/filer/reader_at.go @@ -38,9 +38,12 @@ type LookupFileIdFunctionType func(fileId string) (targetUrls []string, err erro func LookupFn(filerClient filer_pb.FilerClient) LookupFileIdFunctionType { vidCache := make(map[string]*filer_pb.Locations) + var vicCacheLock sync.RWMutex return func(fileId string) (targetUrls []string, err error) { vid := VolumeId(fileId) + vicCacheLock.RLock() locations, found := vidCache[vid] + vicCacheLock.RUnlock() waitTime := time.Second for !found && waitTime < ReadWaitTime { @@ -58,7 +61,9 @@ func LookupFn(filerClient filer_pb.FilerClient) LookupFileIdFunctionType { glog.V(0).Infof("failed to locate %s", fileId) return fmt.Errorf("failed to locate %s", fileId) } + vicCacheLock.Lock() vidCache[vid] = locations + vicCacheLock.Unlock() return nil }) |
