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

blockstore: Refactor Rocks iterator methods #4030

Open
wants to merge 6 commits into
base: master
Choose a base branch
from

Conversation

steviez
Copy link

@steviez steviez commented Dec 10, 2024

Problem

There will be an upcoming PR for #3850, this breaks out some cleanup and refactoring that will enable that PR to come in with a smaller diff. No functional changes in this PR.

Summary of Changes

Comment on lines +2201 to +2204
) -> impl Iterator<Item = (Box<[u8]>, Box<[u8]>)> + '_ {
// The conversion of key back into Box<[u8]> incurs an extra
// allocation. However, this is test code and the goal is to
// maximize code reuse over efficiency
Copy link
Author

@steviez steviez Dec 10, 2024

Choose a reason for hiding this comment

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

I added this comment for the interim, but this duplicate allocation/conversion will go away later in upcoming PR. I think the comment is valid regardless tho

IteratorMode::Start => RocksIteratorMode::Start,
IteratorMode::End => RocksIteratorMode::End,
};
fn iterator_cf(&self, cf: &ColumnFamily, iterator_mode: RocksIteratorMode) -> DBIterator {
Copy link
Author

Choose a reason for hiding this comment

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

The method in Rocks is now a simple pass-through

Comment on lines +1074 to +1083
let (first_index, _value) = blockstore
.transaction_memos_cf
.iterator_cf_raw_key(IteratorMode::Start)
.next()
.unwrap();
let (last_index, _value) = blockstore
.transaction_memos_cf
.iterator_cf_raw_key(IteratorMode::End)
.next()
.unwrap();
Copy link
Author

Choose a reason for hiding this comment

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

We can't use get_index_bounds() here since this is operating on a different column.

I could hypothetically parameterize get_index_bounds() to take a column instead of Blockstore (currently, get_index_bounds() uses transaction_status_cf). However, I think that will make things more difficult for a future PR so I'd rather hold off on that for now. IMO, what I did here is still cleaner than what was there (ie no .0)

Comment on lines -871 to +870
.iterator_cf_raw_key(IteratorMode::Start)
.collect();
assert_eq!(statuses.len(), 15);
.iter(IteratorMode::Start)
Copy link
Author

@steviez steviez Dec 10, 2024

Choose a reason for hiding this comment

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

I started off wanting to kill iterator_cf_raw_key() altogether. However, we still need it for the cases where we perform compaction.

Regardless, I opted to use iter() where possible/it made more sense instead of iterator_cf_raw_key() to work towards being able to remove the test only iterator_cf_raw_key() function

@steviez steviez requested review from cpubot and bw-solana December 10, 2024 18:17
Copy link

@cpubot cpubot left a comment

Choose a reason for hiding this comment

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

Not an expert here, but LGTM

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.

2 participants