Introduce ttl eviction for RecycleStore (#15513)

This commit is contained in:
Ryo Onodera
2021-02-25 17:27:27 +09:00
committed by GitHub
parent d8ba56ec09
commit 21b43009f6
3 changed files with 157 additions and 9 deletions

View File

@@ -21,7 +21,7 @@ use std::{
Arc, RwLock,
},
thread::{self, sleep, Builder, JoinHandle},
time::Duration,
time::{Duration, Instant},
};
const INTERVAL_MS: u64 = 100;
@@ -30,6 +30,13 @@ const SHRUNKEN_ACCOUNT_PER_INTERVAL: usize =
SHRUNKEN_ACCOUNT_PER_SEC / (1000 / INTERVAL_MS as usize);
const CLEAN_INTERVAL_BLOCKS: u64 = 100;
// This value is chosen to spread the dropping cost over 3 expiration checks
// RecycleStores are fully populated almost all of its lifetime. So, otherwise
// this would drop MAX_RECYCLE_STORES mmaps at once in the worst case...
// (Anyway, the dropping part is outside the AccountsDb::recycle_stores lock
// and dropped in this AccountsBackgroundServe, so this shouldn't matter much)
const RECYCLE_STORE_EXPIRATION_INTERVAL_SECS: u64 = crate::accounts_db::EXPIRATION_TTL_SECONDS / 3;
pub type SnapshotRequestSender = Sender<SnapshotRequest>;
pub type SnapshotRequestReceiver = Receiver<SnapshotRequest>;
pub type DroppedSlotsSender = Sender<Slot>;
@@ -286,6 +293,7 @@ impl AccountsBackgroundService {
let mut last_cleaned_block_height = 0;
let mut removed_slots_count = 0;
let mut total_remove_slots_time = 0;
let mut last_expiration_check_time = Instant::now();
let t_background = Builder::new()
.name("solana-accounts-background".to_string())
.spawn(move || loop {
@@ -304,6 +312,8 @@ impl AccountsBackgroundService {
&mut total_remove_slots_time,
);
Self::expire_old_recycle_stores(&bank, &mut last_expiration_check_time);
// Check to see if there were any requests for snapshotting banks
// < the current root bank `bank` above.
@@ -397,6 +407,16 @@ impl AccountsBackgroundService {
*removed_slots_count = 0;
}
}
fn expire_old_recycle_stores(bank: &Bank, last_expiration_check_time: &mut Instant) {
let now = Instant::now();
if now.duration_since(*last_expiration_check_time).as_secs()
> RECYCLE_STORE_EXPIRATION_INTERVAL_SECS
{
bank.expire_old_recycle_stores();
*last_expiration_check_time = now;
}
}
}
#[cfg(test)]