Skip to content

Commit

Permalink
txpool/blob: use struct BlobStoreCleanupStat to represent the cleanup…
Browse files Browse the repository at this point in the history
… stat

Signed-off-by: jsvisa <[email protected]>
  • Loading branch information
jsvisa committed Mar 4, 2024
1 parent 8213bc5 commit e13d15f
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 16 deletions.
14 changes: 7 additions & 7 deletions crates/transaction-pool/src/blobstore/disk.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//! A simple diskstore for blobs

use crate::{blobstore::BlobStoreSize, BlobStore, BlobStoreError};
use crate::blobstore::{BlobStore, BlobStoreCleanupStat, BlobStoreError, BlobStoreSize};
use alloy_rlp::{Decodable, Encodable};
use parking_lot::{Mutex, RwLock};
use reth_primitives::{BlobTransactionSidecar, TxHash, B256};
Expand Down Expand Up @@ -71,12 +71,12 @@ impl BlobStore for DiskFileBlobStore {
Ok(())
}

fn cleanup(&self) -> (usize, usize) {
fn cleanup(&self) -> BlobStoreCleanupStat {
let txs_to_delete = {
let mut txs_to_delete = self.inner.txs_to_delete.write();
std::mem::take(&mut *txs_to_delete)
};
let (mut delete_succeed, mut delete_failed) = (0, 0);
let mut stat = BlobStoreCleanupStat::default();
let mut subsize = 0;
debug!(target:"txpool::blob", num_blobs=%txs_to_delete.len(), "Removing blobs from disk");
for tx in txs_to_delete {
Expand All @@ -85,17 +85,17 @@ impl BlobStore for DiskFileBlobStore {
subsize += meta.len();
});
match fs::remove_file(&path) {
Ok(_) => delete_succeed += 1,
Ok(_) => stat.delete_succeed += 1,
Err(e) => {
delete_failed += 1;
stat.delete_failed += 1;
let err = DiskFileBlobStoreError::DeleteFile(tx, path, e);
debug!(target:"txpool::blob", %err);
}
};
}
self.inner.size_tracker.sub_size(subsize as usize);
self.inner.size_tracker.sub_len(delete_succeed);
(delete_succeed, delete_failed)
self.inner.size_tracker.sub_len(stat.delete_succeed);
stat
}

fn get(&self, tx: B256) -> Result<Option<BlobTransactionSidecar>, BlobStoreError> {
Expand Down
8 changes: 5 additions & 3 deletions crates/transaction-pool/src/blobstore/mem.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use crate::blobstore::{BlobStore, BlobStoreError, BlobStoreSize, BlobTransactionSidecar};
use crate::blobstore::{
BlobStore, BlobStoreCleanupStat, BlobStoreError, BlobStoreSize, BlobTransactionSidecar,
};
use parking_lot::RwLock;
use reth_primitives::B256;
use std::{collections::HashMap, sync::Arc};
Expand Down Expand Up @@ -67,8 +69,8 @@ impl BlobStore for InMemoryBlobStore {
Ok(())
}

fn cleanup(&self) -> (usize, usize) {
(0, 0)
fn cleanup(&self) -> BlobStoreCleanupStat {
BlobStoreCleanupStat::default()
}

// Retrieves the decoded blob data for the given transaction hash.
Expand Down
9 changes: 8 additions & 1 deletion crates/transaction-pool/src/blobstore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ pub trait BlobStore: fmt::Debug + Send + Sync + 'static {
///
/// This is intended to be called in the background to clean up any old or unused data, in case
/// the store uses deferred cleanup: [DiskFileBlobStore]
fn cleanup(&self) -> (usize, usize);
fn cleanup(&self) -> BlobStoreCleanupStat;

/// Retrieves the decoded blob data for the given transaction hash.
fn get(&self, tx: B256) -> Result<Option<BlobTransactionSidecar>, BlobStoreError>;
Expand Down Expand Up @@ -140,6 +140,13 @@ impl PartialEq for BlobStoreSize {
}
}

/// Statistics for the cleanup operation.
#[derive(Debug, Default)]
pub struct BlobStoreCleanupStat {
pub(crate) delete_succeed: usize,
pub(crate) delete_failed: usize,
}

#[cfg(test)]
mod tests {
use super::*;
Expand Down
6 changes: 3 additions & 3 deletions crates/transaction-pool/src/blobstore/noop.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use crate::blobstore::{BlobStore, BlobStoreError, BlobTransactionSidecar};
use crate::blobstore::{BlobStore, BlobStoreCleanupStat, BlobStoreError, BlobTransactionSidecar};
use reth_primitives::B256;

/// A blobstore implementation that does nothing
Expand All @@ -23,8 +23,8 @@ impl BlobStore for NoopBlobStore {
Ok(())
}

fn cleanup(&self) -> (usize, usize) {
(0, 0)
fn cleanup(&self) -> BlobStoreCleanupStat {
BlobStoreCleanupStat::default()
}

fn get(&self, _tx: B256) -> Result<Option<BlobTransactionSidecar>, BlobStoreError> {
Expand Down
4 changes: 2 additions & 2 deletions crates/transaction-pool/src/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -794,8 +794,8 @@ where

/// Cleans up the blob store
pub(crate) fn cleanup_blobs(&self) {
let (_, failed) = self.blob_store.cleanup();
self.blob_store_metrics.blobstore_failed_deletes.increment(failed as u64);
let stat = self.blob_store.cleanup();
self.blob_store_metrics.blobstore_failed_deletes.increment(stat.delete_failed as u64);
self.update_blob_store_metrics();
}

Expand Down

0 comments on commit e13d15f

Please sign in to comment.