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
@@ -27,9 +27,11 @@ type FilerSource struct {
|
||||
Dir string
|
||||
address string
|
||||
proxyByFiler bool
|
||||
dataCenter string
|
||||
}
|
||||
|
||||
func (fs *FilerSource) Initialize(configuration util.Configuration, prefix string) error {
|
||||
fs.dataCenter = configuration.GetString(prefix + "dataCenter")
|
||||
return fs.DoInitialize(
|
||||
"",
|
||||
configuration.GetString(prefix+"grpcAddress"),
|
||||
@@ -84,7 +86,13 @@ func (fs *FilerSource) LookupFileId(part string) (fileUrls []string, err error)
|
||||
|
||||
if !fs.proxyByFiler {
|
||||
for _, loc := range locations.Locations {
|
||||
fileUrls = append(fileUrls, fmt.Sprintf("http://%s/%s?readDeleted=true", loc.Url, part))
|
||||
fileUrl := fmt.Sprintf("http://%s/%s?readDeleted=true", loc.Url, part)
|
||||
// Prefer same data center
|
||||
if fs.dataCenter != "" && fs.dataCenter == loc.DataCenter {
|
||||
fileUrls = append([]string{fileUrl}, fileUrls...)
|
||||
} else {
|
||||
fileUrls = append(fileUrls, fileUrl)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
fileUrls = append(fileUrls, fmt.Sprintf("http://%s/?proxyChunkId=%s", fs.address, part))
|
||||
@@ -131,6 +139,10 @@ func (fs *FilerSource) AdjustedUrl(location *filer_pb.Location) string {
|
||||
return location.Url
|
||||
}
|
||||
|
||||
func (fs *FilerSource) GetDataCenter() string {
|
||||
return fs.dataCenter
|
||||
}
|
||||
|
||||
func volumeId(fileId string) string {
|
||||
lastCommaIndex := strings.LastIndex(fileId, ",")
|
||||
if lastCommaIndex > 0 {
|
||||
|
||||
Reference in New Issue
Block a user