aboutsummaryrefslogtreecommitdiff
path: root/weed/filer/reader_at.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/filer/reader_at.go')
-rw-r--r--weed/filer/reader_at.go22
1 files changed, 15 insertions, 7 deletions
diff --git a/weed/filer/reader_at.go b/weed/filer/reader_at.go
index 70228705b..2b3e77d1b 100644
--- a/weed/filer/reader_at.go
+++ b/weed/filer/reader_at.go
@@ -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)
- }
-
- for i := len(targetUrls) - 1; i > 0; i-- {
- j := rand.Intn(i + 1)
- targetUrls[i], targetUrls[j] = targetUrls[j], targetUrls[i]
+ if fcDataCenter == "" || fcDataCenter != loc.DataCenter {
+ otherTargetUrls = append(otherTargetUrls, targetUrl)
+ } else {
+ sameDcTargetUrls = append(sameDcTargetUrls, targetUrl)
+ }
}
-
+ 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
}
}