Skip to content

Commit e8861cf

Browse files
authored
vars: add pd_enable_follower_handle_region to support get region from pd follower (#49231)
close #49747
1 parent 8c49f5c commit e8861cf

File tree

6 files changed

+42
-0
lines changed

6 files changed

+42
-0
lines changed

pkg/domain/domain_sysvars.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,15 @@ func (do *Domain) setPDClientDynamicOption(name, sVal string) {
6969
break
7070
}
7171
variable.EnableTSOFollowerProxy.Store(val)
72+
case variable.PDEnableFollowerHandleRegion:
73+
val := variable.TiDBOptOn(sVal)
74+
// Note: EnableFollowerHandle is only used for region API now.
75+
// If pd support more APIs in follower, the pd option may be changed.
76+
err := do.updatePDClient(pd.EnableFollowerHandle, val)
77+
if err != nil {
78+
break
79+
}
80+
variable.EnablePDFollowerHandleRegion.Store(val)
7281
}
7382
}
7483

pkg/executor/set_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -652,6 +652,12 @@ func TestSetVar(t *testing.T) {
652652
tk.MustExec("set global tidb_enable_tso_follower_proxy = 0")
653653
tk.MustQuery("select @@tidb_enable_tso_follower_proxy").Check(testkit.Rows("0"))
654654
require.Error(t, tk.ExecToErr("set tidb_enable_tso_follower_proxy = 1"))
655+
tk.MustQuery("select @@pd_enable_follower_handle_region").Check(testkit.Rows("0"))
656+
tk.MustExec("set global pd_enable_follower_handle_region = 1")
657+
tk.MustQuery("select @@pd_enable_follower_handle_region").Check(testkit.Rows("1"))
658+
tk.MustExec("set global pd_enable_follower_handle_region = 0")
659+
tk.MustQuery("select @@pd_enable_follower_handle_region").Check(testkit.Rows("0"))
660+
require.Error(t, tk.ExecToErr("set pd_enable_follower_handle_region = 1"))
655661

656662
tk.MustQuery("select @@tidb_enable_historical_stats").Check(testkit.Rows("1"))
657663
tk.MustExec("set global tidb_enable_historical_stats = 1")

pkg/sessionctx/variable/sysvar.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -706,6 +706,12 @@ var defaultSysVars = []*SysVar{
706706
(*SetPDClientDynamicOption.Load())(TiDBEnableTSOFollowerProxy, val)
707707
return nil
708708
}},
709+
{Scope: ScopeGlobal, Name: PDEnableFollowerHandleRegion, Value: BoolToOnOff(DefPDEnableFollowerHandleRegion), Type: TypeBool, GetGlobal: func(_ context.Context, sv *SessionVars) (string, error) {
710+
return BoolToOnOff(EnablePDFollowerHandleRegion.Load()), nil
711+
}, SetGlobal: func(_ context.Context, s *SessionVars, val string) error {
712+
(*SetPDClientDynamicOption.Load())(PDEnableFollowerHandleRegion, val)
713+
return nil
714+
}},
709715
{Scope: ScopeGlobal, Name: TiDBEnableLocalTxn, Value: BoolToOnOff(DefTiDBEnableLocalTxn), Hidden: true, Type: TypeBool, Depended: true, GetGlobal: func(_ context.Context, sv *SessionVars) (string, error) {
710716
return BoolToOnOff(EnableLocalTxn.Load()), nil
711717
}, SetGlobal: func(_ context.Context, s *SessionVars, val string) error {

pkg/sessionctx/variable/tidb_vars.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,6 +722,9 @@ const (
722722
// TiDBEnableTSOFollowerProxy indicates whether to enable the TSO Follower Proxy feature of PD client.
723723
TiDBEnableTSOFollowerProxy = "tidb_enable_tso_follower_proxy"
724724

725+
// PDEnableFollowerHandleRegion indicates whether to enable the PD Follower handle region API.
726+
PDEnableFollowerHandleRegion = "pd_enable_follower_handle_region"
727+
725728
// TiDBEnableOrderedResultMode indicates if stabilize query results.
726729
TiDBEnableOrderedResultMode = "tidb_enable_ordered_result_mode"
727730

@@ -1290,6 +1293,7 @@ const (
12901293
DefTiDBEnableLocalTxn = false
12911294
DefTiDBTSOClientBatchMaxWaitTime = 0.0 // 0ms
12921295
DefTiDBEnableTSOFollowerProxy = false
1296+
DefPDEnableFollowerHandleRegion = false
12931297
DefTiDBEnableOrderedResultMode = false
12941298
DefTiDBEnablePseudoForOutdatedStats = false
12951299
DefTiDBRegardNULLAsPoint = true
@@ -1476,6 +1480,7 @@ var (
14761480
EnableLocalTxn = atomic.NewBool(DefTiDBEnableLocalTxn)
14771481
MaxTSOBatchWaitInterval = atomic.NewFloat64(DefTiDBTSOClientBatchMaxWaitTime)
14781482
EnableTSOFollowerProxy = atomic.NewBool(DefTiDBEnableTSOFollowerProxy)
1483+
EnablePDFollowerHandleRegion = atomic.NewBool(DefPDEnableFollowerHandleRegion)
14791484
RestrictedReadOnly = atomic.NewBool(DefTiDBRestrictedReadOnly)
14801485
VarTiDBSuperReadOnly = atomic.NewBool(DefTiDBSuperReadOnly)
14811486
PersistAnalyzeOptions = atomic.NewBool(DefTiDBPersistAnalyzeOptions)

tests/integrationtest/r/session/vars.result

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,17 @@ set global tidb_enable_tso_follower_proxy = off;
6262
select @@tidb_enable_tso_follower_proxy;
6363
@@tidb_enable_tso_follower_proxy
6464
0
65+
select @@pd_enable_follower_handle_region;
66+
@@pd_enable_follower_handle_region
67+
0
68+
set global pd_enable_follower_handle_region = on;
69+
select @@pd_enable_follower_handle_region;
70+
@@pd_enable_follower_handle_region
71+
1
72+
set global pd_enable_follower_handle_region = off;
73+
select @@pd_enable_follower_handle_region;
74+
@@pd_enable_follower_handle_region
75+
0
6576
set tidb_tso_client_batch_max_wait_time = 0;
6677
Error 1229 (HY000): Variable 'tidb_tso_client_batch_max_wait_time' is a GLOBAL variable and should be set with SET GLOBAL
6778
set global tidb_enable_tso_follower_proxy = default;

tests/integrationtest/t/session/vars.test

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,11 @@ set global tidb_enable_tso_follower_proxy = on;
3535
select @@tidb_enable_tso_follower_proxy;
3636
set global tidb_enable_tso_follower_proxy = off;
3737
select @@tidb_enable_tso_follower_proxy;
38+
select @@pd_enable_follower_handle_region;
39+
set global pd_enable_follower_handle_region = on;
40+
select @@pd_enable_follower_handle_region;
41+
set global pd_enable_follower_handle_region = off;
42+
select @@pd_enable_follower_handle_region;
3843
-- error 1229
3944
set tidb_tso_client_batch_max_wait_time = 0;
4045
set global tidb_enable_tso_follower_proxy = default;

0 commit comments

Comments
 (0)