diff --git a/sessionctx/variable/BUILD.bazel b/sessionctx/variable/BUILD.bazel index 17ff6a6bc482c..48977fa134a72 100644 --- a/sessionctx/variable/BUILD.bazel +++ b/sessionctx/variable/BUILD.bazel @@ -33,6 +33,7 @@ go_library( "//sessionctx/sessionstates", "//sessionctx/stmtctx", "//sessionctx/variable/featuretag/concurrencyddl", + "//sessionctx/variable/featuretag/distributereorg", "//tidb-binlog/pump_client", "//types", "//types/parser_driver", diff --git a/sessionctx/variable/featuretag/distributereorg/BUILD.bazel b/sessionctx/variable/featuretag/distributereorg/BUILD.bazel new file mode 100644 index 0000000000000..153ce052ecbb2 --- /dev/null +++ b/sessionctx/variable/featuretag/distributereorg/BUILD.bazel @@ -0,0 +1,11 @@ +load("@io_bazel_rules_go//go:def.bzl", "go_library") + +go_library( + name = "distributereorg", + srcs = [ + "default.go", + "non_default.go", + ], + importpath = "github.com/pingcap/tidb/sessionctx/variable/featuretag/distributereorg", + visibility = ["//visibility:public"], +) diff --git a/sessionctx/variable/featuretag/distributereorg/default.go b/sessionctx/variable/featuretag/distributereorg/default.go new file mode 100644 index 0000000000000..910629adde825 --- /dev/null +++ b/sessionctx/variable/featuretag/distributereorg/default.go @@ -0,0 +1,20 @@ +// Copyright 2022 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build !featuretag + +package distributereorg + +// TiDBEnableDistributeReorg is a feature tag +const TiDBEnableDistributeReorg bool = false diff --git a/sessionctx/variable/featuretag/distributereorg/non_default.go b/sessionctx/variable/featuretag/distributereorg/non_default.go new file mode 100644 index 0000000000000..f6286ba5b3409 --- /dev/null +++ b/sessionctx/variable/featuretag/distributereorg/non_default.go @@ -0,0 +1,20 @@ +// Copyright 2022 PingCAP, Inc. +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. + +//go:build featuretag + +package distributereorg + +// TiDBEnableDistributeReorg is a feature tag +const TiDBEnableDistributeReorg bool = true diff --git a/sessionctx/variable/sysvar.go b/sessionctx/variable/sysvar.go index b11af728bc5c2..368e86ce1332d 100644 --- a/sessionctx/variable/sysvar.go +++ b/sessionctx/variable/sysvar.go @@ -1116,6 +1116,14 @@ var defaultSysVars = []*SysVar{ }, GetGlobal: func(_ context.Context, vars *SessionVars) (string, error) { return BoolToOnOff(EnableMDL.Load()), nil }}, + {Scope: ScopeGlobal, Name: TiDBDDLEnableDistributeReorg, Value: BoolToOnOff(DefTiDBDDLEnableDistributeReorg), Type: TypeBool, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { + if DDLEnableDistributeReorg.Load() != TiDBOptOn(val) { + DDLEnableDistributeReorg.Store(TiDBOptOn(val)) + } + return nil + }, GetGlobal: func(_ context.Context, s *SessionVars) (string, error) { + return BoolToOnOff(DDLEnableDistributeReorg.Load()), nil + }}, {Scope: ScopeGlobal, Name: TiDBEnableNoopVariables, Value: BoolToOnOff(DefTiDBEnableNoopVariables), Type: TypeEnum, PossibleValues: []string{Off, On}, SetGlobal: func(_ context.Context, s *SessionVars, val string) error { EnableNoopVariables.Store(TiDBOptOn(val)) return nil diff --git a/sessionctx/variable/sysvar_test.go b/sessionctx/variable/sysvar_test.go index 3613870004bad..d198379070b3f 100644 --- a/sessionctx/variable/sysvar_test.go +++ b/sessionctx/variable/sysvar_test.go @@ -674,6 +674,27 @@ func TestDefaultMemoryDebugModeValue(t *testing.T) { require.Equal(t, val, "0") } +func TestSetTIDBDistributeReorg(t *testing.T) { + vars := NewSessionVars(nil) + mock := NewMockGlobalAccessor4Tests() + mock.SessionVars = vars + vars.GlobalVarsAccessor = mock + + // Set to on + err := mock.SetGlobalSysVar(context.Background(), TiDBDDLEnableDistributeReorg, On) + require.NoError(t, err) + val, err := mock.GetGlobalSysVar(TiDBDDLEnableDistributeReorg) + require.NoError(t, err) + require.Equal(t, On, val) + + // Set to off + err = mock.SetGlobalSysVar(context.Background(), TiDBDDLEnableDistributeReorg, Off) + require.NoError(t, err) + val, err = mock.GetGlobalSysVar(TiDBDDLEnableDistributeReorg) + require.NoError(t, err) + require.Equal(t, Off, val) +} + func TestDefaultPartitionPruneMode(t *testing.T) { vars := NewSessionVars(nil) mock := NewMockGlobalAccessor4Tests() diff --git a/sessionctx/variable/tidb_vars.go b/sessionctx/variable/tidb_vars.go index 7c9175487d79f..ef7e1e4e1ef21 100644 --- a/sessionctx/variable/tidb_vars.go +++ b/sessionctx/variable/tidb_vars.go @@ -21,6 +21,7 @@ import ( "github.com/pingcap/tidb/config" "github.com/pingcap/tidb/parser/mysql" "github.com/pingcap/tidb/sessionctx/variable/featuretag/concurrencyddl" + "github.com/pingcap/tidb/sessionctx/variable/featuretag/distributereorg" "github.com/pingcap/tidb/util/memory" "github.com/pingcap/tidb/util/paging" "github.com/pingcap/tidb/util/size" @@ -841,6 +842,8 @@ const ( TiDBMaxAutoAnalyzeTime = "tidb_max_auto_analyze_time" // TiDBEnableConcurrentDDL indicates whether to enable the new DDL framework. TiDBEnableConcurrentDDL = "tidb_enable_concurrent_ddl" + // TiDBDDLEnableDistributeReorg indicates whether to enable the new Reorg framework. + TiDBDDLEnableDistributeReorg = "tidb_ddl_distribute_reorg" // TiDBGenerateBinaryPlan indicates whether binary plan should be generated in slow log and statements summary. TiDBGenerateBinaryPlan = "tidb_generate_binary_plan" // TiDBEnableGCAwareMemoryTrack indicates whether to turn-on GC-aware memory track. @@ -1078,6 +1081,7 @@ const ( DefTiDBEnablePrepPlanCacheMemoryMonitor = true DefTiDBPrepPlanCacheMemoryGuardRatio = 0.1 DefTiDBEnableConcurrentDDL = concurrencyddl.TiDBEnableConcurrentDDL + DefTiDBDDLEnableDistributeReorg = distributereorg.TiDBEnableDistributeReorg DefTiDBSimplifiedMetrics = false DefTiDBEnablePaging = true DefTiFlashFineGrainedShuffleStreamCount = 0 @@ -1176,6 +1180,7 @@ var ( // variables for plan cache PreparedPlanCacheMemoryGuardRatio = atomic.NewFloat64(DefTiDBPrepPlanCacheMemoryGuardRatio) EnableConcurrentDDL = atomic.NewBool(DefTiDBEnableConcurrentDDL) + DDLEnableDistributeReorg = atomic.NewBool(DefTiDBDDLEnableDistributeReorg) DDLForce2Queue = atomic.NewBool(false) EnableNoopVariables = atomic.NewBool(DefTiDBEnableNoopVariables) EnableMDL = atomic.NewBool(false)