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

Optimize max_flushed_root update in flushing roots #4320

Merged
merged 3 commits into from
Jan 10, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 12 additions & 10 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6295,30 +6295,32 @@ 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);
Copy link
Author

Choose a reason for hiding this comment

The 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.
// Regardless of whether this slot was *just* flushed from the cache by
// the above loop. 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.
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)
}

Expand Down
Loading