Skip to content

Commit

Permalink
br: modify the column of Restore Statement (#36281)
Browse files Browse the repository at this point in the history
close #36142, close #37029
  • Loading branch information
MoCuishle28 authored Sep 22, 2022
1 parent e7d0c46 commit b84ea23
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 6 deletions.
3 changes: 2 additions & 1 deletion br/pkg/task/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -580,7 +580,8 @@ func RunRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
TTL: utils.DefaultBRGCSafePointTTL,
ID: utils.MakeSafePointID(),
}
g.Record("BackupTS", restoreTS)
g.Record("BackupTS", backupMeta.EndVersion)
g.Record("RestoreTS", restoreTS)

// restore checksum will check safe point with its start ts, see details at
// https://github.com/pingcap/tidb/blob/180c02127105bed73712050594da6ead4d70a85f/store/tikv/kv.go#L186-L190
Expand Down
17 changes: 14 additions & 3 deletions executor/brie.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@ type brieTaskInfo struct {
storage string
connID uint64
backupTS uint64
restoreTS uint64
archiveSize uint64
message string
}
Expand Down Expand Up @@ -411,9 +412,17 @@ func (e *BRIEExec) Next(ctx context.Context, req *chunk.Chunk) error {

req.AppendString(0, e.info.storage)
req.AppendUint64(1, e.info.archiveSize)
req.AppendUint64(2, e.info.backupTS)
req.AppendTime(3, e.info.queueTime)
req.AppendTime(4, e.info.execTime)
switch e.info.kind {
case ast.BRIEKindBackup:
req.AppendUint64(2, e.info.backupTS)
req.AppendTime(3, e.info.queueTime)
req.AppendTime(4, e.info.execTime)
case ast.BRIEKindRestore:
req.AppendUint64(2, e.info.backupTS)
req.AppendUint64(3, e.info.restoreTS)
req.AppendTime(4, e.info.queueTime)
req.AppendTime(5, e.info.execTime)
}
e.info = nil
return nil
}
Expand Down Expand Up @@ -569,6 +578,8 @@ func (gs *tidbGlueSession) Record(name string, value uint64) {
switch name {
case "BackupTS":
gs.info.backupTS = value
case "RestoreTS":
gs.info.restoreTS = value
case "Size":
gs.info.archiveSize = value
}
Expand Down
7 changes: 5 additions & 2 deletions planner/core/planbuilder.go
Original file line number Diff line number Diff line change
Expand Up @@ -2925,14 +2925,17 @@ func buildCancelDDLJobsFields() (*expression.Schema, types.NameSlice) {
return schema.col2Schema(), schema.names
}

func buildBRIESchema() (*expression.Schema, types.NameSlice) {
func buildBRIESchema(kind ast.BRIEKind) (*expression.Schema, types.NameSlice) {
longlongSize, _ := mysql.GetDefaultFieldLengthAndDecimal(mysql.TypeLonglong)
datetimeSize, _ := mysql.GetDefaultFieldLengthAndDecimal(mysql.TypeDatetime)

schema := newColumnsWithNames(5)
schema.Append(buildColumnWithName("", "Destination", mysql.TypeVarchar, 255))
schema.Append(buildColumnWithName("", "Size", mysql.TypeLonglong, longlongSize))
schema.Append(buildColumnWithName("", "BackupTS", mysql.TypeLonglong, longlongSize))
if kind == ast.BRIEKindRestore {
schema.Append(buildColumnWithName("", "Cluster TS", mysql.TypeLonglong, longlongSize))
}
schema.Append(buildColumnWithName("", "Queue Time", mysql.TypeDatetime, datetimeSize))
schema.Append(buildColumnWithName("", "Execution Time", mysql.TypeDatetime, datetimeSize))
return schema.col2Schema(), schema.names
Expand Down Expand Up @@ -3178,7 +3181,7 @@ func (b *PlanBuilder) buildSimple(ctx context.Context, node ast.StmtNode) (Plan,
return nil, err
}
case *ast.BRIEStmt:
p.setSchemaAndNames(buildBRIESchema())
p.setSchemaAndNames(buildBRIESchema(raw.Kind))
if raw.Kind == ast.BRIEKindRestore {
err := ErrSpecificAccessDenied.GenWithStackByArgs("SUPER or RESTORE_ADMIN")
b.visitInfo = appendDynamicVisitInfo(b.visitInfo, "RESTORE_ADMIN", false, err)
Expand Down

0 comments on commit b84ea23

Please sign in to comment.