Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

*: add facility to print the iterator stack #3682

Merged
merged 1 commit into from
Jul 8, 2024

Conversation

RaduBerinde
Copy link
Member

@RaduBerinde RaduBerinde commented Jun 21, 2024

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

@RaduBerinde RaduBerinde requested a review from jbowens June 21, 2024 17:58
@RaduBerinde RaduBerinde requested a review from a team as a code owner June 21, 2024 17:58
@cockroach-teamcity
Copy link
Member

This change is Reviewable

@nicktrav
Copy link
Contributor

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.

Copy link
Member Author

@RaduBerinde RaduBerinde left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TFTR!

I added the level for level iterators and filenum for "leaf" iterators.

I'm not sure right now how to use it during tracing, since it depends when you look at the tree. I think if we add more information, printing it at the end might be useful.

*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

Reviewable status: 0 of 30 files reviewed, all discussions resolved (waiting on @jbowens)

@RaduBerinde RaduBerinde force-pushed the iterator-stack branch 3 times, most recently from 98a2481 to f64a665 Compare June 25, 2024 18:44
@RaduBerinde
Copy link
Member Author

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

@RaduBerinde
Copy link
Member Author

Friendly ping

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
```
Copy link
Collaborator

@jbowens jbowens left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 4 of 30 files at r1, 2 of 19 files at r2, 3 of 15 files at r3.
Reviewable status: 9 of 34 files reviewed, all discussions resolved

@RaduBerinde
Copy link
Member Author

TFTR!

@RaduBerinde RaduBerinde merged commit 7920d96 into cockroachdb:master Jul 8, 2024
11 checks passed
@RaduBerinde RaduBerinde deleted the iterator-stack branch July 8, 2024 20:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants