@@ -6296,30 +6296,33 @@ impl AccountsDb {
62966296 } ) ;
62976297
62986298 // 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) ;
63006300
63016301 // Iterate from highest to lowest so that we don't need to flush earlier
63026302 // outdated updates in earlier roots
63036303 let mut num_roots_flushed = 0 ;
63046304 let mut flush_stats = FlushStats :: default ( ) ;
6305- for & root in cached_roots . iter ( ) . rev ( ) {
6305+ for & root in flushed_roots . iter ( ) . rev ( ) {
63066306 if let Some ( stats) =
63076307 self . flush_slot_cache_with_clean ( root, should_flush_f. as_mut ( ) , max_clean_root)
63086308 {
63096309 num_roots_flushed += 1 ;
63106310 flush_stats. accumulate ( & stats) ;
63116311 }
6312+ }
63126313
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 ( ) {
63206323 self . accounts_cache . set_max_flush_root ( root) ;
63216324 }
6322- let num_new_roots = cached_roots . len ( ) ;
6325+ let num_new_roots = flushed_roots . len ( ) ;
63236326 ( num_new_roots, num_roots_flushed, flush_stats)
63246327 }
63256328
0 commit comments