Skip to content

Commit

Permalink
add dirty_store when flush
Browse files Browse the repository at this point in the history
  • Loading branch information
HaoranYi committed Jan 6, 2025
1 parent 7740b82 commit ed868c6
Showing 1 changed file with 23 additions and 13 deletions.
36 changes: 23 additions & 13 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6295,33 +6295,42 @@ 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);

// 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.
self.accounts_cache.set_max_flush_root(root);
if let Some(storage) = self.storage.get_slot_storage_entry(root) {
// In this loop, "flush_slot_cache_with_clean" will handle
// cleaning the accounts for only the "flushed_roots". However,
// these "flushed_roots" may trigger additional clean for older
// roots. Therefore, we need to add them to "dirty_stores" for
// clean to pick up such additional cleaning.
self.dirty_stores.entry(root).or_insert(storage);
}
}

// Only add to the uncleaned roots set *after* we've flushed the previous roots,
// so that clean will actually be able to clean the slots.
let num_new_roots = cached_roots.len();
// 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.
flushed_roots.last().map(|&root| {
self.accounts_cache.set_max_flush_root(root);
});

let num_new_roots = flushed_roots.len();
(num_new_roots, num_roots_flushed, flush_stats)
}

Expand Down Expand Up @@ -8384,6 +8393,7 @@ impl AccountsDb {
.storage
.get_slot_storage_entry_shrinking_in_progress_ok(slot)
{
info!("haoran add_dirty_store when rooting: {}", slot);
self.dirty_stores.insert(slot, store);
}
store_time.stop();
Expand Down

0 comments on commit ed868c6

Please sign in to comment.