Skip to content

Commit

Permalink
glue,task: let the tasks inform the glue about the BackupTS and Size. (
Browse files Browse the repository at this point in the history
  • Loading branch information
kennytm authored and 3pointer committed Jun 23, 2020
1 parent e288e6b commit 547c245
Show file tree
Hide file tree
Showing 9 changed files with 33 additions and 2 deletions.
5 changes: 5 additions & 0 deletions pkg/backup/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -859,6 +859,11 @@ func (bc *Client) ChecksumMatches(local []Checksum) (bool, error) {
return true, nil
}

// ArchiveSize returns the total size of the archive (before encryption)
func (bc *Client) ArchiveSize() uint64 {
return utils.ArchiveSize(&bc.backupMeta)
}

// CollectFileInfo collects ungrouped file summary information, like kv count and size.
func (bc *Client) CollectFileInfo() {
for _, file := range bc.backupMeta.Files {
Expand Down
3 changes: 3 additions & 0 deletions pkg/glue/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ type Glue interface {
OwnsStorage() bool

StartProgress(ctx context.Context, cmdName string, total int64, redirectLog bool) Progress

// Record records some information useful for log-less summary.
Record(name string, value uint64)
}

// Session is an abstraction of the session.Session interface.
Expand Down
6 changes: 5 additions & 1 deletion pkg/gluetidb/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,11 @@ func (g Glue) StartProgress(ctx context.Context, cmdName string, total int64, re
return g.tikvGlue.StartProgress(ctx, cmdName, total, redirectLog)
}

// Execute implements glue.Session.
// Record implements glue.Glue
func (g Glue) Record(name string, value uint64) {
g.tikvGlue.Record(name, value)
}

func (gs *tidbSession) Execute(ctx context.Context, sql string) error {
_, err := gs.se.Execute(ctx, sql)
return err
Expand Down
3 changes: 3 additions & 0 deletions pkg/gluetikv/glue.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ func (Glue) StartProgress(ctx context.Context, cmdName string, total int64, redi
return progress{ch: utils.StartProgress(ctx, cmdName, total, redirectLog)}
}

// Record implements glue.Glue
func (Glue) Record(string, uint64) {}

type progress struct {
ch chan<- struct{}
}
Expand Down
3 changes: 3 additions & 0 deletions pkg/task/backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func RunBackup(c context.Context, g glue.Glue, cmdName string, cfg *BackupConfig
if err != nil {
return err
}
g.Record("BackupTS", backupTS)

ranges, backupSchemas, err := backup.BuildBackupRangeAndSchema(
mgr.GetDomain(), mgr.GetTiKV(), tableFilter, backupTS)
Expand Down Expand Up @@ -232,6 +233,8 @@ func RunBackup(c context.Context, g glue.Glue, cmdName string, cfg *BackupConfig
return err
}

g.Record("Size", client.ArchiveSize())

// Set task summary to success status.
summary.SetSuccessStatus(true)
return nil
Expand Down
2 changes: 2 additions & 0 deletions pkg/task/backup_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,8 @@ func RunBackupRaw(c context.Context, g glue.Glue, cmdName string, cfg *RawKvConf
return err
}

g.Record("Size", client.ArchiveSize())

// Set task summary to success status.
summary.SetSuccessStatus(true)
return nil
Expand Down
1 change: 1 addition & 0 deletions pkg/task/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func RunRestore(c context.Context, g glue.Glue, cmdName string, cfg *RestoreConf
if err != nil {
return err
}
g.Record("Size", utils.ArchiveSize(backupMeta))
if err = client.InitBackupMeta(backupMeta, u); err != nil {
return err
}
Expand Down
1 change: 1 addition & 0 deletions pkg/task/restore_raw.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ func RunRestoreRaw(c context.Context, g glue.Glue, cmdName string, cfg *RestoreR
if err != nil {
return err
}
g.Record("Size", utils.ArchiveSize(backupMeta))
if err = client.InitBackupMeta(backupMeta, u); err != nil {
return err
}
Expand Down
11 changes: 10 additions & 1 deletion pkg/utils/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,16 @@ func LoadBackupTables(meta *backup.BackupMeta) (map[string]*Database, error) {
return databases, nil
}

// EncloseName formats name in sql.
// ArchiveSize returns the total size of the backup archive.
func ArchiveSize(meta *backup.BackupMeta) uint64 {
total := uint64(meta.Size())
for _, file := range meta.Files {
total += file.Size_
}
return total
}

// EncloseName formats name in sql
func EncloseName(name string) string {
return "`" + strings.ReplaceAll(name, "`", "``") + "`"
}

0 comments on commit 547c245

Please sign in to comment.