aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2019-06-28 09:47:29 -0700
committerChris Lu <chris.lu@gmail.com>2019-06-28 09:47:29 -0700
commit9f3f2f7c79d7c88e211566af99640bb3eb3186da (patch)
treebaaf4dab614038e56aed1dec0a73acc5ac06851b
parent327336ecf392c373838223b3bc74d500f2be4e3f (diff)
downloadseaweedfs-9f3f2f7c79d7c88e211566af99640bb3eb3186da.tar.xz
seaweedfs-9f3f2f7c79d7c88e211566af99640bb3eb3186da.zip
protect locations slice
fix https://github.com/chrislusf/seaweedfs/issues/995
-rw-r--r--weed/wdclient/vid_map.go19
1 files changed, 13 insertions, 6 deletions
diff --git a/weed/wdclient/vid_map.go b/weed/wdclient/vid_map.go
index 2556049c3..4c43a225a 100644
--- a/weed/wdclient/vid_map.go
+++ b/weed/wdclient/vid_map.go
@@ -37,12 +37,7 @@ func (vc *vidMap) LookupVolumeServerUrl(vid string) (serverUrl string, err error
return "", err
}
- locations := vc.GetLocations(uint32(id))
- if len(locations) == 0 {
- return "", fmt.Errorf("volume %d not found", id)
- }
-
- return locations[vc.r.Intn(len(locations))].Url, nil
+ return vc.GetRandomLocation(uint32(id))
}
func (vc *vidMap) LookupFileId(fileId string) (fullUrl string, err error) {
@@ -85,6 +80,18 @@ func (vc *vidMap) GetLocations(vid uint32) (locations []Location) {
return vc.vid2Locations[vid]
}
+func (vc *vidMap) GetRandomLocation(vid uint32) (serverUrl string, err error) {
+ vc.RLock()
+ defer vc.RUnlock()
+
+ locations := vc.vid2Locations[vid]
+ if len(locations) == 0 {
+ return "", fmt.Errorf("volume %d not found", id)
+ }
+
+ return locations[vc.r.Intn(len(locations))].Url, nil
+}
+
func (vc *vidMap) addLocation(vid uint32, location Location) {
vc.Lock()
defer vc.Unlock()