mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
add lock for vidCache
This commit is contained in:
parent
81cf8d04df
commit
bd103c143a
|
@ -38,9 +38,12 @@ type LookupFileIdFunctionType func(fileId string) (targetUrls []string, err erro
|
||||||
func LookupFn(filerClient filer_pb.FilerClient) LookupFileIdFunctionType {
|
func LookupFn(filerClient filer_pb.FilerClient) LookupFileIdFunctionType {
|
||||||
|
|
||||||
vidCache := make(map[string]*filer_pb.Locations)
|
vidCache := make(map[string]*filer_pb.Locations)
|
||||||
|
var vicCacheLock sync.RWMutex
|
||||||
return func(fileId string) (targetUrls []string, err error) {
|
return func(fileId string) (targetUrls []string, err error) {
|
||||||
vid := VolumeId(fileId)
|
vid := VolumeId(fileId)
|
||||||
|
vicCacheLock.RLock()
|
||||||
locations, found := vidCache[vid]
|
locations, found := vidCache[vid]
|
||||||
|
vicCacheLock.RUnlock()
|
||||||
|
|
||||||
waitTime := time.Second
|
waitTime := time.Second
|
||||||
for !found && waitTime < ReadWaitTime {
|
for !found && waitTime < ReadWaitTime {
|
||||||
|
@ -58,7 +61,9 @@ func LookupFn(filerClient filer_pb.FilerClient) LookupFileIdFunctionType {
|
||||||
glog.V(0).Infof("failed to locate %s", fileId)
|
glog.V(0).Infof("failed to locate %s", fileId)
|
||||||
return fmt.Errorf("failed to locate %s", fileId)
|
return fmt.Errorf("failed to locate %s", fileId)
|
||||||
}
|
}
|
||||||
|
vicCacheLock.Lock()
|
||||||
vidCache[vid] = locations
|
vidCache[vid] = locations
|
||||||
|
vicCacheLock.Unlock()
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue