Skip to content

Commit

Permalink
sessionctx/variable: set DEFAULT_VALUE for 'tidb_txn_mode' (#48500)
Browse files Browse the repository at this point in the history
close #48492
  • Loading branch information
highpon authored Jan 2, 2024
1 parent c20874e commit 7af117d
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
17 changes: 16 additions & 1 deletion pkg/session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,11 +1041,15 @@ const (
// version 181
// add column `bdr_role` to `mysql.tidb_ddl_job` and `mysql.tidb_ddl_history`.
version181 = 181

// version 182
// set tidb_txn_mode to Optimistic when tidb_txn_mode is not set.
version182 = 182
)

// currentBootstrapVersion is defined as a variable, so we can modify its value for testing.
// please make sure this is the largest version
var currentBootstrapVersion int64 = version181
var currentBootstrapVersion int64 = version182

// DDL owner key's expired time is ManagerSessionTTL seconds, we should wait the time and give more time to have a chance to finish it.
var internalSQLTimeout = owner.ManagerSessionTTL + 15
Expand Down Expand Up @@ -1202,6 +1206,7 @@ var (
upgradeToVer179,
upgradeToVer180,
upgradeToVer181,
upgradeToVer182,
}
)

Expand Down Expand Up @@ -2948,6 +2953,16 @@ func upgradeToVer181(s sessiontypes.Session, ver int64) {
doReentrantDDL(s, "ALTER TABLE mysql.tidb_ddl_history ADD COLUMN `bdr_role` varchar(64)", infoschema.ErrColumnExists)
}

func upgradeToVer182(s sessiontypes.Session, ver int64) {
if ver >= version182 {
return
}
sql := fmt.Sprintf("INSERT HIGH_PRIORITY IGNORE INTO %s.%s VALUES('%s', '%s')",
mysql.SystemDB, mysql.GlobalVariablesTable,
variable.TiDBTxnMode, variable.OptimisticTxnMode)
mustExecute(s, sql)
}

func writeOOMAction(s sessiontypes.Session) {
comment := "oom-action is `log` by default in v3.0.x, `cancel` by default in v4.0.11+"
mustExecute(s, `INSERT HIGH_PRIORITY INTO %n.%n VALUES (%?, %?, %?) ON DUPLICATE KEY UPDATE VARIABLE_VALUE= %?`,
Expand Down
7 changes: 6 additions & 1 deletion pkg/sessionctx/variable/sysvar.go
Original file line number Diff line number Diff line change
Expand Up @@ -1908,7 +1908,7 @@ var defaultSysVars = []*SysVar{
s.ConstraintCheckInPlace = TiDBOptOn(val)
return nil
}},
{Scope: ScopeGlobal | ScopeSession, Name: TiDBTxnMode, Value: DefTiDBTxnMode, AllowEmptyAll: true, Type: TypeEnum, PossibleValues: []string{"pessimistic", "optimistic"}, SetSession: func(s *SessionVars, val string) error {
{Scope: ScopeGlobal | ScopeSession, Name: TiDBTxnMode, Value: DefTiDBTxnMode, AllowEmptyAll: true, Type: TypeEnum, PossibleValues: []string{PessimisticTxnMode, OptimisticTxnMode}, SetSession: func(s *SessionVars, val string) error {
s.TxnMode = strings.ToUpper(val)
return nil
}},
Expand Down Expand Up @@ -3001,6 +3001,11 @@ var SetCharsetVariables = []string{
const (
// MaskPwd is the mask of password for LDAP variables.
MaskPwd = "******"

// PessimisticTxnMode is the name for tidb_txn_mode system variable.
PessimisticTxnMode = "pessimistic"
// OptimisticTxnMode is the name for tidb_txn_mode system variable.
OptimisticTxnMode = "optimistic"
)

const (
Expand Down
2 changes: 1 addition & 1 deletion pkg/sessionctx/variable/tidb_vars.go
Original file line number Diff line number Diff line change
Expand Up @@ -1223,7 +1223,7 @@ const (
DefTiFlashQuerySpillRatio = 0.7
DefTiDBEnableTiFlashPipelineMode = true
DefTiDBMPPStoreFailTTL = "60s"
DefTiDBTxnMode = ""
DefTiDBTxnMode = PessimisticTxnMode
DefTiDBRowFormatV1 = 1
DefTiDBRowFormatV2 = 2
DefTiDBDDLReorgWorkerCount = 4
Expand Down
2 changes: 1 addition & 1 deletion tests/integrationtest/r/infoschema/tables.result
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ innodb_compression_level GLOBAL 6 8 NULL NULL NULL YES
SET GLOBAL innodb_compression_level = DEFAULT;
SELECT * FROM variables_info WHERE variable_name = 'tidb_txn_mode';
VARIABLE_NAME VARIABLE_SCOPE DEFAULT_VALUE CURRENT_VALUE MIN_VALUE MAX_VALUE POSSIBLE_VALUES IS_NOOP
tidb_txn_mode SESSION,GLOBAL pessimistic NULL NULL pessimistic,optimistic NO
tidb_txn_mode SESSION,GLOBAL pessimistic pessimistic NULL NULL pessimistic,optimistic NO
SELECT * FROM variables_info WHERE variable_name = 'max_connections' AND is_noop='NO';
VARIABLE_NAME VARIABLE_SCOPE DEFAULT_VALUE CURRENT_VALUE MIN_VALUE MAX_VALUE POSSIBLE_VALUES IS_NOOP
max_connections INSTANCE 0 0 0 100000 NULL NO
Expand Down

0 comments on commit 7af117d

Please sign in to comment.