Skip to content

Commit bd31724

Browse files
committed
roachtest: ensure backup-restore workloads get positive seed
As of #153615, the seed passed to the workloads could be a negative integer, but the workload command cannot take a negative seed, causing the workload and the test to fail. This patch ensures negative seeds aren't passed to workloads. Fixes #152498 Release note: none
1 parent 1c99d43 commit bd31724

File tree

3 files changed

+14
-8
lines changed

3 files changed

+14
-8
lines changed

pkg/cmd/roachtest/tests/BUILD.bazel

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,6 @@ go_library(
241241
"//pkg/cmd/roachtest/grafana",
242242
"//pkg/cmd/roachtest/option",
243243
"//pkg/cmd/roachtest/registry",
244-
"//pkg/cmd/roachtest/roachtestflags",
245244
"//pkg/cmd/roachtest/roachtestutil",
246245
"//pkg/cmd/roachtest/roachtestutil/clusterupgrade",
247246
"//pkg/cmd/roachtest/roachtestutil/mixedversion",

pkg/cmd/roachtest/tests/backup_restore_roundtrip.go

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,11 @@ func backupRestoreRoundTrip(
134134
) {
135135
pauseProbability := 0.2
136136
testRNG, seed := randutil.NewLockedPseudoRand()
137-
t.L().Printf("random seed: %d", seed)
137+
138+
// Workload can only take a positive int as a seed, but seed could be a
139+
// negative int. Ensure the seed passed to workload is an int.
140+
workloadSeed := testRNG.Int63()
141+
t.L().Printf("random seed: %d; workload seed: %d", seed, workloadSeed)
138142

139143
envOption := install.EnvOption([]string{
140144
"COCKROACH_MIN_RANGE_MAX_BYTES=1",
@@ -157,7 +161,7 @@ func backupRestoreRoundTrip(
157161

158162
dbs := []string{"bank", "tpcc", schemaChangeDB}
159163
d, runBackgroundWorkload, _, err := createDriversForBackupRestore(
160-
ctx, t, c, m, testRNG, seed, testUtils, dbs,
164+
ctx, t, c, m, testRNG, workloadSeed, testUtils, dbs,
161165
)
162166
if err != nil {
163167
return err
@@ -421,12 +425,12 @@ func createDriversForBackupRestore(
421425
c cluster.Cluster,
422426
m cluster.Monitor,
423427
rng *rand.Rand,
424-
seed int64,
428+
workloadSeed int64,
425429
testUtils *CommonTestUtils,
426430
dbs []string,
427431
) (*BackupRestoreTestDriver, func() (func(), error), [][]string, error) {
428432
runBackgroundWorkload, err := startBackgroundWorkloads(
429-
ctx, t.L(), c, m, rng, seed, c.CRDBNodes(), c.WorkloadNode(), testUtils, dbs,
433+
ctx, t.L(), c, m, rng, workloadSeed, c.CRDBNodes(), c.WorkloadNode(), testUtils, dbs,
430434
)
431435
if err != nil {
432436
return nil, nil, nil, err

pkg/cmd/roachtest/tests/mixed_version_backup.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@ 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"
3433
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/roachtestutil"
3534
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/roachtestutil/clusterupgrade"
3635
"github.com/cockroachdb/cockroach/pkg/cmd/roachtest/roachtestutil/mixedversion"
@@ -2934,6 +2933,10 @@ func registerBackupMixedVersion(r registry.Registry) {
29342933
)
29352934
testRNG := mvt.RNG()
29362935

2936+
// Workload can only take a positive int as a seed, but seed could be a
2937+
// negative int. Ensure the seed passed to workload is an int.
2938+
workloadSeed := testRNG.Int63()
2939+
29372940
dbs := []string{"bank", "tpcc"}
29382941
backupTest, err := newMixedVersionBackup(t, c, c.CRDBNodes(), dbs)
29392942
if err != nil {
@@ -2951,8 +2954,8 @@ func registerBackupMixedVersion(r registry.Registry) {
29512954
// for the cluster used in this test without overloading it,
29522955
// which can make the backups take much longer to finish.
29532956
const numWarehouses = 100
2954-
bankInit, bankRun := bankWorkloadCmd(t.L(), testRNG, roachtestflags.GlobalSeed, c.CRDBNodes(), false)
2955-
tpccInit, tpccRun := tpccWorkloadCmd(t.L(), testRNG, roachtestflags.GlobalSeed, numWarehouses, c.CRDBNodes())
2957+
bankInit, bankRun := bankWorkloadCmd(t.L(), testRNG, workloadSeed, c.CRDBNodes(), false)
2958+
tpccInit, tpccRun := tpccWorkloadCmd(t.L(), testRNG, workloadSeed, numWarehouses, c.CRDBNodes())
29562959

29572960
mvt.OnStartup("set short job interval", backupTest.setShortJobIntervals)
29582961
mvt.OnStartup("take backup in previous version", backupTest.maybeTakePreviousVersionBackup)

0 commit comments

Comments
 (0)