-
Notifications
You must be signed in to change notification settings - Fork 0
Draft Fix chunk cache key and metadata retrieval #104
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
base: main
Are you sure you want to change the base?
Changes from 4 commits
b3de156
0ee8298
57df55d
587aa29
cce5926
a4af1cb
de30640
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
@@ -22,11 +22,11 @@ struct ChunkCacheEntry { | |||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
impl ChunkCacheEntry { | ||||||||||||||||||||||||||||||||||
/// Return a ChunkCacheEntry object | ||||||||||||||||||||||||||||||||||
fn new(key: &str, value: Bytes) -> Self { | ||||||||||||||||||||||||||||||||||
fn new(key: &str, value: &Bytes) -> Self { | ||||||||||||||||||||||||||||||||||
let key = key.to_owned(); | ||||||||||||||||||||||||||||||||||
// Make sure we own the `Bytes` so we don't see unexpected, but not incorrect, | ||||||||||||||||||||||||||||||||||
// behaviour caused by the zero copy of `Bytes`. i.e. let us choose when to copy. | ||||||||||||||||||||||||||||||||||
let value = Bytes::copy_from_slice(&value); | ||||||||||||||||||||||||||||||||||
let value = Bytes::copy_from_slice(value); | ||||||||||||||||||||||||||||||||||
Self { key, value } | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
@@ -103,7 +103,7 @@ impl ChunkCache { | |||||||||||||||||||||||||||||||||
/// | ||||||||||||||||||||||||||||||||||
/// * `key`: Unique key identifying the chunk | ||||||||||||||||||||||||||||||||||
/// * `value`: Chunk `Bytes` to be cached | ||||||||||||||||||||||||||||||||||
pub async fn set(&self, key: &str, value: Bytes) -> Result<(), ActiveStorageError> { | ||||||||||||||||||||||||||||||||||
pub async fn set(&self, key: &str, value: &Bytes) -> Result<(), ActiveStorageError> { | ||||||||||||||||||||||||||||||||||
match self.sender.send(ChunkCacheEntry::new(key, value)).await { | ||||||||||||||||||||||||||||||||||
Ok(_) => Ok(()), | ||||||||||||||||||||||||||||||||||
Err(e) => Err(ActiveStorageError::ChunkCacheError { | ||||||||||||||||||||||||||||||||||
|
@@ -118,8 +118,7 @@ impl ChunkCache { | |||||||||||||||||||||||||||||||||
/// | ||||||||||||||||||||||||||||||||||
/// * `key`: Unique key identifying the chunk | ||||||||||||||||||||||||||||||||||
pub async fn get_metadata(&self, key: &str) -> Option<Metadata> { | ||||||||||||||||||||||||||||||||||
let state = self.cache.load_state().await; | ||||||||||||||||||||||||||||||||||
state.metadata.get(key).cloned() | ||||||||||||||||||||||||||||||||||
self.cache.get_metadata(key).await | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
/// Retrieves chunk `Bytes` from the cache for an unique key. | ||||||||||||||||||||||||||||||||||
|
@@ -320,6 +319,26 @@ impl SimpleDiskCache { | |||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||
/// Retrieves chunk metadata from the cache for an unique key. | ||||||||||||||||||||||||||||||||||
|
/// Retrieves chunk metadata from the cache for an unique key. | |
/// Retrieves chunk metadata from the cache for a unique key. |
Outdated
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is there anything we can do to avoid the unwraps here? Or we could at least log the error for easier debugging with something like
fs::remove_file(path.join(self.filename_for_key(key).await)) | |
.await | |
.unwrap(); | |
// Remove the metadata file | |
fs::remove_file(path.join(self.filename_for_key(key).await + ".meta")) | |
.await | |
.unwrap(); | |
fs::remove_file(path.join(self.filename_for_key(key).await)) | |
.await | |
.map_err(|e| log::error!("Failed to remove cache data with: {}", e) | |
.unwrap(); | |
// Remove the metadata file | |
fs::remove_file(path.join(self.filename_for_key(key).await + ".meta")) | |
.await | |
.map_err(|e| log::error!("Failed to remove cache metadata with: {}", e) | |
.unwrap(); |
N.B. We might also want to add this map_error
pattern anywhere else in the code that we need to use unwrap / expect.
Uh oh!
There was an error while loading. Please reload this page.