diff options
| author | hilimd <68371223+hilimd@users.noreply.github.com> | 2020-10-22 15:50:49 +0800 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2020-10-22 15:50:49 +0800 |
| commit | cf7a1c722fa82fa78c546f68e4814fff7dc6d1e2 (patch) | |
| tree | 1470a0d158a31b516e02202c004dfb413a29e186 /weed/filer/reader_at.go | |
| parent | ab1105c52472946efab9713bf15df45e14ff4514 (diff) | |
| parent | 5179e559f74cf7aed562f785e40bef46da3191bf (diff) | |
| download | seaweedfs-cf7a1c722fa82fa78c546f68e4814fff7dc6d1e2.tar.xz seaweedfs-cf7a1c722fa82fa78c546f68e4814fff7dc6d1e2.zip | |
Merge pull request #32 from chrislusf/master
sync
Diffstat (limited to 'weed/filer/reader_at.go')
| -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 }) |
