From 038cb5799bfb3566e48285299916f79e3f00372f Mon Sep 17 00:00:00 2001 From: Rohit Nayak Date: Sat, 17 Jun 2023 16:53:26 +0000 Subject: [PATCH 1/2] Add BackupPosition and BackupTime as metrics to vttablet Signed-off-by: Rohit Nayak --- .../endtoend/backup/vtctlbackup/backup_utils.go | 16 ++++++++++++++++ go/vt/vttablet/tabletmanager/restore.go | 12 ++++++++++++ 2 files changed, 28 insertions(+) diff --git a/go/test/endtoend/backup/vtctlbackup/backup_utils.go b/go/test/endtoend/backup/vtctlbackup/backup_utils.go index 54c80749039..9767d6f6d4f 100644 --- a/go/test/endtoend/backup/vtctlbackup/backup_utils.go +++ b/go/test/endtoend/backup/vtctlbackup/backup_utils.go @@ -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) diff --git a/go/vt/vttablet/tabletmanager/restore.go b/go/vt/vttablet/tabletmanager/restore.go index c75de958328..833e19e9917 100644 --- a/go/vt/vttablet/tabletmanager/restore.go +++ b/go/vt/vttablet/tabletmanager/restore.go @@ -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" @@ -53,6 +55,9 @@ var ( restoreFromBackupTsStr string restoreConcurrency = 4 waitForBackupInterval time.Duration + + statsRestoreBackupTime *stats.String + statsRestoreBackupPosition *stats.String ) func registerRestoreFlags(fs *pflag.FlagSet) { @@ -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. @@ -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 From 90e59767580f4cba185bc61370ef219a078e3a77 Mon Sep 17 00:00:00 2001 From: deepthi Date: Wed, 21 Jun 2023 01:21:07 +0000 Subject: [PATCH 2/2] add to release notes Signed-off-by: deepthi --- changelog/16.0/16.0.0/release_notes.md | 6 ++++++ changelog/17.0/17.0.0/release_notes.md | 6 ++++++ 2 files changed, 12 insertions(+) diff --git a/changelog/16.0/16.0.0/release_notes.md b/changelog/16.0/16.0.0/release_notes.md index 729f192d54b..3de11f680bc 100644 --- a/changelog/16.0/16.0.0/release_notes.md +++ b/changelog/16.0/16.0.0/release_notes.md @@ -5,6 +5,7 @@ - **[Known Issues](#known-issues)** - [MySQL & Xtrabackup known issue](#mysql-xtrabackup-ddl) + - [VTTablet Restore Metrics](#vttablet-restore-metrics) - **[Major Changes](#major-changes)** - **[Breaking Changes](#breaking-changes)** - [VTGate Advertised MySQL Version](#advertised-mysql-version) @@ -100,6 +101,11 @@ or > ALTER TABLE your_table ENGINE=InnoDB; ``` +#### VTTablet Restore Metrics + +As part of the VTTablet Sidecar Schema Maintenance Refactor in v16.0.0, we dropped the `local_metadata` table from the sidecar database schema. This table was storing a couple of metrics related to restores from backup, which have now been lost. +They have been re-introduced in v17.0.0 as metrics that can be accessed from `/debug/vars`. + ## Major Changes ### Breaking Changes diff --git a/changelog/17.0/17.0.0/release_notes.md b/changelog/17.0/17.0.0/release_notes.md index d7abe7dce88..dc1809d5512 100644 --- a/changelog/17.0/17.0.0/release_notes.md +++ b/changelog/17.0/17.0.0/release_notes.md @@ -12,6 +12,7 @@ - [Shard name validation in TopoServer](#shard-name-validation) - [Compression CLI flags removed from vtctld and vtctldclient binaries](#remove-compression-flags-from-vtctld-binaries) - [VtctldClient command RestoreFromBackup will now use the correct context](#VtctldClient-RestoreFromBackup) + - [VTTablet Restore Metrics](#vttablet-restore-metrics) - **[New command line flags and behavior](#new-flag)** - [Builtin backup: read buffering flags](#builtin-backup-read-buffering-flags) - [Manifest backup external decompressor command](#manifest-backup-external-decompressor-command) @@ -132,6 +133,11 @@ Prior to v17, this asynchronous process could run indefinitely in the background this behavior was changed to use a context with a timeout of `action_timeout`. If you are using VtctldClient to initiate a restore, make sure you provide an appropriate value for action_timeout to give enough time for the restore process to complete. Otherwise, the restore will throw an error if the context expires before it completes. +#### VTTablet Restore Metrics + +As part of the VTTablet Sidecar Schema Maintenance Refactor in v16.0.0, we dropped the `local_metadata` table from the sidecar database schema. This table was storing a couple of metrics related to restores from backup. +They have now been re-introduced as metrics that can be accessed from `/debug/vars`. + ### Vttablet's transaction throttler now also throttles DML outside of `BEGIN; ...; COMMIT;` blocks Prior to v17, `vttablet`'s transaction throttler (enabled with `--enable-tx-throttler`) would only throttle requests done inside an explicit transaction, i.e., a `BEGIN; ...; COMMIT;` block.