Skip to content

Commit

Permalink
ddl: fix repeatedly recover table error (pingcap#16116)
Browse files Browse the repository at this point in the history
  • Loading branch information
crazycs520 authored Apr 8, 2020
1 parent eeac2eb commit dda190a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions executor/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,12 @@ func (e *DDLExec) executeRecoverTable(s *ast.RecoverTableStmt) error {
if err != nil {
return err
}
// 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)
}

autoIncID, autoRandID, err := e.getTableAutoIDsFromSnapshot(job)
if err != nil {
return err
Expand Down
6 changes: 6 additions & 0 deletions executor/executor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -4695,6 +4695,12 @@ func (s *testRecoverTable) TestRecoverTable(c *C) {
tk.MustExec("insert into t_recover values (10)")
tk.MustQuery("select * from t_recover;").Check(testkit.Rows("1", "7", "8", "9", "10"))

// Test for recover one table multiple time.
tk.MustExec("drop table t_recover")
tk.MustExec("flashback table t_recover to t_recover_tmp")
_, err = tk.Exec(fmt.Sprintf("recover table t_recover"))
c.Assert(infoschema.ErrTableExists.Equal(err), IsTrue)

gcEnable, err := gcutil.CheckGCEnable(tk.Se)
c.Assert(err, IsNil)
c.Assert(gcEnable, Equals, false)
Expand Down

0 comments on commit dda190a

Please sign in to comment.