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

Manual cherry-pick of 13339 #13733

Merged
merged 3 commits into from
Aug 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
15 changes: 14 additions & 1 deletion go/test/endtoend/backup/vtctlbackup/backup_utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -446,7 +446,7 @@ func primaryBackup(t *testing.T) {
// Restore the older/first backup -- using the timestamp we saved -- on the original primary tablet (primary)
err = localCluster.VtctlclientProcess.ExecuteCommand("RestoreFromBackup", "--", "--backup_timestamp", firstBackupTimestamp, primary.Alias)
require.Nil(t, err)

verifyRestorePositionAndTimeStats(t, primary.VttabletProcess.GetVars())
// Re-init the shard -- making the original primary tablet (primary) primary again -- for subsequent tests
err = localCluster.VtctlclientProcess.InitShardPrimary(keyspaceName, shardName, cell, primary.TabletUID)
require.Nil(t, err)
Expand Down Expand Up @@ -1048,3 +1048,16 @@ func TestReplicaRestoreToPos(t *testing.T, restoreToPos mysql.Position, expectEr
}
require.NoErrorf(t, err, "output: %v", output)
}

func verifyRestorePositionAndTimeStats(t *testing.T, vars map[string]any) {
require.Contains(t, vars, "RestoredBackupTime")
backupTime := vars["RestoredBackupTime"].(string)
require.NotEqual(t, "", backupTime)

require.Contains(t, vars, "RestorePosition")
backupPosition := vars["RestorePosition"].(string)
require.NotEqual(t, "", backupPosition)
rp, err := mysql.DecodePosition(backupPosition)
require.NoError(t, err)
require.False(t, rp.IsZero())
}
15 changes: 15 additions & 0 deletions go/vt/vttablet/tabletmanager/restore.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import (
"io"
"time"

"vitess.io/vitess/go/stats"

"github.com/spf13/pflag"

"vitess.io/vitess/go/mysql"
Expand Down Expand Up @@ -52,8 +54,16 @@ var (
restoreFromBackupTsStr string
restoreConcurrency = 4
waitForBackupInterval time.Duration

statsRestoredBackupTime *stats.String
statsRestoreBackupPosition *stats.String
)

func init() {
statsRestoredBackupTime = stats.NewString("RestoredBackupTime")
statsRestoreBackupPosition = stats.NewString("RestorePosition")
}

func registerRestoreFlags(fs *pflag.FlagSet) {
fs.BoolVar(&restoreFromBackup, "restore_from_backup", restoreFromBackup, "(init restore parameter) will check BackupStorage for a recent backup at startup and start there")
fs.StringVar(&restoreFromBackupTsStr, "restore_from_backup_ts", restoreFromBackupTsStr, "(init restore parameter) if set, restore the latest backup taken at or before this timestamp. Example: '2021-04-29.133050'")
Expand Down Expand Up @@ -225,6 +235,11 @@ 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))
statsRestoredBackupTime.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