Skip to content

Commit

Permalink
parser: add parser support to PiTR (#42826)
Browse files Browse the repository at this point in the history
close #42825
  • Loading branch information
BornChanger authored Apr 10, 2023
1 parent 03b8605 commit 08085bc
Show file tree
Hide file tree
Showing 5 changed files with 10,485 additions and 10,019 deletions.
114 changes: 88 additions & 26 deletions parser/ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3116,22 +3116,38 @@ type BRIEOptionType uint16

const (
BRIEKindBackup BRIEKind = iota
BRIEKindCancelJob
BRIEKindStreamStart
BRIEKindStreamMetaData
BRIEKindStreamStatus
BRIEKindStreamPause
BRIEKindStreamResume
BRIEKindStreamStop
BRIEKindStreamPurge
BRIEKindRestore

BRIEKindRestorePIT
BRIEKindShowJob
BRIEKindShowQuery
BRIEKindShowBackupMeta
// common BRIE options
BRIEOptionRateLimit BRIEOptionType = iota + 1
BRIEOptionConcurrency
BRIEOptionChecksum
BRIEOptionSendCreds
BRIEOptionCheckpoint
BRIEOptionStartTS
BRIEOptionUntilTS
// backup options
BRIEOptionBackupTimeAgo
BRIEOptionBackupTS
BRIEOptionBackupTSO
BRIEOptionLastBackupTS
BRIEOptionLastBackupTSO
BRIEOptionGCTTL
// restore options
BRIEOptionOnline
BRIEOptionFullBackupStorage
BRIEOptionRestoredTS
// import options
BRIEOptionAnalyze
BRIEOptionBackend
Expand Down Expand Up @@ -3166,6 +3182,30 @@ func (kind BRIEKind) String() string {
return "BACKUP"
case BRIEKindRestore:
return "RESTORE"
case BRIEKindStreamStart:
return "BACKUP LOGS"
case BRIEKindStreamStop:
return "STOP BACKUP LOGS"
case BRIEKindStreamPause:
return "PAUSE BACKUP LOGS"
case BRIEKindStreamResume:
return "RESUME BACKUP LOGS"
case BRIEKindStreamStatus:
return "SHOW BACKUP LOGS STATUS"
case BRIEKindStreamMetaData:
return "SHOW BACKUP LOGS METADATA"
case BRIEKindStreamPurge:
return "PURGE BACKUP LOGS"
case BRIEKindRestorePIT:
return "RESTORE POINT"
case BRIEKindShowJob:
return "SHOW BR JOB"
case BRIEKindShowQuery:
return "SHOW BR JOB QUERY"
case BRIEKindCancelJob:
return "CANCEL BR JOB"
case BRIEKindShowBackupMeta:
return "SHOW BACKUP METADATA"
default:
return ""
}
Expand Down Expand Up @@ -3217,6 +3257,16 @@ func (kind BRIEOptionType) String() string {
return "CSV_SEPARATOR"
case BRIEOptionCSVTrimLastSeparators:
return "CSV_TRIM_LAST_SEPARATORS"
case BRIEOptionFullBackupStorage:
return "FULL_BACKUP_STORAGE"
case BRIEOptionRestoredTS:
return "RESTORED_TS"
case BRIEOptionStartTS:
return "START_TS"
case BRIEOptionUntilTS:
return "UNTIL_TS"
case BRIEOptionGCTTL:
return "GC_TTL"
default:
return ""
}
Expand Down Expand Up @@ -3245,7 +3295,7 @@ func (opt *BRIEOption) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord(opt.Tp.String())
ctx.WritePlain(" = ")
switch opt.Tp {
case BRIEOptionBackupTS, BRIEOptionLastBackupTS, BRIEOptionBackend, BRIEOptionOnDuplicate, BRIEOptionTiKVImporter, BRIEOptionCSVDelimiter, BRIEOptionCSVNull, BRIEOptionCSVSeparator:
case BRIEOptionBackupTS, BRIEOptionLastBackupTS, BRIEOptionBackend, BRIEOptionOnDuplicate, BRIEOptionTiKVImporter, BRIEOptionCSVDelimiter, BRIEOptionCSVNull, BRIEOptionCSVSeparator, BRIEOptionFullBackupStorage, BRIEOptionRestoredTS, BRIEOptionStartTS, BRIEOptionUntilTS, BRIEOptionGCTTL:
ctx.WriteString(opt.StrValue)
case BRIEOptionBackupTimeAgo:
ctx.WritePlainf("%d ", opt.UintValue/1000)
Expand Down Expand Up @@ -3278,6 +3328,7 @@ type BRIEStmt struct {
Schemas []string
Tables []*TableName
Storage string
JobID int64
Options []*BRIEOption
}

Expand All @@ -3300,37 +3351,48 @@ func (n *BRIEStmt) Accept(v Visitor) (Node, bool) {
func (n *BRIEStmt) Restore(ctx *format.RestoreCtx) error {
ctx.WriteKeyWord(n.Kind.String())

switch {
case len(n.Tables) != 0:
ctx.WriteKeyWord(" TABLE ")
for index, table := range n.Tables {
if index != 0 {
ctx.WritePlain(", ")
}
if err := table.Restore(ctx); err != nil {
return errors.Annotatef(err, "An error occurred while restore BRIEStmt.Tables[%d]", index)
switch n.Kind {
case BRIEKindRestore, BRIEKindBackup:
switch {
case len(n.Tables) != 0:
ctx.WriteKeyWord(" TABLE ")
for index, table := range n.Tables {
if index != 0 {
ctx.WritePlain(", ")
}
if err := table.Restore(ctx); err != nil {
return errors.Annotatef(err, "An error occurred while restore BRIEStmt.Tables[%d]", index)
}
}
}
case len(n.Schemas) != 0:
ctx.WriteKeyWord(" DATABASE ")
for index, schema := range n.Schemas {
if index != 0 {
ctx.WritePlain(", ")
case len(n.Schemas) != 0:
ctx.WriteKeyWord(" DATABASE ")
for index, schema := range n.Schemas {
if index != 0 {
ctx.WritePlain(", ")
}
ctx.WriteName(schema)
}
ctx.WriteName(schema)
default:
ctx.WriteKeyWord(" DATABASE")
ctx.WritePlain(" *")
}
default:
ctx.WriteKeyWord(" DATABASE")
ctx.WritePlain(" *")
}

switch n.Kind {
case BRIEKindBackup:
if n.Kind == BRIEKindBackup {
ctx.WriteKeyWord(" TO ")
ctx.WriteString(n.Storage)
} else {
ctx.WriteKeyWord(" FROM ")
ctx.WriteString(n.Storage)
}
case BRIEKindCancelJob, BRIEKindShowJob, BRIEKindShowQuery:
ctx.WritePlainf(" %d", n.JobID)
case BRIEKindStreamStart:
ctx.WriteKeyWord(" TO ")
case BRIEKindRestore:
ctx.WriteString(n.Storage)
case BRIEKindRestorePIT, BRIEKindStreamMetaData, BRIEKindShowBackupMeta, BRIEKindStreamPurge:
ctx.WriteKeyWord(" FROM ")
ctx.WriteString(n.Storage)
}
ctx.WriteString(n.Storage)

for _, opt := range n.Options {
ctx.WritePlain(" ")
Expand Down
8 changes: 8 additions & 0 deletions parser/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,7 @@ var tokenMap = map[string]int{
"BOOLEAN": booleanType,
"BOTH": both,
"BOUND": bound,
"BR": br,
"BRIEF": briefType,
"BTREE": btree,
"BUCKETS": buckets,
Expand Down Expand Up @@ -372,8 +373,10 @@ var tokenMap = map[string]int{
"FORMAT": format,
"FROM": from,
"FULL": full,
"FULL_BACKUP_STORAGE": fullBackupStorage,
"FULLTEXT": fulltext,
"FUNCTION": function,
"GC_TTL": gcTTL,
"GENERAL": general,
"GENERATED": generated,
"GET_FORMAT": getFormat,
Expand Down Expand Up @@ -495,6 +498,7 @@ var tokenMap = map[string]int{
"MEMORY": memory,
"MEMBER": member,
"MERGE": merge,
"METADATA": metadata,
"MICROSECOND": microsecond,
"MIN_ROWS": minRows,
"MIN": min,
Expand Down Expand Up @@ -567,6 +571,7 @@ var tokenMap = map[string]int{
"PLAN": plan,
"PLAN_CACHE": planCache,
"PLUGINS": plugins,
"POINT": point,
"POLICY": policy,
"POSITION": position,
"PRE_SPLIT_REGIONS": preSplitRegions,
Expand Down Expand Up @@ -624,6 +629,7 @@ var tokenMap = map[string]int{
"RESTART": restart,
"RESTORE": restore,
"RESTORES": restores,
"RESTORED_TS": restoredTS,
"RESTRICT": restrict,
"REVERSE": reverse,
"REVOKE": revoke,
Expand Down Expand Up @@ -699,6 +705,7 @@ var tokenMap = map[string]int{
"SSL": ssl,
"STALENESS": staleness,
"START": start,
"START_TS": startTS,
"STARTING": starting,
"STATISTICS": statistics,
"STATS_AUTO_RECALC": statsAutoRecalc,
Expand Down Expand Up @@ -801,6 +808,7 @@ var tokenMap = map[string]int{
"UNKNOWN": unknown,
"UNLOCK": unlock,
"UNSIGNED": unsigned,
"UNTIL_TS": untilTS,
"UPDATE": update,
"USAGE": usage,
"USE": use,
Expand Down
Loading

0 comments on commit 08085bc

Please sign in to comment.