diff --git a/embed/templates/scripts/run_drainer.sh.tpl b/embed/templates/scripts/run_drainer.sh.tpl index ce8a76bafa..fcc1fb4012 100644 --- a/embed/templates/scripts/run_drainer.sh.tpl +++ b/embed/templates/scripts/run_drainer.sh.tpl @@ -29,5 +29,4 @@ exec bin/drainer \ --pd-urls="{{template "PDList" .Endpoints}}" \ --data-dir="{{.DataDir}}" \ --log-file="{{.LogDir}}/drainer.log" \ - --config=conf/drainer.toml \ - --initial-commit-ts={{.CommitTs}} 2>> "{{.LogDir}}/drainer_stderr.log" + --config=conf/drainer.toml 2>> "{{.LogDir}}/drainer_stderr.log" diff --git a/pkg/cluster/ansible/service.go b/pkg/cluster/ansible/service.go index 7b98161516..b93b4a46a8 100644 --- a/pkg/cluster/ansible/service.go +++ b/pkg/cluster/ansible/service.go @@ -196,7 +196,8 @@ func parseDirs(ctx context.Context, user string, ins spec.InstanceSpec, sshTimeo 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) + newIns.Config = make(map[string]interface{}) + newIns.Config["initial_commit_ts"] = int64(tmpTs) } } return newIns, nil diff --git a/pkg/cluster/spec/drainer.go b/pkg/cluster/spec/drainer.go index 6066648108..80676d46c4 100644 --- a/pkg/cluster/spec/drainer.go +++ b/pkg/cluster/spec/drainer.go @@ -38,7 +38,7 @@ type DrainerSpec struct { DeployDir string `yaml:"deploy_dir,omitempty"` DataDir string `yaml:"data_dir,omitempty"` LogDir string `yaml:"log_dir,omitempty"` - CommitTS int64 `yaml:"commit_ts" default:"-1" validate:"commit_ts:editable"` + CommitTS *int64 `yaml:"commit_ts,omitempty" validate:"commit_ts:editable"` // do not use it anymore, exist for compatibility Offline bool `yaml:"offline,omitempty"` NumaNode string `yaml:"numa_node,omitempty" validate:"numa_node:editable"` Config map[string]interface{} `yaml:"config,omitempty" validate:"config:ignore"` @@ -168,8 +168,6 @@ func (i *DrainerInstance) InitConfig( paths.Log, ).WithPort(spec.Port).WithNumaNode(spec.NumaNode).AppendEndpoints(topo.Endpoints(deployUser)...) - cfg.WithCommitTs(spec.CommitTS) - fp := filepath.Join(paths.Cache, fmt.Sprintf("run_drainer_%s_%d.sh", i.GetHost(), i.GetPort())) if err := cfg.ConfigToFile(fp); err != nil { diff --git a/pkg/cluster/spec/spec.go b/pkg/cluster/spec/spec.go index 4337efe188..f8b6370e87 100644 --- a/pkg/cluster/spec/spec.go +++ b/pkg/cluster/spec/spec.go @@ -356,6 +356,9 @@ func (s *Specification) UnmarshalYAML(unmarshal func(interface{}) error) error { } } + // --initial-commit-ts should not be recorded at run_drainer.sh #1682 + s.removeCommitTS() + return s.Validate() } @@ -866,6 +869,21 @@ func setHostArch(field reflect.Value, hostArch map[string]string) error { return nil } +// when upgrade form old tiup-cluster, replace spec.CommitTS with spec.Config["initial_commit_ts"] +func (s *Specification) removeCommitTS() { + _, ok1 := s.ServerConfigs.Drainer["initial_commit_ts"] + for _, spec := range s.Drainers { + _, ok2 := spec.Config["initial_commit_ts"] + if !ok1 && !ok2 && spec.CommitTS != nil && *spec.CommitTS != -1 { + if spec.Config == nil { + spec.Config = make(map[string]interface{}) + } + spec.Config["initial_commit_ts"] = *spec.CommitTS + } + spec.CommitTS = nil + } +} + // GetGrafanaConfig returns global grafana configurations func (s *Specification) GetGrafanaConfig() map[string]string { return s.ServerConfigs.Grafana diff --git a/pkg/cluster/template/scripts/drainer.go b/pkg/cluster/template/scripts/drainer.go index ed2831965a..c1f0c1030e 100644 --- a/pkg/cluster/template/scripts/drainer.go +++ b/pkg/cluster/template/scripts/drainer.go @@ -31,7 +31,6 @@ type DrainerScript struct { DataDir string LogDir string NumaNode string - CommitTs int64 Endpoints []*PDScript } @@ -44,7 +43,6 @@ func NewDrainerScript(nodeID, ip, deployDir, dataDir, logDir string) *DrainerScr DeployDir: deployDir, DataDir: dataDir, LogDir: logDir, - CommitTs: -1, } } @@ -60,12 +58,6 @@ func (c *DrainerScript) WithNumaNode(numa string) *DrainerScript { return c } -// WithCommitTs set CommitTs field of DrainerScript -func (c *DrainerScript) WithCommitTs(ts int64) *DrainerScript { - c.CommitTs = ts - return c -} - // AppendEndpoints add new DrainerScript to Endpoints field func (c *DrainerScript) AppendEndpoints(ends ...*PDScript) *DrainerScript { c.Endpoints = append(c.Endpoints, ends...)