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

Improve error handling and reporting when removing cache blocks #1043

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
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
21 changes: 16 additions & 5 deletions mountpoint-s3/src/data_cache/disk_data_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -335,11 +335,19 @@ impl DiskDataCache {
let path_to_remove = self.get_path_for_block_key(&to_remove);
trace!("evicting block at {}", path_to_remove.display());
if let Err(remove_err) = fs::remove_file(&path_to_remove) {
warn!("unable to remove invalid block: {:?}", remove_err);
if remove_err.kind() != ErrorKind::NotFound {
warn!("unable to evict block: {:?}", remove_err);
}
}
}
Ok(())
}

fn remove_block_from_usage(&self, block_key: &DiskBlockKey) {
if let Some(usage) = &self.usage {
usage.lock().unwrap().remove(block_key);
}
}
}

/// Hash the cache key using its fields as well as the [CACHE_VERSION].
Expand Down Expand Up @@ -389,12 +397,15 @@ impl DataCache for DiskDataCache {
metrics::counter!("disk_data_cache.block_hit").increment(0);
metrics::counter!("disk_data_cache.block_err").increment(1);
match fs::remove_file(&path) {
Ok(()) => {
if let Some(usage) = &self.usage {
usage.lock().unwrap().remove(&block_key);
Ok(()) => self.remove_block_from_usage(&block_key),
Err(remove_err) => {
// We failed to delete the block.
if remove_err.kind() == ErrorKind::NotFound {
// No need to report or try again.
self.remove_block_from_usage(&block_key);
}
warn!("unable to remove invalid block: {:?}", remove_err);
}
Err(remove_err) => warn!("unable to remove invalid block: {:?}", remove_err),
}
Err(err)
}
Expand Down
13 changes: 12 additions & 1 deletion mountpoint-s3/src/object.rs
Original file line number Diff line number Diff line change
@@ -1,14 +1,25 @@
use std::fmt::Debug;

use mountpoint_s3_client::types::ETag;

use crate::sync::Arc;

/// Identifier for a specific version of an S3 object.
/// Formed by the object key and etag. Holds its components in an [Arc], so it can be cheaply cloned.
#[derive(Clone, Debug, Hash, PartialEq, Eq)]
#[derive(Clone, Hash, PartialEq, Eq)]
pub struct ObjectId {
inner: Arc<InnerObjectId>,
}

impl Debug for ObjectId {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.debug_struct("ObjectId")
.field("key", &self.inner.key)
.field("etag", &self.inner.etag)
.finish()
}
}

#[derive(Debug, Hash, PartialEq, Eq)]
struct InnerObjectId {
key: String,
Expand Down
Loading