Skip to content

Commit f809321

Browse files
committed
Ensure client ID is included in chunk cache lookup key
1 parent 0d70386 commit f809321

File tree

4 files changed

+29
-5
lines changed

4 files changed

+29
-5
lines changed

Cargo.lock

Lines changed: 6 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ zerocopy = { version = "0.6.1", features = ["alloc", "simd"] }
7070
zune-inflate = "0.2.54"
7171
cached = { version = "0.54.0", features = ["disk_store", "async"] }
7272
bytes = { version = "1.9.0", features = ["serde"] }
73+
uuid = { version = "1.12.1", features = ["v4"] }
7374

7475
[dev-dependencies]
7576
criterion = { version = "0.4", features = ["async_tokio", "html_reports"] }

src/app.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ async fn schema() -> &'static str {
178178
disk = true,
179179
create = r##"{ DiskCacheBuilder::new("test-cache").set_disk_directory("./").build().expect("valid disk cache builder") }"##,
180180
key = "String",
181-
convert = r##"{ format!("{:?}", request_data) }"##
181+
convert = r##"{ format!("{},{:?}", client, request_data) }"##
182182
)]
183183
async fn download_object<'a>(
184184
client: &s3_client::S3Client,

src/s3_client.rs

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
//! A simplified S3 client that supports downloading objects.
22
//! It attempts to hide the complexities of working with the AWS SDK for S3.
33
4+
use std::fmt::Display;
5+
46
use crate::error::ActiveStorageError;
57
use crate::resource_manager::ResourceManager;
68

@@ -88,10 +90,24 @@ impl S3ClientMap {
8890
}
8991

9092
/// S3 client object.
91-
#[derive(Clone, Debug)]
93+
#[derive(Clone)]
9294
pub struct S3Client {
9395
/// Underlying AWS SDK S3 client object.
9496
client: Client,
97+
/// A unique identifier for the client
98+
// TODO: Make this a hash of url + access key + secret key
99+
// using https://github.com/RustCrypto/hashes?tab=readme-ov-file
100+
// This will be more urgently required once an ageing mechanism
101+
// is implemented for [crate::S3ClientMap].
102+
id: String,
103+
}
104+
105+
// Required so that client can be used as part of the lookup
106+
// key for a local chunk cache.
107+
impl Display for S3Client {
108+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
109+
write!(f, "{}", self.id)
110+
}
95111
}
96112

97113
impl S3Client {
@@ -120,7 +136,10 @@ impl S3Client {
120136
.force_path_style(true)
121137
.build();
122138
let client = Client::from_conf(s3_config);
123-
Self { client }
139+
Self {
140+
client,
141+
id: uuid::Uuid::new_v4().to_string(),
142+
}
124143
}
125144

126145
/// Downloads an object from object storage and returns the data as Bytes

0 commit comments

Comments
 (0)