Skip to content

Commit

Permalink
metamorphic: add test option to disable lazy-combined iteration
Browse files Browse the repository at this point in the history
In 20% of random runs, disable lazy-combined iteration.
  • Loading branch information
jbowens committed Sep 6, 2022
1 parent 3358c2b commit ade651d
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 2 deletions.
6 changes: 5 additions & 1 deletion db.go
Original file line number Diff line number Diff line change
Expand Up @@ -925,6 +925,9 @@ func (d *DB) newIterInternal(batch *Batch, s *Snapshot, o *IterOptions) *Iterato
dbi.saveBounds(o.LowerBound, o.UpperBound)
}
dbi.opts.logger = d.opts.Logger
if d.opts.private.disableLazyCombinedIteration {
dbi.opts.disableLazyCombinedIteration = true
}
if batch != nil {
dbi.batchSeqNum = dbi.batch.nextSeqNum()
}
Expand Down Expand Up @@ -976,7 +979,8 @@ func finishInitializingIter(buf *iterAlloc) *Iterator {
// contains any range keys.
useLazyCombinedIteration := dbi.rangeKey == nil &&
dbi.opts.KeyTypes == IterKeyTypePointsAndRanges &&
(dbi.batch == nil || dbi.batch.countRangeKeys == 0)
(dbi.batch == nil || dbi.batch.countRangeKeys == 0) &&
!dbi.opts.disableLazyCombinedIteration
if useLazyCombinedIteration {
// The user requested combined iteration, and there's no indexed
// batch currently containing range keys that would prevent lazy
Expand Down
13 changes: 12 additions & 1 deletion internal/metamorphic/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,18 @@ func standardOptions() []*testOptions {
func randomOptions(rng *rand.Rand) *testOptions {
var testOpts = &testOptions{}
opts := defaultOptions()
testOpts.opts = opts

if rng.Intn(5) == 0 /* 20% */ {
// The `disable_lazy_combined_iteration` option is private, and there's
// no way to set it through the public interface. The only method is
// through Parse.
parseOptions(testOpts, `
[Options]
disable_lazy_combined_iteration=true
`)
}

opts.BytesPerSync = 1 << uint(rng.Intn(28)) // 1B - 256MB
opts.Cache = cache.New(1 << uint(rng.Intn(30))) // 1B - 1GB
opts.DisableWAL = rng.Intn(2) == 0
Expand Down Expand Up @@ -317,7 +329,6 @@ func randomOptions(rng *rand.Rand) *testOptions {
lopts.TargetFileSize = 1 << uint(rng.Intn(28)) // 1 - 256MB
opts.Levels = []pebble.LevelOptions{lopts}

testOpts.opts = opts
// Explicitly disable disk-backed FS's for the random configurations. The
// single standard test configuration that uses a disk-backed FS is
// sufficient.
Expand Down
22 changes: 22 additions & 0 deletions options.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,11 +163,15 @@ type IterOptions struct {
// existing is not low or if we just expect a one-time Seek (where loading the
// data block directly is better).
UseL6Filters bool

// Internal options.

logger Logger
// Level corresponding to this file. Only passed in if constructed by a
// levelIter.
level manifest.Level
// disableLazyCombinedIteration is an internal testing option.
disableLazyCombinedIteration bool

// NB: If adding new Options, you must account for them in iterator
// construction and Iterator.SetOptions.
Expand Down Expand Up @@ -780,6 +784,13 @@ type Options struct {
// against the FS are made after the DB is closed, the FS may leak a
// goroutine indefinitely.
fsCloser io.Closer

// disableLazyCombinedIteration is a private option used by the
// metamorphic tests to test equivalence between lazy-combined iteration
// and constructing the range-key iterator upfront. It's a private
// option to avoid littering the public interface with options that we
// do not want to allow users to actually configure.
disableLazyCombinedIteration bool
}
}

Expand Down Expand Up @@ -1028,6 +1039,15 @@ func (o *Options) String() string {
fmt.Fprintf(&buf, " max_writer_concurrency=%d\n", o.Experimental.MaxWriterConcurrency)
fmt.Fprintf(&buf, " force_writer_parallelism=%t\n", o.Experimental.ForceWriterParallelism)

// Private options.
if o.private.disableLazyCombinedIteration {
// This option is only encoded if true, because we do not want it to
// appear in production serialized Options files, since it's a
// testing-only option. It's only serialized when true, which still
// ensures that the metamorphic tests may propagate it to subprocesses.
fmt.Fprintln(&buf, " disable_lazy_combined_iteration=true")
}

for i := range o.Levels {
l := &o.Levels[i]
fmt.Fprintf(&buf, "\n")
Expand Down Expand Up @@ -1170,6 +1190,8 @@ func (o *Options) Parse(s string, hooks *ParseHooks) error {
o.FlushDelayDeleteRange, err = time.ParseDuration(value)
case "disable_wal":
o.DisableWAL, err = strconv.ParseBool(value)
case "disable_lazy_combined_iteration":
o.private.disableLazyCombinedIteration, err = strconv.ParseBool(value)
case "flush_delay_delete_range":
o.FlushDelayDeleteRange, err = time.ParseDuration(value)
case "flush_delay_range_key":
Expand Down

0 comments on commit ade651d

Please sign in to comment.