Skip to content

Commit

Permalink
br: fix integration test cases with --with-sys-table (#39655) (#39730)
Browse files Browse the repository at this point in the history
close #39692
  • Loading branch information
ti-chi-bot committed Dec 8, 2022
1 parent 8d97150 commit ee79dac
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 1 deletion.
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

0 comments on commit ee79dac

Please sign in to comment.