Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Commit b38a535

Browse files
authored
Hack to skip cleanup_dead_slots upon snapshot load (#8562)
automerge
1 parent 218b02a commit b38a535

File tree

3 files changed

+51
-7
lines changed

3 files changed

+51
-7
lines changed

ledger/src/snapshot_utils.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -447,16 +447,18 @@ pub fn bank_from_archive<P: AsRef<Path>>(
447447
let mut snapshot_version = String::new();
448448
File::open(unpacked_version_file).and_then(|mut f| f.read_to_string(&mut snapshot_version))?;
449449

450-
let bank = rebuild_bank_from_snapshots(
450+
let mut bank = rebuild_bank_from_snapshots(
451451
snapshot_version.trim(),
452452
account_paths,
453453
&unpacked_snapshots_dir,
454454
unpacked_accounts_dir,
455455
)?;
456456

457+
bank.work_around_dead_slots_cleaning_bug(true);
457458
if !bank.verify_snapshot_bank() {
458459
panic!("Snapshot bank for slot {} failed to verify", bank.slot());
459460
}
461+
bank.work_around_dead_slots_cleaning_bug(false);
460462
measure.stop();
461463
info!("{}", measure);
462464

runtime/src/accounts_db.rs

Lines changed: 40 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,8 @@ pub struct AccountsDB {
452452
min_num_stores: usize,
453453

454454
pub bank_hashes: RwLock<HashMap<Slot, BankHashInfo>>,
455+
456+
pub dont_cleanup_dead_slots: AtomicBool,
455457
}
456458

457459
impl Default for AccountsDB {
@@ -474,6 +476,7 @@ impl Default for AccountsDB {
474476
.unwrap(),
475477
min_num_stores: num_threads,
476478
bank_hashes: RwLock::new(bank_hashes),
479+
dont_cleanup_dead_slots: AtomicBool::new(false),
477480
}
478481
}
479482
}
@@ -1296,6 +1299,10 @@ impl AccountsDB {
12961299
}
12971300

12981301
fn cleanup_dead_slots(&self, dead_slots: &mut HashSet<Slot>) {
1302+
if self.dont_cleanup_dead_slots.load(Ordering::Relaxed) {
1303+
return;
1304+
}
1305+
12991306
if !dead_slots.is_empty() {
13001307
{
13011308
let mut index = self.accounts_index.write().unwrap();
@@ -2290,10 +2297,10 @@ pub mod tests {
22902297
assert_load_account(&accounts, current_slot, pubkey, zero_lamport);
22912298
}
22922299

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+
{
22972304
let some_lamport = 223;
22982305
let zero_lamport = 0;
22992306
let dummy_lamport = 999;
@@ -2332,15 +2339,42 @@ pub mod tests {
23322339
accounts.store(current_slot, &[(&dummy_pubkey, &dummy_account)]);
23332340
accounts.add_root(current_slot);
23342341

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+
}
23372348

23382349
assert_load_account(&accounts, current_slot, pubkey, some_lamport);
23392350
assert_load_account(&accounts, current_slot, purged_pubkey1, 0);
23402351
assert_load_account(&accounts, current_slot, purged_pubkey2, 0);
23412352
assert_load_account(&accounts, current_slot, dummy_pubkey, dummy_lamport);
23422353
}
23432354

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+
23442378
#[test]
23452379
#[ignore]
23462380
fn test_store_account_stress() {

runtime/src/bank.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1721,6 +1721,14 @@ impl Bank {
17211721
self.rc.parent = RwLock::new(Some(parent.clone()));
17221722
}
17231723

1724+
pub fn work_around_dead_slots_cleaning_bug(&mut self, flag: bool) {
1725+
self.rc
1726+
.accounts
1727+
.accounts_db
1728+
.dont_cleanup_dead_slots
1729+
.store(flag, Ordering::Relaxed);
1730+
}
1731+
17241732
pub fn set_inflation(&self, inflation: Inflation) {
17251733
*self.inflation.write().unwrap() = inflation;
17261734
}

0 commit comments

Comments
 (0)