Skip to content

Commit

Permalink
cluster: use initial_commit_ts in drainer config file instead of star…
Browse files Browse the repository at this point in the history
…t script (#1706)
  • Loading branch information
nexustar authored Jan 6, 2022
1 parent ad88444 commit e7e5689
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 14 deletions.
3 changes: 1 addition & 2 deletions embed/templates/scripts/run_drainer.sh.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -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"
3 changes: 2 additions & 1 deletion pkg/cluster/ansible/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 1 addition & 3 deletions pkg/cluster/spec/drainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand Down Expand Up @@ -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 {
Expand Down
18 changes: 18 additions & 0 deletions pkg/cluster/spec/spec.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}

Expand Down Expand Up @@ -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
Expand Down
8 changes: 0 additions & 8 deletions pkg/cluster/template/scripts/drainer.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ type DrainerScript struct {
DataDir string
LogDir string
NumaNode string
CommitTs int64
Endpoints []*PDScript
}

Expand All @@ -44,7 +43,6 @@ func NewDrainerScript(nodeID, ip, deployDir, dataDir, logDir string) *DrainerScr
DeployDir: deployDir,
DataDir: dataDir,
LogDir: logDir,
CommitTs: -1,
}
}

Expand All @@ -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...)
Expand Down

0 comments on commit e7e5689

Please sign in to comment.