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

Multilevel cache #1064

Merged
merged 2 commits into from
Nov 6, 2024
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion mountpoint-s3/src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ pub struct CliArgs {
#[cfg(feature = "block_size")]
#[clap(
long,
help = "Size of a cache block in KiB [Default: 1024 (1 MiB) for disk cache and for S3 Express cache]",
help = "Size of a cache block in KiB [Default: 1024 (1 MiB)]",
help_heading = CACHING_OPTIONS_HEADER,
value_name = "KiB",
requires = "cache_group",
Expand Down
3 changes: 3 additions & 0 deletions mountpoint-s3/src/data_cache/express_data_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,8 @@ where
};

pin_mut!(result);
// Guarantee that the request will start even in case of `initial_read_window == 0`.
result.as_mut().increment_read_window(self.block_size as usize);

// TODO: optimize for the common case of a single chunk.
let mut buffer = BytesMut::default();
Expand All @@ -89,6 +91,7 @@ where
}
buffer.extend_from_slice(&body);

// Ensure the flow-control window is large enough.
result.as_mut().increment_read_window(self.block_size as usize);
passaro marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems unnecessary now, doesn't it?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to keep it for now and review when we optimize for the single chunk case (see TODO above).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll need to account for a case when the block object is larger than block_size for some reason. If we've just removed this line the read may freeze. If we've kept it as it is now MP may attempt to read an unbounded amount of data to RAM.

This requires a bit more thinking, so I agree that it's better to address in the following PR.

}
Err(ObjectClientError::ServiceError(GetObjectError::NoSuchKey)) => return Ok(None),
Expand Down
11 changes: 4 additions & 7 deletions mountpoint-s3/src/data_cache/multilevel_cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,6 @@ use crate::object::ObjectId;
use super::{BlockIndex, ChecksummedBytes, DataCache, DataCacheResult};

/// A data cache which uses both the local disk and S3 Express One Zone bucket as a storage.
passaro marked this conversation as resolved.
Show resolved Hide resolved
/// Disk cache is assumed to be faster so this is quiried first on `get_block` requests. An
/// S3 Express One Zone cache is checked when data is missing on disk. Both caches are
/// populated on `put_block`.
pub struct MultilevelDataCache<DiskCache, ExpressCache, Runtime> {
passaro marked this conversation as resolved.
Show resolved Hide resolved
disk_cache: Arc<DiskCache>,
express_cache: ExpressCache,
Expand All @@ -21,11 +18,9 @@ pub struct MultilevelDataCache<DiskCache, ExpressCache, Runtime> {
impl<DiskCache: DataCache, ExpressCache: DataCache, Runtime: Spawn>
MultilevelDataCache<DiskCache, ExpressCache, Runtime>
{
/// Both the `disk_cache` and `express_cache` must be configured with the same `block_size`.
pub fn new(disk_cache: Arc<DiskCache>, express_cache: ExpressCache, runtime: Runtime) -> Self {
// Method `MultilevelDataCache::block_size` relies on block sizes of both caches to be equal.
// `CachingPartStream`, being the user of cache, uses this method to split S3 object into blocks.
// Allowing non-matching block sizes would mean splitting objects in 2 different ways and imply
// the different interface for the `MultilevelDataCache`.
// The same blocks are written to both caches. The `block_size`-s must match.
assert_eq!(
disk_cache.block_size(),
express_cache.block_size(),
Expand All @@ -46,6 +41,7 @@ where
ExpressCache: DataCache + Sync,
Runtime: Spawn + Sync,
{
/// Gets a block from one of the underlying caches. Populates the disk cache with data fetched from the S3 Express cache.
async fn get_block(
&self,
cache_key: &ObjectId,
Expand Down Expand Up @@ -82,6 +78,7 @@ where
DataCacheResult::Ok(None)
}

/// Puts a block to both caches.
async fn put_block(
&self,
cache_key: ObjectId,
Expand Down
Loading