Skip to content

Commit ee79dac

Browse files
authored
br: fix integration test cases with --with-sys-table (#39655) (#39730)
close #39692
1 parent 8d97150 commit ee79dac

File tree

3 files changed

+35
-1
lines changed

3 files changed

+35
-1
lines changed

br/pkg/restore/client.go

+23
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,29 @@ func (rc *Client) CheckSysTableCompatibility(dom *domain.Domain, tables []*metau
988988
backupCol.Name, backupCol.FieldType.String())
989989
}
990990
}
991+
992+
if backupTi.Name.L == sysUserTableName {
993+
// check whether the columns of table in cluster are less than the backup data
994+
clusterColMap := make(map[string]*model.ColumnInfo)
995+
for i := range ti.Columns {
996+
col := ti.Columns[i]
997+
clusterColMap[col.Name.L] = col
998+
}
999+
// order can be different
1000+
for i := range backupTi.Columns {
1001+
col := backupTi.Columns[i]
1002+
clusterCol := clusterColMap[col.Name.L]
1003+
if clusterCol == nil {
1004+
log.Error("missing column in cluster data",
1005+
zap.Stringer("table", table.Info.Name),
1006+
zap.String("col", fmt.Sprintf("%s %s", col.Name, col.FieldType.String())))
1007+
return errors.Annotatef(berrors.ErrRestoreIncompatibleSys,
1008+
"missing column in cluster data, table: %s, col: %s %s",
1009+
table.Info.Name.O,
1010+
col.Name, col.FieldType.String())
1011+
}
1012+
}
1013+
}
9911014
}
9921015
return nil
9931016
}

br/pkg/restore/client_test.go

+10
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,16 @@ func TestCheckSysTableCompatibility(t *testing.T) {
203203
Info: mockedUserTI,
204204
}})
205205
require.NoError(t, err)
206+
userTI.Columns = userTI.Columns[:len(userTI.Columns)-1]
207+
208+
// user table in cluster have less columns(failed)
209+
mockedUserTI = userTI.Clone()
210+
mockedUserTI.Columns = append(mockedUserTI.Columns, &model.ColumnInfo{Name: model.NewCIStr("new-name")})
211+
err = client.CheckSysTableCompatibility(cluster.Domain, []*metautil.Table{{
212+
DB: tmpSysDB,
213+
Info: mockedUserTI,
214+
}})
215+
require.True(t, berrors.ErrRestoreIncompatibleSys.Equal(err))
206216

207217
// column order mismatch(success)
208218
mockedUserTI = userTI.Clone()

br/tests/br_full_cluster_restore/run.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,8 @@ restart_services
5555
# mock incompatible manually
5656
run_sql "alter table mysql.user add column xx int;"
5757
run_br restore full --with-sys-table --log-file $br_log_file -s "local://$backup_dir" > $res_file 2>&1 || true
58-
check_contains "the target cluster is not compatible with the backup data"
58+
run_sql "select count(*) from mysql.user"
59+
check_contains "count(*): 6"
5960

6061
echo "--> incompatible system table: less column on target cluster"
6162
restart_services

0 commit comments

Comments
 (0)