aboutsummaryrefslogtreecommitdiff
path: root/weed/wdclient/masterclient.go
diff options
context:
space:
mode:
Diffstat (limited to 'weed/wdclient/masterclient.go')
-rw-r--r--weed/wdclient/masterclient.go28
1 files changed, 19 insertions, 9 deletions
diff --git a/weed/wdclient/masterclient.go b/weed/wdclient/masterclient.go
index 3612d978c..8b361aa67 100644
--- a/weed/wdclient/masterclient.go
+++ b/weed/wdclient/masterclient.go
@@ -62,12 +62,19 @@ func (mc *MasterClient) LookupFileIdWithFallback(fileId string) (fullUrls []stri
for vid, vidLocation := range resp.VolumeIdLocations {
for _, vidLoc := range vidLocation.Locations {
loc := Location{
- Url: vidLoc.Url,
- PublicUrl: vidLoc.PublicUrl,
- GrpcPort: int(vidLoc.GrpcPort),
+ Url: vidLoc.Url,
+ PublicUrl: vidLoc.PublicUrl,
+ GrpcPort: int(vidLoc.GrpcPort),
+ DataCenter: vidLoc.DataCenter,
}
mc.vidMap.addLocation(uint32(vid), loc)
- fullUrls = append(fullUrls, "http://"+loc.Url+"/"+fileId)
+ httpUrl := "http://" + loc.Url + "/" + fileId
+ // Prefer same data center
+ if mc.DataCenter != "" && mc.DataCenter == loc.DataCenter {
+ fullUrls = append([]string{httpUrl}, fullUrls...)
+ } else {
+ fullUrls = append(fullUrls, httpUrl)
+ }
}
}
return nil
@@ -181,12 +188,10 @@ func (mc *MasterClient) tryConnectToMaster(master pb.ServerAddress) (nextHintedL
stats.MasterClientConnectCounter.WithLabelValues(stats.RedirectedToLeader).Inc()
return nil
}
- //mc.vidMap = newVidMap("")
mc.resetVidMap()
mc.updateVidMap(resp)
} else {
mc.resetVidMap()
- //mc.vidMap = newVidMap("")
}
mc.currentMaster = master
@@ -206,7 +211,6 @@ func (mc *MasterClient) tryConnectToMaster(master pb.ServerAddress) (nextHintedL
stats.MasterClientConnectCounter.WithLabelValues(stats.RedirectedToLeader).Inc()
return nil
}
-
mc.updateVidMap(resp)
}
@@ -237,6 +241,7 @@ func (mc *MasterClient) tryConnectToMaster(master pb.ServerAddress) (nextHintedL
func (mc *MasterClient) updateVidMap(resp *master_pb.KeepConnectedResponse) {
// process new volume location
+ glog.V(1).Infof("updateVidMap() resp.VolumeLocation.DataCenter %v", resp.VolumeLocation.DataCenter)
loc := Location{
Url: resp.VolumeLocation.Url,
PublicUrl: resp.VolumeLocation.PublicUrl,
@@ -273,8 +278,13 @@ func (mc *MasterClient) WithClient(streamingMode bool, fn func(client master_pb.
}
func (mc *MasterClient) resetVidMap() {
- tail := &vidMap{vid2Locations: mc.vid2Locations, ecVid2Locations: mc.ecVid2Locations, cache: mc.cache}
- mc.vidMap = newVidMap("")
+ tail := &vidMap{
+ vid2Locations: mc.vid2Locations,
+ ecVid2Locations: mc.ecVid2Locations,
+ DataCenter: mc.DataCenter,
+ cache: mc.cache,
+ }
+ mc.vidMap = newVidMap(mc.DataCenter)
mc.vidMap.cache = tail
for i := 0; i < mc.vidMapCacheSize && tail.cache != nil; i++ {