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

Make bootstrap system variables code cleaner #34754

Closed
morgo opened this issue May 17, 2022 · 0 comments · Fixed by #34755
Closed

Make bootstrap system variables code cleaner #34754

morgo opened this issue May 17, 2022 · 0 comments · Fixed by #34755
Assignees
Labels
type/enhancement The issue or PR belongs to an enhancement.

Comments

@morgo
Copy link
Contributor

morgo commented May 17, 2022

Enhancement

In #33769 two of the issues need to make changes to session/bootstrap.go so that they change the oom-action and run-auto-analyze settings for when bootstrapping in the test suite.

This made it very clear that this code is currently not very clean, and could be improved:

tidb/session/bootstrap.go

Lines 1967 to 2011 in d2ada35

// Init global system variables table.
values := make([]string, 0, len(variable.GetSysVars()))
for k, v := range variable.GetSysVars() {
// Only global variables should be inserted.
if v.HasGlobalScope() {
vVal := v.Value
if v.Name == variable.TiDBTxnMode && config.GetGlobalConfig().Store == "tikv" {
vVal = "pessimistic"
}
if v.Name == variable.TiDBRowFormatVersion {
vVal = strconv.Itoa(variable.DefTiDBRowFormatV2)
}
if v.Name == variable.TiDBPartitionPruneMode {
vVal = variable.DefTiDBPartitionPruneMode
if flag.Lookup("test.v") != nil || flag.Lookup("check.v") != nil || config.CheckTableBeforeDrop {
// enable Dynamic Prune by default in test case.
vVal = string(variable.Dynamic)
}
}
if v.Name == variable.TiDBEnableChangeMultiSchema {
vVal = variable.Off
if flag.Lookup("test.v") != nil || flag.Lookup("check.v") != nil {
// enable change multi schema in test case for compatibility with old cases.
vVal = variable.On
}
}
if v.Name == variable.TiDBEnableAsyncCommit && config.GetGlobalConfig().Store == "tikv" {
vVal = variable.On
}
if v.Name == variable.TiDBEnable1PC && config.GetGlobalConfig().Store == "tikv" {
vVal = variable.On
}
if v.Name == variable.TiDBEnableMutationChecker {
vVal = variable.On
}
if v.Name == variable.TiDBTxnAssertionLevel {
vVal = variable.AssertionFastStr
}
value := fmt.Sprintf(`("%s", "%s")`, strings.ToLower(k), vVal)
values = append(values, value)
}
}
sql := fmt.Sprintf("INSERT HIGH_PRIORITY INTO %s.%s VALUES %s;", mysql.SystemDB, mysql.GlobalVariablesTable,
strings.Join(values, ", "))
mustExecute(s, sql)

@morgo morgo added the type/enhancement The issue or PR belongs to an enhancement. label May 17, 2022
@morgo morgo self-assigned this May 24, 2022
ti-chi-bot pushed a commit that referenced this issue Jun 21, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/enhancement The issue or PR belongs to an enhancement.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant