Skip to content

Commit

Permalink
txpool: track failed delete blobs in cleanup
Browse files Browse the repository at this point in the history
Signed-off-by: jsvisa <[email protected]>
  • Loading branch information
jsvisa committed Mar 4, 2024
1 parent 4049093 commit 6fb1580
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 24 deletions.
20 changes: 12 additions & 8 deletions crates/transaction-pool/src/blobstore/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -71,27 +71,31 @@ impl BlobStore for DiskFileBlobStore {
Ok(())
}

fn cleanup(&self) {
fn cleanup(&self) -> (usize, usize) {
let txs_to_delete = {
let mut txs_to_delete = self.inner.txs_to_delete.write();
std::mem::take(&mut *txs_to_delete)
};
let mut deleted_blobs = txs_to_delete.len();
let (mut delete_succeed, mut delete_failed) = (0, 0);
let mut subsize = 0;
debug!(target:"txpool::blob", num_blobs=%txs_to_delete.len(), "Removing blobs from disk");
for tx in txs_to_delete {
let path = self.inner.blob_disk_file(tx);
let _ = fs::metadata(&path).map(|meta| {
subsize += meta.len();
});
let _ = fs::remove_file(&path).map_err(|e| {
deleted_blobs -= 1;
let err = DiskFileBlobStoreError::DeleteFile(tx, path, e);
debug!(target:"txpool::blob", %err);
});
match fs::remove_file(&path) {
Ok(_) => delete_succeed += 1,
Err(e) => {
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(deleted_blobs);
self.inner.size_tracker.sub_len(delete_succeed);
(delete_succeed, delete_failed)
}

fn get(&self, tx: B256) -> Result<Option<BlobTransactionSidecar>, BlobStoreError> {
Expand Down
4 changes: 3 additions & 1 deletion crates/transaction-pool/src/blobstore/mem.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,9 @@ impl BlobStore for InMemoryBlobStore {
Ok(())
}

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

// Retrieves the decoded blob data for the given transaction hash.
fn get(&self, tx: B256) -> Result<Option<BlobTransactionSidecar>, BlobStoreError> {
Expand Down
5 changes: 3 additions & 2 deletions crates/transaction-pool/src/blobstore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,11 +34,12 @@ pub trait BlobStore: fmt::Debug + Send + Sync + 'static {
/// Deletes multiple blob sidecars from the store
fn delete_all(&self, txs: Vec<B256>) -> Result<(), BlobStoreError>;

/// A maintenance function that can be called periodically to clean up the blob store.
/// A maintenance function that can be called periodically to clean up the blob store, returns
/// the number of successfully deleted blobs and the number of failed deletions.
///
/// 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);
fn cleanup(&self) -> (usize, usize);

/// Retrieves the decoded blob data for the given transaction hash.
fn get(&self, tx: B256) -> Result<Option<BlobTransactionSidecar>, BlobStoreError>;
Expand Down
4 changes: 3 additions & 1 deletion crates/transaction-pool/src/blobstore/noop.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,9 @@ impl BlobStore for NoopBlobStore {
Ok(())
}

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

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

/// Delete a blob from the blob store
pub(crate) fn delete_blob(&self, blob: TxHash) {
if let Err(err) = self.blob_store.delete(blob) {
warn!(target: "txpool", %err, "[{:?}] failed to delete blobs", blob);
self.blob_store_metrics.blobstore_failed_deletes.increment(1);
}
self.update_blob_store_metrics();
let _ = self.blob_store.delete(blob);
}

/// Delete all blobs from the blob store
pub(crate) fn delete_blobs(&self, txs: Vec<TxHash>) {
let num = txs.len();
if let Err(err) = self.blob_store.delete_all(txs) {
warn!(target: "txpool", %err,?num, "failed to delete blobs");
self.blob_store_metrics.blobstore_failed_deletes.increment(num as u64);
}
self.update_blob_store_metrics();
let _ = self.blob_store.delete_all(txs);
}

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

Expand Down

0 comments on commit 6fb1580

Please sign in to comment.