Skip to content

Commit

Permalink
vars: add pd_enable_follower_handle_region to support get region f…
Browse files Browse the repository at this point in the history
…rom pd follower (#49231)

close #49747
  • Loading branch information
CabinfeverB authored Jan 4, 2024
1 parent 8c49f5c commit e8861cf
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 0 deletions.
9 changes: 9 additions & 0 deletions pkg/domain/domain_sysvars.go
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ func (do *Domain) setPDClientDynamicOption(name, sVal string) {
break
}
variable.EnableTSOFollowerProxy.Store(val)
case variable.PDEnableFollowerHandleRegion:
val := variable.TiDBOptOn(sVal)
// Note: EnableFollowerHandle is only used for region API now.
// If pd support more APIs in follower, the pd option may be changed.
err := do.updatePDClient(pd.EnableFollowerHandle, val)
if err != nil {
break
}
variable.EnablePDFollowerHandleRegion.Store(val)
}
}

Expand Down
6 changes: 6 additions & 0 deletions pkg/executor/set_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -652,6 +652,12 @@ func TestSetVar(t *testing.T) {
tk.MustExec("set global tidb_enable_tso_follower_proxy = 0")
tk.MustQuery("select @@tidb_enable_tso_follower_proxy").Check(testkit.Rows("0"))
require.Error(t, tk.ExecToErr("set tidb_enable_tso_follower_proxy = 1"))
tk.MustQuery("select @@pd_enable_follower_handle_region").Check(testkit.Rows("0"))
tk.MustExec("set global pd_enable_follower_handle_region = 1")
tk.MustQuery("select @@pd_enable_follower_handle_region").Check(testkit.Rows("1"))
tk.MustExec("set global pd_enable_follower_handle_region = 0")
tk.MustQuery("select @@pd_enable_follower_handle_region").Check(testkit.Rows("0"))
require.Error(t, tk.ExecToErr("set pd_enable_follower_handle_region = 1"))

tk.MustQuery("select @@tidb_enable_historical_stats").Check(testkit.Rows("1"))
tk.MustExec("set global tidb_enable_historical_stats = 1")
Expand Down
6 changes: 6 additions & 0 deletions pkg/sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -706,6 +706,12 @@ var defaultSysVars = []*SysVar{
(*SetPDClientDynamicOption.Load())(TiDBEnableTSOFollowerProxy, val)
return nil
}},
{Scope: ScopeGlobal, Name: PDEnableFollowerHandleRegion, Value: BoolToOnOff(DefPDEnableFollowerHandleRegion), Type: TypeBool, GetGlobal: func(_ context.Context, sv *SessionVars) (string, error) {
return BoolToOnOff(EnablePDFollowerHandleRegion.Load()), nil
}, SetGlobal: func(_ context.Context, s *SessionVars, val string) error {
(*SetPDClientDynamicOption.Load())(PDEnableFollowerHandleRegion, val)
return nil
}},
{Scope: ScopeGlobal, Name: TiDBEnableLocalTxn, Value: BoolToOnOff(DefTiDBEnableLocalTxn), Hidden: true, Type: TypeBool, Depended: true, GetGlobal: func(_ context.Context, sv *SessionVars) (string, error) {
return BoolToOnOff(EnableLocalTxn.Load()), nil
}, SetGlobal: func(_ context.Context, s *SessionVars, val string) error {
Expand Down
5 changes: 5 additions & 0 deletions pkg/sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -722,6 +722,9 @@ const (
// TiDBEnableTSOFollowerProxy indicates whether to enable the TSO Follower Proxy feature of PD client.
TiDBEnableTSOFollowerProxy = "tidb_enable_tso_follower_proxy"

// PDEnableFollowerHandleRegion indicates whether to enable the PD Follower handle region API.
PDEnableFollowerHandleRegion = "pd_enable_follower_handle_region"

// TiDBEnableOrderedResultMode indicates if stabilize query results.
TiDBEnableOrderedResultMode = "tidb_enable_ordered_result_mode"

Expand Down Expand Up @@ -1290,6 +1293,7 @@ const (
DefTiDBEnableLocalTxn = false
DefTiDBTSOClientBatchMaxWaitTime = 0.0 // 0ms
DefTiDBEnableTSOFollowerProxy = false
DefPDEnableFollowerHandleRegion = false
DefTiDBEnableOrderedResultMode = false
DefTiDBEnablePseudoForOutdatedStats = false
DefTiDBRegardNULLAsPoint = true
Expand Down Expand Up @@ -1476,6 +1480,7 @@ var (
EnableLocalTxn = atomic.NewBool(DefTiDBEnableLocalTxn)
MaxTSOBatchWaitInterval = atomic.NewFloat64(DefTiDBTSOClientBatchMaxWaitTime)
EnableTSOFollowerProxy = atomic.NewBool(DefTiDBEnableTSOFollowerProxy)
EnablePDFollowerHandleRegion = atomic.NewBool(DefPDEnableFollowerHandleRegion)
RestrictedReadOnly = atomic.NewBool(DefTiDBRestrictedReadOnly)
VarTiDBSuperReadOnly = atomic.NewBool(DefTiDBSuperReadOnly)
PersistAnalyzeOptions = atomic.NewBool(DefTiDBPersistAnalyzeOptions)
Expand Down
11 changes: 11 additions & 0 deletions tests/integrationtest/r/session/vars.result
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,17 @@ set global tidb_enable_tso_follower_proxy = off;
select @@tidb_enable_tso_follower_proxy;
@@tidb_enable_tso_follower_proxy
0
select @@pd_enable_follower_handle_region;
@@pd_enable_follower_handle_region
0
set global pd_enable_follower_handle_region = on;
select @@pd_enable_follower_handle_region;
@@pd_enable_follower_handle_region
1
set global pd_enable_follower_handle_region = off;
select @@pd_enable_follower_handle_region;
@@pd_enable_follower_handle_region
0
set tidb_tso_client_batch_max_wait_time = 0;
Error 1229 (HY000): Variable 'tidb_tso_client_batch_max_wait_time' is a GLOBAL variable and should be set with SET GLOBAL
set global tidb_enable_tso_follower_proxy = default;
Expand Down
5 changes: 5 additions & 0 deletions tests/integrationtest/t/session/vars.test
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ set global tidb_enable_tso_follower_proxy = on;
select @@tidb_enable_tso_follower_proxy;
set global tidb_enable_tso_follower_proxy = off;
select @@tidb_enable_tso_follower_proxy;
select @@pd_enable_follower_handle_region;
set global pd_enable_follower_handle_region = on;
select @@pd_enable_follower_handle_region;
set global pd_enable_follower_handle_region = off;
select @@pd_enable_follower_handle_region;
-- error 1229
set tidb_tso_client_batch_max_wait_time = 0;
set global tidb_enable_tso_follower_proxy = default;
Expand Down

0 comments on commit e8861cf

Please sign in to comment.