aboutsummaryrefslogtreecommitdiff
path: root/weed/wdclient/vid_map.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/wdclient/vid_map.go')
-rw-r--r--weed/wdclient/vid_map.go14
1 files changed, 11 insertions, 3 deletions
diff --git a/weed/wdclient/vid_map.go b/weed/wdclient/vid_map.go
index 691b27c6d..255bac279 100644
--- a/weed/wdclient/vid_map.go
+++ b/weed/wdclient/vid_map.go
@@ -62,6 +62,13 @@ func (vc *vidMap) getLocationIndex(length int) (int, error) {
return int(atomic.AddInt32(&vc.cursor, 1)) % length, nil
}
+func (vc *vidMap) isSameDataCenter(loc *Location) bool {
+ if vc.DataCenter == "" || loc.DataCenter == "" || vc.DataCenter != loc.DataCenter {
+ return false
+ }
+ return true
+}
+
func (vc *vidMap) LookupVolumeServerUrl(vid string) (serverUrls []string, err error) {
id, err := strconv.Atoi(vid)
if err != nil {
@@ -75,10 +82,10 @@ func (vc *vidMap) LookupVolumeServerUrl(vid string) (serverUrls []string, err er
}
var sameDcServers, otherDcServers []string
for _, loc := range locations {
- if vc.DataCenter == "" || loc.DataCenter == "" || vc.DataCenter != loc.DataCenter {
- otherDcServers = append(otherDcServers, loc.Url)
- } else {
+ if vc.isSameDataCenter(&loc) {
sameDcServers = append(sameDcServers, loc.Url)
+ } else {
+ otherDcServers = append(otherDcServers, loc.Url)
}
}
rand.Shuffle(len(sameDcServers), func(i, j int) {
@@ -87,6 +94,7 @@ func (vc *vidMap) LookupVolumeServerUrl(vid string) (serverUrls []string, err er
rand.Shuffle(len(otherDcServers), func(i, j int) {
otherDcServers[i], otherDcServers[j] = otherDcServers[j], otherDcServers[i]
})
+ // Prefer same data center
serverUrls = append(sameDcServers, otherDcServers...)
return
}