Skip to content

Commit 706c3fa

Browse files
authored
session: fix tidb_enable_gc_aware_memory_track after upgrade (#40173) (#40179)
ref #39971, close #40174
1 parent 80c7ab9 commit 706c3fa

File tree

2 files changed

+66
-1
lines changed

2 files changed

+66
-1
lines changed

session/bootstrap.go

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -732,11 +732,13 @@ const (
732732
version107 = 107
733733
// version108 adds the table tidb_ttl_table_status
734734
version108 = 108
735+
// version109 sets tidb_enable_gc_aware_memory_track to off when a cluster upgrades from some version lower than v6.5.0.
736+
version109 = 109
735737
)
736738

737739
// currentBootstrapVersion is defined as a variable, so we can modify its value for testing.
738740
// please make sure this is the largest version
739-
var currentBootstrapVersion int64 = version108
741+
var currentBootstrapVersion int64 = version109
740742

741743
// 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.
742744
var internalSQLTimeout = owner.ManagerSessionTTL + 15
@@ -849,6 +851,7 @@ var (
849851
upgradeToVer106,
850852
upgradeToVer107,
851853
upgradeToVer108,
854+
upgradeToVer109,
852855
}
853856
)
854857

@@ -2191,6 +2194,15 @@ func upgradeToVer108(s Session, ver int64) {
21912194
doReentrantDDL(s, CreateTTLTableStatus)
21922195
}
21932196

2197+
// For users that upgrade TiDB from a 6.2-6.4 version, we want to disable tidb gc_aware_memory_track by default.
2198+
func upgradeToVer109(s Session, ver int64) {
2199+
if ver >= version109 {
2200+
return
2201+
}
2202+
mustExecute(s, "REPLACE HIGH_PRIORITY INTO %n.%n VALUES (%?, %?);",
2203+
mysql.SystemDB, mysql.GlobalVariablesTable, variable.TiDBEnableGCAwareMemoryTrack, 0)
2204+
}
2205+
21942206
func writeOOMAction(s Session) {
21952207
comment := "oom-action is `log` by default in v3.0.x, `cancel` by default in v4.0.11+"
21962208
mustExecute(s, `INSERT HIGH_PRIORITY INTO %n.%n VALUES (%?, %?, %?) ON DUPLICATE KEY UPDATE VARIABLE_VALUE= %?`,

session/bootstrap_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1275,3 +1275,56 @@ func TestTiDBCostModelUpgradeFrom610To650(t *testing.T) {
12751275
}()
12761276
}
12771277
}
1278+
1279+
func TestTiDBGCAwareUpgradeFrom630To650(t *testing.T) {
1280+
ctx := context.Background()
1281+
store, _ := createStoreAndBootstrap(t)
1282+
defer func() { require.NoError(t, store.Close()) }()
1283+
1284+
// upgrade from 6.3 to 6.5+.
1285+
ver63 := version93
1286+
seV63 := createSessionAndSetID(t, store)
1287+
txn, err := store.Begin()
1288+
require.NoError(t, err)
1289+
m := meta.NewMeta(txn)
1290+
err = m.FinishBootstrap(int64(ver63))
1291+
require.NoError(t, err)
1292+
err = txn.Commit(context.Background())
1293+
require.NoError(t, err)
1294+
mustExec(t, seV63, fmt.Sprintf("update mysql.tidb set variable_value=%d where variable_name='tidb_server_version'", ver63))
1295+
mustExec(t, seV63, fmt.Sprintf("update mysql.GLOBAL_VARIABLES set variable_value='%s' where variable_name='%s'", "1", variable.TiDBEnableGCAwareMemoryTrack))
1296+
mustExec(t, seV63, "commit")
1297+
unsetStoreBootstrapped(store.UUID())
1298+
ver, err := getBootstrapVersion(seV63)
1299+
require.NoError(t, err)
1300+
require.Equal(t, int64(ver63), ver)
1301+
1302+
// We are now in 6.3, tidb_enable_gc_aware_memory_track is ON.
1303+
res := mustExec(t, seV63, fmt.Sprintf("select * from mysql.GLOBAL_VARIABLES where variable_name='%s'", variable.TiDBEnableGCAwareMemoryTrack))
1304+
chk := res.NewChunk(nil)
1305+
err = res.Next(ctx, chk)
1306+
require.NoError(t, err)
1307+
require.Equal(t, 1, chk.NumRows())
1308+
row := chk.GetRow(0)
1309+
require.Equal(t, 2, row.Len())
1310+
require.Equal(t, "1", row.GetString(1))
1311+
1312+
// Upgrade to 6.5.
1313+
domCurVer, err := BootstrapSession(store)
1314+
require.NoError(t, err)
1315+
defer domCurVer.Close()
1316+
seCurVer := createSessionAndSetID(t, store)
1317+
ver, err = getBootstrapVersion(seCurVer)
1318+
require.NoError(t, err)
1319+
require.Equal(t, currentBootstrapVersion, ver)
1320+
1321+
// We are now in 6.5.
1322+
res = mustExec(t, seCurVer, fmt.Sprintf("select * from mysql.GLOBAL_VARIABLES where variable_name='%s'", variable.TiDBEnableGCAwareMemoryTrack))
1323+
chk = res.NewChunk(nil)
1324+
err = res.Next(ctx, chk)
1325+
require.NoError(t, err)
1326+
require.Equal(t, 1, chk.NumRows())
1327+
row = chk.GetRow(0)
1328+
require.Equal(t, 2, row.Len())
1329+
require.Equal(t, "0", row.GetString(1))
1330+
}

0 commit comments

Comments
 (0)