Skip to content
Open
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
14 changes: 7 additions & 7 deletions br/pkg/restore/snap_client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -172,7 +172,7 @@ type SnapClient struct {
// restore from a checkpoint inherits the same restoreUUID.
restoreUUID uuid.UUID

checkPrivilegeTableRowsCollateCompatiblity bool
privilegeTableRowsCollateCompatibility bool
}

// NewRestoreClient returns a new RestoreClient.
Expand Down Expand Up @@ -275,16 +275,16 @@ func (rc *SnapClient) GetSupportPolicy() bool {
return rc.supportPolicy
}

// SetCheckPrivilegeTableRowsCollateCompatiblity set switch to check
// SetCheckPrivilegeTableRowsCollateCompatibility set switch to check
// privilege tables with different collate columns
func (rc *SnapClient) SetCheckPrivilegeTableRowsCollateCompatiblity(v bool) {
rc.checkPrivilegeTableRowsCollateCompatiblity = v
func (rc *SnapClient) SetCheckPrivilegeTableRowsCollateCompatibility(v bool) {
rc.privilegeTableRowsCollateCompatibility = v
}

// GetCheckPrivilegeTableRowsCollateCompatiblity get switch to check
// GetCheckPrivilegeTableRowsCollateCompatibility get switch to check
// privilege tables with different collate columns
func (rc *SnapClient) GetCheckPrivilegeTableRowsCollateCompatiblity() bool {
return rc.checkPrivilegeTableRowsCollateCompatiblity
func (rc *SnapClient) GetCheckPrivilegeTableRowsCollateCompatibility() bool {
return rc.privilegeTableRowsCollateCompatibility
}

func (rc *SnapClient) updateConcurrency() {
Expand Down
18 changes: 12 additions & 6 deletions br/pkg/restore/snap_client/systable_restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,13 @@ var unRecoverableTable = map[string]map[string]struct{}{
},
}

type checkPrivilegeTableRowsCollateCompatiblitySQLPair struct {
type checkPrivilegeTableRowsCollateCompatibilitySQLPair struct {
upstreamCollateSQL string
downstreamCollateSQL string
columns map[string]struct{}
}

var collateCompatibilityTables = map[string]map[string]checkPrivilegeTableRowsCollateCompatiblitySQLPair{
var collateCompatibilityTables = map[string]map[string]checkPrivilegeTableRowsCollateCompatibilitySQLPair{
"mysql": {
"db": {
upstreamCollateSQL: "SELECT COUNT(1) FROM __TiDB_BR_Temporary_mysql.db",
Expand Down Expand Up @@ -531,7 +531,7 @@ func (rc *SnapClient) replaceTemporaryTableToSystable(ctx context.Context, ti *m
log.Info("replace into existing table",
zap.String("table", tableName),
zap.Stringer("schema", db.Name))
if rc.checkPrivilegeTableRowsCollateCompatiblity {
if rc.privilegeTableRowsCollateCompatibility {
if err := rc.checkPrivilegeTableRowsCollateCompatibility(ctx, dbName, tableName, ti, db.ExistingTables[tableName]); err != nil {
return err
}
Expand Down Expand Up @@ -607,11 +607,17 @@ func CheckSysTableCompatibility(dom *domain.Domain, tables []*metautil.Table, co
col := ti.Columns[i]
backupCol := backupColMap[col.Name.L]
if backupCol == nil {
// skip when the backed up mysql.user table is missing columns.
// mysql.user may gain new columns in newer TiDB versions. In that case the
// schemas are still logically compatible, but loading the backed-up data
// directly into the temporary table with the newer schema can fail checksum
// validation because the upstream snapshot does not contain the new column.
// Fall back to non-physical loading for mysql.user when the backup is
// missing target columns.
if backupTi.Name.L == sysUserTableName {
log.Warn("missing column in backup data",
zap.Stringer("table", table.Info.Name),
zap.String("col", fmt.Sprintf("%s %s", col.Name, col.FieldType.String())))
canLoadSysTablePhysical = false
continue
}
log.Error("missing column in backup data",
Expand Down Expand Up @@ -688,11 +694,11 @@ func (rc *SnapClient) checkPrivilegeTableRowsCollateCompatibility(
dbNameL, tableNameL string,
upstreamTable, downstreamTable *model.TableInfo,
) error {
collateCompatiblityTableMap, exists := collateCompatibilityTables[dbNameL]
collateCompatibilityTableMap, exists := collateCompatibilityTables[dbNameL]
if !exists {
return nil
}
collateCompatibilityColumnMap, exists := collateCompatiblityTableMap[tableNameL]
collateCompatibilityColumnMap, exists := collateCompatibilityTableMap[tableNameL]
if !exists {
return nil
}
Expand Down
6 changes: 3 additions & 3 deletions br/pkg/restore/snap_client/systable_restore_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,15 @@ func TestCheckSysTableCompatibility(t *testing.T) {
require.NoError(t, err)

var canLoadSysTablePhysical bool
// user table in cluster have more columns(success)
// user table in cluster have more columns(failed)
mockedUserTI := userTI.Clone()
userTI.Columns = append(userTI.Columns, &model.ColumnInfo{Name: ast.NewCIStr("new-name")})
canLoadSysTablePhysical, err = snapclient.CheckSysTableCompatibility(cluster.Domain, []*metautil.Table{{
DB: tmpSysDB,
Info: mockedUserTI,
}}, false)
require.NoError(t, err)
require.True(t, canLoadSysTablePhysical)
require.False(t, canLoadSysTablePhysical)
userTI.Columns = userTI.Columns[:len(userTI.Columns)-1]

// user table in cluster have less columns(failed)
Expand Down Expand Up @@ -233,7 +233,7 @@ func TestCheckPrivilegeTableRowsCollateCompatibility(t *testing.T) {
defer rc.Close()
err := rc.InitConnections(g, cluster.Storage)
require.NoError(t, err)
rc.SetCheckPrivilegeTableRowsCollateCompatiblity(true)
rc.SetCheckPrivilegeTableRowsCollateCompatibility(true)

se, err := g.CreateSession(cluster.Storage)
require.NoError(t, err)
Expand Down
8 changes: 4 additions & 4 deletions br/pkg/task/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -747,7 +747,7 @@ func configureRestoreClient(ctx context.Context, client *snapclient.SnapClient,
client.SetPlacementPolicyMode(cfg.WithPlacementPolicy)
client.SetWithSysTable(cfg.WithSysTable)
client.SetRewriteMode(ctx)
client.SetCheckPrivilegeTableRowsCollateCompatiblity(cfg.SysCheckCollation)
client.SetCheckPrivilegeTableRowsCollateCompatibility(cfg.SysCheckCollation)
return nil
}

Expand Down Expand Up @@ -1463,17 +1463,17 @@ func runSnapshotRestore(c context.Context, mgr *conn.Mgr, g glue.Glue, cmdName s
}

if client.IsFullClusterRestore() && client.HasBackedUpSysDB() {
canLoadSysTablePhysical, err := snapclient.CheckSysTableCompatibility(mgr.GetDomain(), tables, client.GetCheckPrivilegeTableRowsCollateCompatiblity())
canLoadSysTablePhysical, err := snapclient.CheckSysTableCompatibility(mgr.GetDomain(), tables, client.GetCheckPrivilegeTableRowsCollateCompatibility())
if err != nil {
return errors.Trace(err)
}
if loadSysTablePhysical && !canLoadSysTablePhysical {
log.Info("The system tables schema is not compatible. Fallback to logically load system tables.")
loadSysTablePhysical = false
}
if client.GetCheckPrivilegeTableRowsCollateCompatiblity() && canLoadSysTablePhysical {
if client.GetCheckPrivilegeTableRowsCollateCompatibility() && canLoadSysTablePhysical {
log.Info("The system tables schema match so no need to set sys check collation")
client.SetCheckPrivilegeTableRowsCollateCompatiblity(false)
client.SetCheckPrivilegeTableRowsCollateCompatibility(false)
}
}

Expand Down
Loading