Skip to content

Commit 4a0e420

Browse files
crazycs520ti-chi-bot
authored andcommitted
This is an automated cherry-pick of pingcap#56965
Signed-off-by: ti-chi-bot <[email protected]>
1 parent bf0766b commit 4a0e420

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

pkg/executor/ddl.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -405,7 +405,7 @@ func (e *DDLExec) executeRecoverTable(s *ast.RecoverTableStmt) error {
405405
// Check the table ID was not exists.
406406
tbl, ok := dom.InfoSchema().TableByID(tblInfo.ID)
407407
if ok {
408-
return infoschema.ErrTableExists.GenWithStack("Table '%-.192s' already been recover to '%-.192s', can't be recover repeatedly", s.Table.Name.O, tbl.Meta().Name.O)
408+
return infoschema.ErrTableExists.GenWithStack("Table '%-.192s' already been recover to '%-.192s', can't be recover repeatedly", tblInfo.Name.O, tbl.Meta().Name.O)
409409
}
410410

411411
m := domain.GetDomain(e.Ctx()).GetSnapshotMeta(job.StartTS)

pkg/executor/recover_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,23 @@ package executor_test
1717
import (
1818
"context"
1919
"fmt"
20+
<<<<<<< HEAD
21+
=======
22+
"strconv"
23+
"sync"
24+
>>>>>>> 474aed53cf0 (ddl: fix issue that recover table by job id may cause panic (#56965))
2025
"testing"
2126
"time"
2227

2328
"github.com/pingcap/failpoint"
2429
ddlutil "github.com/pingcap/tidb/pkg/ddl/util"
2530
"github.com/pingcap/tidb/pkg/errno"
2631
"github.com/pingcap/tidb/pkg/infoschema"
32+
<<<<<<< HEAD
33+
=======
34+
"github.com/pingcap/tidb/pkg/kv"
35+
"github.com/pingcap/tidb/pkg/meta/model"
36+
>>>>>>> 474aed53cf0 (ddl: fix issue that recover table by job id may cause panic (#56965))
2737
"github.com/pingcap/tidb/pkg/parser/auth"
2838
"github.com/pingcap/tidb/pkg/sessionctx/variable"
2939
"github.com/pingcap/tidb/pkg/testkit"
@@ -124,6 +134,21 @@ func TestRecoverTable(t *testing.T) {
124134
err = tk.ExecToErr("recover table t_recover")
125135
require.True(t, infoschema.ErrTableExists.Equal(err))
126136

137+
// Test drop table failed and then recover the table should also be failed.
138+
tk.MustExec("drop table if exists t_recover2")
139+
tk.MustExec("create table t_recover2 (a int);")
140+
jobID := int64(0)
141+
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/onJobRunBefore", func(job *model.Job) {
142+
if job.Type == model.ActionDropTable && jobID == 0 {
143+
jobID = job.ID
144+
}
145+
})
146+
tk.MustExec("drop table t_recover2")
147+
tk.MustExec("recover table by job " + strconv.Itoa(int(jobID)))
148+
err = tk.ExecToErr("recover table by job " + strconv.Itoa(int(jobID)))
149+
require.Error(t, err)
150+
require.Equal(t, "[schema:1050]Table 't_recover2' already been recover to 't_recover2', can't be recover repeatedly", err.Error())
151+
127152
gcEnable, err := gcutil.CheckGCEnable(tk.Session())
128153
require.NoError(t, err)
129154
require.False(t, gcEnable)

0 commit comments

Comments
 (0)