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

br: fix integration test cases with --with-sys-table #39655

Merged
merged 7 commits into from
Dec 7, 2022
Merged
Show file tree
Hide file tree
Changes from 2 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
23 changes: 23 additions & 0 deletions br/pkg/restore/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -988,6 +988,29 @@ func (rc *Client) CheckSysTableCompatibility(dom *domain.Domain, tables []*metau
backupCol.Name, backupCol.FieldType.String())
}
}

if backupTi.Name.L == sysUserTableName {
// check whether the columns of table in cluster are less than the backup data
clusterColMap := make(map[string]*model.ColumnInfo)
for i := range ti.Columns {
col := ti.Columns[i]
clusterColMap[col.Name.L] = col
}
// order can be different
for i := range backupTi.Columns {
col := backupTi.Columns[i]
clusterCol := clusterColMap[col.Name.L]
if clusterCol == nil {
log.Error("missing column in cluster data",
zap.Stringer("table", table.Info.Name),
zap.String("col", fmt.Sprintf("%s %s", col.Name, col.FieldType.String())))
return errors.Annotatef(berrors.ErrRestoreIncompatibleSys,
"missing column in cluster data, table: %s, col: %s %s",
table.Info.Name.O,
col.Name, col.FieldType.String())
}
}
}
}
return nil
}
Expand Down
10 changes: 10 additions & 0 deletions br/pkg/restore/client_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,16 @@ func TestCheckSysTableCompatibility(t *testing.T) {
Info: mockedUserTI,
}})
require.NoError(t, err)
userTI.Columns = userTI.Columns[:len(userTI.Columns)-1]

// user table in cluster have less columns(failed)
mockedUserTI = userTI.Clone()
mockedUserTI.Columns = append(mockedUserTI.Columns, &model.ColumnInfo{Name: model.NewCIStr("new-name")})
err = client.CheckSysTableCompatibility(cluster.Domain, []*metautil.Table{{
DB: tmpSysDB,
Info: mockedUserTI,
}})
require.True(t, berrors.ErrRestoreIncompatibleSys.Equal(err))

// column order mismatch(success)
mockedUserTI = userTI.Clone()
Expand Down
3 changes: 2 additions & 1 deletion br/tests/br_full_cluster_restore/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,8 @@ restart_services
# mock incompatible manually
run_sql "alter table mysql.user add column xx int;"
run_br restore full --with-sys-table --log-file $br_log_file -s "local://$backup_dir" > $res_file 2>&1 || true
check_contains "the target cluster is not compatible with the backup data"
run_sql "select count(*) from mysql.user"
check_contains "count(*): 6"

echo "--> incompatible system table: less column on target cluster"
restart_services
Expand Down