From 3d6ed63824ac2190ba0522d897ef9addb8823140 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 18 Oct 2023 16:36:48 +0200 Subject: check_quotas: avoid re-fetching object from object table --- src/api/s3/multipart.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/api/s3/multipart.rs') diff --git a/src/api/s3/multipart.rs b/src/api/s3/multipart.rs index 52ea8e78..b6001142 100644 --- a/src/api/s3/multipart.rs +++ b/src/api/s3/multipart.rs @@ -233,7 +233,7 @@ pub async fn handle_complete_multipart_upload( // Get object and multipart upload let key = key.to_string(); - let (_, mut object_version, mpu) = get_upload(&garage, &bucket.id, &key, &upload_id).await?; + let (object, mut object_version, mpu) = get_upload(&garage, &bucket.id, &key, &upload_id).await?; if mpu.parts.is_empty() { return Err(Error::bad_request("No data was uploaded")); @@ -331,7 +331,7 @@ pub async fn handle_complete_multipart_upload( // Calculate total size of final object let total_size = parts.iter().map(|x| x.size.unwrap()).sum(); - if let Err(e) = check_quotas(&garage, bucket, &key, total_size).await { + if let Err(e) = check_quotas(&garage, bucket, &key, total_size, Some(&object)).await { object_version.state = ObjectVersionState::Aborted; let final_object = Object::new(bucket.id, key.clone(), vec![object_version]); garage.object_table.insert(&final_object).await?; -- cgit v1.2.3 From d146cdd5b66ca1d3ed65ce93ca42c6db22defc09 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Wed, 18 Oct 2023 16:38:26 +0200 Subject: cargo fmt --- src/api/s3/multipart.rs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/api/s3/multipart.rs') diff --git a/src/api/s3/multipart.rs b/src/api/s3/multipart.rs index b6001142..978ad9cf 100644 --- a/src/api/s3/multipart.rs +++ b/src/api/s3/multipart.rs @@ -233,7 +233,8 @@ pub async fn handle_complete_multipart_upload( // Get object and multipart upload let key = key.to_string(); - let (object, mut object_version, mpu) = get_upload(&garage, &bucket.id, &key, &upload_id).await?; + let (object, mut object_version, mpu) = + get_upload(&garage, &bucket.id, &key, &upload_id).await?; if mpu.parts.is_empty() { return Err(Error::bad_request("No data was uploaded")); -- cgit v1.2.3 From c6cde1f1437a6cab90b22df6fe0641e5ad34c287 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 20 Oct 2023 13:20:47 +0200 Subject: remove now-unused key parameter in check_quotas --- src/api/s3/multipart.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/api/s3/multipart.rs') diff --git a/src/api/s3/multipart.rs b/src/api/s3/multipart.rs index 978ad9cf..672ab198 100644 --- a/src/api/s3/multipart.rs +++ b/src/api/s3/multipart.rs @@ -332,7 +332,7 @@ pub async fn handle_complete_multipart_upload( // Calculate total size of final object let total_size = parts.iter().map(|x| x.size.unwrap()).sum(); - if let Err(e) = check_quotas(&garage, bucket, &key, total_size, Some(&object)).await { + if let Err(e) = check_quotas(&garage, bucket, total_size, Some(&object)).await { object_version.state = ObjectVersionState::Aborted; let final_object = Object::new(bucket.id, key.clone(), vec![object_version]); garage.object_table.insert(&final_object).await?; -- cgit v1.2.3 From 8686cfd0b10a49048021102a08d637b0d4fe6a91 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 20 Oct 2023 13:37:37 +0200 Subject: s3 api: also ensure increasing timestamps for create_multipart_upload --- src/api/s3/multipart.rs | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'src/api/s3/multipart.rs') 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 -- cgit v1.2.3 From c82d91c6bccf307186332b6c5c6fc0b128b1b2b1 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 20 Oct 2023 13:55:34 +0200 Subject: DeleteObject: always insert a deletion marker with a bigger timestamp than everything before --- src/api/s3/multipart.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'src/api/s3/multipart.rs') diff --git a/src/api/s3/multipart.rs b/src/api/s3/multipart.rs index aaf271ab..6b786318 100644 --- a/src/api/s3/multipart.rs +++ b/src/api/s3/multipart.rs @@ -9,7 +9,6 @@ use md5::{Digest as Md5Digest, Md5}; use garage_table::*; use garage_util::async_hash::*; use garage_util::data::*; -use garage_util::time::*; use garage_model::bucket_table::Bucket; use garage_model::garage::Garage; @@ -35,7 +34,7 @@ pub async fn handle_create_multipart_upload( let existing_object = garage.object_table.get(&bucket_id, &key).await?; let upload_id = gen_uuid(); - let timestamp = next_timestamp(&existing_object); + let timestamp = next_timestamp(existing_object.as_ref()); let headers = get_headers(req.headers())?; -- cgit v1.2.3