Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cluster: use initial_commit_ts in drainer config file instead of start script #1706

Merged
merged 6 commits into from
Jan 6, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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