Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

sessionctx/variable: set DEFAULT_VALUE for 'tidb_txn_mode' #48500

Merged
merged 13 commits into from
Jan 2, 2024
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
Defined2014 marked this conversation as resolved.
Show resolved Hide resolved
// 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