Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

parser: add parser support to PiTR #42826

Merged
merged 9 commits into from
Apr 10, 2023
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
114 changes: 88 additions & 26 deletions parser/ast/misc.go
Original file line number Diff line number Diff line change
Expand Up @@ -3107,22 +3107,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 @@ -3157,6 +3173,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 @@ -3208,6 +3248,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 @@ -3236,7 +3286,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 @@ -3269,6 +3319,7 @@ type BRIEStmt struct {
Schemas []string
Tables []*TableName
Storage string
JobID int64
Options []*BRIEOption
}

Expand All @@ -3291,37 +3342,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 @@ -192,6 +192,7 @@ var tokenMap = map[string]int{
"BOOLEAN": booleanType,
"BOTH": both,
"BOUND": bound,
"BR": br,
"BRIEF": briefType,
"BTREE": btree,
"BUCKETS": buckets,
Expand Down Expand Up @@ -362,8 +363,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 @@ -485,6 +488,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 @@ -557,6 +561,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 @@ -614,6 +619,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 @@ -689,6 +695,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 @@ -791,6 +798,7 @@ var tokenMap = map[string]int{
"UNKNOWN": unknown,
"UNLOCK": unlock,
"UNSIGNED": unsigned,
"UNTIL_TS": untilTS,
"UPDATE": update,
"USAGE": usage,
"USE": use,
Expand Down
Loading