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

ddl: tidb_scatter_region variable supports setting value in both upper/lower case #57677

Merged
merged 4 commits into from
Nov 26, 2024
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
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)
Copy link
Collaborator

@Benjamin2037 Benjamin2037 Nov 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

you can also add some mixed "TablE" cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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