diff --git a/br/pkg/restore/snap_client/systable_restore_test.go b/br/pkg/restore/snap_client/systable_restore_test.go index 8b1b464023af0..358f457c55007 100644 --- a/br/pkg/restore/snap_client/systable_restore_test.go +++ b/br/pkg/restore/snap_client/systable_restore_test.go @@ -116,5 +116,5 @@ func TestCheckSysTableCompatibility(t *testing.T) { // // The above variables are in the file br/pkg/restore/systable_restore.go func TestMonitorTheSystemTableIncremental(t *testing.T) { - require.Equal(t, int64(216), session.CurrentBootstrapVersion) + require.Equal(t, int64(217), session.CurrentBootstrapVersion) } diff --git a/pkg/session/bootstrap.go b/pkg/session/bootstrap.go index 3c11e6f8c8ee6..8d5ff98248530 100644 --- a/pkg/session/bootstrap.go +++ b/pkg/session/bootstrap.go @@ -1182,11 +1182,15 @@ const ( // version 216 // changes variable `tidb_scatter_region` value from ON to "table" and OFF to "". version216 = 216 + + // version 217 + // Keep tidb_schema_cache_size to 0 if this variable does not exist (upgrading from old version pre 8.1). + version217 = 217 ) // 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 = version216 +var currentBootstrapVersion int64 = version217 // 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 @@ -1358,6 +1362,7 @@ var ( upgradeToVer214, upgradeToVer215, upgradeToVer216, + upgradeToVer217, } ) @@ -3267,6 +3272,15 @@ func upgradeToVer216(s sessiontypes.Session, ver int64) { mustExecute(s, "UPDATE mysql.global_variables SET VARIABLE_VALUE='table' WHERE VARIABLE_NAME = 'tidb_scatter_region' AND VARIABLE_VALUE = 'ON'") } +func upgradeToVer217(s sessiontypes.Session, ver int64) { + if ver >= version217 { + return + } + // If tidb_schema_cache_size does not exist, insert a record and set the value to 0 + // Otherwise do nothing. + mustExecute(s, "INSERT IGNORE INTO mysql.global_variables VALUES ('tidb_schema_cache_size', 0)") +} + // initGlobalVariableIfNotExists initialize a global variable with specific val if it does not exist. func initGlobalVariableIfNotExists(s sessiontypes.Session, name string, val any) { ctx := kv.WithInternalSourceType(context.Background(), kv.InternalTxnBootstrap)