From ab2232ab2b6188da337c8df215f4372aef8e1b04 Mon Sep 17 00:00:00 2001 From: Allen Zhong Date: Wed, 23 Sep 2020 16:35:37 +0800 Subject: [PATCH] cluster: fix custom port handling for drainer on importing (#806) --- pkg/cluster/ansible/inventory.go | 4 ++++ pkg/cluster/ansible/{dirs.go => service.go} | 6 ++++++ .../ansible/{dirs_test.go => service_test.go} | 0 pkg/cluster/ansible/test-data/inventory.ini | 3 ++- pkg/cluster/ansible/test-data/meta.yaml | 14 +++++++++++--- 5 files changed, 23 insertions(+), 4 deletions(-) rename pkg/cluster/ansible/{dirs.go => service.go} (97%) rename pkg/cluster/ansible/{dirs_test.go => service_test.go} (100%) diff --git a/pkg/cluster/ansible/inventory.go b/pkg/cluster/ansible/inventory.go index 2d0f9837c2..9bd0bd8b4c 100644 --- a/pkg/cluster/ansible/inventory.go +++ b/pkg/cluster/ansible/inventory.go @@ -556,6 +556,10 @@ func parseGroupVars(dir, ansCfgFile string, clsMeta *spec.ClusterMeta, inv *aini if port, ok := grpVarsAll["drainer_port"]; ok { tmpIns.Port, _ = strconv.Atoi(port) } + // apply values from the host + if port, ok := srv.Vars["drainer_port"]; ok { + tmpIns.Port, _ = strconv.Atoi(port) + } log.Debugf("Imported %s node %s:%d.", tmpIns.Role(), tmpIns.Host, tmpIns.GetMainPort()) diff --git a/pkg/cluster/ansible/dirs.go b/pkg/cluster/ansible/service.go similarity index 97% rename from pkg/cluster/ansible/dirs.go rename to pkg/cluster/ansible/service.go index 5aeada6ec7..6d488b0e43 100644 --- a/pkg/cluster/ansible/dirs.go +++ b/pkg/cluster/ansible/service.go @@ -16,6 +16,7 @@ package ansible import ( "fmt" "path/filepath" + "strconv" "strings" "time" @@ -183,6 +184,11 @@ func parseDirs(user string, ins spec.InstanceSpec, sshTimeout int64, sshType exe newIns.LogDir = logDir continue } + if strings.Contains(line, "--initial-commit-ts=") { + tsArg := strings.Split(line, " ")[4] // 4 whitespaces ahead + tmpTs, _ := strconv.Atoi(strings.TrimPrefix(tsArg, "--initial-commit-ts=")) + newIns.CommitTS = int64(tmpTs) + } } return newIns, nil case spec.ComponentPrometheus: diff --git a/pkg/cluster/ansible/dirs_test.go b/pkg/cluster/ansible/service_test.go similarity index 100% rename from pkg/cluster/ansible/dirs_test.go rename to pkg/cluster/ansible/service_test.go diff --git a/pkg/cluster/ansible/test-data/inventory.ini b/pkg/cluster/ansible/test-data/inventory.ini index 07e9bf4740..c63965ac5b 100644 --- a/pkg/cluster/ansible/test-data/inventory.ini +++ b/pkg/cluster/ansible/test-data/inventory.ini @@ -44,9 +44,10 @@ TiDB-PD-218 ansible_host=172.16.1.218 ansible_port=30000 ## Binlog Part [pump_servers] 172.16.1.219 -172.16.1.220 +172.16.1.220 pump_port=8333 [drainer_servers] +172.16.1.220 drainer_port=8444 172.16.1.221 [tiflash_servers] diff --git a/pkg/cluster/ansible/test-data/meta.yaml b/pkg/cluster/ansible/test-data/meta.yaml index cb246ce5ae..7bd2ec8a63 100644 --- a/pkg/cluster/ansible/test-data/meta.yaml +++ b/pkg/cluster/ansible/test-data/meta.yaml @@ -139,12 +139,20 @@ topology: - host: 172.16.1.220 ssh_port: 9999 imported: true - port: 8250 - deploy_dir: /home/tiopsimport/ansible-deploy/pump-8250 - data_dir: data/pump-8250 + port: 8333 + deploy_dir: /home/tiopsimport/ansible-deploy/pump-8333 + data_dir: data/pump-8333 arch: amd64 os: linux drainer_servers: + - host: 172.16.1.220 + ssh_port: 9999 + imported: true + port: 8444 + deploy_dir: /home/tiopsimport/ansible-deploy/drainer-8444 + data_dir: data/drainer-8444 + arch: amd64 + os: linux - host: 172.16.1.221 ssh_port: 9999 imported: true