-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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 1 commit
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 |
|---|---|---|
|
|
@@ -730,21 +730,27 @@ impl<T: IndexValue, U: DiskIndexValue + From<T> + Into<T>> AccountsIndex<T, U> { | |
| for pubkey_list in self.iter(range.as_ref(), returns_items) { | ||
|
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 pubkey_list -> pubkeys?
Author
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. done |
||
| iterator_timer.stop(); | ||
| iterator_elapsed += iterator_timer.as_us(); | ||
| for (pubkey, list) in pubkey_list { | ||
| for pubkey in pubkey_list { | ||
| num_keys_iterated += 1; | ||
| let mut read_lock_timer = Measure::start("read_lock"); | ||
| let list_r = &list.slot_list.read().unwrap(); | ||
| read_lock_timer.stop(); | ||
| read_lock_elapsed += read_lock_timer.as_us(); | ||
| let mut latest_slot_timer = Measure::start("latest_slot"); | ||
| if let Some(index) = self.latest_slot(Some(ancestors), list_r, max_root) { | ||
| latest_slot_timer.stop(); | ||
| latest_slot_elapsed += latest_slot_timer.as_us(); | ||
| let mut load_account_timer = Measure::start("load_account"); | ||
| func(&pubkey, (&list_r[index].1, list_r[index].0)); | ||
| load_account_timer.stop(); | ||
| load_account_elapsed += load_account_timer.as_us(); | ||
| } | ||
| self.get_and_then(&pubkey, |entry| { | ||
| if let Some(list) = entry { | ||
| let mut read_lock_timer = Measure::start("read_lock"); | ||
| let list_r = &list.slot_list.read().unwrap(); | ||
| read_lock_timer.stop(); | ||
| read_lock_elapsed += read_lock_timer.as_us(); | ||
| let mut latest_slot_timer = Measure::start("latest_slot"); | ||
| if let Some(index) = self.latest_slot(Some(ancestors), list_r, max_root) { | ||
| latest_slot_timer.stop(); | ||
| latest_slot_elapsed += latest_slot_timer.as_us(); | ||
| let mut load_account_timer = Measure::start("load_account"); | ||
| func(&pubkey, (&list_r[index].1, list_r[index].0)); | ||
| load_account_timer.stop(); | ||
| load_account_elapsed += load_account_timer.as_us(); | ||
| } | ||
| } | ||
| let add_to_in_mem_cache = false; | ||
| (add_to_in_mem_cache, ()) | ||
| }); | ||
| if config.is_aborted() { | ||
| return; | ||
| } | ||
|
|
||
| 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. | ||
|
|
||
|
brooksprumo marked this conversation as resolved.
|
Uh oh!
There was an error while loading. Please reload this page.