Skip to content

Commit

Permalink
colblk: show iter commands
Browse files Browse the repository at this point in the history
It's pretty hard to look at an `iter` testcase and see which key
matches which command. This commit adds a `ShowCommands` option and
uses it for the data block tests.
  • Loading branch information
RaduBerinde committed Oct 1, 2024
1 parent b3453b7 commit 1168228
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 209 deletions.
21 changes: 17 additions & 4 deletions internal/itertest/datadriven.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"strings"
"testing"

"github.com/cockroachdb/crlib/crstrings"
"github.com/cockroachdb/datadriven"
"github.com/cockroachdb/pebble/internal/base"
"github.com/cockroachdb/pebble/internal/keyspan"
Expand All @@ -22,6 +23,7 @@ import (

type iterCmdOpts struct {
fmtKV formatKV
showCommands bool
withoutNewlines bool
stats *base.InternalIteratorStats
}
Expand All @@ -39,6 +41,12 @@ func Condensed(opts *iterCmdOpts) {
opts.withoutNewlines = true
}

// ShowCommands configures RunInternalIterCmd to show the command in each output
// line (so you don't have to visually match the line to the command).
func ShowCommands(opts *iterCmdOpts) {
opts.showCommands = true
}

// Verbose configures RunInternalIterCmd to output verbose results.
func Verbose(opts *iterCmdOpts) { opts.fmtKV = verboseFormatKV }

Expand Down Expand Up @@ -125,11 +133,13 @@ func RunInternalIterCmdWriter(
require.NoError(t, err)
return &kv.K, v
}
for _, line := range strings.Split(d.Input, "\n") {
lines := crstrings.Lines(d.Input)
maxCmdLen := 1
for _, line := range lines {
maxCmdLen = max(maxCmdLen, len(line))
}
for _, line := range lines {
parts := strings.Fields(line)
if len(parts) == 0 {
continue
}
var key *base.InternalKey
var value []byte
switch parts[0] {
Expand Down Expand Up @@ -222,6 +232,9 @@ func RunInternalIterCmdWriter(
fmt.Fprintf(w, "unknown op: %s", parts[0])
return
}
if o.showCommands {
fmt.Fprintf(w, "%*s: ", min(maxCmdLen, 40), line)
}
o.fmtKV(w, key, value, iter)
if !o.withoutNewlines {
fmt.Fprintln(w)
Expand Down
14 changes: 10 additions & 4 deletions sstable/colblk/data_block_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,21 @@ func TestDataBlock(t *testing.T) {
fmt.Fprintf(&buf, "LastKey: %s\n%s", lastKey.Pretty(testkeys.Comparer.FormatKey), f.String())
return buf.String()
case "iter":
var transforms block.IterTransforms
var seqNum uint64
var syntheticPrefix, syntheticSuffix string
td.MaybeScanArgs(t, "synthetic-seq-num", &seqNum)
transforms.SyntheticSeqNum = block.SyntheticSeqNum(seqNum)
transforms.HideObsoletePoints = td.HasArg("hide-obsolete-points")
td.MaybeScanArgs(t, "synthetic-prefix", &syntheticPrefix)
td.MaybeScanArgs(t, "synthetic-suffix", &syntheticSuffix)
transforms := block.IterTransforms{
SyntheticSeqNum: block.SyntheticSeqNum(seqNum),
HideObsoletePoints: td.HasArg("hide-obsolete-points"),
SyntheticPrefix: []byte(syntheticPrefix),
SyntheticSuffix: []byte(syntheticSuffix),
}
it.Init(&r, testKeysSchema.NewKeySeeker(), getLazyValuer(func([]byte) base.LazyValue {
return base.LazyValue{ValueOrHandle: []byte("mock external value")}
}), transforms)
var o []itertest.IterOpt
o := []itertest.IterOpt{itertest.ShowCommands}
if td.HasArg("verbose") {
o = append(o, itertest.Verbose)
}
Expand Down
16 changes: 8 additions & 8 deletions sstable/colblk/testdata/data_block/bundle_search
Original file line number Diff line number Diff line change
Expand Up @@ -528,11 +528,11 @@ seek-ge bac
seek-ge bacl
seek-ge bacu
----
backache:v
backslide:v
backslide:v
backhanded:v
backhanded:v
bacchanal:v
bacteria:v
.
seek-ge backache: backache:v
seek-ge backslide: backslide:v
seek-ge backslid: backslide:v
seek-ge backhanded: backhanded:v
seek-ge backhande: backhanded:v
seek-ge bac: bacchanal:v
seek-ge bacl: bacteria:v
seek-ge bacu: .
60 changes: 30 additions & 30 deletions sstable/colblk/testdata/data_block/external_value
Original file line number Diff line number Diff line change
Expand Up @@ -290,27 +290,27 @@ next
next
next
----
blockprefix_apple@98:apple98
blockprefix_apple@52:mock external value
blockprefix_apple@23:mock external value
blockprefix_apple@11:mock external value
blockprefix_banana@94:banana94
blockprefix_banana@93:
blockprefix_banana@93:mock external value
blockprefix_banana@72:mock external value
blockprefix_banana@9:mock external value
blockprefix_banana@1:mock external value
blockprefix_coconut:coconut
blockprefix_coconut@92:mock external value
blockprefix_coconut@35:mock external value
blockprefix_coconut@22:mock external value
blockprefix_coconut@21:mock external value
blockprefix_coconut@1:mock external value
blockprefix_guava@99:mock external value
blockprefix_kiwi@99:mock external value
blockprefix_kiwi@98:mock external value
blockprefix_lemon@92:
.
first: blockprefix_apple@98:apple98
next: blockprefix_apple@52:mock external value
next: blockprefix_apple@23:mock external value
next: blockprefix_apple@11:mock external value
next: blockprefix_banana@94:banana94
next: blockprefix_banana@93:
next: blockprefix_banana@93:mock external value
next: blockprefix_banana@72:mock external value
next: blockprefix_banana@9:mock external value
next: blockprefix_banana@1:mock external value
next: blockprefix_coconut:coconut
next: blockprefix_coconut@92:mock external value
next: blockprefix_coconut@35:mock external value
next: blockprefix_coconut@22:mock external value
next: blockprefix_coconut@21:mock external value
next: blockprefix_coconut@1:mock external value
next: blockprefix_guava@99:mock external value
next: blockprefix_kiwi@99:mock external value
next: blockprefix_kiwi@98:mock external value
next: blockprefix_lemon@92:
next: .

# Scan across the block using next prefix.

Expand All @@ -323,17 +323,17 @@ next-prefix
next-prefix
next-prefix
----
blockprefix_apple@98:apple98
blockprefix_banana@94:banana94
blockprefix_coconut:coconut
blockprefix_guava@99:mock external value
blockprefix_kiwi@99:mock external value
blockprefix_lemon@92:
.
first: blockprefix_apple@98:apple98
next-prefix: blockprefix_banana@94:banana94
next-prefix: blockprefix_coconut:coconut
next-prefix: blockprefix_guava@99:mock external value
next-prefix: blockprefix_kiwi@99:mock external value
next-prefix: blockprefix_lemon@92:
next-prefix: .

iter
seek-ge blockprefix_banana@73
next-prefix
----
blockprefix_banana@72:mock external value
blockprefix_coconut:coconut
seek-ge blockprefix_banana@73: blockprefix_banana@72:mock external value
next-prefix: blockprefix_coconut:coconut
12 changes: 6 additions & 6 deletions sstable/colblk/testdata/data_block/finish_without_final_row
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,12 @@ next
next
next
----
a@10:apple
b@5:banana
b@2:blueberry
c@9:coconut
c@6:cantelope
.
first: a@10:apple
next: b@5:banana
next: b@2:blueberry
next: c@9:coconut
next: c@6:cantelope
next: .

init
----
Expand Down
18 changes: 9 additions & 9 deletions sstable/colblk/testdata/data_block/next_prefix
Original file line number Diff line number Diff line change
Expand Up @@ -252,17 +252,17 @@ next-prefix
next-prefix
next-prefix
----
blockprefix_apple@98:apple98
blockprefix_banana@94:banana94
blockprefix_coconut:coconut
blockprefix_guava@99:guava99
blockprefix_kiwi@99:kiwi99
blockprefix_lemon@92:
.
first: blockprefix_apple@98:apple98
next-prefix: blockprefix_banana@94:banana94
next-prefix: blockprefix_coconut:coconut
next-prefix: blockprefix_guava@99:guava99
next-prefix: blockprefix_kiwi@99:kiwi99
next-prefix: blockprefix_lemon@92:
next-prefix: .

iter
seek-ge blockprefix_banana@73
next-prefix
----
blockprefix_banana@72:banana72
blockprefix_coconut:coconut
seek-ge blockprefix_banana@73: blockprefix_banana@72:banana72
next-prefix: blockprefix_coconut:coconut
Loading

0 comments on commit 1168228

Please sign in to comment.