Skip to content

Commit cf48eff

Browse files
committed
roachtest: use set seed in backup/restore workloads
An issue we face today with test failures on our backup/restore roachtests is reproducibility, especially in failures relating to corruption. Part of that reason is that when running our workloads in our roundtrip tests, we do not set a seed for the workloads. This patch updates our backup/restore roachtests to match the workload's seed to the test run's seed. Epic: None Release note: None
1 parent 1e2b120 commit cf48eff

File tree

3 files changed

+29
-14
lines changed

3 files changed

+29
-14
lines changed

pkg/cmd/roachtest/tests/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,7 @@ go_library(
241241
"//pkg/cmd/roachtest/grafana",
242242
"//pkg/cmd/roachtest/option",
243243
"//pkg/cmd/roachtest/registry",
244+
"//pkg/cmd/roachtest/roachtestflags",
244245
"//pkg/cmd/roachtest/roachtestutil",
245246
"//pkg/cmd/roachtest/roachtestutil/clusterupgrade",
246247
"//pkg/cmd/roachtest/roachtestutil/mixedversion",

pkg/cmd/roachtest/tests/backup_restore_roundtrip.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ func backupRestoreRoundTrip(
157157

158158
dbs := []string{"bank", "tpcc", schemaChangeDB}
159159
d, runBackgroundWorkload, _, err := createDriversForBackupRestore(
160-
ctx, t, c, m, testRNG, testUtils, dbs,
160+
ctx, t, c, m, testRNG, seed, testUtils, dbs,
161161
)
162162
if err != nil {
163163
return err
@@ -243,6 +243,7 @@ func startBackgroundWorkloads(
243243
c cluster.Cluster,
244244
m cluster.Monitor,
245245
testRNG *rand.Rand,
246+
seed int64,
246247
roachNodes, workloadNode option.NodeListOption,
247248
testUtils *CommonTestUtils,
248249
dbs []string,
@@ -254,9 +255,9 @@ func startBackgroundWorkloads(
254255
if testUtils.mock {
255256
numWarehouses = 10
256257
}
257-
tpccInit, tpccRun := tpccWorkloadCmd(l, testRNG, numWarehouses, roachNodes)
258-
bankInit, bankRun := bankWorkloadCmd(l, testRNG, roachNodes, testUtils.mock)
259-
scInit, scRun := schemaChangeWorkloadCmd(l, testRNG, roachNodes, testUtils.mock)
258+
tpccInit, tpccRun := tpccWorkloadCmd(l, testRNG, seed, numWarehouses, roachNodes)
259+
bankInit, bankRun := bankWorkloadCmd(l, testRNG, seed, roachNodes, testUtils.mock)
260+
scInit, scRun := schemaChangeWorkloadCmd(l, testRNG, seed, roachNodes, testUtils.mock)
260261
if err := prepSchemaChangeWorkload(ctx, workloadNode, testUtils, testRNG); err != nil {
261262
return nil, err
262263
}
@@ -420,11 +421,12 @@ func createDriversForBackupRestore(
420421
c cluster.Cluster,
421422
m cluster.Monitor,
422423
rng *rand.Rand,
424+
seed int64,
423425
testUtils *CommonTestUtils,
424426
dbs []string,
425427
) (*BackupRestoreTestDriver, func() (func(), error), [][]string, error) {
426428
runBackgroundWorkload, err := startBackgroundWorkloads(
427-
ctx, t.L(), c, m, rng, c.CRDBNodes(), c.WorkloadNode(), testUtils, dbs,
429+
ctx, t.L(), c, m, rng, seed, c.CRDBNodes(), c.WorkloadNode(), testUtils, dbs,
428430
)
429431
if err != nil {
430432
return nil, nil, nil, err
@@ -460,7 +462,7 @@ func testOnlineRestoreRecovery(ctx context.Context, t test.Test, c cluster.Clust
460462

461463
dbs := []string{"bank", "tpcc", schemaChangeDB}
462464
d, runBackgroundWorkload, _, err := createDriversForBackupRestore(
463-
ctx, t, c, m, testRNG, testUtils, dbs,
465+
ctx, t, c, m, testRNG, seed, testUtils, dbs,
464466
)
465467
if err != nil {
466468
return err

pkg/cmd/roachtest/tests/mixed_version_backup.go

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/cluster"
3131
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/option"
3232
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/registry"
33+
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/roachtestflags"
3334
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/roachtestutil"
3435
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/roachtestutil/clusterupgrade"
3536
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/roachtestutil/mixedversion"
@@ -2950,8 +2951,8 @@ func registerBackupMixedVersion(r registry.Registry) {
29502951
// for the cluster used in this test without overloading it,
29512952
// which can make the backups take much longer to finish.
29522953
const numWarehouses = 100
2953-
bankInit, bankRun := bankWorkloadCmd(t.L(), testRNG, c.CRDBNodes(), false)
2954-
tpccInit, tpccRun := tpccWorkloadCmd(t.L(), testRNG, numWarehouses, c.CRDBNodes())
2954+
bankInit, bankRun := bankWorkloadCmd(t.L(), testRNG, roachtestflags.GlobalSeed, c.CRDBNodes(), false)
2955+
tpccInit, tpccRun := tpccWorkloadCmd(t.L(), testRNG, roachtestflags.GlobalSeed, numWarehouses, c.CRDBNodes())
29552956

29562957
mvt.OnStartup("set short job interval", backupTest.setShortJobIntervals)
29572958
mvt.OnStartup("take backup in previous version", backupTest.maybeTakePreviousVersionBackup)
@@ -2989,23 +2990,29 @@ func registerBackupMixedVersion(r registry.Registry) {
29892990
}
29902991

29912992
func tpccWorkloadCmd(
2992-
l *logger.Logger, testRNG *rand.Rand, numWarehouses int, roachNodes option.NodeListOption,
2993+
l *logger.Logger,
2994+
testRNG *rand.Rand,
2995+
seed int64,
2996+
numWarehouses int,
2997+
roachNodes option.NodeListOption,
29932998
) (init *roachtestutil.Command, run *roachtestutil.Command) {
29942999
init = roachtestutil.NewCommand("./cockroach workload init tpcc").
29953000
MaybeOption(testRNG.Intn(2) == 0, "families").
29963001
Arg("{pgurl%s}", roachNodes).
2997-
Flag("warehouses", numWarehouses)
3002+
Flag("warehouses", numWarehouses).
3003+
MaybeFlag(seed != 0, "seed", seed)
29983004
run = roachtestutil.NewCommand("./cockroach workload run tpcc").
29993005
Arg("{pgurl%s}", roachNodes).
30003006
Flag("warehouses", numWarehouses).
3007+
MaybeFlag(seed != 0, "seed", seed).
30013008
Option("tolerate-errors")
30023009
l.Printf("tpcc init: %s", init)
30033010
l.Printf("tpcc run: %s", run)
30043011
return init, run
30053012
}
30063013

30073014
func bankWorkloadCmd(
3008-
l *logger.Logger, testRNG *rand.Rand, roachNodes option.NodeListOption, mock bool,
3015+
l *logger.Logger, testRNG *rand.Rand, seed int64, roachNodes option.NodeListOption, mock bool,
30093016
) (init *roachtestutil.Command, run *roachtestutil.Command) {
30103017
bankRows := bankPossibleRows[testRNG.Intn(len(bankPossibleRows))]
30113018
possiblePayloads := bankPossiblePayloadBytes
@@ -3024,31 +3031,36 @@ func bankWorkloadCmd(
30243031
init = roachtestutil.NewCommand("./cockroach workload init bank").
30253032
Flag("rows", bankRows).
30263033
MaybeFlag(bankPayload != 0, "payload-bytes", bankPayload).
3034+
MaybeFlag(seed != 0, "seed", seed).
30273035
Flag("ranges", 0).
30283036
Arg("{pgurl%s}", roachNodes)
30293037
run = roachtestutil.NewCommand("./cockroach workload run bank").
30303038
Arg("{pgurl%s}", roachNodes).
3039+
MaybeFlag(seed != 0, "seed", seed).
30313040
Option("tolerate-errors")
30323041
l.Printf("bank init: %s", init)
30333042
l.Printf("bank run: %s", run)
30343043
return init, run
30353044
}
30363045

30373046
func schemaChangeWorkloadCmd(
3038-
l *logger.Logger, testRNG *rand.Rand, roachNodes option.NodeListOption, mock bool,
3047+
l *logger.Logger, testRNG *rand.Rand, seed int64, roachNodes option.NodeListOption, mock bool,
30393048
) (init *roachtestutil.Command, run *roachtestutil.Command) {
30403049
maxOps := 1000
30413050
concurrency := 5
30423051
if mock {
30433052
maxOps = 10
30443053
concurrency = 2
30453054
}
3046-
initCmd := roachtestutil.NewCommand("./workload init schemachange").
3055+
if seed == 0 {
3056+
seed = testRNG.Int63()
3057+
}
3058+
initCmd := roachtestutil.NewCommand("COCKROACH_RANDOM_SEED=%d ./workload init schemachange", seed).
30473059
Arg("{pgurl%s}", roachNodes)
30483060
// TODO (msbutler): ideally we'd use the `db` flag to explicitly set the
30493061
// database, but it is currently broken:
30503062
// https://github.com/cockroachdb/cockroach/issues/115545
3051-
runCmd := roachtestutil.NewCommand("COCKROACH_RANDOM_SEED=%d ./workload run schemachange", testRNG.Int63()).
3063+
runCmd := roachtestutil.NewCommand("COCKROACH_RANDOM_SEED=%d ./workload run schemachange", seed).
30523064
Flag("verbose", 1).
30533065
Flag("max-ops", maxOps).
30543066
Flag("concurrency", concurrency).

0 commit comments

Comments
 (0)