Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#55044
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
RidRisR authored and ti-chi-bot committed Feb 17, 2025
1 parent 84f6a9a commit 9744e52
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 0 deletions.
11 changes: 11 additions & 0 deletions br/pkg/task/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -884,7 +884,11 @@ func runSnapshotRestore(c context.Context, mgr *conn.Mgr, g glue.Glue, cmdName s
if cfg.WithSysTable {
client.InitFullClusterRestore(cfg.ExplicitFilter)
}
<<<<<<< HEAD
} else if client.IsFull() && checkpointFirstRun && cfg.CheckRequirements {
=======
} else if checkpointFirstRun && cfg.CheckRequirements {
>>>>>>> f47130249bb (br: Add pre-check of duplicate table in the downstream (#55044))
if err := checkTableExistence(ctx, mgr, tables, g); err != nil {
schedulersRemovable = true
return errors.Trace(err)
Expand Down Expand Up @@ -1323,6 +1327,13 @@ func Exhaust(ec <-chan error) []error {
}

func checkTableExistence(ctx context.Context, mgr *conn.Mgr, tables []*metautil.Table, g glue.Glue) error {
<<<<<<< HEAD
=======
// Tasks from br clp client use other checks to validate
if g.GetClient() != glue.ClientSql {
return nil
}
>>>>>>> f47130249bb (br: Add pre-check of duplicate table in the downstream (#55044))
message := "table already exists: "
allUnique := true
for _, table := range tables {
Expand Down
5 changes: 5 additions & 0 deletions tests/realtikvtest/brietest/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,11 @@ go_test(
"//pkg/executor",
"//pkg/parser/mysql",
"//pkg/session",
<<<<<<< HEAD
=======
"//pkg/sessionctx/binloginfo",
"//pkg/store/mockstore/mockcopr",
>>>>>>> f47130249bb (br: Add pre-check of duplicate table in the downstream (#55044))
"//pkg/testkit",
"//pkg/testkit/testsetup",
"//tests/realtikvtest",
Expand Down
19 changes: 19 additions & 0 deletions tests/realtikvtest/brietest/brie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,28 @@ func TestExistedTables(t *testing.T) {
sqlTmp := strings.ReplaceAll(tmp, "'", "''")
executor.ResetGlobalBRIEQueueForTest()
tk.MustExec("use test;")
<<<<<<< HEAD
for i := 0; i < 5; i++ {
=======
for i := 0; i < 10; i++ {
>>>>>>> f47130249bb (br: Add pre-check of duplicate table in the downstream (#55044))
tableName := fmt.Sprintf("foo%d", i)
tk.MustExec(fmt.Sprintf("create table %s(pk int primary key auto_increment, v varchar(255));", tableName))
tk.MustExec(fmt.Sprintf("insert into %s(v) values %s;", tableName, strings.TrimSuffix(strings.Repeat("('hello, world'),", 100), ",")))
}

<<<<<<< HEAD
// full backup
done := make(chan struct{})
go func() {
defer close(done)
backupQuery := fmt.Sprintf("BACKUP DATABASE * TO 'local://%s/full'", sqlTmp)
=======
done := make(chan struct{})
go func() {
defer close(done)
backupQuery := fmt.Sprintf("BACKUP DATABASE * TO 'local://%s'", sqlTmp)
>>>>>>> f47130249bb (br: Add pre-check of duplicate table in the downstream (#55044))
_ = tk.MustQuery(backupQuery)
}()
select {
Expand All @@ -160,7 +171,11 @@ func TestExistedTables(t *testing.T) {
done = make(chan struct{})
go func() {
defer close(done)
<<<<<<< HEAD
restoreQuery := fmt.Sprintf("RESTORE DATABASE * FROM 'local://%s/full'", sqlTmp)
=======
restoreQuery := fmt.Sprintf("RESTORE DATABASE * FROM 'local://%s'", sqlTmp)
>>>>>>> f47130249bb (br: Add pre-check of duplicate table in the downstream (#55044))
res, err := tk.Exec(restoreQuery)
require.NoError(t, err)

Expand All @@ -173,6 +188,7 @@ func TestExistedTables(t *testing.T) {
case <-done:
}

<<<<<<< HEAD
// db level backup
done = make(chan struct{})
go func() {
Expand Down Expand Up @@ -347,6 +363,9 @@ func TestExistedTablesOfIncremental_2(t *testing.T) {
_ = tk.MustQuery(restoreIncrementalQuery)

for i := 0; i < 5; i++ {
=======
for i := 0; i < 10; i++ {
>>>>>>> f47130249bb (br: Add pre-check of duplicate table in the downstream (#55044))
tableName := fmt.Sprintf("foo%d", i)
tk.MustExec(fmt.Sprintf("drop table %s;", tableName))
}
Expand Down

0 comments on commit 9744e52

Please sign in to comment.