mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-23 01:15:35 +08:00
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:

committed by
GitHub

parent
28a1f42962
commit
4d08393b7c
@@ -66,17 +66,25 @@ func LookupFn(filerClient filer_pb.FilerClient) wdclient.LookupFileIdFunctionTyp
|
||||
return nil, err
|
||||
}
|
||||
|
||||
fcDataCenter := filerClient.GetDataCenter()
|
||||
var sameDcTargetUrls, otherTargetUrls []string
|
||||
for _, loc := range locations.Locations {
|
||||
volumeServerAddress := filerClient.AdjustedUrl(loc)
|
||||
targetUrl := fmt.Sprintf("http://%s/%s", volumeServerAddress, fileId)
|
||||
targetUrls = append(targetUrls, targetUrl)
|
||||
if fcDataCenter == "" || fcDataCenter != loc.DataCenter {
|
||||
otherTargetUrls = append(otherTargetUrls, targetUrl)
|
||||
} else {
|
||||
sameDcTargetUrls = append(sameDcTargetUrls, targetUrl)
|
||||
}
|
||||
}
|
||||
|
||||
for i := len(targetUrls) - 1; i > 0; i-- {
|
||||
j := rand.Intn(i + 1)
|
||||
targetUrls[i], targetUrls[j] = targetUrls[j], targetUrls[i]
|
||||
}
|
||||
|
||||
rand.Shuffle(len(sameDcTargetUrls), func(i, j int) {
|
||||
sameDcTargetUrls[i], sameDcTargetUrls[j] = sameDcTargetUrls[j], sameDcTargetUrls[i]
|
||||
})
|
||||
rand.Shuffle(len(otherTargetUrls), func(i, j int) {
|
||||
otherTargetUrls[i], otherTargetUrls[j] = otherTargetUrls[j], otherTargetUrls[i]
|
||||
})
|
||||
// Prefer same data center
|
||||
targetUrls = append(sameDcTargetUrls, otherTargetUrls...)
|
||||
return
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user