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

sessionctx: add TiDBDDLEnableDistributeReorg flag #39663

Merged
merged 3 commits into from
Dec 7, 2022
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
1 change: 1 addition & 0 deletions sessionctx/variable/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
11 changes: 11 additions & 0 deletions sessionctx/variable/featuretag/distributereorg/BUILD.bazel
Original file line number Diff line number Diff line change
@@ -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"],
)
20 changes: 20 additions & 0 deletions sessionctx/variable/featuretag/distributereorg/default.go
Original file line number Diff line number Diff line change
@@ -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
20 changes: 20 additions & 0 deletions sessionctx/variable/featuretag/distributereorg/non_default.go
Original file line number Diff line number Diff line change
@@ -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
8 changes: 8 additions & 0 deletions sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions sessionctx/variable/sysvar_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
5 changes: 5 additions & 0 deletions sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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.
Expand Down Expand Up @@ -1078,6 +1081,7 @@ const (
DefTiDBEnablePrepPlanCacheMemoryMonitor = true
DefTiDBPrepPlanCacheMemoryGuardRatio = 0.1
DefTiDBEnableConcurrentDDL = concurrencyddl.TiDBEnableConcurrentDDL
DefTiDBDDLEnableDistributeReorg = distributereorg.TiDBEnableDistributeReorg
DefTiDBSimplifiedMetrics = false
DefTiDBEnablePaging = true
DefTiFlashFineGrainedShuffleStreamCount = 0
Expand Down Expand Up @@ -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)
Expand Down