Skip to content

Commit

Permalink
builtinbackup: log during restore as restore, not as backup (#16483)
Browse files Browse the repository at this point in the history
Signed-off-by: deepthi <[email protected]>
  • Loading branch information
deepthi authored Jul 26, 2024
1 parent 59408f9 commit 373cf34
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
2 changes: 1 addition & 1 deletion go/test/endtoend/backup/vtctlbackup/backup_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1032,7 +1032,7 @@ func verifySemiSyncStatus(t *testing.T, vttablet *cluster.Vttablet, expectedStat
}

func terminateBackup(t *testing.T, alias string) {
stopBackupMsg := "Done taking Backup"
stopBackupMsg := "Completed backing up"
if useXtrabackup {
stopBackupMsg = "Starting backup with"
useXtrabackup = false
Expand Down
16 changes: 10 additions & 6 deletions go/vt/mysqlctl/builtinbackupengine.go
Original file line number Diff line number Diff line change
Expand Up @@ -766,21 +766,25 @@ func (bp *backupPipe) HashString() string {
return hex.EncodeToString(bp.crc32.Sum(nil))
}

func (bp *backupPipe) ReportProgress(period time.Duration, logger logutil.Logger) {
func (bp *backupPipe) ReportProgress(period time.Duration, logger logutil.Logger, restore bool) {
messageStr := "restoring "
if !restore {
messageStr = "backing up "
}
tick := time.NewTicker(period)
defer tick.Stop()
for {
select {
case <-bp.done:
logger.Infof("Done taking Backup %q", bp.filename)
logger.Infof("Completed %s %q", messageStr, bp.filename)
return
case <-tick.C:
written := float64(atomic.LoadInt64(&bp.nn))
if bp.maxSize == 0 {
logger.Infof("Backup %q: %.02fkb", bp.filename, written/1024.0)
logger.Infof("%s %q: %.02fkb", messageStr, bp.filename, written/1024.0)
} else {
maxSize := float64(bp.maxSize)
logger.Infof("Backup %q: %.02f%% (%.02f/%.02fkb)", bp.filename, 100.0*written/maxSize, written/1024.0, maxSize/1024.0)
logger.Infof("%s %q: %.02f%% (%.02f/%.02fkb)", messageStr, bp.filename, 100.0*written/maxSize, written/1024.0, maxSize/1024.0)
}
}
}
Expand Down Expand Up @@ -813,7 +817,7 @@ func (be *BuiltinBackupEngine) backupFile(ctx context.Context, params BackupPara
}

br := newBackupReader(fe.Name, fi.Size(), timedSource)
go br.ReportProgress(builtinBackupProgress, params.Logger)
go br.ReportProgress(builtinBackupProgress, params.Logger, false /*restore*/)

// Open the destination file for writing, and a buffer.
params.Logger.Infof("Backing up file: %v", fe.Name)
Expand Down Expand Up @@ -1078,7 +1082,7 @@ func (be *BuiltinBackupEngine) restoreFile(ctx context.Context, params RestorePa
}()

br := newBackupReader(name, 0, timedSource)
go br.ReportProgress(builtinBackupProgress, params.Logger)
go br.ReportProgress(builtinBackupProgress, params.Logger, true /*restore*/)
var reader io.Reader = br

// Open the destination file for writing.
Expand Down

0 comments on commit 373cf34

Please sign in to comment.