aboutsummaryrefslogtreecommitdiff
path: root/weed/wdclient/vid_map.go
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2021-11-12 11:30:11 -0800
committerChris Lu <chris.lu@gmail.com>2021-11-12 11:30:11 -0800
commit7bf891c00a8258ee40db46d302b0be1cc5a1d7d4 (patch)
tree10b47f9d67c78c70f4849749e4624f6029f78bee /weed/wdclient/vid_map.go
parent1f75f1f9dc19f74a76028420a724a4ab984c4b3d (diff)
downloadseaweedfs-7bf891c00a8258ee40db46d302b0be1cc5a1d7d4.tar.xz
seaweedfs-7bf891c00a8258ee40db46d302b0be1cc5a1d7d4.zip
randomize same-dc servers and other-dc servers
Diffstat (limited to 'weed/wdclient/vid_map.go')
-rw-r--r--weed/wdclient/vid_map.go13
1 files changed, 11 insertions, 2 deletions
diff --git a/weed/wdclient/vid_map.go b/weed/wdclient/vid_map.go
index 670d1ad77..e0bea2a01 100644
--- a/weed/wdclient/vid_map.go
+++ b/weed/wdclient/vid_map.go
@@ -4,6 +4,7 @@ import (
"errors"
"fmt"
"github.com/chrislusf/seaweedfs/weed/pb"
+ "math/rand"
"strconv"
"strings"
"sync"
@@ -69,13 +70,21 @@ func (vc *vidMap) LookupVolumeServerUrl(vid string) (serverUrls []string, err er
if !found {
return nil, fmt.Errorf("volume %d not found", id)
}
+ var sameDcServers, otherDcServers []string
for _, loc := range locations {
if vc.DataCenter == "" || loc.DataCenter == "" || vc.DataCenter != loc.DataCenter {
- serverUrls = append(serverUrls, loc.Url)
+ sameDcServers = append(sameDcServers, loc.Url)
} else {
- serverUrls = append([]string{loc.Url}, serverUrls...)
+ otherDcServers = append(otherDcServers, loc.Url)
}
}
+ rand.Shuffle(len(sameDcServers), func(i, j int) {
+ sameDcServers[i], sameDcServers[j] = sameDcServers[j], sameDcServers[i]
+ })
+ rand.Shuffle(len(otherDcServers), func(i, j int) {
+ otherDcServers[i], otherDcServers[j] = otherDcServers[j], otherDcServers[i]
+ })
+ serverUrls = append(sameDcServers, otherDcServers...)
return
}