-
Notifications
You must be signed in to change notification settings - Fork 271
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
Optimize max_flushed_root update in flushing roots #4320
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 |
---|---|---|
|
@@ -6295,30 +6295,33 @@ impl AccountsDb { | |
}); | ||
|
||
// Always flush up to `requested_flush_root`, which is necessary for things like snapshotting. | ||
let cached_roots: BTreeSet<Slot> = self.accounts_cache.clear_roots(requested_flush_root); | ||
let flushed_roots: BTreeSet<Slot> = self.accounts_cache.clear_roots(requested_flush_root); | ||
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. rename: cached_roots -> flushed_roots for clarity. |
||
|
||
// Iterate from highest to lowest so that we don't need to flush earlier | ||
// outdated updates in earlier roots | ||
let mut num_roots_flushed = 0; | ||
let mut flush_stats = FlushStats::default(); | ||
for &root in cached_roots.iter().rev() { | ||
for &root in flushed_roots.iter().rev() { | ||
if let Some(stats) = | ||
self.flush_slot_cache_with_clean(root, should_flush_f.as_mut(), max_clean_root) | ||
{ | ||
num_roots_flushed += 1; | ||
flush_stats.accumulate(&stats); | ||
} | ||
} | ||
|
||
// Regardless of whether this slot was *just* flushed from the cache by the above | ||
// `flush_slot_cache()`, we should update the `max_flush_root`. | ||
// This is because some rooted slots may be flushed to storage *before* they are marked as root. | ||
// This can occur for instance when | ||
// the cache is overwhelmed, we flushed some yet to be rooted frozen slots | ||
// These slots may then *later* be marked as root, so we still need to handle updating the | ||
// `max_flush_root` in the accounts cache. | ||
// Note that self.flush_slot_cache_with_clean() can return None if the | ||
// slot is already been flushed. This can happen if the cache is | ||
// overwhelmed and we flushed some yet to be rooted frozen slots. | ||
// However, Independent of whether the last slot was actually flushed | ||
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 Independent -> independent 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. yeah. I will change it in another pr so that people don't need to re-approve this one again. |
||
// from the cache by the above loop, we should always update the | ||
// `max_flush_root` to the max of the flushed roots, because that's | ||
// max_flushed_root tracks the logical last root that was flushed to | ||
// storage by snapshotting. | ||
if let Some(&root) = flushed_roots.last() { | ||
self.accounts_cache.set_max_flush_root(root); | ||
} | ||
let num_new_roots = cached_roots.len(); | ||
let num_new_roots = flushed_roots.len(); | ||
(num_new_roots, num_roots_flushed, flush_stats) | ||
} | ||
|
||
|
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.
Since we can prove that slot > max_flush_root, we don't need to check root > max_flush_root.
And since we remove the slot > max_flush_root check, there is no need to special case
root == 0
for genesis block too.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.
Is this because roots are monotonically increasing?
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.
yes, exactly!