Skip to content

Commit

Permalink
*: fix variable problem during initialization (#38971) (#38976)
Browse files Browse the repository at this point in the history
close #38973
  • Loading branch information
ti-chi-bot authored Nov 9, 2022
1 parent 786e3b4 commit 274d9c5
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 4 deletions.
1 change: 1 addition & 0 deletions sessionctx/variable/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ go_test(
],
embed = [":variable"],
flaky = True,
shard_count = 2,
deps = [
"//config",
"//kv",
Expand Down
6 changes: 4 additions & 2 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -746,7 +746,8 @@ var defaultSysVars = []*SysVar{
if floatValue < 0 && floatValue > 0.9 {
return "", ErrWrongValueForVar.GenWithStackByArgs(TiDBGOGCTunerThreshold, normalizedValue)
}
if globalMemoryLimitTuner < floatValue+0.05 {
// globalMemoryLimitTuner must not be 0. it will be 0 when tidb_server_memory_limit_gc_trigger is not set during startup.
if globalMemoryLimitTuner != 0 && globalMemoryLimitTuner < floatValue+0.05 {
return "", errors.New("tidb_gogc_tuner_threshold should be less than tidb_server_memory_limit_gc_trigger - 0.05")
}
return strconv.FormatFloat(floatValue, 'f', -1, 64), nil
Expand Down Expand Up @@ -837,7 +838,8 @@ var defaultSysVars = []*SysVar{
if floatValue < 0.51 && floatValue > 1 { // 51% ~ 100%
return "", ErrWrongValueForVar.GenWithStackByArgs(TiDBServerMemoryLimitGCTrigger, normalizedValue)
}
if floatValue < gogcTunerThreshold+0.05 {
// gogcTunerThreshold must not be 0. it will be 0 when tidb_gogc_tuner_threshold is not set during startup.
if gogcTunerThreshold != 0 && floatValue < gogcTunerThreshold+0.05 {
return "", errors.New("tidb_server_memory_limit_gc_trigger should be greater than tidb_gogc_tuner_threshold + 0.05")
}

Expand Down
8 changes: 6 additions & 2 deletions sessionctx/variable/variable_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -436,18 +436,22 @@ func TestDefaultValuesAreSettable(t *testing.T) {
for _, sv := range GetSysVars() {
if sv.HasSessionScope() && !sv.ReadOnly {
val, err := sv.Validate(vars, sv.Value, ScopeSession)
require.Equal(t, val, sv.Value)
require.NoError(t, err)
require.Equal(t, val, sv.Value)
}

if sv.HasGlobalScope() && !sv.ReadOnly {
val, err := sv.Validate(vars, sv.Value, ScopeGlobal)
require.Equal(t, val, sv.Value)
require.NoError(t, err)
require.Equal(t, val, sv.Value)
}
}
}

func TestLimitBetweenVariable(t *testing.T) {
require.Less(t, DefTiDBGOGCTunerThreshold+0.05, DefTiDBServerMemoryLimitGCTrigger)
}

// TestSysVarNameIsLowerCase tests that no new sysvars are added with uppercase characters.
// In MySQL variables are always lowercase, and can be set in a case-insensitive way.
func TestSysVarNameIsLowerCase(t *testing.T) {
Expand Down

0 comments on commit 274d9c5

Please sign in to comment.