Skip to content

Commit

Permalink
Add RestorePosition and RestoredBackupTime as metrics to vttablet (#1…
Browse files Browse the repository at this point in the history
…3339)

* Add BackupPosition and BackupTime as metrics to vttablet

Signed-off-by: Rohit Nayak <rohit@planetscale.com>

* add to release notes

Signed-off-by: deepthi <deepthi@planetscale.com>

---------

Signed-off-by: Rohit Nayak <rohit@planetscale.com>
Signed-off-by: deepthi <deepthi@planetscale.com>
Co-authored-by: deepthi <deepthi@planetscale.com>
Signed-off-by: Florent Poinsard <florent.poinsard@outlook.fr>
  • Loading branch information
2 people authored and frouioui committed Jun 23, 2023
1 parent 44dcb9f commit 1257833
Show file tree
Hide file tree
Showing 4 changed files with 40 additions and 0 deletions.
6 changes: 6 additions & 0 deletions changelog/16.0/16.0.0/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -100,6 +101,11 @@ or
> ALTER TABLE your_table ENGINE=InnoDB;
```

#### <a id="vttablet-restore-metrics">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`.

## <a id="major-changes"/>Major Changes

### <a id="breaking-changes"/>Breaking Changes
Expand Down
6 changes: 6 additions & 0 deletions changelog/17.0/17.0.0/release_notes.md
Original file line number Diff line number Diff line change
Expand Up @@ -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-command-restorefrombackup-will-now-use-the-correct-context)
- [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)
Expand Down Expand Up @@ -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.

#### <a id="vttablet-restore-metrics">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`.

### <a id="Vttablet-TxThrottler">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.
Expand Down
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 1257833

Please sign in to comment.