Skip to content

Commit

Permalink
ddl: tidb_scatter_region variable supports setting value in both up…
Browse files Browse the repository at this point in the history
…per/lower case (#57677)

close #57669
  • Loading branch information
River2000i authored Nov 26, 2024
1 parent 2125737 commit dcc9dcc
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
25 changes: 25 additions & 0 deletions pkg/ddl/table_split_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,10 @@ func TestScatterRegion(t *testing.T) {
tk.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows("table"))
tk.MustExec("set @@tidb_scatter_region = 'global';")
tk.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows("global"))
tk.MustExec("set @@tidb_scatter_region = 'TABLE';")
tk.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows("table"))
tk.MustExec("set @@tidb_scatter_region = 'GLOBAL';")
tk.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows("global"))
tk.MustExec("set @@tidb_scatter_region = '';")
tk.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows(""))

Expand All @@ -111,13 +115,34 @@ func TestScatterRegion(t *testing.T) {
tk.MustQuery("select @@global.tidb_scatter_region;").Check(testkit.Rows("global"))
tk.MustExec("set global tidb_scatter_region = '';")
tk.MustQuery("select @@global.tidb_scatter_region;").Check(testkit.Rows(""))
tk2 = testkit.NewTestKit(t, store)
tk2.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows(""))

tk.MustExec("set global tidb_scatter_region = 'TABLE';")
tk.MustQuery("select @@global.tidb_scatter_region;").Check(testkit.Rows("table"))
tk.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows(""))
tk2 = testkit.NewTestKit(t, store)
tk2.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows("table"))

tk.MustExec("set global tidb_scatter_region = 'GLOBAL';")
tk.MustQuery("select @@global.tidb_scatter_region;").Check(testkit.Rows("global"))
tk.MustExec("set global tidb_scatter_region = '';")
tk.MustQuery("select @@global.tidb_scatter_region;").Check(testkit.Rows(""))

err := tk.ExecToErr("set @@tidb_scatter_region = 'test';")
require.ErrorContains(t, err, "invalid value for 'test', it should be either '', 'table' or 'global'")
err = tk.ExecToErr("set @@tidb_scatter_region = 'te st';")
require.ErrorContains(t, err, "invalid value for 'te st', it should be either '', 'table' or 'global'")
err = tk.ExecToErr("set @@tidb_scatter_region = '1';")
require.ErrorContains(t, err, "invalid value for '1', it should be either '', 'table' or 'global'")
err = tk.ExecToErr("set @@tidb_scatter_region = 0;")
require.ErrorContains(t, err, "invalid value for '0', it should be either '', 'table' or 'global'")

tk.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows(""))
tk.MustExec("set @@tidb_scatter_region = 'TaBlE';")
tk.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows("table"))
tk.MustExec("set @@tidb_scatter_region = 'gLoBaL';")
tk.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows("global"))
}

type kvStore interface {
Expand Down
7 changes: 4 additions & 3 deletions pkg/sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -818,10 +818,11 @@ var defaultSysVars = []*SysVar{
return vars.ScatterRegion, nil
},
Validation: func(vars *SessionVars, normalizedValue string, originalValue string, scope ScopeFlag) (string, error) {
if normalizedValue != ScatterOff && normalizedValue != ScatterTable && normalizedValue != ScatterGlobal {
return "", fmt.Errorf("invalid value for '%s', it should be either '%s', '%s' or '%s'", normalizedValue, ScatterOff, ScatterTable, ScatterGlobal)
lowerVal := strings.ToLower(normalizedValue)
if lowerVal != ScatterOff && lowerVal != ScatterTable && lowerVal != ScatterGlobal {
return "", fmt.Errorf("invalid value for '%s', it should be either '%s', '%s' or '%s'", lowerVal, ScatterOff, ScatterTable, ScatterGlobal)
}
return normalizedValue, nil
return lowerVal, nil
},
},
{Scope: ScopeGlobal, Name: TiDBEnableStmtSummary, Value: BoolToOnOff(DefTiDBEnableStmtSummary), Type: TypeBool, AllowEmpty: true,
Expand Down

0 comments on commit dcc9dcc

Please sign in to comment.