From 5de3ddfddbe426d812702809530d387371b3ab2d Mon Sep 17 00:00:00 2001 From: Xiaoju Wu Date: Mon, 26 Dec 2022 21:06:16 +0800 Subject: [PATCH 1/5] This is an automated cherry-pick of #40173 Signed-off-by: ti-chi-bot --- session/bootstrap.go | 21 ++++++++++++++++ session/bootstrap_test.go | 53 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 74 insertions(+) diff --git a/session/bootstrap.go b/session/bootstrap.go index a3c98a014b4e2..4bb000d6ba15b 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -732,6 +732,13 @@ const ( version107 = 107 // version108 adds the table tidb_ttl_table_status version108 = 108 +<<<<<<< HEAD +======= + // version109 add column source to mysql.stats_meta_history + version109 = 109 + // version110 sets tidb_enable_gc_aware_memory_track to off when a cluster upgrades from some version lower than v6.5.0. + version110 = 110 +>>>>>>> fc714e2108 (session: fix tidb_enable_gc_aware_memory_track after upgrade (#40173)) ) // currentBootstrapVersion is defined as a variable, so we can modify its value for testing. @@ -849,6 +856,11 @@ var ( upgradeToVer106, upgradeToVer107, upgradeToVer108, +<<<<<<< HEAD +======= + upgradeToVer109, + upgradeToVer110, +>>>>>>> fc714e2108 (session: fix tidb_enable_gc_aware_memory_track after upgrade (#40173)) } ) @@ -2191,6 +2203,15 @@ func upgradeToVer108(s Session, ver int64) { doReentrantDDL(s, CreateTTLTableStatus) } +// For users that upgrade TiDB from a 6.2-6.4 version, we want to disable tidb gc_aware_memory_track by default. +func upgradeToVer110(s Session, ver int64) { + if ver >= version110 { + return + } + mustExecute(s, "REPLACE HIGH_PRIORITY INTO %n.%n VALUES (%?, %?);", + mysql.SystemDB, mysql.GlobalVariablesTable, variable.TiDBEnableGCAwareMemoryTrack, 0) +} + func writeOOMAction(s 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= %?`, diff --git a/session/bootstrap_test.go b/session/bootstrap_test.go index f7ced237b0170..b7c9f79959027 100644 --- a/session/bootstrap_test.go +++ b/session/bootstrap_test.go @@ -1275,3 +1275,56 @@ func TestTiDBCostModelUpgradeFrom610To650(t *testing.T) { }() } } + +func TestTiDBGCAwareUpgradeFrom630To650(t *testing.T) { + ctx := context.Background() + store, _ := createStoreAndBootstrap(t) + defer func() { require.NoError(t, store.Close()) }() + + // upgrade from 6.3 to 6.5+. + ver63 := version93 + seV63 := createSessionAndSetID(t, store) + txn, err := store.Begin() + require.NoError(t, err) + m := meta.NewMeta(txn) + err = m.FinishBootstrap(int64(ver63)) + require.NoError(t, err) + err = txn.Commit(context.Background()) + require.NoError(t, err) + mustExec(t, seV63, fmt.Sprintf("update mysql.tidb set variable_value=%d where variable_name='tidb_server_version'", ver63)) + mustExec(t, seV63, fmt.Sprintf("update mysql.GLOBAL_VARIABLES set variable_value='%s' where variable_name='%s'", "1", variable.TiDBEnableGCAwareMemoryTrack)) + mustExec(t, seV63, "commit") + unsetStoreBootstrapped(store.UUID()) + ver, err := getBootstrapVersion(seV63) + require.NoError(t, err) + require.Equal(t, int64(ver63), ver) + + // We are now in 6.3, tidb_enable_gc_aware_memory_track is ON. + res := mustExecToRecodeSet(t, seV63, fmt.Sprintf("select * from mysql.GLOBAL_VARIABLES where variable_name='%s'", variable.TiDBEnableGCAwareMemoryTrack)) + chk := res.NewChunk(nil) + err = res.Next(ctx, chk) + require.NoError(t, err) + require.Equal(t, 1, chk.NumRows()) + row := chk.GetRow(0) + require.Equal(t, 2, row.Len()) + require.Equal(t, "1", row.GetString(1)) + + // Upgrade to 6.5. + domCurVer, err := BootstrapSession(store) + require.NoError(t, err) + defer domCurVer.Close() + seCurVer := createSessionAndSetID(t, store) + ver, err = getBootstrapVersion(seCurVer) + require.NoError(t, err) + require.Equal(t, currentBootstrapVersion, ver) + + // We are now in 6.5. + res = mustExecToRecodeSet(t, seCurVer, fmt.Sprintf("select * from mysql.GLOBAL_VARIABLES where variable_name='%s'", variable.TiDBEnableGCAwareMemoryTrack)) + chk = res.NewChunk(nil) + err = res.Next(ctx, chk) + require.NoError(t, err) + require.Equal(t, 1, chk.NumRows()) + row = chk.GetRow(0) + require.Equal(t, 2, row.Len()) + require.Equal(t, "0", row.GetString(1)) +} From 330ea5ce0621266fa505659087ca8ca26754ebd0 Mon Sep 17 00:00:00 2001 From: wuxiaoju Date: Mon, 26 Dec 2022 23:18:59 +0800 Subject: [PATCH 2/5] fix conflicts --- session/bootstrap.go | 6 ------ 1 file changed, 6 deletions(-) diff --git a/session/bootstrap.go b/session/bootstrap.go index 4bb000d6ba15b..1789cc8745d4d 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -732,13 +732,10 @@ const ( version107 = 107 // version108 adds the table tidb_ttl_table_status version108 = 108 -<<<<<<< HEAD -======= // version109 add column source to mysql.stats_meta_history version109 = 109 // version110 sets tidb_enable_gc_aware_memory_track to off when a cluster upgrades from some version lower than v6.5.0. version110 = 110 ->>>>>>> fc714e2108 (session: fix tidb_enable_gc_aware_memory_track after upgrade (#40173)) ) // currentBootstrapVersion is defined as a variable, so we can modify its value for testing. @@ -856,11 +853,8 @@ var ( upgradeToVer106, upgradeToVer107, upgradeToVer108, -<<<<<<< HEAD -======= upgradeToVer109, upgradeToVer110, ->>>>>>> fc714e2108 (session: fix tidb_enable_gc_aware_memory_track after upgrade (#40173)) } ) From 17cf25473bc129ce972dace4d0b7e2f22dc7dcf8 Mon Sep 17 00:00:00 2001 From: wuxiaoju Date: Mon, 26 Dec 2022 23:33:51 +0800 Subject: [PATCH 3/5] update currentBootstrapVersion --- session/bootstrap.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/session/bootstrap.go b/session/bootstrap.go index 1789cc8745d4d..eb3a9927e13f6 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -740,7 +740,7 @@ const ( // 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 = version108 +var currentBootstrapVersion int64 = version110 // 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 From 951b8fd302e99afa755a696f2e27c4af26cd0f1c Mon Sep 17 00:00:00 2001 From: wuxiaoju Date: Tue, 27 Dec 2022 00:07:07 +0800 Subject: [PATCH 4/5] update version --- session/bootstrap.go | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/session/bootstrap.go b/session/bootstrap.go index eb3a9927e13f6..104e01b230f8b 100644 --- a/session/bootstrap.go +++ b/session/bootstrap.go @@ -732,15 +732,13 @@ const ( version107 = 107 // version108 adds the table tidb_ttl_table_status version108 = 108 - // version109 add column source to mysql.stats_meta_history + // version109 sets tidb_enable_gc_aware_memory_track to off when a cluster upgrades from some version lower than v6.5.0. version109 = 109 - // version110 sets tidb_enable_gc_aware_memory_track to off when a cluster upgrades from some version lower than v6.5.0. - version110 = 110 ) // 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 = version110 +var currentBootstrapVersion int64 = version109 // 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 @@ -854,7 +852,6 @@ var ( upgradeToVer107, upgradeToVer108, upgradeToVer109, - upgradeToVer110, } ) @@ -2198,8 +2195,8 @@ func upgradeToVer108(s Session, ver int64) { } // For users that upgrade TiDB from a 6.2-6.4 version, we want to disable tidb gc_aware_memory_track by default. -func upgradeToVer110(s Session, ver int64) { - if ver >= version110 { +func upgradeToVer109(s Session, ver int64) { + if ver >= version109 { return } mustExecute(s, "REPLACE HIGH_PRIORITY INTO %n.%n VALUES (%?, %?);", From bebff0d86349d29e93a3eceed4c365aa6fac6d06 Mon Sep 17 00:00:00 2001 From: wuxiaoju Date: Tue, 27 Dec 2022 10:32:09 +0800 Subject: [PATCH 5/5] fix --- session/bootstrap_test.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/session/bootstrap_test.go b/session/bootstrap_test.go index b7c9f79959027..087d5efdbcd09 100644 --- a/session/bootstrap_test.go +++ b/session/bootstrap_test.go @@ -1300,7 +1300,7 @@ func TestTiDBGCAwareUpgradeFrom630To650(t *testing.T) { require.Equal(t, int64(ver63), ver) // We are now in 6.3, tidb_enable_gc_aware_memory_track is ON. - res := mustExecToRecodeSet(t, seV63, fmt.Sprintf("select * from mysql.GLOBAL_VARIABLES where variable_name='%s'", variable.TiDBEnableGCAwareMemoryTrack)) + res := mustExec(t, seV63, fmt.Sprintf("select * from mysql.GLOBAL_VARIABLES where variable_name='%s'", variable.TiDBEnableGCAwareMemoryTrack)) chk := res.NewChunk(nil) err = res.Next(ctx, chk) require.NoError(t, err) @@ -1319,7 +1319,7 @@ func TestTiDBGCAwareUpgradeFrom630To650(t *testing.T) { require.Equal(t, currentBootstrapVersion, ver) // We are now in 6.5. - res = mustExecToRecodeSet(t, seCurVer, fmt.Sprintf("select * from mysql.GLOBAL_VARIABLES where variable_name='%s'", variable.TiDBEnableGCAwareMemoryTrack)) + res = mustExec(t, seCurVer, fmt.Sprintf("select * from mysql.GLOBAL_VARIABLES where variable_name='%s'", variable.TiDBEnableGCAwareMemoryTrack)) chk = res.NewChunk(nil) err = res.Next(ctx, chk) require.NoError(t, err)