Skip to content

Commit 60241a4

Browse files
committed
*: replace IteratorDebug with treesteps.Node
Switch to using the treesteps infrastructure for debug printing of iterator trees.
1 parent 2a097e0 commit 60241a4

34 files changed

+202
-212
lines changed

batch.go

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ import (
2929
"github.com/cockroachdb/pebble/internal/rangedel"
3030
"github.com/cockroachdb/pebble/internal/rangekey"
3131
"github.com/cockroachdb/pebble/internal/rawalloc"
32-
"github.com/cockroachdb/pebble/internal/treeprinter"
32+
"github.com/cockroachdb/pebble/internal/treesteps"
3333
)
3434

3535
const (
@@ -1867,9 +1867,9 @@ func (i *batchIter) SetBounds(lower, upper []byte) {
18671867

18681868
func (i *batchIter) SetContext(_ context.Context) {}
18691869

1870-
// DebugTree is part of the InternalIterator interface.
1871-
func (i *batchIter) DebugTree(tp treeprinter.Node) {
1872-
tp.Childf("%T(%p)", i, i)
1870+
// TreeStepsNode is part of the InternalIterator interface.
1871+
func (i *batchIter) TreeStepsNode() treesteps.NodeInfo {
1872+
return treesteps.NodeInfof(i, "%T(%p)", i, i)
18731873
}
18741874

18751875
type flushableBatchEntry struct {
@@ -2378,9 +2378,9 @@ func (i *flushableBatchIter) SetBounds(lower, upper []byte) {
23782378

23792379
func (i *flushableBatchIter) SetContext(_ context.Context) {}
23802380

2381-
// DebugTree is part of the InternalIterator interface.
2382-
func (i *flushableBatchIter) DebugTree(tp treeprinter.Node) {
2383-
tp.Childf("%T(%p)", i, i)
2381+
// TreeStepsNode is part of the InternalIterator interface.
2382+
func (i *flushableBatchIter) TreeStepsNode() treesteps.NodeInfo {
2383+
return treesteps.NodeInfof(i, "%T(%p)", i, i)
23842384
}
23852385

23862386
// flushFlushableBatchIter is similar to flushableBatchIter but it keeps track

error_iter.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import (
99

1010
"github.com/cockroachdb/pebble/internal/base"
1111
"github.com/cockroachdb/pebble/internal/keyspan"
12-
"github.com/cockroachdb/pebble/internal/treeprinter"
12+
"github.com/cockroachdb/pebble/internal/treesteps"
1313
)
1414

1515
type errorIter struct {
@@ -73,8 +73,8 @@ func (c *errorIter) SetBounds(lower, upper []byte) {}
7373

7474
func (c *errorIter) SetContext(_ context.Context) {}
7575

76-
func (c *errorIter) DebugTree(tp treeprinter.Node) {
77-
tp.Childf("%T(%p)", c, c)
76+
func (c *errorIter) TreeStepsNode() treesteps.NodeInfo {
77+
return treesteps.NodeInfof(c, "%T(%p)", c, c)
7878
}
7979

8080
type errorKeyspanIter struct {
@@ -94,4 +94,6 @@ func (i *errorKeyspanIter) SetContext(ctx context.Context) {}
9494
func (i *errorKeyspanIter) Close() {}
9595
func (*errorKeyspanIter) String() string { return "error" }
9696
func (*errorKeyspanIter) WrapChildren(wrap keyspan.WrapFn) {}
97-
func (i *errorKeyspanIter) DebugTree(tp treeprinter.Node) { tp.Childf("%T(%p)", i, i) }
97+
func (i *errorKeyspanIter) TreeStepsNode() treesteps.NodeInfo {
98+
return treesteps.NodeInfof(i, "%T(%p)", i, i)
99+
}

get.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ import (
1414
"github.com/cockroachdb/pebble/internal/base"
1515
"github.com/cockroachdb/pebble/internal/keyspan"
1616
"github.com/cockroachdb/pebble/internal/manifest"
17-
"github.com/cockroachdb/pebble/internal/treeprinter"
17+
"github.com/cockroachdb/pebble/internal/treesteps"
1818
"github.com/cockroachdb/pebble/sstable/blob"
1919
"github.com/cockroachdb/pebble/sstable/block"
2020
)
@@ -288,12 +288,11 @@ func (g *getIter) SetBounds(lower, upper []byte) {
288288

289289
func (g *getIter) SetContext(_ context.Context) {}
290290

291-
// DebugTree is part of the InternalIterator interface.
292-
func (g *getIter) DebugTree(tp treeprinter.Node) {
293-
n := tp.Childf("%T(%p)", g, g)
294-
if g.iter != nil {
295-
g.iter.DebugTree(n)
296-
}
291+
// TreeStepsNode is part of the InternalIterator interface.
292+
func (g *getIter) TreeStepsNode() treesteps.NodeInfo {
293+
info := treesteps.NodeInfof(g, "%T(%p)", g, g)
294+
info.AddChildren(g.iter)
295+
return info
297296
}
298297

299298
func (g *getIter) initializeNextIterator() (ok bool) {

internal/arenaskl/iterator.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ import (
2222
"sync"
2323

2424
"github.com/cockroachdb/pebble/internal/base"
25-
"github.com/cockroachdb/pebble/internal/treeprinter"
25+
"github.com/cockroachdb/pebble/internal/treesteps"
2626
)
2727

2828
type splice struct {
@@ -249,9 +249,9 @@ func (it *Iterator) SetBounds(lower, upper []byte) {
249249
// SetContext implements base.InternalIterator.
250250
func (it *Iterator) SetContext(_ context.Context) {}
251251

252-
// DebugTree is part of the InternalIterator interface.
253-
func (it *Iterator) DebugTree(tp treeprinter.Node) {
254-
tp.Childf("%T(%p)", it, it)
252+
// TreeStepsNode is part of the InternalIterator interface.
253+
func (it *Iterator) TreeStepsNode() treesteps.NodeInfo {
254+
return treesteps.NodeInfof(it, "%T(%p)", it, it)
255255
}
256256

257257
func (it *Iterator) decodeKey() {

internal/base/internal.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -664,6 +664,13 @@ func (kv *InternalKV) IsExclusiveSentinel() bool {
664664
return kv.K.IsExclusiveSentinel()
665665
}
666666

667+
func (kv *InternalKV) String() string {
668+
if kv == nil {
669+
return "<nil>"
670+
}
671+
return kv.K.String()
672+
}
673+
667674
// AtomicSeqNum is an atomic SeqNum.
668675
type AtomicSeqNum struct {
669676
value atomic.Uint64

internal/base/iterator.go

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010
"time"
1111

1212
"github.com/cockroachdb/pebble/internal/humanize"
13-
"github.com/cockroachdb/pebble/internal/treeprinter"
13+
"github.com/cockroachdb/pebble/internal/treesteps"
1414
"github.com/cockroachdb/pebble/sstable/block/blockkind"
1515
"github.com/cockroachdb/redact"
1616
)
@@ -220,7 +220,7 @@ type InternalIterator interface {
220220

221221
fmt.Stringer
222222

223-
IteratorDebug
223+
treesteps.Node
224224
}
225225

226226
// TopLevelIterator extends InternalIterator to include an additional absolute
@@ -516,19 +516,3 @@ func (s *InternalIteratorStats) SafeFormat(p redact.SafePrinter, verb rune) {
516516
humanize.Bytes.Uint64(s.SeparatedPointValue.ValueBytesFetched))
517517
}
518518
}
519-
520-
// IteratorDebug is an interface implemented by all internal iterators and
521-
// fragment iterators.
522-
type IteratorDebug interface {
523-
// DebugTree prints the entire iterator stack, used for debugging.
524-
//
525-
// Each implementation should perform a single Child/Childf call on tp.
526-
DebugTree(tp treeprinter.Node)
527-
}
528-
529-
// DebugTree returns the iterator tree as a multi-line string.
530-
func DebugTree(iter IteratorDebug) string {
531-
tp := treeprinter.New()
532-
iter.DebugTree(tp)
533-
return tp.String()
534-
}

internal/base/test_utils.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"strconv"
1212
"strings"
1313

14-
"github.com/cockroachdb/pebble/internal/treeprinter"
14+
"github.com/cockroachdb/pebble/internal/treesteps"
1515
)
1616

1717
// NewDeletableSumValueMerger return a ValueMerger which computes the sum of its
@@ -253,9 +253,9 @@ func (f *FakeIter) SetBounds(lower, upper []byte) {
253253
// SetContext is part of the InternalIterator interface.
254254
func (f *FakeIter) SetContext(_ context.Context) {}
255255

256-
// DebugTree is part of the InternalIterator interface.
257-
func (f *FakeIter) DebugTree(tp treeprinter.Node) {
258-
tp.Childf("%T(%p)", f, f)
256+
// TreeStepsNode is part of the InternalIterator interface.
257+
func (f *FakeIter) TreeStepsNode() treesteps.NodeInfo {
258+
return treesteps.NodeInfof(f, "%T(%p)", f, f)
259259
}
260260

261261
// ParseUserKeyBounds parses UserKeyBounds from a string representation of the

internal/invalidating/iter.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ import (
1010

1111
"github.com/cockroachdb/pebble/internal/base"
1212
"github.com/cockroachdb/pebble/internal/invariants"
13-
"github.com/cockroachdb/pebble/internal/treeprinter"
13+
"github.com/cockroachdb/pebble/internal/treesteps"
1414
)
1515

1616
// MaybeWrapIfInvariants wraps some iterators with an invalidating iterator.
@@ -164,12 +164,11 @@ func (i *iter) SetContext(ctx context.Context) {
164164
i.iter.SetContext(ctx)
165165
}
166166

167-
// DebugTree is part of the InternalIterator interface.
168-
func (i *iter) DebugTree(tp treeprinter.Node) {
169-
n := tp.Childf("%T(%p)", i, i)
170-
if i.iter != nil {
171-
i.iter.DebugTree(n)
172-
}
167+
// TreeStepsNode is part of the InternalIterator interface.
168+
func (i *iter) TreeStepsNode() treesteps.NodeInfo {
169+
info := treesteps.NodeInfof(i, "%T(%p)", i, i)
170+
info.AddChildren(i.iter)
171+
return info
173172
}
174173

175174
func (i *iter) String() string {

internal/itertest/probe.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111

1212
"github.com/cockroachdb/pebble/internal/base"
1313
"github.com/cockroachdb/pebble/internal/dsl"
14-
"github.com/cockroachdb/pebble/internal/treeprinter"
14+
"github.com/cockroachdb/pebble/internal/treesteps"
1515
)
1616

1717
// OpKind indicates the type of iterator operation being performed.
@@ -249,12 +249,11 @@ func (p *probeIterator) SetContext(ctx context.Context) {
249249
}
250250
}
251251

252-
// DebugTree is part of the InternalIterator interface.
253-
func (p *probeIterator) DebugTree(tp treeprinter.Node) {
254-
n := tp.Childf("%T(%p)", p, p)
255-
if p.iter != nil {
256-
p.iter.DebugTree(n)
257-
}
252+
// TreeStepsNode is part of the InternalIterator interface.
253+
func (p *probeIterator) TreeStepsNode() treesteps.NodeInfo {
254+
info := treesteps.NodeInfof(p, "%T(%p)", p, p)
255+
info.AddChildren(p.iter)
256+
return info
258257
}
259258

260259
func (p *probeIterator) String() string {

internal/keyspan/assert_iter.go

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import (
1111
"github.com/cockroachdb/errors"
1212
"github.com/cockroachdb/pebble/internal/base"
1313
"github.com/cockroachdb/pebble/internal/invariants"
14-
"github.com/cockroachdb/pebble/internal/treeprinter"
14+
"github.com/cockroachdb/pebble/internal/treesteps"
1515
)
1616

1717
// Assert wraps an iterator which asserts that operations return sane results.
@@ -181,10 +181,9 @@ func (i *assertIter) WrapChildren(wrap WrapFn) {
181181
i.iter = wrap(i.iter)
182182
}
183183

184-
// DebugTree is part of the FragmentIterator interface.
185-
func (i *assertIter) DebugTree(tp treeprinter.Node) {
186-
n := tp.Childf("%T(%p)", i, i)
187-
if i.iter != nil {
188-
i.iter.DebugTree(n)
189-
}
184+
// TreeStepsNode is part of the FragmentIterator interface.
185+
func (i *assertIter) TreeStepsNode() treesteps.NodeInfo {
186+
info := treesteps.NodeInfof(i, "%T(%p)", i, i)
187+
info.AddChildren(i.iter)
188+
return info
190189
}

0 commit comments

Comments
 (0)