aboutsummaryrefslogtreecommitdiff
path: root/weed/replication
diff options
context:
space:
mode:
authorKonstantin Lebedev <9497591+kmlebedev@users.noreply.github.com>2022-08-05 05:35:00 +0500
committerGitHub <noreply@github.com>2022-08-04 17:35:00 -0700
commit4d08393b7ca8b1a34ed65532955de76cf8843ec2 (patch)
treeb764fe5f4b927d9b9cf1b83a2f19c87a91d81c8e /weed/replication
parent28a1f42962a3c22fa341d62e52ed014ae17c508f (diff)
downloadseaweedfs-4d08393b7ca8b1a34ed65532955de76cf8843ec2.tar.xz
seaweedfs-4d08393b7ca8b1a34ed65532955de76cf8843ec2.zip
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
Diffstat (limited to 'weed/replication')
-rw-r--r--weed/replication/sink/filersink/fetch_write.go5
-rw-r--r--weed/replication/sink/filersink/filer_sink.go1
-rw-r--r--weed/replication/source/filer_source.go14
3 files changed, 19 insertions, 1 deletions
diff --git a/weed/replication/sink/filersink/fetch_write.go b/weed/replication/sink/filersink/fetch_write.go
index 540e16da4..7b3e22b90 100644
--- a/weed/replication/sink/filersink/fetch_write.go
+++ b/weed/replication/sink/filersink/fetch_write.go
@@ -139,6 +139,11 @@ func (fs *FilerSink) WithFilerClient(streamingMode bool, fn func(filer_pb.Seawee
}, fs.grpcAddress, fs.grpcDialOption)
}
+
func (fs *FilerSink) AdjustedUrl(location *filer_pb.Location) string {
return location.Url
}
+
+func (fs *FilerSink) GetDataCenter() string {
+ return fs.dataCenter
+}
diff --git a/weed/replication/sink/filersink/filer_sink.go b/weed/replication/sink/filersink/filer_sink.go
index 4df69f3fc..9a795d4ec 100644
--- a/weed/replication/sink/filersink/filer_sink.go
+++ b/weed/replication/sink/filersink/filer_sink.go
@@ -52,6 +52,7 @@ func (fs *FilerSink) IsIncremental() bool {
func (fs *FilerSink) Initialize(configuration util.Configuration, prefix string) error {
fs.isIncremental = configuration.GetBool(prefix + "is_incremental")
+ fs.dataCenter = configuration.GetString(prefix + "dataCenter")
return fs.DoInitialize(
"",
configuration.GetString(prefix+"grpcAddress"),
diff --git a/weed/replication/source/filer_source.go b/weed/replication/source/filer_source.go
index f6b310355..6c69b735c 100644
--- a/weed/replication/source/filer_source.go
+++ b/weed/replication/source/filer_source.go
@@ -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 {