Skip to content

Commit

Permalink
cluster: support check timezone (#1890)
Browse files Browse the repository at this point in the history
  • Loading branch information
nexustar authored May 26, 2022
1 parent 956b072 commit bda2367
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 0 deletions.
8 changes: 8 additions & 0 deletions pkg/cluster/manager/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -334,6 +334,14 @@ func checkSystemInfo(
topo,
opt.Opr,
).
// check for time zone
CheckSys(
inst.GetHost(),
"",
task.CheckTypeTimeZone,
topo,
opt.Opr,
).
// check for system limits
Shell(
inst.GetHost(),
Expand Down
47 changes: 47 additions & 0 deletions pkg/cluster/operation/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ var (
CheckNameTHP = "thp"
CheckNameDirPermission = "permission"
CheckNameDirExist = "exist"
CheckNameTimeZone = "timezone"
)

// CheckResult is the result of a check
Expand Down Expand Up @@ -950,3 +951,49 @@ func CheckDirIsExist(ctx context.Context, e ctxt.Executor, path string) []*Check

return results
}

// CheckTimeZone performs checks if time zone is the same
func CheckTimeZone(ctx context.Context, topo *spec.Specification, host string, rawData []byte) []*CheckResult {
var results []*CheckResult
var insightInfo, pd0insightInfo insight.InsightInfo
if err := json.Unmarshal(rawData, &insightInfo); err != nil {
return append(results, &CheckResult{
Name: CheckNameTimeZone,
Err: err,
})
}

if len(topo.PDServers) < 1 {
return append(results, &CheckResult{
Name: CheckNameTimeZone,
Err: fmt.Errorf("no pd found"),
})
}
// skip compare with itself
if topo.PDServers[0].Host == host {
return nil
}
pd0stdout, _, _ := ctxt.GetInner(ctx).GetOutputs(topo.PDServers[0].Host)
if err := json.Unmarshal(pd0stdout, &pd0insightInfo); err != nil {
return append(results, &CheckResult{
Name: CheckNameTimeZone,
Err: err,
})
}

timezone := insightInfo.SysInfo.Node.Timezone
pd0timezone := pd0insightInfo.SysInfo.Node.Timezone

if timezone == pd0timezone {
results = append(results, &CheckResult{
Name: CheckNameTimeZone,
Msg: "time zone is the same as the first PD machine: " + timezone,
})
} else {
results = append(results, &CheckResult{
Name: CheckNameTimeZone,
Err: fmt.Errorf("time zone is %s, but the firt PD is %s", timezone, pd0timezone),
})
}
return results
}
3 changes: 3 additions & 0 deletions pkg/cluster/task/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ var (
CheckTypeFIO = "fio"
CheckTypePermission = "permission"
ChecktypeIsExist = "exist"
CheckTypeTimeZone = "timezone"
)

// place the check utilities are stored
Expand Down Expand Up @@ -155,6 +156,8 @@ func (c *CheckSys) Execute(ctx context.Context) error {
}
// check partition mount options for data_dir
storeResults(ctx, c.host, operator.CheckDirIsExist(ctx, e, c.checkDir))
case CheckTypeTimeZone:
storeResults(ctx, c.host, operator.CheckTimeZone(ctx, c.topo, c.host, stdout))
}

return nil
Expand Down

0 comments on commit bda2367

Please sign in to comment.