Skip to content

Commit

Permalink
sql: use seeded random for schemachange opsgen
Browse files Browse the repository at this point in the history
A schemachange TestWorkload failure was difficult to
reproduce; to address this, this patch uses randutil's
`NewTestRand()` to allow for a global seed to be set when
stressing this test.

Epic: none

Release note: none
  • Loading branch information
annrpom committed Aug 18, 2023
1 parent a0c30d2 commit b21b3e5
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
1 change: 1 addition & 0 deletions pkg/workload/schemachange/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ go_library(
"//pkg/sql/sem/tree",
"//pkg/sql/types",
"//pkg/util/encoding",
"//pkg/util/randutil",
"//pkg/util/syncutil",
"//pkg/util/timeutil",
"//pkg/workload",
Expand Down
12 changes: 7 additions & 5 deletions pkg/workload/schemachange/schemachange.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import (
"encoding/json"
"fmt"
"io"
"math/rand"
"os"
"regexp"
"sync"
Expand All @@ -27,6 +26,7 @@ import (

"github.com/cockroachdb/cockroach/pkg/clusterversion"
"github.com/cockroachdb/cockroach/pkg/sql/pgwire/pgcode"
"github.com/cockroachdb/cockroach/pkg/util/randutil"
"github.com/cockroachdb/cockroach/pkg/util/syncutil"
"github.com/cockroachdb/cockroach/pkg/util/timeutil"
"github.com/cockroachdb/cockroach/pkg/workload"
Expand Down Expand Up @@ -184,7 +184,10 @@ func (s *schemaChange) Ops(
if err != nil {
return workload.QueryLoad{}, err
}
ops := newDeck(rand.New(rand.NewSource(timeutil.Now().UnixNano())), opWeights...)
stdoutLog := makeAtomicLog(os.Stdout)
rng, seed := randutil.NewTestRand()
stdoutLog.printLn(fmt.Sprintf("using random seed: %d", seed))
ops := newDeck(rng, opWeights...)
// A separate deck is constructed of only schema changes supported
// by the declarative schema changer. This deck has equal weights,
// only for supported schema changes.
Expand All @@ -194,11 +197,10 @@ func (s *schemaChange) Ops(
declarativeOpWeights[idx] = weight
}
}
declarativeOps := newDeck(rand.New(rand.NewSource(timeutil.Now().UnixNano())), declarativeOpWeights...)
declarativeOps := newDeck(rng, declarativeOpWeights...)

ql := workload.QueryLoad{SQLDatabase: sqlDatabase}

stdoutLog := makeAtomicLog(os.Stdout)
var artifactsLog *atomicLog
if s.logFilePath != "" {
err := s.initJSONLogFile(s.logFilePath)
Expand All @@ -215,7 +217,7 @@ func (s *schemaChange) Ops(
seqNum: seqNum,
errorRate: s.errorRate,
enumPct: s.enumPct,
rng: rand.New(rand.NewSource(timeutil.Now().UnixNano())),
rng: rng,
ops: ops,
declarativeOps: declarativeOps,
maxSourceTables: s.maxSourceTables,
Expand Down

0 comments on commit b21b3e5

Please sign in to comment.