Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add pruning related persistence API #9232

Merged
merged 1 commit into from
Jul 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
49 changes: 48 additions & 1 deletion crates/engine/tree/src/persistence.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,18 @@ impl<DB: Database> Persistence<DB> {
fn remove_blocks_above(&self, _block_number: u64) -> Vec<ExecutedBlock> {
todo!("implement this")
}

/// Prunes block data before the given block hash according to the configured prune
/// configuration.
fn prune_before(&self, _block_hash: B256) {
todo!("implement this")
}

/// Removes static file related data from the database, depending on the current block height in
/// existing static files.
fn clean_static_file_duplicates(&self) {
todo!("implement this")
}
}

impl<DB> Persistence<DB>
Expand Down Expand Up @@ -135,7 +147,6 @@ where
while let Ok(action) = self.incoming.recv() {
match action {
PersistenceAction::RemoveBlocksAbove((new_tip_num, sender)) => {
// spawn blocking so we can poll the thread later
let output = self.remove_blocks_above(new_tip_num);
sender.send(output).unwrap();
}
Expand All @@ -147,6 +158,14 @@ where
self.write(blocks).unwrap();
sender.send(last_block_hash).unwrap();
}
PersistenceAction::PruneBefore((block_hash, sender)) => {
self.prune_before(block_hash);
sender.send(()).unwrap();
}
PersistenceAction::CleanStaticFileDuplicates(sender) => {
self.clean_static_file_duplicates();
sender.send(()).unwrap();
}
}
}
}
Expand All @@ -161,6 +180,14 @@ pub enum PersistenceAction {

/// Removes the blocks above the given block number from the database.
RemoveBlocksAbove((u64, oneshot::Sender<Vec<ExecutedBlock>>)),

/// Prune associated block data before the given hash, according to already-configured prune
/// modes.
PruneBefore((B256, oneshot::Sender<()>)),

/// Trigger a read of static file data, and delete data depending on the highest block in each
/// static file segment.
CleanStaticFileDuplicates(oneshot::Sender<()>),
}

/// A handle to the persistence task
Expand Down Expand Up @@ -198,4 +225,24 @@ impl PersistenceHandle {
.expect("should be able to send");
rx.await.expect("todo: err handling")
}

/// Tells the persistence task to remove block data before the given hash, according to the
/// configured prune config.
pub async fn prune_before(&self, block_hash: B256) {
let (tx, rx) = oneshot::channel();
self.sender
.send(PersistenceAction::PruneBefore((block_hash, tx)))
.expect("should be able to send");
rx.await.expect("todo: err handling")
}

/// Tells the persistence task to read static file data, and delete data depending on the
/// highest block in each static file segment.
pub async fn clean_static_file_duplicates(&self) {
let (tx, rx) = oneshot::channel();
self.sender
.send(PersistenceAction::CleanStaticFileDuplicates(tx))
.expect("should be able to send");
rx.await.expect("todo: err handling")
}
}
Loading