Skip to content

Commit

Permalink
chore: introduce tuple type for pruned info
Browse files Browse the repository at this point in the history
  • Loading branch information
mattsse committed Nov 12, 2024
1 parent fa5daef commit 1cb1b09
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 16 deletions.
8 changes: 2 additions & 6 deletions crates/prune/prune/src/event.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
use alloy_primitives::BlockNumber;
use reth_prune_types::{PruneProgress, PruneSegment};
use reth_prune_types::PrunedSegmentInfo;
use std::time::Duration;

/// An event emitted by a [Pruner][crate::Pruner].
Expand All @@ -8,9 +8,5 @@ pub enum PrunerEvent {
/// Emitted when pruner started running.
Started { tip_block_number: BlockNumber },
/// Emitted when pruner finished running.
Finished {
tip_block_number: BlockNumber,
elapsed: Duration,
stats: Vec<(PruneSegment, usize, PruneProgress)>,
},
Finished { tip_block_number: BlockNumber, elapsed: Duration, stats: Vec<PrunedSegmentInfo> },
}
18 changes: 11 additions & 7 deletions crates/prune/prune/src/pruner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use reth_exex_types::FinishedExExHeight;
use reth_provider::{
DBProvider, DatabaseProviderFactory, PruneCheckpointReader, PruneCheckpointWriter,
};
use reth_prune_types::{PruneLimiter, PruneProgress, PruneSegment, PrunerOutput};
use reth_prune_types::{PruneLimiter, PruneProgress, PrunedSegmentInfo, PrunerOutput};
use reth_tokio_util::{EventSender, EventStream};
use std::time::{Duration, Instant};
use tokio::sync::watch;
Expand All @@ -21,8 +21,6 @@ pub type PrunerResult = Result<PrunerOutput, PrunerError>;
/// The pruner type itself with the result of [`Pruner::run`]
pub type PrunerWithResult<S, DB> = (Pruner<S, DB>, PrunerResult);

type PrunerStats = Vec<(PruneSegment, usize, PruneProgress)>;

/// Pruner with preset provider factory.
pub type PrunerWithFactory<PF> = Pruner<<PF as DatabaseProviderFactory>::ProviderRW, PF>;

Expand Down Expand Up @@ -174,14 +172,15 @@ where
/// be pruned according to the highest `static_files`. Segments are parts of the database that
/// represent one or more tables.
///
/// Returns [`PrunerStats`], total number of entries pruned, and [`PruneProgress`].
/// Returns a list of stats per pruned segment, total number of entries pruned, and
/// [`PruneProgress`].
fn prune_segments(
&mut self,
provider: &Provider,
tip_block_number: BlockNumber,
limiter: &mut PruneLimiter,
) -> Result<(PrunerStats, usize, PrunerOutput), PrunerError> {
let mut stats = PrunerStats::new();
) -> Result<(Vec<PrunedSegmentInfo>, usize, PrunerOutput), PrunerError> {
let mut stats = Vec::with_capacity(self.segments.len());
let mut pruned = 0;
let mut output = PrunerOutput {
progress: PruneProgress::Finished,
Expand Down Expand Up @@ -249,7 +248,12 @@ where
if segment_output.pruned > 0 {
limiter.increment_deleted_entries_count_by(segment_output.pruned);
pruned += segment_output.pruned;
stats.push((segment.segment(), segment_output.pruned, segment_output.progress));
let info = PrunedSegmentInfo {
segment: segment.segment(),
pruned: segment_output.pruned,
progress: segment_output.progress,
};
stats.push(info);
}
} else {
debug!(target: "pruner", segment = ?segment.segment(), purpose = ?segment.purpose(), "Nothing to prune for the segment");
Expand Down
3 changes: 2 additions & 1 deletion crates/prune/types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ pub use checkpoint::PruneCheckpoint;
pub use limiter::PruneLimiter;
pub use mode::PruneMode;
pub use pruner::{
PruneInterruptReason, PruneProgress, PrunerOutput, SegmentOutput, SegmentOutputCheckpoint,
PruneInterruptReason, PruneProgress, PrunedSegmentInfo, PrunerOutput, SegmentOutput,
SegmentOutputCheckpoint,
};
pub use segment::{PrunePurpose, PruneSegment, PruneSegmentError};
use serde::{Deserialize, Serialize};
Expand Down
14 changes: 12 additions & 2 deletions crates/prune/types/src/pruner.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
use alloy_primitives::{BlockNumber, TxNumber};

use crate::{PruneCheckpoint, PruneLimiter, PruneMode, PruneSegment};
use alloy_primitives::{BlockNumber, TxNumber};

/// Pruner run output.
#[derive(Debug)]
Expand All @@ -17,6 +16,17 @@ impl From<PruneProgress> for PrunerOutput {
}
}

/// Represents information of a pruner run for a segment.
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct PrunedSegmentInfo {
/// The pruned segment
pub segment: PruneSegment,
/// Number of pruned entries
pub pruned: usize,
/// Prune progress
pub progress: PruneProgress,
}

/// Segment pruning output.
#[derive(Debug, Clone, Copy, Eq, PartialEq)]
pub struct SegmentOutput {
Expand Down

0 comments on commit 1cb1b09

Please sign in to comment.