-
Notifications
You must be signed in to change notification settings - Fork 4.4k
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
Uses fold+reduce for handling duplicate pubkeys during index generation #34011
Merged
brooksprumo
merged 2 commits into
solana-labs:master
from
brooksprumo:generate-index/uncleaned-roots/reduce
Nov 10, 2023
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9397,51 +9397,84 @@ impl AccountsDb { | |
..GenerateIndexTimings::default() | ||
}; | ||
|
||
// subtract data.len() from accounts_data_len for all old accounts that are in the index twice | ||
let mut accounts_data_len_dedup_timer = | ||
Measure::start("handle accounts data len duplicates"); | ||
let uncleaned_roots = Mutex::new(IntSet::default()); | ||
if pass == 0 { | ||
let accounts_data_len_from_duplicates = unique_pubkeys_by_bin | ||
#[derive(Debug, Default)] | ||
struct DuplicatePubkeysVisitedInfo { | ||
accounts_data_len_from_duplicates: u64, | ||
uncleaned_roots: IntSet<Slot>, | ||
} | ||
impl DuplicatePubkeysVisitedInfo { | ||
fn reduce(mut a: Self, mut b: Self) -> Self { | ||
if a.uncleaned_roots.len() >= b.uncleaned_roots.len() { | ||
a.merge(b); | ||
a | ||
} else { | ||
b.merge(a); | ||
b | ||
} | ||
} | ||
fn merge(&mut self, other: Self) { | ||
self.accounts_data_len_from_duplicates += | ||
other.accounts_data_len_from_duplicates; | ||
self.uncleaned_roots.extend(other.uncleaned_roots); | ||
} | ||
} | ||
|
||
// subtract data.len() from accounts_data_len for all old accounts that are in the index twice | ||
let mut accounts_data_len_dedup_timer = | ||
Measure::start("handle accounts data len duplicates"); | ||
let DuplicatePubkeysVisitedInfo { | ||
accounts_data_len_from_duplicates, | ||
uncleaned_roots, | ||
} = unique_pubkeys_by_bin | ||
.par_iter() | ||
.map(|unique_keys| { | ||
unique_keys | ||
.par_chunks(4096) | ||
.map(|pubkeys| { | ||
let (count, uncleaned_roots_this_group) = self | ||
.visit_duplicate_pubkeys_during_startup( | ||
pubkeys, | ||
&rent_collector, | ||
&timings, | ||
); | ||
let mut uncleaned_roots = uncleaned_roots.lock().unwrap(); | ||
uncleaned_roots_this_group.into_iter().for_each(|slot| { | ||
uncleaned_roots.insert(slot); | ||
}); | ||
count | ||
}) | ||
.sum::<u64>() | ||
}) | ||
.sum(); | ||
.fold( | ||
DuplicatePubkeysVisitedInfo::default, | ||
|accum, pubkeys_by_bin| { | ||
let intermediate = pubkeys_by_bin | ||
.par_chunks(4096) | ||
.fold(DuplicatePubkeysVisitedInfo::default, |accum, pubkeys| { | ||
let (accounts_data_len_from_duplicates, uncleaned_roots) = self | ||
.visit_duplicate_pubkeys_during_startup( | ||
pubkeys, | ||
&rent_collector, | ||
&timings, | ||
); | ||
let intermediate = DuplicatePubkeysVisitedInfo { | ||
accounts_data_len_from_duplicates, | ||
uncleaned_roots, | ||
}; | ||
DuplicatePubkeysVisitedInfo::reduce(accum, intermediate) | ||
}) | ||
.reduce( | ||
DuplicatePubkeysVisitedInfo::default, | ||
DuplicatePubkeysVisitedInfo::reduce, | ||
); | ||
DuplicatePubkeysVisitedInfo::reduce(accum, intermediate) | ||
}, | ||
) | ||
.reduce( | ||
DuplicatePubkeysVisitedInfo::default, | ||
DuplicatePubkeysVisitedInfo::reduce, | ||
); | ||
accounts_data_len_dedup_timer.stop(); | ||
timings.accounts_data_len_dedup_time_us = accounts_data_len_dedup_timer.as_us(); | ||
timings.slots_to_clean = uncleaned_roots.len() as u64; | ||
|
||
self.accounts_index | ||
.add_uncleaned_roots(uncleaned_roots.into_iter()); | ||
accounts_data_len.fetch_sub(accounts_data_len_from_duplicates, Ordering::Relaxed); | ||
info!( | ||
"accounts data len: {}", | ||
accounts_data_len.load(Ordering::Relaxed) | ||
); | ||
} | ||
accounts_data_len_dedup_timer.stop(); | ||
timings.accounts_data_len_dedup_time_us = accounts_data_len_dedup_timer.as_us(); | ||
|
||
let uncleaned_roots = uncleaned_roots.into_inner().unwrap(); | ||
timings.slots_to_clean = uncleaned_roots.len() as u64; | ||
|
||
if pass == 0 { | ||
// Need to add these last, otherwise older updates will be cleaned | ||
for root in &slots { | ||
self.accounts_index.add_root(*root); | ||
} | ||
self.accounts_index | ||
.add_uncleaned_roots(uncleaned_roots.into_iter()); | ||
Comment on lines
-9443
to
-9444
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. This was moved up into the block that makes |
||
|
||
self.set_storage_count_and_alive_bytes(storage_info, &mut timings); | ||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Following from https://github.com/solana-labs/solana/pull/34011/files#r1389679091, those lines were moved here.