diff options
| author | chrislu <chris.lu@gmail.com> | 2025-10-30 20:17:15 -0700 |
|---|---|---|
| committer | chrislu <chris.lu@gmail.com> | 2025-10-30 20:17:15 -0700 |
| commit | 7275613cc38a53b09c5357f94ba5d14a2febfe7b (patch) | |
| tree | 67ee83f93dcdd9b54ca1d37ecbbe317a920b9ef5 | |
| parent | 3b1755a1ee8594a41f4aa94f9cf84bd1407d30b7 (diff) | |
| download | seaweedfs-7275613cc38a53b09c5357f94ba5d14a2febfe7b.tar.xz seaweedfs-7275613cc38a53b09c5357f94ba5d14a2febfe7b.zip | |
fix more concurrent access
| -rw-r--r-- | weed/wdclient/masterclient.go | 12 |
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 |
