Skip to content

Commit

Permalink
sessionctx: add TiDBDDLEnableDistributeReorg flag (#39663)
Browse files Browse the repository at this point in the history
ref #37120
  • Loading branch information
Defined2014 authored Dec 7, 2022
1 parent 032e6fd commit 442c044
Show file tree
Hide file tree
Showing 7 changed files with 86 additions and 0 deletions.
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

0 comments on commit 442c044

Please sign in to comment.