aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChris Lu <chris.lu@uber.com>2019-03-19 22:20:14 -0700
committerChris Lu <chris.lu@uber.com>2019-03-19 22:20:14 -0700
commit5ae4b963a47a98426392b5434a9c3e26ad550e27 (patch)
tree86b203267b384420f1af9b86449e296c2cc4773a
parentf3d316a846473fe8f33a90172291608d764a264d (diff)
downloadseaweedfs-5ae4b963a47a98426392b5434a9c3e26ad550e27.tar.xz
seaweedfs-5ae4b963a47a98426392b5434a9c3e26ad550e27.zip
avoid using global rand
-rw-r--r--weed/wdclient/vid_map.go5
1 files changed, 4 insertions, 1 deletions
diff --git a/weed/wdclient/vid_map.go b/weed/wdclient/vid_map.go
index aef29f56f..64c24a809 100644
--- a/weed/wdclient/vid_map.go
+++ b/weed/wdclient/vid_map.go
@@ -7,6 +7,7 @@ import (
"strconv"
"strings"
"sync"
+ "time"
"github.com/chrislusf/seaweedfs/weed/glog"
)
@@ -19,11 +20,13 @@ type Location struct {
type vidMap struct {
sync.RWMutex
vid2Locations map[uint32][]Location
+ r *rand.Rand
}
func newVidMap() vidMap {
return vidMap{
vid2Locations: make(map[uint32][]Location),
+ r: rand.New(rand.NewSource(time.Now().UnixNano())),
}
}
@@ -39,7 +42,7 @@ func (vc *vidMap) LookupVolumeServerUrl(vid string) (serverUrl string, err error
return "", fmt.Errorf("volume %d not found", id)
}
- return locations[rand.Intn(len(locations))].Url, nil
+ return locations[vc.r.Intn(len(locations))].Url, nil
}
func (vc *vidMap) LookupFileId(fileId string) (fullUrl string, err error) {