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

Commit

Permalink
Change the latest slot snapshot storage from VecDeque to Option
Browse files Browse the repository at this point in the history
  • Loading branch information
xiangzhu70 committed Jan 5, 2023
1 parent 083cbef commit b340b53
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 31 deletions.
1 change: 1 addition & 0 deletions core/src/validator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -625,6 +625,7 @@ impl Validator {
snapshot_request_sender,
snapshot_request_receiver,
accounts_package_sender,
latest_slot_snapshot_storages: None,
};
let pruned_banks_request_handler = PrunedBanksRequestHandler {
pruned_banks_receiver,
Expand Down
1 change: 1 addition & 0 deletions core/tests/epoch_accounts_hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -210,6 +210,7 @@ impl BackgroundServices {
snapshot_request_sender,
snapshot_request_receiver,
accounts_package_sender,
latest_slot_snapshot_storages: None,
};
let pruned_banks_request_handler = PrunedBanksRequestHandler {
pruned_banks_receiver,
Expand Down
21 changes: 8 additions & 13 deletions core/tests/snapshots.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use {
AbsRequestHandlers, AbsRequestSender, AccountsBackgroundService,
PrunedBanksRequestHandler, SnapshotRequestHandler,
},
accounts_db::{self, SnapshotStorages, ACCOUNTS_DB_CONFIG_FOR_TESTING},
accounts_db::{self, ACCOUNTS_DB_CONFIG_FOR_TESTING},
accounts_hash::AccountsHash,
accounts_index::AccountSecondaryIndexes,
bank::{Bank, BankSlotDelta},
Expand Down Expand Up @@ -51,7 +51,7 @@ use {
},
solana_streamer::socket::SocketAddrSpace,
std::{
collections::{HashSet, VecDeque},
collections::HashSet,
fs,
io::{Error, ErrorKind},
path::PathBuf,
Expand Down Expand Up @@ -234,13 +234,13 @@ fn run_bank_forks_snapshot_n<F>(

let (snapshot_request_sender, snapshot_request_receiver) = unbounded();
let request_sender = AbsRequestSender::new(snapshot_request_sender.clone());
let snapshot_request_handler = SnapshotRequestHandler {
let mut snapshot_request_handler = SnapshotRequestHandler {
snapshot_config: snapshot_test_config.snapshot_config.clone(),
snapshot_request_sender,
snapshot_request_receiver,
accounts_package_sender,
latest_slot_snapshot_storages: None,
};
let mut snapshot_slot_storages: VecDeque<SnapshotStorages> = VecDeque::new();
for slot in 1..=last_slot {
let mut bank = Bank::new_from_parent(&bank_forks[slot - 1], &Pubkey::default(), slot);
f(&mut bank, mint_keypair);
Expand All @@ -252,12 +252,7 @@ fn run_bank_forks_snapshot_n<F>(
// set_root should send a snapshot request
bank_forks.set_root(bank.slot(), &request_sender, None);
bank.update_accounts_hash_for_tests();
snapshot_request_handler.handle_snapshot_requests(
false,
0,
&mut None,
&mut snapshot_slot_storages,
);
snapshot_request_handler.handle_snapshot_requests(false, 0, &mut None);
}
}

Expand Down Expand Up @@ -755,15 +750,15 @@ fn test_bank_forks_incremental_snapshot(

let (snapshot_request_sender, snapshot_request_receiver) = unbounded();
let request_sender = AbsRequestSender::new(snapshot_request_sender.clone());
let snapshot_request_handler = SnapshotRequestHandler {
let mut snapshot_request_handler = SnapshotRequestHandler {
snapshot_config: snapshot_test_config.snapshot_config.clone(),
snapshot_request_sender,
snapshot_request_receiver,
accounts_package_sender,
latest_slot_snapshot_storages: None,
};

let mut last_full_snapshot_slot = None;
let mut snapshot_slot_storages: VecDeque<SnapshotStorages> = VecDeque::new();
for slot in 1..=LAST_SLOT {
// Make a new bank and perform some transactions
let bank = {
Expand Down Expand Up @@ -795,7 +790,6 @@ fn test_bank_forks_incremental_snapshot(
false,
0,
&mut last_full_snapshot_slot,
&mut snapshot_slot_storages,
);
}

Expand Down Expand Up @@ -1017,6 +1011,7 @@ fn test_snapshots_with_background_services(
snapshot_request_sender,
snapshot_request_receiver,
accounts_package_sender: accounts_package_sender.clone(),
latest_slot_snapshot_storages: None,
};
let pruned_banks_request_handler = PrunedBanksRequestHandler {
pruned_banks_receiver,
Expand Down
1 change: 1 addition & 0 deletions ledger-tool/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1138,6 +1138,7 @@ fn load_bank_forks(
snapshot_request_sender,
snapshot_request_receiver,
accounts_package_sender,
latest_slot_snapshot_storages: None,
};
let pruned_banks_receiver =
AccountsBackgroundService::setup_bank_drop_callback(bank_forks.clone());
Expand Down
27 changes: 9 additions & 18 deletions runtime/src/accounts_background_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@
//!
//! This can be expensive since we have to walk the append vecs being cleaned up.
use std::collections::VecDeque;

mod stats;
use {
crate::{
Expand Down Expand Up @@ -141,16 +139,16 @@ pub struct SnapshotRequestHandler {
pub snapshot_request_sender: SnapshotRequestSender,
pub snapshot_request_receiver: SnapshotRequestReceiver,
pub accounts_package_sender: Sender<AccountsPackage>,
pub latest_slot_snapshot_storages: Option<SnapshotStorages>,
}

impl SnapshotRequestHandler {
// Returns the latest requested snapshot slot, if one exists
pub fn handle_snapshot_requests(
&self,
&mut self,
test_hash_calculation: bool,
non_snapshot_time_us: u128,
last_full_snapshot_slot: &mut Option<Slot>,
snapshot_slot_storages: &mut VecDeque<SnapshotStorages>,
) -> Option<Result<u64, SnapshotError>> {
let (
snapshot_request,
Expand Down Expand Up @@ -184,7 +182,6 @@ impl SnapshotRequestHandler {
last_full_snapshot_slot,
snapshot_request,
accounts_package_type,
snapshot_slot_storages,
))
}

Expand Down Expand Up @@ -263,13 +260,12 @@ impl SnapshotRequestHandler {
}

fn handle_snapshot_request(
&self,
&mut self,
test_hash_calculation: bool,
non_snapshot_time_us: u128,
last_full_snapshot_slot: &mut Option<Slot>,
snapshot_request: SnapshotRequest,
accounts_package_type: AccountsPackageType,
snapshot_slot_storages: &mut VecDeque<SnapshotStorages>,
) -> Result<u64, SnapshotError> {
debug!(
"handling snapshot request: {:?}, {:?}",
Expand Down Expand Up @@ -379,12 +375,10 @@ impl SnapshotRequestHandler {
accounts_hash_for_testing,
)
.expect("new accounts package for snapshot");
snapshot_slot_storages.push_back(snapshot_storages);
// Update the option, so the older one is released, causing the release of
// its reference counts of the appendvecs
let _ret = self.latest_slot_snapshot_storages.insert(snapshot_storages);

// Remove the older ones, causing them to release the reference counts of the appendvecs
while snapshot_slot_storages.len() > 1 {
snapshot_slot_storages.pop_front();
}
accounts_package
}
SnapshotRequestType::EpochAccountsHash => {
Expand Down Expand Up @@ -515,17 +509,15 @@ pub struct AbsRequestHandlers {
impl AbsRequestHandlers {
// Returns the latest requested snapshot block height, if one exists
pub fn handle_snapshot_requests(
&self,
&mut self,
test_hash_calculation: bool,
non_snapshot_time_us: u128,
last_full_snapshot_slot: &mut Option<Slot>,
snapshot_slot_storages: &mut VecDeque<SnapshotStorages>,
) -> Option<Result<u64, SnapshotError>> {
self.snapshot_request_handler.handle_snapshot_requests(
test_hash_calculation,
non_snapshot_time_us,
last_full_snapshot_slot,
snapshot_slot_storages,
)
}
}
Expand All @@ -538,7 +530,7 @@ impl AccountsBackgroundService {
pub fn new(
bank_forks: Arc<RwLock<BankForks>>,
exit: &Arc<AtomicBool>,
request_handlers: AbsRequestHandlers,
mut request_handlers: AbsRequestHandlers,
test_hash_calculation: bool,
mut last_full_snapshot_slot: Option<Slot>,
) -> Self {
Expand All @@ -548,7 +540,6 @@ impl AccountsBackgroundService {
let mut removed_slots_count = 0;
let mut total_remove_slots_time = 0;
let mut last_expiration_check_time = Instant::now();
let mut snapshot_slot_storages: VecDeque<SnapshotStorages> = VecDeque::new();
let t_background = Builder::new()
.name("solBgAccounts".to_string())
.spawn(move || {
Expand Down Expand Up @@ -609,7 +600,6 @@ impl AccountsBackgroundService {
test_hash_calculation,
non_snapshot_time,
&mut last_full_snapshot_slot,
&mut snapshot_slot_storages,
)
})
.flatten();
Expand Down Expand Up @@ -817,6 +807,7 @@ mod test {
snapshot_request_sender: snapshot_request_sender.clone(),
snapshot_request_receiver,
accounts_package_sender,
latest_slot_snapshot_storages: None,
};

let send_snapshot_request = |snapshot_root_bank, request_type| {
Expand Down

0 comments on commit b340b53

Please sign in to comment.