Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pkg/executor/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -414,7 +414,7 @@ func (e *DDLExec) executeRecoverTable(s *ast.RecoverTableStmt) error {
// Check the table ID was not exists.
tbl, ok := dom.InfoSchema().TableByID(context.Background(), 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
17 changes: 17 additions & 0 deletions pkg/executor/recover_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ package executor_test
import (
"context"
"fmt"
"strconv"
"sync"
"testing"
"time"
Expand All @@ -26,6 +27,7 @@ import (
"github.com/pingcap/tidb/pkg/errno"
"github.com/pingcap/tidb/pkg/infoschema"
"github.com/pingcap/tidb/pkg/kv"
"github.com/pingcap/tidb/pkg/meta/model"
"github.com/pingcap/tidb/pkg/parser/auth"
"github.com/pingcap/tidb/pkg/sessionctx/variable"
"github.com/pingcap/tidb/pkg/store/mockstore"
Expand Down Expand Up @@ -130,6 +132,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