-
Notifications
You must be signed in to change notification settings - Fork 1k
Refactor Accounts Index and AccountsIndexIterator #6923
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,8 +1,5 @@ | ||
| use { | ||
| super::{ | ||
| account_map_entry::AccountMapEntry, in_mem_accounts_index::InMemAccountsIndex, | ||
| AccountsIndex, DiskIndexValue, IndexValue, | ||
| }, | ||
| super::{in_mem_accounts_index::InMemAccountsIndex, AccountsIndex, DiskIndexValue, IndexValue}, | ||
| solana_pubkey::Pubkey, | ||
| std::{ | ||
| ops::{Bound, RangeBounds}, | ||
|
|
@@ -18,7 +15,7 @@ pub struct AccountsIndexIterator<'a, T: IndexValue, U: DiskIndexValue + From<T> | |
| end_bound: Bound<&'a Pubkey>, | ||
| start_bin: usize, | ||
| end_bin_inclusive: usize, | ||
| items: Vec<(Pubkey, Arc<AccountMapEntry<T>>)>, | ||
| items: Vec<Pubkey>, | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: rename AccountsIndexIterator -> AccountsIndexPubkeyIterator? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. IMO let's rename in a separate PR. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's fine. |
||
| returns_items: AccountsIndexIteratorReturnsItems, | ||
| } | ||
|
|
||
|
|
@@ -61,18 +58,23 @@ impl<'a, T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndexIter | |
| impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> Iterator | ||
| for AccountsIndexIterator<'_, T, U> | ||
| { | ||
| type Item = Vec<(Pubkey, Arc<AccountMapEntry<T>>)>; | ||
| type Item = Vec<Pubkey>; | ||
| fn next(&mut self) -> Option<Self::Item> { | ||
| let range = (self.start_bound, self.end_bound); | ||
| while self.items.len() < ITER_BATCH_SIZE { | ||
| if self.start_bin > self.end_bin_inclusive { | ||
| break; | ||
| } | ||
|
|
||
| let bin = self.start_bin; | ||
| let map = &self.account_maps[bin]; | ||
| let mut items = map.items(&(self.start_bound, self.end_bound)); | ||
| let mut items = map | ||
| .keys() | ||
| .into_iter() | ||
| .filter(|k| range.contains(&k)) | ||
| .collect::<Vec<_>>(); | ||
| if self.returns_items == AccountsIndexIteratorReturnsItems::Sorted { | ||
| items.sort_unstable_by(|a, b| a.0.cmp(&b.0)); | ||
| items.sort_unstable(); | ||
| } | ||
| self.items.append(&mut items); | ||
| self.start_bin += 1; | ||
|
|
@@ -141,7 +143,7 @@ mod tests { | |
| let x = iter.next().unwrap(); | ||
| assert_eq!(x.len(), 2 * ITER_BATCH_SIZE); | ||
| assert_eq!( | ||
| x.is_sorted_by(|a, b| a.0 < b.0), | ||
| x.is_sorted(), | ||
| returns_items == AccountsIndexIteratorReturnsItems::Sorted | ||
| ); | ||
| assert_eq!(iter.items.len(), 0); // should be empty. | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👍