From 92c6486339b9094e4c64329d9e83edafd7990876 Mon Sep 17 00:00:00 2001 From: Jiaqiang Huang <96465211+River2000i@users.noreply.github.com> Date: Mon, 25 Nov 2024 17:23:14 +0800 Subject: [PATCH 1/3] tidb_scatter_region variable supports setting values in both upper/lower case --- pkg/ddl/table_split_test.go | 17 +++++++++++++++++ pkg/sessionctx/variable/sysvar.go | 7 ++++--- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/pkg/ddl/table_split_test.go b/pkg/ddl/table_split_test.go index 7ee9ebec021c4..8cf5be3bfb54b 100644 --- a/pkg/ddl/table_split_test.go +++ b/pkg/ddl/table_split_test.go @@ -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("")) @@ -107,6 +111,19 @@ func TestScatterRegion(t *testing.T) { 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("")) + 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 = '';") diff --git a/pkg/sessionctx/variable/sysvar.go b/pkg/sessionctx/variable/sysvar.go index 80c88266ce97c..5afeca38d14a7 100644 --- a/pkg/sessionctx/variable/sysvar.go +++ b/pkg/sessionctx/variable/sysvar.go @@ -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, From 5c59bb4d5c92850b83137bfb96e863b2cbd9c4e8 Mon Sep 17 00:00:00 2001 From: Jiaqiang Huang <96465211+River2000i@users.noreply.github.com> Date: Mon, 25 Nov 2024 18:14:28 +0800 Subject: [PATCH 2/3] fix --- pkg/ddl/table_split_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pkg/ddl/table_split_test.go b/pkg/ddl/table_split_test.go index 8cf5be3bfb54b..dd0c9287d9ba7 100644 --- a/pkg/ddl/table_split_test.go +++ b/pkg/ddl/table_split_test.go @@ -124,7 +124,7 @@ func TestScatterRegion(t *testing.T) { tk2 = testkit.NewTestKit(t, store) tk2.MustQuery("select @@tidb_scatter_region;").Check(testkit.Rows("table")) - tk.MustExec("set global tidb_scatter_region = 'global';") + 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("")) From 7c010d8688436770f7212a05d08c170238070332 Mon Sep 17 00:00:00 2001 From: Jiaqiang Huang <96465211+River2000i@users.noreply.github.com> Date: Mon, 25 Nov 2024 20:10:52 +0800 Subject: [PATCH 3/3] add test --- pkg/ddl/table_split_test.go | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/pkg/ddl/table_split_test.go b/pkg/ddl/table_split_test.go index dd0c9287d9ba7..b47b6939988f0 100644 --- a/pkg/ddl/table_split_test.go +++ b/pkg/ddl/table_split_test.go @@ -131,10 +131,18 @@ func TestScatterRegion(t *testing.T) { 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 {