Skip to content

Commit

Permalink
This is an automated cherry-pick of pingcap#56965
Browse files Browse the repository at this point in the history
Signed-off-by: ti-chi-bot <[email protected]>
  • Loading branch information
crazycs520 authored and ti-chi-bot committed Dec 3, 2024
1 parent bf0766b commit 4a0e420
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
2 changes: 1 addition & 1 deletion pkg/executor/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -405,7 +405,7 @@ func (e *DDLExec) executeRecoverTable(s *ast.RecoverTableStmt) error {
// Check the table ID was not exists.
tbl, ok := dom.InfoSchema().TableByID(tblInfo.ID)
if ok {
return infoschema.ErrTableExists.GenWithStack("Table '%-.192s' already been recover to '%-.192s', can't be recover repeatedly", s.Table.Name.O, tbl.Meta().Name.O)
return infoschema.ErrTableExists.GenWithStack("Table '%-.192s' already been recover to '%-.192s', can't be recover repeatedly", tblInfo.Name.O, tbl.Meta().Name.O)
}

m := domain.GetDomain(e.Ctx()).GetSnapshotMeta(job.StartTS)
Expand Down
25 changes: 25 additions & 0 deletions pkg/executor/recover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,23 @@ package executor_test
import (
"context"
"fmt"
<<<<<<< HEAD
=======
"strconv"
"sync"
>>>>>>> 474aed53cf0 (ddl: fix issue that recover table by job id may cause panic (#56965))
"testing"
"time"

"github.com/pingcap/failpoint"
ddlutil "github.com/pingcap/tidb/pkg/ddl/util"
"github.com/pingcap/tidb/pkg/errno"
"github.com/pingcap/tidb/pkg/infoschema"
<<<<<<< HEAD
=======
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/meta/model"
>>>>>>> 474aed53cf0 (ddl: fix issue that recover table by job id may cause panic (#56965))
"github.com/pingcap/tidb/pkg/parser/auth"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
"github.com/pingcap/tidb/pkg/testkit"
Expand Down Expand Up @@ -124,6 +134,21 @@ func TestRecoverTable(t *testing.T) {
err = tk.ExecToErr("recover table t_recover")
require.True(t, infoschema.ErrTableExists.Equal(err))

// Test drop table failed and then recover the table should also be failed.
tk.MustExec("drop table if exists t_recover2")
tk.MustExec("create table t_recover2 (a int);")
jobID := int64(0)
testfailpoint.EnableCall(t, "github.com/pingcap/tidb/pkg/ddl/onJobRunBefore", func(job *model.Job) {
if job.Type == model.ActionDropTable && jobID == 0 {
jobID = job.ID
}
})
tk.MustExec("drop table t_recover2")
tk.MustExec("recover table by job " + strconv.Itoa(int(jobID)))
err = tk.ExecToErr("recover table by job " + strconv.Itoa(int(jobID)))
require.Error(t, err)
require.Equal(t, "[schema:1050]Table 't_recover2' already been recover to 't_recover2', can't be recover repeatedly", err.Error())

gcEnable, err := gcutil.CheckGCEnable(tk.Session())
require.NoError(t, err)
require.False(t, gcEnable)
Expand Down

0 comments on commit 4a0e420

Please sign in to comment.