@@ -452,6 +452,8 @@ pub struct AccountsDB {
452
452
min_num_stores : usize ,
453
453
454
454
pub bank_hashes : RwLock < HashMap < Slot , BankHashInfo > > ,
455
+
456
+ pub dont_cleanup_dead_slots : AtomicBool ,
455
457
}
456
458
457
459
impl Default for AccountsDB {
@@ -474,6 +476,7 @@ impl Default for AccountsDB {
474
476
. unwrap ( ) ,
475
477
min_num_stores : num_threads,
476
478
bank_hashes : RwLock :: new ( bank_hashes) ,
479
+ dont_cleanup_dead_slots : AtomicBool :: new ( false ) ,
477
480
}
478
481
}
479
482
}
@@ -1296,6 +1299,10 @@ impl AccountsDB {
1296
1299
}
1297
1300
1298
1301
fn cleanup_dead_slots ( & self , dead_slots : & mut HashSet < Slot > ) {
1302
+ if self . dont_cleanup_dead_slots . load ( Ordering :: Relaxed ) {
1303
+ return ;
1304
+ }
1305
+
1299
1306
if !dead_slots. is_empty ( ) {
1300
1307
{
1301
1308
let mut index = self . accounts_index . write ( ) . unwrap ( ) ;
@@ -2290,10 +2297,10 @@ pub mod tests {
2290
2297
assert_load_account ( & accounts, current_slot, pubkey, zero_lamport) ;
2291
2298
}
2292
2299
2293
- # [ test ]
2294
- fn test_accounts_purge_chained ( ) {
2295
- solana_logger :: setup ( ) ;
2296
-
2300
+ fn with_chained_zero_lamport_accounts < F > ( f : F )
2301
+ where
2302
+ F : Fn ( AccountsDB , Slot ) -> ( AccountsDB , bool ) ,
2303
+ {
2297
2304
let some_lamport = 223 ;
2298
2305
let zero_lamport = 0 ;
2299
2306
let dummy_lamport = 999 ;
@@ -2332,15 +2339,42 @@ pub mod tests {
2332
2339
accounts. store ( current_slot, & [ ( & dummy_pubkey, & dummy_account) ] ) ;
2333
2340
accounts. add_root ( current_slot) ;
2334
2341
2335
- purge_zero_lamport_accounts ( & accounts, current_slot) ;
2336
- let accounts = reconstruct_accounts_db_via_serialization ( & accounts, current_slot) ;
2342
+ let ( accounts, skip_account_assertion) = f ( accounts, current_slot) ;
2343
+
2344
+ assert_eq ! ( 4 , accounts. accounts_index. read( ) . unwrap( ) . roots. len( ) ) ;
2345
+ if skip_account_assertion {
2346
+ return ;
2347
+ }
2337
2348
2338
2349
assert_load_account ( & accounts, current_slot, pubkey, some_lamport) ;
2339
2350
assert_load_account ( & accounts, current_slot, purged_pubkey1, 0 ) ;
2340
2351
assert_load_account ( & accounts, current_slot, purged_pubkey2, 0 ) ;
2341
2352
assert_load_account ( & accounts, current_slot, dummy_pubkey, dummy_lamport) ;
2342
2353
}
2343
2354
2355
+ #[ test]
2356
+ fn test_accounts_purge_chained_purge_before_snapshot_restore ( ) {
2357
+ solana_logger:: setup ( ) ;
2358
+ with_chained_zero_lamport_accounts ( |accounts, current_slot| {
2359
+ purge_zero_lamport_accounts ( & accounts, current_slot) ;
2360
+ let accounts = reconstruct_accounts_db_via_serialization ( & accounts, current_slot) ;
2361
+ ( accounts, false )
2362
+ } ) ;
2363
+ }
2364
+
2365
+ #[ test]
2366
+ fn test_accounts_purge_chained_purge_after_snapshot_restore ( ) {
2367
+ solana_logger:: setup ( ) ;
2368
+ with_chained_zero_lamport_accounts ( |accounts, current_slot| {
2369
+ let accounts = reconstruct_accounts_db_via_serialization ( & accounts, current_slot) ;
2370
+ accounts
2371
+ . dont_cleanup_dead_slots
2372
+ . store ( true , Ordering :: Relaxed ) ;
2373
+ purge_zero_lamport_accounts ( & accounts, current_slot) ;
2374
+ ( accounts, true )
2375
+ } ) ;
2376
+ }
2377
+
2344
2378
#[ test]
2345
2379
#[ ignore]
2346
2380
fn test_store_account_stress ( ) {
0 commit comments