Skip to content

Commit

Permalink
parser: let parser support flashback cluster (pingcap#37230)
Browse files Browse the repository at this point in the history
  • Loading branch information
Defined2014 authored Aug 19, 2022
1 parent 900870b commit 39cffe5
Show file tree
Hide file tree
Showing 7 changed files with 10,022 additions and 9,941 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/license-checker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ name: License checker
on:
push:
branches:
- master
- feature/flashback-cluster
pull_request:
branches:
- master
- feature/flashback-cluster

concurrency:
group: ${{ github.ref }}-${{ github.workflow }}
Expand Down
6 changes: 6 additions & 0 deletions executor/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,8 @@ func (e *DDLExec) Next(ctx context.Context, req *chunk.Chunk) (err error) {
err = e.executeRecoverTable(x)
case *ast.FlashBackTableStmt:
err = e.executeFlashbackTable(x)
case *ast.FlashBackClusterStmt:
err = e.executeFlashBackCluster(x)
case *ast.RenameTableStmt:
err = e.executeRenameTable(x)
case *ast.TruncateTableStmt:
Expand Down Expand Up @@ -514,6 +516,10 @@ func (e *DDLExec) getRecoverTableByTableName(tableName *ast.TableName) (*model.J
return jobInfo, tableInfo, nil
}

func (e *DDLExec) executeFlashBackCluster(s *ast.FlashBackClusterStmt) error {
return dbterror.ErrGeneralUnsupportedDDL.GenWithStackByArgs("FLASHBACK CLUSTER")
}

func (e *DDLExec) executeFlashbackTable(s *ast.FlashBackTableStmt) error {
job, tblInfo, err := e.getRecoverTableByTableName(s.Table)
if err != nil {
Expand Down
32 changes: 32 additions & 0 deletions parser/ast/ddl.go
Original file line number Diff line number Diff line change
Expand Up @@ -4038,6 +4038,38 @@ func (n *RecoverTableStmt) Accept(v Visitor) (Node, bool) {
return v.Leave(n)
}

// FlashBackClusterStmt is a statement to restore the cluster to the specified timestamp
type FlashBackClusterStmt struct {
ddlNode

AsOf AsOfClause
}

// Restore implements Node interface
func (n *FlashBackClusterStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord("FLASHBACK CLUSTER ")
if err := n.AsOf.Restore(ctx); err != nil {
return errors.Annotate(err, "An error occurred while splicing FlashBackClusterStmt.Asof")
}
return nil
}

// Accept implements Node Accept interface.
func (n *FlashBackClusterStmt) Accept(v Visitor) (Node, bool) {
newNode, skipChildren := v.Enter(n)
if skipChildren {
return v.Leave(newNode)
}

n = newNode.(*FlashBackClusterStmt)
node, ok := n.AsOf.Accept(v)
if !ok {
return n, false
}
n.AsOf = *node.(*AsOfClause)
return v.Leave(n)
}

// FlashBackTableStmt is a statement to restore a dropped/truncate table.
type FlashBackTableStmt struct {
ddlNode
Expand Down
1 change: 1 addition & 0 deletions parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,7 @@ var tokenMap = map[string]int{
"CLEANUP": cleanup,
"CLIENT": client,
"CLIENT_ERRORS_SUMMARY": clientErrorsSummary,
"CLUSTER": cluster,
"CLUSTERED": clustered,
"CMSKETCH": cmSketch,
"COALESCE": coalesce,
Expand Down
Loading

0 comments on commit 39cffe5

Please sign in to comment.