Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions pkg/storage/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ go_library(
"//pkg/util/metamorphic",
"//pkg/util/mon",
"//pkg/util/protoutil",
"//pkg/util/randutil",
"//pkg/util/syncutil",
"//pkg/util/sysutil",
"//pkg/util/timeutil",
Expand Down
7 changes: 5 additions & 2 deletions pkg/storage/intent_interleaving_iter.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import (
"github.com/cockroachdb/cockroach/pkg/roachpb"
"github.com/cockroachdb/cockroach/pkg/util"
"github.com/cockroachdb/cockroach/pkg/util/protoutil"
"github.com/cockroachdb/cockroach/pkg/util/randutil"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/pebble"
)
Expand Down Expand Up @@ -1477,6 +1478,7 @@ func (i *intentInterleavingIter) assertInvariants() error {
// changes to unsafe keys retrieved from MVCCIterators.
type unsafeMVCCIterator struct {
MVCCIterator
rng *rand.Rand
keyBuf []byte
rawKeyBuf []byte
rawMVCCKeyBuf []byte
Expand All @@ -1485,7 +1487,8 @@ type unsafeMVCCIterator struct {
// gcassert:inline
func maybeWrapInUnsafeIter(iter MVCCIterator) MVCCIterator {
if util.RaceEnabled {
return &unsafeMVCCIterator{MVCCIterator: iter}
rng, _ := randutil.NewPseudoRand()
return &unsafeMVCCIterator{MVCCIterator: iter, rng: rng}
}
return iter
}
Expand Down Expand Up @@ -1547,7 +1550,7 @@ func (i *unsafeMVCCIterator) UnsafeRawMVCCKey() []byte {
}

func (i *unsafeMVCCIterator) mangleBufs() {
if rand.Intn(2) == 0 {
if i.rng.Intn(2) == 0 {
for _, b := range [3][]byte{i.keyBuf, i.rawKeyBuf, i.rawMVCCKeyBuf} {
for i := range b {
b[i] = 0
Expand Down
1 change: 1 addition & 0 deletions pkg/storage/pebbleiter/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ go_library(
visibility = ["//visibility:public"],
deps = [
"//pkg/util",
"//pkg/util/randutil",
"@com_github_cockroachdb_errors//:errors",
"@com_github_cockroachdb_pebble//:pebble",
],
Expand Down
13 changes: 8 additions & 5 deletions pkg/storage/pebbleiter/crdb_test_on.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/cockroachdb/cockroach/pkg/util"
"github.com/cockroachdb/cockroach/pkg/util/randutil"
"github.com/cockroachdb/errors"
"github.com/cockroachdb/pebble"
)
Expand All @@ -26,12 +27,14 @@ type Iterator = *assertionIter
// MaybeWrap returns the provided Pebble iterator, wrapped with double close
// detection.
func MaybeWrap(iter *pebble.Iterator) Iterator {
return &assertionIter{Iterator: iter, closedCh: make(chan struct{})}
rng, _ := randutil.NewPseudoRand()
return &assertionIter{Iterator: iter, rng: rng, closedCh: make(chan struct{})}
}

// assertionIter wraps a *pebble.Iterator with assertion checking.
type assertionIter struct {
*pebble.Iterator
rng *rand.Rand
closed bool
closedCh chan struct{}
// unsafeBufs hold buffers used for returning values with short lifetimes to
Expand Down Expand Up @@ -243,11 +246,11 @@ func (i *assertionIter) PrevWithLimit(limit []byte) pebble.IterValidityState {
// to the caller. This is used to ensure that the client respects the Pebble
// iterator interface and the lifetimes of buffers it returns.
func (i *assertionIter) maybeMangleBufs() {
if rand.Intn(2) == 0 {
if i.rng.Intn(2) == 0 {
idx := i.unsafeBufs.idx
zero(i.unsafeBufs.key[idx])
zero(i.unsafeBufs.val[idx])
if rand.Intn(2) == 0 {
if i.rng.Intn(2) == 0 {
// Switch to a new buffer for the next iterator position.
i.unsafeBufs.idx = (i.unsafeBufs.idx + 1) % 2
}
Expand All @@ -273,7 +276,7 @@ func (i *assertionIter) maybeSaveAndMangleRangeKeyBufs() {
// Randomly zero them to ensure we catch bugs where they're reused.
idx := i.rangeKeyBufs.idx
mangleBuf := &i.rangeKeyBufs.bufs[idx]
if rand.Intn(2) == 0 {
if i.rng.Intn(2) == 0 {
mangleBuf.mangle()
}
// If the new iterator position has range keys, copy them to our buffers.
Expand All @@ -283,7 +286,7 @@ func (i *assertionIter) maybeSaveAndMangleRangeKeyBufs() {
if _, hasRange := i.Iterator.HasPointAndRange(); !hasRange {
return
}
switchBuffers := rand.Intn(2) == 0
switchBuffers := i.rng.Intn(2) == 0
if switchBuffers {
// Switch to a new buffer for the new range key state.
i.rangeKeyBufs.idx = (idx + 1) % 2
Expand Down