Skip to content

Commit

Permalink
reuse snapshotMeta
Browse files Browse the repository at this point in the history
  • Loading branch information
lcwangchao committed Dec 16, 2021
1 parent 3336b37 commit 625e924
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions executor/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ import (
"github.com/pingcap/tidb/parser/mysql"
"github.com/pingcap/tidb/parser/terror"
"github.com/pingcap/tidb/planner/core"
"github.com/pingcap/tidb/sessionctx"
"github.com/pingcap/tidb/sessionctx/variable"
"github.com/pingcap/tidb/table"
"github.com/pingcap/tidb/table/temptable"
Expand Down Expand Up @@ -622,7 +621,7 @@ func (e *DDLExec) executeRecoverTable(s *ast.RecoverTableStmt) error {
return err
}

if tblInfo, err = recoverTablePlacement(e.ctx, job.StartTS, tblInfo); err != nil {
if tblInfo, err = recoverTablePlacement(m, tblInfo); err != nil {
return err
}

Expand All @@ -642,17 +641,13 @@ func (e *DDLExec) executeRecoverTable(s *ast.RecoverTableStmt) error {

// recoverTablePlacement is used when recover/flashback table.
// It will replace the placement policy of table with the direct options because the original policy may be deleted
func recoverTablePlacement(ctx sessionctx.Context, snapshotTS uint64, tblInfo *model.TableInfo) (*model.TableInfo, error) {
is, err := domain.GetDomain(ctx).GetSnapshotInfoSchema(snapshotTS)
if err != nil {
return nil, err
}

func recoverTablePlacement(snapshotMeta *meta.Meta, tblInfo *model.TableInfo) (*model.TableInfo, error) {
if ref := tblInfo.PlacementPolicyRef; ref != nil {
policy, ok := is.PolicyByName(ref.Name)
if !ok || policy.ID != ref.ID {
return nil, errors.Errorf("Cannot find policy with name '%s', ID: '%d'", ref.Name, ref.ID)
policy, err := snapshotMeta.GetPolicy(ref.ID)
if err != nil {
return nil, errors.Trace(err)
}

tblInfo.PlacementPolicyRef = nil
tblInfo.DirectPlacementOpts = policy.PlacementSettings
}
Expand All @@ -665,9 +660,9 @@ func recoverTablePlacement(ctx sessionctx.Context, snapshotTS uint64, tblInfo *m
continue
}

policy, ok := is.PolicyByName(ref.Name)
if !ok || policy.ID != ref.ID {
return nil, errors.Errorf("Cannot find policy with name '%s', ID: '%d'", ref.Name, ref.ID)
policy, err := snapshotMeta.GetPolicy(ref.ID)
if err != nil {
return nil, errors.Trace(err)
}

def.PlacementPolicyRef = nil
Expand Down Expand Up @@ -831,7 +826,7 @@ func (e *DDLExec) executeFlashbackTable(s *ast.FlashBackTableStmt) error {
return err
}

if tblInfo, err = recoverTablePlacement(e.ctx, job.StartTS, tblInfo); err != nil {
if tblInfo, err = recoverTablePlacement(m, tblInfo); err != nil {
return err
}

Expand Down

0 comments on commit 625e924

Please sign in to comment.