Skip to content

Commit

Permalink
Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dmakarov committed Oct 18, 2024
1 parent afd45c6 commit e705dce
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
19 changes: 13 additions & 6 deletions accounts-db/src/accounts_db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,10 @@ const SHRINK_COLLECT_CHUNK_SIZE: usize = 50;
/// candidates for shrinking.
const SHRINK_INSERT_ANCIENT_THRESHOLD: usize = 10;

/// Default value for the number of ancient storages the ancient slot
/// combining should converge to.
pub const MAX_ANCIENT_SLOTS_DEFAULT: usize = 100_000;

#[derive(Debug, Default, Clone, Copy, PartialEq, Eq)]
pub enum CreateAncientStorage {
/// ancient storages are created by appending
Expand Down Expand Up @@ -15884,16 +15888,19 @@ pub mod tests {
assert!(db
.get_sorted_potential_ancient_slots(oldest_non_ancient_slot)
.is_empty());
let root0 = 0;
let root0 = MAX_ANCIENT_SLOTS_DEFAULT as u64 + ancient_append_vec_offset as u64 + 1;
db.add_root(root0);
let root1 = 1;
let root1 = root0 + 1;
db.add_root(root1);
let oldest_non_ancient_slot = db.get_oldest_non_ancient_slot(&epoch_schedule);
assert!(db
.get_sorted_potential_ancient_slots(oldest_non_ancient_slot)
.is_empty());
let completed_slot = epoch_schedule.slots_per_epoch;
db.accounts_index.add_root(completed_slot);
db.accounts_index.add_root(AccountsDb::apply_offset_to_slot(
completed_slot,
ancient_append_vec_offset,
));
let oldest_non_ancient_slot = db.get_oldest_non_ancient_slot(&epoch_schedule);
// get_sorted_potential_ancient_slots uses 'less than' as opposed to 'less or equal'
// so, we need to get more than an epoch away to get the first valid root
Expand All @@ -15903,17 +15910,17 @@ pub mod tests {
let completed_slot = epoch_schedule.slots_per_epoch + root0;
db.accounts_index.add_root(AccountsDb::apply_offset_to_slot(
completed_slot,
-ancient_append_vec_offset,
ancient_append_vec_offset,
));
let oldest_non_ancient_slot = db.get_oldest_non_ancient_slot(&epoch_schedule);
assert_eq!(
db.get_sorted_potential_ancient_slots(oldest_non_ancient_slot),
vec![root0]
vec![root0, root1]
);
let completed_slot = epoch_schedule.slots_per_epoch + root1;
db.accounts_index.add_root(AccountsDb::apply_offset_to_slot(
completed_slot,
-ancient_append_vec_offset,
ancient_append_vec_offset,
));
let oldest_non_ancient_slot = db.get_oldest_non_ancient_slot(&epoch_schedule);
assert_eq!(
Expand Down
3 changes: 2 additions & 1 deletion accounts-db/src/ancient_append_vecs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ use {
stats::{ShrinkAncientStats, ShrinkStatsSub},
AccountFromStorage, AccountStorageEntry, AccountsDb, AliveAccounts,
GetUniqueAccountsResult, ShrinkCollect, ShrinkCollectAliveSeparatedByRefs,
MAX_ANCIENT_SLOTS_DEFAULT,
},
accounts_file::AccountsFile,
active_stats::ActiveStatItem,
Expand Down Expand Up @@ -344,7 +345,7 @@ impl AccountsDb {
let tuning = PackedAncientStorageTuning {
// Slots old enough to be ancient. Setting this parameter
// to 100k makes ancient storages to be approx 5M.
max_ancient_slots: 100_000,
max_ancient_slots: MAX_ANCIENT_SLOTS_DEFAULT,
// Don't re-pack anything just to shrink.
// shrink_candidate_slots will handle these old storages.
percent_of_alive_shrunk_data: 0,
Expand Down

0 comments on commit e705dce

Please sign in to comment.