From 8686cfd0b10a49048021102a08d637b0d4fe6a91 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 20 Oct 2023 13:37:37 +0200 Subject: [PATCH] s3 api: also ensure increasing timestamps for create_multipart_upload --- src/api/s3/multipart.rs | 7 +++++-- src/api/s3/put.rs | 14 +++++++++----- 2 files changed, 14 insertions(+), 7 deletions(-) diff --git a/src/api/s3/multipart.rs b/src/api/s3/multipart.rs index 672ab198..aaf271ab 100644 --- a/src/api/s3/multipart.rs +++ b/src/api/s3/multipart.rs @@ -30,10 +30,13 @@ pub async fn handle_create_multipart_upload( req: &Request, bucket_name: &str, bucket_id: Uuid, - key: &str, + key: &String, ) -> Result, Error> { + let existing_object = garage.object_table.get(&bucket_id, &key).await?; + let upload_id = gen_uuid(); - let timestamp = now_msec(); + let timestamp = next_timestamp(&existing_object); + let headers = get_headers(req.headers())?; // Create object in object table diff --git a/src/api/s3/put.rs b/src/api/s3/put.rs index 62a1f76a..c4df7561 100644 --- a/src/api/s3/put.rs +++ b/src/api/s3/put.rs @@ -86,11 +86,7 @@ pub(crate) async fn save_stream> + Unpin>( // Generate identity of new version let version_uuid = gen_uuid(); - let version_timestamp = existing_object - .as_ref() - .and_then(|obj| obj.versions().iter().map(|v| v.timestamp).max()) - .map(|t| std::cmp::max(t + 1, now_msec())) - .unwrap_or_else(now_msec); + let version_timestamp = next_timestamp(&existing_object); // If body is small enough, store it directly in the object table // as "inline data". We can then return immediately. @@ -532,3 +528,11 @@ pub(crate) fn get_headers(headers: &HeaderMap) -> Result) -> u64 { + existing_object + .as_ref() + .and_then(|obj| obj.versions().iter().map(|v| v.timestamp).max()) + .map(|t| std::cmp::max(t + 1, now_msec())) + .unwrap_or_else(now_msec) +}