From edabc32d9238f17198a58cabfe01949802381fd8 Mon Sep 17 00:00:00 2001 From: MoCuishle28 <32541204+MoCuishle28@users.noreply.github.com> Date: Wed, 7 Dec 2022 18:48:05 +0800 Subject: [PATCH] br: fix integration test cases with `--with-sys-table` (#39655) close pingcap/tidb#39692 --- br/pkg/restore/client.go | 23 +++++++++++++++++++++++ br/pkg/restore/client_test.go | 10 ++++++++++ br/tests/br_full_cluster_restore/run.sh | 3 ++- 3 files changed, 35 insertions(+), 1 deletion(-) diff --git a/br/pkg/restore/client.go b/br/pkg/restore/client.go index 9e4e5a389b935..7b14c493710dc 100644 --- a/br/pkg/restore/client.go +++ b/br/pkg/restore/client.go @@ -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 } diff --git a/br/pkg/restore/client_test.go b/br/pkg/restore/client_test.go index e1f12ddbf7a1d..ae943a96f276b 100644 --- a/br/pkg/restore/client_test.go +++ b/br/pkg/restore/client_test.go @@ -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() diff --git a/br/tests/br_full_cluster_restore/run.sh b/br/tests/br_full_cluster_restore/run.sh index e75b4d49fc914..14074e61f3825 100644 --- a/br/tests/br_full_cluster_restore/run.sh +++ b/br/tests/br_full_cluster_restore/run.sh @@ -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