Skip to content

Commit

Permalink
Remove unused 'cached_block_indices' method in DataCache trait (#607)
Browse files Browse the repository at this point in the history
Signed-off-by: Daniel Carl Jones <djonesoa@amazon.com>
  • Loading branch information
dannycjones authored Nov 16, 2023
1 parent a1e4d86 commit 52dfe29
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 78 deletions.
14 changes: 0 additions & 14 deletions mountpoint-s3/src/data_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,6 @@
mod disk_data_cache;
mod in_memory_data_cache;

use std::ops::RangeBounds;

use mountpoint_s3_client::types::ETag;
use thiserror::Error;

Expand Down Expand Up @@ -52,16 +50,4 @@ pub trait DataCache {

/// Returns the block size for the data cache.
fn block_size(&self) -> u64;

/// For the given range of blocks, which are present in the cache?
/// Indices in the vector are already sorted.
///
/// It is possible that the **blocks may be deleted before reading**, or may be corrupted or inaccessible.
/// This method only indicates that a cache entry was present at the time of calling.
/// There is no guarantee that the data will still be available at the time of reading.
fn cached_block_indices<R: RangeBounds<BlockIndex>>(
&self,
cache_key: &CacheKey,
range: R,
) -> DataCacheResult<Vec<BlockIndex>>;
}
9 changes: 0 additions & 9 deletions mountpoint-s3/src/data_cache/disk_data_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use std::fs;
use std::io::{ErrorKind, Read, Write};
use std::ops::RangeBounds;
use std::path::PathBuf;

use bytes::Bytes;
Expand Down Expand Up @@ -248,14 +247,6 @@ impl DataCache for DiskDataCache {
fn block_size(&self) -> u64 {
self.block_size
}

fn cached_block_indices<R: RangeBounds<BlockIndex>>(
&self,
_cache_key: &CacheKey,
_range: R,
) -> DataCacheResult<Vec<BlockIndex>> {
todo!("implement or deprecate");
}
}

#[cfg(test)]
Expand Down
55 changes: 0 additions & 55 deletions mountpoint-s3/src/data_cache/in_memory_data_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
use std::collections::HashMap;
use std::default::Default;
use std::ops::RangeBounds;

use super::{BlockIndex, CacheKey, ChecksummedBytes, DataCache, DataCacheResult};
use crate::sync::RwLock;
Expand Down Expand Up @@ -40,21 +39,6 @@ impl DataCache for InMemoryDataCache {
fn block_size(&self) -> u64 {
self.block_size
}

fn cached_block_indices<R: RangeBounds<BlockIndex>>(
&self,
cache_key: &CacheKey,
range: R,
) -> DataCacheResult<Vec<BlockIndex>> {
let data = self.data.read().unwrap();
let mut result = match data.get(cache_key) {
None => Vec::new(),
Some(blocks) => blocks.keys().filter(|idx| range.contains(idx)).copied().collect(),
};
result.sort();

Ok(result)
}
}

#[cfg(test)]
Expand Down Expand Up @@ -139,43 +123,4 @@ mod tests {
"cache entry returned should match original bytes after put"
);
}

#[test]
fn test_cached_indices() {
let data_1 = Bytes::from_static(b"Hello world");
let data_1 = ChecksummedBytes::from_bytes(data_1.clone());
let data_2 = Bytes::from_static(b"Foo bar");
let data_2 = ChecksummedBytes::from_bytes(data_2.clone());

let cache = InMemoryDataCache::new(8 * 1024 * 1024);
let cache_key_1 = CacheKey {
s3_key: "a".into(),
etag: ETag::for_tests(),
};
let cache_key_2 = CacheKey {
s3_key: "b".into(),
etag: ETag::for_tests(),
};

let cached_indices = cache
.cached_block_indices(&cache_key_1, 0..5)
.expect("should not error");
let expected: Vec<BlockIndex> = Vec::new();
assert_eq!(cached_indices, expected);

cache
.put_block(cache_key_1.clone(), 2, data_1.clone())
.expect("no reason to error, cache is accessible");
cache
.put_block(cache_key_1.clone(), 3, data_2.clone())
.expect("no reason to error, cache is accessible");
cache
.put_block(cache_key_2.clone(), 5, data_2.clone())
.expect("no reason to error, cache is accessible");

let cached_indices = cache
.cached_block_indices(&cache_key_1, 0..12)
.expect("should not error");
assert_eq!(cached_indices, vec![2, 3]);
}
}

0 comments on commit 52dfe29

Please sign in to comment.