Skip to content

Commit

Permalink
Add BackupPosition and BackupTime as metrics to vttablet
Browse files Browse the repository at this point in the history
Signed-off-by: Rohit Nayak <rohit@planetscale.com>
  • Loading branch information
rohit-nayak-ps committed Jun 17, 2023
1 parent 1b412e8 commit 3b4ea59
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 0 deletions.
16 changes: 16 additions & 0 deletions go/test/endtoend/backup/vtctlbackup/backup_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -1233,11 +1233,27 @@ func verifyTabletBackupStats(t *testing.T, vars map[string]any) {
if backupstorage.BackupStorageImplementation == "file" {
require.Contains(t, bd, "BackupStorage.File.File:Write")
}

}

func verifyRestorePositionAndTimeStats(t *testing.T, vars map[string]any) {
backupPosition := vars["RestorePosition"].(string)
backupTime := vars["RestoredBackupTime"].(string)
require.Contains(t, vars, "RestoredBackupTime")
require.Contains(t, vars, "RestorePosition")
require.NotEqual(t, "", backupPosition)
require.NotEqual(t, "", backupTime)
rp, err := mysql.DecodePosition(backupPosition)
require.NoError(t, err)
require.False(t, rp.IsZero())
}

func verifyTabletRestoreStats(t *testing.T, vars map[string]any) {
// Currently only the builtin backup engine instruments bytes-processed
// counts.

verifyRestorePositionAndTimeStats(t, vars)

if !useXtrabackup {
require.Contains(t, vars, "RestoreBytes")
bb := vars["RestoreBytes"].(map[string]any)
Expand Down
12 changes: 12 additions & 0 deletions go/vt/vttablet/tabletmanager/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ import (

"github.com/spf13/pflag"

"vitess.io/vitess/go/stats"

"vitess.io/vitess/go/mysql"
"vitess.io/vitess/go/vt/dbconfigs"
"vitess.io/vitess/go/vt/hook"
Expand Down Expand Up @@ -53,6 +55,9 @@ var (
restoreFromBackupTsStr string
restoreConcurrency = 4
waitForBackupInterval time.Duration

statsRestoreBackupTime *stats.String
statsRestoreBackupPosition *stats.String
)

func registerRestoreFlags(fs *pflag.FlagSet) {
Expand Down Expand Up @@ -93,6 +98,9 @@ func init() {

servenv.OnParseFor("vtcombo", registerPointInTimeRestoreFlags)
servenv.OnParseFor("vttablet", registerPointInTimeRestoreFlags)

statsRestoreBackupTime = stats.NewString("RestoredBackupTime")
statsRestoreBackupPosition = stats.NewString("RestorePosition")
}

// RestoreData is the main entry point for backup restore.
Expand Down Expand Up @@ -222,6 +230,10 @@ func (tm *TabletManager) restoreDataLocked(ctx context.Context, logger logutil.L
var backupManifest *mysqlctl.BackupManifest
for {
backupManifest, err = mysqlctl.Restore(ctx, params)
if backupManifest != nil {
statsRestoreBackupPosition.Set(mysql.EncodePosition(backupManifest.Position))
statsRestoreBackupTime.Set(backupManifest.BackupTime)
}
params.Logger.Infof("Restore: got a restore manifest: %v, err=%v, waitForBackupInterval=%v", backupManifest, err, waitForBackupInterval)
if waitForBackupInterval == 0 {
break
Expand Down

0 comments on commit 3b4ea59

Please sign in to comment.