Skip to content

Commit

Permalink
Log actual and target storage size in 'should_prune'
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex6323 committed Mar 21, 2022
1 parent 226fdc2 commit 932a760
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 9 deletions.
2 changes: 1 addition & 1 deletion bee-ledger/src/workers/consensus/worker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -356,7 +356,7 @@ where
}
}

match should_prune(&tangle, ledger_index, pruning_delay, &pruning_config) {
match should_prune(&tangle, &storage, ledger_index, pruning_delay, &pruning_config) {
Ok((start_index, target_index)) => {
if let Err(e) =
prune::prune(&tangle, &storage, &bus, start_index, target_index, &pruning_config)
Expand Down
22 changes: 15 additions & 7 deletions bee-ledger/src/workers/pruning/condition.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,25 +17,33 @@ pub enum PruningSkipReason {
BelowThreshold { reached_in: u32 },
}

pub(crate) fn should_prune<B: StorageBackend>(
tangle: &Tangle<B>,
pub(crate) fn should_prune<S: StorageBackend>(
tangle: &Tangle<S>,
storage: &S,
ledger_index: LedgerIndex,
pruning_delay: u32,
max_milestones_to_keep: u32,
config: &PruningConfig,
) -> Result<(MilestoneIndex, MilestoneIndex), PruningSkipReason> {
if !config.pruning_milestones().enabled() {
) -> Result<(MilestoneIndex, MilestoneIndex), PruningSkipReason>
{
log::debug!(
"Storage size: actual {} limit {}",
storage.size().expect("ok storage size").expect("some storage size"),
config.pruning_by_size().target_size()
);

if !config.pruning_milestones().enabled() && !config.pruning_by_size().enabled() {
return Err(PruningSkipReason::Disabled);
}

let pruning_index = *tangle.get_pruning_index() + 1;
let pruning_threshold = pruning_index + pruning_delay;
let pruning_threshold = pruning_index + max_milestones_to_keep;

if *ledger_index < pruning_threshold {
Err(PruningSkipReason::BelowThreshold {
reached_in: pruning_threshold - *ledger_index,
})
} else {
let target_pruning_index = *ledger_index - pruning_delay;
let target_pruning_index = *ledger_index - max_milestones_to_keep;

Ok((
pruning_index.into(),
Expand Down
1 change: 0 additions & 1 deletion bee-ledger/src/workers/pruning/prune.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ pub async fn prune<S: StorageBackend>(
let index = MilestoneIndex(index);

debug!("Pruning milestone {}...", index);
debug!("Storage size: actual {} limit {}", storage.size().expect("ok storage size").expect("some storage size"), config.pruning_by_size().target_size());

// Measurement of the full pruning step.
let full_prune = Instant::now();
Expand Down

0 comments on commit 932a760

Please sign in to comment.