@@ -6296,30 +6296,33 @@ impl AccountsDb {
6296
6296
} ) ;
6297
6297
6298
6298
// Always flush up to `requested_flush_root`, which is necessary for things like snapshotting.
6299
- let cached_roots : BTreeSet < Slot > = self . accounts_cache . clear_roots ( requested_flush_root) ;
6299
+ let flushed_roots : BTreeSet < Slot > = self . accounts_cache . clear_roots ( requested_flush_root) ;
6300
6300
6301
6301
// Iterate from highest to lowest so that we don't need to flush earlier
6302
6302
// outdated updates in earlier roots
6303
6303
let mut num_roots_flushed = 0 ;
6304
6304
let mut flush_stats = FlushStats :: default ( ) ;
6305
- for & root in cached_roots . iter ( ) . rev ( ) {
6305
+ for & root in flushed_roots . iter ( ) . rev ( ) {
6306
6306
if let Some ( stats) =
6307
6307
self . flush_slot_cache_with_clean ( root, should_flush_f. as_mut ( ) , max_clean_root)
6308
6308
{
6309
6309
num_roots_flushed += 1 ;
6310
6310
flush_stats. accumulate ( & stats) ;
6311
6311
}
6312
+ }
6312
6313
6313
- // Regardless of whether this slot was *just* flushed from the cache by the above
6314
- // `flush_slot_cache()`, we should update the `max_flush_root`.
6315
- // This is because some rooted slots may be flushed to storage *before* they are marked as root.
6316
- // This can occur for instance when
6317
- // the cache is overwhelmed, we flushed some yet to be rooted frozen slots
6318
- // These slots may then *later* be marked as root, so we still need to handle updating the
6319
- // `max_flush_root` in the accounts cache.
6314
+ // Note that self.flush_slot_cache_with_clean() can return None if the
6315
+ // slot is already been flushed. This can happen if the cache is
6316
+ // overwhelmed and we flushed some yet to be rooted frozen slots.
6317
+ // However, Independent of whether the last slot was actually flushed
6318
+ // from the cache by the above loop, we should always update the
6319
+ // `max_flush_root` to the max of the flushed roots, because that's
6320
+ // max_flushed_root tracks the logical last root that was flushed to
6321
+ // storage by snapshotting.
6322
+ if let Some ( & root) = flushed_roots. last ( ) {
6320
6323
self . accounts_cache . set_max_flush_root ( root) ;
6321
6324
}
6322
- let num_new_roots = cached_roots . len ( ) ;
6325
+ let num_new_roots = flushed_roots . len ( ) ;
6323
6326
( num_new_roots, num_roots_flushed, flush_stats)
6324
6327
}
6325
6328
0 commit comments