Skip to content

Commit

Permalink
roachtest: add backup-restore/online-restore test
Browse files Browse the repository at this point in the history
This patch adds a new variant of the backup-restore roundtrip framework which
only runs online restore. Due to OR limitations, this test never runs
incremental backups, revision history backups, or encrypted backups.

Epic: none

Release note: none
  • Loading branch information
msbutler committed Apr 25, 2024
1 parent d772813 commit 3cc66c0
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 17 deletions.
9 changes: 8 additions & 1 deletion pkg/cmd/roachtest/tests/backup_restore_roundtrip.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ const numFullBackups = 5
type roundTripSpecs struct {
name string
metamorphicRangeSize bool
onlineRestore bool
mock bool
skip string
}
Expand All @@ -65,6 +66,12 @@ func registerBackupRestoreRoundTrip(r registry.Registry) {
name: "backup-restore/small-ranges",
metamorphicRangeSize: true,
},
{
name: "backup-restore/online-restore",
metamorphicRangeSize: false,
onlineRestore: true,
skip: "it fails consistently",
},
{
name: "backup-restore/mock",
mock: true,
Expand Down Expand Up @@ -115,7 +122,7 @@ func backupRestoreRoundTrip(
m := c.NewMonitor(ctx, roachNodes)

m.Go(func(ctx context.Context) error {
testUtils, err := newCommonTestUtils(ctx, t, c, roachNodes, sp.mock)
testUtils, err := newCommonTestUtils(ctx, t, c, roachNodes, sp.mock, sp.onlineRestore)
if err != nil {
return err
}
Expand Down
44 changes: 29 additions & 15 deletions pkg/cmd/roachtest/tests/mixed_version_backup.go
Original file line number Diff line number Diff line change
Expand Up @@ -467,10 +467,11 @@ func (ep encryptionPassphrase) String() string {
// newBackupOptions returns a list of backup options to be used when
// creating a new backup. Each backup option has a 50% chance of being
// included.
func newBackupOptions(rng *rand.Rand) []backupOption {
possibleOpts := []backupOption{
revisionHistory{},
newEncryptionPassphrase(rng),
func newBackupOptions(rng *rand.Rand, onlineRestoreExpected bool) []backupOption {
possibleOpts := []backupOption{}
if !onlineRestoreExpected {
possibleOpts = append(possibleOpts, revisionHistory{})
possibleOpts = append(possibleOpts, newEncryptionPassphrase(rng))
}

var options []backupOption
Expand Down Expand Up @@ -1788,7 +1789,7 @@ func (d *BackupRestoreTestDriver) runBackup(
case fullBackup:
btype := d.newBackupScope(rng)
name := d.backupCollectionName(d.nextBackupID(), b.namePrefix, btype)
createOptions := newBackupOptions(rng)
createOptions := newBackupOptions(rng, d.testUtils.onlineRestore)
collection = newBackupCollection(name, btype, createOptions, d.cluster.IsLocal())
l.Printf("creating full backup for %s", collection.name)
case incrementalBackup:
Expand Down Expand Up @@ -1953,6 +1954,9 @@ func (d *BackupRestoreTestDriver) createBackupCollection(
if d.testUtils.mock {
numIncrementals = 1
}
if d.testUtils.onlineRestore {
numIncrementals = 0
}
l.Printf("creating %d incremental backups", numIncrementals)
for i := 0; i < numIncrementals; i++ {
d.randomWait(l, rng)
Expand Down Expand Up @@ -2243,6 +2247,9 @@ func (bc *backupCollection) verifyBackupCollection(
if opt := bc.encryptionOption(); opt != nil {
restoreOptions = append(restoreOptions, opt.String())
}
if d.testUtils.onlineRestore {
restoreOptions = append(restoreOptions, "experimental deferred copy")
}

var optionsStr string
if len(restoreOptions) > 0 {
Expand Down Expand Up @@ -2637,10 +2644,11 @@ func prepSchemaChangeWorkload(
}

type CommonTestUtils struct {
t test.Test
cluster cluster.Cluster
roachNodes option.NodeListOption
mock bool
t test.Test
cluster cluster.Cluster
roachNodes option.NodeListOption
mock bool
onlineRestore bool

connCache struct {
mu syncutil.Mutex
Expand All @@ -2652,7 +2660,12 @@ type CommonTestUtils struct {
// and puts these connections in a cache for reuse. The caller should remember to close all connections
// once done with them to prevent any goroutine leaks (CloseConnections).
func newCommonTestUtils(
ctx context.Context, t test.Test, c cluster.Cluster, nodes option.NodeListOption, mock bool,
ctx context.Context,
t test.Test,
c cluster.Cluster,
nodes option.NodeListOption,
mock bool,
onlineRestore bool,
) (*CommonTestUtils, error) {
cc := make([]*gosql.DB, len(nodes))
for _, node := range nodes {
Expand All @@ -2669,10 +2682,11 @@ func newCommonTestUtils(
}

u := &CommonTestUtils{
t: t,
cluster: c,
roachNodes: nodes,
mock: mock,
t: t,
cluster: c,
roachNodes: nodes,
mock: mock,
onlineRestore: onlineRestore,
}
u.connCache.cache = cc
return u, nil
Expand All @@ -2681,7 +2695,7 @@ func newCommonTestUtils(
func (mvb *mixedVersionBackup) CommonTestUtils(ctx context.Context) (*CommonTestUtils, error) {
var err error
mvb.utilsOnce.Do(func() {
mvb.commonTestUtils, err = newCommonTestUtils(ctx, mvb.t, mvb.cluster, mvb.roachNodes, false)
mvb.commonTestUtils, err = newCommonTestUtils(ctx, mvb.t, mvb.cluster, mvb.roachNodes, false, false)
})
return mvb.commonTestUtils, err
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func executeSupportedDDLs(
nodes = helper.Context.NodesInPreviousVersion() // N.B. this is the set of oldNodes.
}
}
testUtils, err := newCommonTestUtils(ctx, t, c, helper.Context.CockroachNodes, false)
testUtils, err := newCommonTestUtils(ctx, t, c, helper.Context.CockroachNodes, false, false)
defer testUtils.CloseConnections()
if err != nil {
return err
Expand Down

0 comments on commit 3cc66c0

Please sign in to comment.