filer prefer volume server in same data center (#3405)

* initial prefer same data center
https://github.com/seaweedfs/seaweedfs/issues/3404

* GetDataCenter

* prefer same data center for ReplicationSource

* GetDataCenterId

* remove glog
This commit is contained in:
Konstantin Lebedev
2022-08-05 05:35:00 +05:00
committed by GitHub
parent 28a1f42962
commit 4d08393b7c
36 changed files with 925 additions and 795 deletions

View File

@@ -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
}