s3 api: also ensure increasing timestamps for create_multipart_upload

This commit is contained in:
Alex Auvolat 2023-10-20 13:37:37 +02:00
parent c6cde1f143
commit 8686cfd0b1
2 changed files with 14 additions and 7 deletions

View file

@ -30,10 +30,13 @@ pub async fn handle_create_multipart_upload(
req: &Request<Body>, req: &Request<Body>,
bucket_name: &str, bucket_name: &str,
bucket_id: Uuid, bucket_id: Uuid,
key: &str, key: &String,
) -> Result<Response<Body>, Error> { ) -> Result<Response<Body>, Error> {
let existing_object = garage.object_table.get(&bucket_id, &key).await?;
let upload_id = gen_uuid(); let upload_id = gen_uuid();
let timestamp = now_msec(); let timestamp = next_timestamp(&existing_object);
let headers = get_headers(req.headers())?; let headers = get_headers(req.headers())?;
// Create object in object table // Create object in object table

View file

@ -86,11 +86,7 @@ pub(crate) async fn save_stream<S: Stream<Item = Result<Bytes, Error>> + Unpin>(
// Generate identity of new version // Generate identity of new version
let version_uuid = gen_uuid(); let version_uuid = gen_uuid();
let version_timestamp = existing_object let version_timestamp = next_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);
// If body is small enough, store it directly in the object table // If body is small enough, store it directly in the object table
// as "inline data". We can then return immediately. // as "inline data". We can then return immediately.
@ -532,3 +528,11 @@ pub(crate) fn get_headers(headers: &HeaderMap<HeaderValue>) -> Result<ObjectVers
other, other,
}) })
} }
pub(crate) fn next_timestamp(existing_object: &Option<Object>) -> 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)
}