diff --git a/pkg/sessionctx/variable/session.go b/pkg/sessionctx/variable/session.go index 29d304d133403..b90c2e84c93f1 100644 --- a/pkg/sessionctx/variable/session.go +++ b/pkg/sessionctx/variable/session.go @@ -955,6 +955,9 @@ type SessionVars struct { // Value set to `false` means never use mpp. allowMPPExecution bool + // EnableCommitTSOrderCheck enables checking order of commit_ts for transactions within a session. + EnableCommitTSOrderCheck bool + // allowTiFlashCop means if we must use mpp way to execute query. // Default value is `false`, means to be determined by the optimizer. // Value set to `true` means we may fall back to TiFlash cop if possible. @@ -2252,6 +2255,7 @@ func NewSessionVars(hctx HookContext) *SessionVars { vars.DMLBatchSize = DefDMLBatchSize vars.AllowBatchCop = DefTiDBAllowBatchCop vars.allowMPPExecution = DefTiDBAllowMPPExecution + vars.EnableCommitTSOrderCheck = DefTiDBEnableCommitTSOrderCheck vars.HashExchangeWithNewCollation = DefTiDBHashExchangeWithNewCollation vars.enforceMPPExecution = DefTiDBEnforceMPPExecution vars.TiFlashMaxThreads = DefTiFlashMaxThreads diff --git a/pkg/sessionctx/variable/sysvar.go b/pkg/sessionctx/variable/sysvar.go index 80c88266ce97c..b75e8c6294ef6 100644 --- a/pkg/sessionctx/variable/sysvar.go +++ b/pkg/sessionctx/variable/sysvar.go @@ -1936,6 +1936,10 @@ var defaultSysVars = []*SysVar{ s.allowTiFlashCop = TiDBOptOn(val) return nil }}, + {Scope: ScopeSession, Name: TiDBEnableCommitTSOrderCheck, Value: Off, Type: TypeBool, SetSession: func(s *SessionVars, val string) error { + s.EnableCommitTSOrderCheck = TiDBOptOn(val) + return nil + }}, {Scope: ScopeGlobal | ScopeSession, Name: TiFlashFastScan, Type: TypeBool, Value: BoolToOnOff(DefTiFlashFastScan), SetSession: func(s *SessionVars, val string) error { s.TiFlashFastScan = TiDBOptOn(val) return nil diff --git a/pkg/sessionctx/variable/sysvar_test.go b/pkg/sessionctx/variable/sysvar_test.go index 5dd0b43367f6c..0a290c7d0c726 100644 --- a/pkg/sessionctx/variable/sysvar_test.go +++ b/pkg/sessionctx/variable/sysvar_test.go @@ -791,6 +791,19 @@ func TestDefaultMemoryDebugModeValue(t *testing.T) { require.Equal(t, val, "0") } +func TestEnableCommitTSOrderCheck(t *testing.T) { + sv := GetSysVar(TiDBEnableCommitTSOrderCheck) + require.True(t, sv.HasSessionScope()) + require.False(t, sv.HasGlobalScope()) + + vars := NewSessionVars(nil) + require.Equal(t, false, vars.EnableCommitTSOrderCheck) + + err := sv.SetSession(vars, On) + require.NoError(t, err) + require.Equal(t, true, vars.EnableCommitTSOrderCheck) +} + func TestSetTIDBDistributeReorg(t *testing.T) { vars := NewSessionVars(nil) mock := NewMockGlobalAccessor4Tests() diff --git a/pkg/sessionctx/variable/tidb_vars.go b/pkg/sessionctx/variable/tidb_vars.go index da1ec04ded9fd..f89d5a17545d3 100644 --- a/pkg/sessionctx/variable/tidb_vars.go +++ b/pkg/sessionctx/variable/tidb_vars.go @@ -402,6 +402,10 @@ const ( // Value set to `false` means never use mpp. TiDBAllowMPPExecution = "tidb_allow_mpp" + // TiDBEnableCommitTSOrderCheck enables checking the order of commit_ts for transactions within a session. + // Default value is `false`, means not to check the order of commit_ts within a session. + TiDBEnableCommitTSOrderCheck = "tidb_enable_commit_ts_order_check" + // TiDBAllowTiFlashCop means we only use MPP mode to query data. // Default value is `true`, means to be determined by the optimizer. // Value set to `false` means we may fall back to TiFlash cop plan if possible. @@ -1309,6 +1313,7 @@ const ( DefPreSplitRegions = 0 DefBlockEncryptionMode = "aes-128-ecb" DefTiDBAllowMPPExecution = true + DefTiDBEnableCommitTSOrderCheck = false DefTiDBAllowTiFlashCop = false DefTiDBHashExchangeWithNewCollation = true DefTiDBEnforceMPPExecution = false