aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--weed/wdclient/masterclient.go12
1 files changed, 7 insertions, 5 deletions
diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go
index 31d8066ba..25111e217 100644
--- a/weed/wdclient/masterclient.go
+++ b/weed/wdclient/masterclient.go
@@ -71,8 +71,12 @@ func (mc *MasterClient) GetLookupFileIdFunction() LookupFileIdFunctionType {
}
func (mc *MasterClient) LookupFileIdWithFallback(ctx context.Context, fileId string) (fullUrls []string, err error) {
- // Try cache first using the fast path
- fullUrls, err = mc.vidMap.LookupFileId(ctx, fileId)
+ // Try cache first using the fast path - need to protect vidMap pointer access
+ mc.vidMapLock.RLock()
+ vm := mc.vidMap
+ mc.vidMapLock.RUnlock()
+
+ fullUrls, err = vm.LookupFileId(ctx, fileId)
if err == nil && len(fullUrls) > 0 {
return
}
@@ -198,7 +202,6 @@ func (mc *MasterClient) LookupVolumeIdsWithFallback(ctx context.Context, volumeI
}
var locations []Location
- mc.vidMapLock.RLock()
for _, masterLoc := range vidLoc.Locations {
loc := Location{
Url: masterLoc.Url,
@@ -206,10 +209,9 @@ func (mc *MasterClient) LookupVolumeIdsWithFallback(ctx context.Context, volumeI
GrpcPort: int(masterLoc.GrpcPort),
DataCenter: masterLoc.DataCenter,
}
- mc.vidMap.addLocation(uint32(vid), loc)
+ mc.addLocation(uint32(vid), loc)
locations = append(locations, loc)
}
- mc.vidMapLock.RUnlock()
if len(locations) > 0 {
batchResult[vidOnly] = locations