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

session: upgrade from old cluster infoschema v2 should not be used #56545

Merged
merged 3 commits into from
Oct 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion br/pkg/restore/snap_client/systable_restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
16 changes: 15 additions & 1 deletion pkg/session/bootstrap.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -1358,6 +1362,7 @@ var (
upgradeToVer214,
upgradeToVer215,
upgradeToVer216,
upgradeToVer217,
}
)

Expand Down Expand Up @@ -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)")
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if there's no such row in global_variables

when we execute this statement, the first domain and infocache has already started, the infocache is still v2 ?

Copy link
Contributor Author

@tiancaiamao tiancaiamao Oct 11, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Later when infoschema reload it would detect the new tidb_schema_cache_size value and change to v1 @D3Hunter

}

// 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)
Expand Down