cockroachdb / pebble

RocksDB/LevelDB inspired key-value database in Go
BSD 3-Clause "New" or "Revised" License
4.6k stars 424 forks source link

*: add facility to print the iterator stack #3682

Open RaduBerinde opened 1 week ago

RaduBerinde commented 1 week ago

To print the entire iterator stack tree, we can now use fmt.Printf("%s", base.DebugTree(iter)) to get something like this:

*pebble.Iterator(0x14003a0ea08)
 ├── *keyspan.InterleavingIter(0x14003ee2030)
 │    ├── *invalidating.iter(0x14007c52f00)
 │    │    └── *pebble.mergingIter(0x14003a0f028)
 │    │         └── *pebble.levelIter(0x14003a0f3a0) L6: fileNum=001316
 │    │              └── *sstable.singleLevelIterator(0x14004bce008) fileNum=001316
 │    └── *keyspan.assertIter(0x14001229950)
 │         └── *keyspan.DefragmentingIter(0x14003ee26e8)
 │              └── *keyspan.BoundedIter(0x14003ee2678)
 │                   └── *keyspanimpl.MergingIter(0x14003ee2300)
 │                        └── *keyspanimpl.LevelIter(0x14003ee2788) L6
 │                             └── *keyspan.assertIter(0x14000753a70)
 │                                  └── *sstable.fragmentBlockIter(0x140000ffb88) fileNum=001316
 └── *invalidating.iter(0x14007c52f00)
      └── *pebble.mergingIter(0x14003a0f028)
           └── *pebble.levelIter(0x14003a0f3a0) L6: fileNum=001316
                └── *sstable.singleLevelIterator(0x14004bce008) fileNum=001316
cockroach-teamcity commented 1 week ago

This change is Reviewable

nicktrav commented 1 week ago

This is really nice! A couple comments.

Any way to annotate the level iters with level numbers? There's possibly other metadata that might be useful too? Position? Direction? Data iterated over so far, etc?

Could this then be useful up in Cockroach, say, for trace spans - we can print this debug stack. It could supplement the iterator stats nicely.

RaduBerinde commented 5 days ago

Ok to merge? This has been useful when debugging some meta failures.