mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2025-09-19 14:17:57 +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
@@ -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++ {
|
||||
|
Reference in New Issue
Block a user