From 4c1aee42d5032066272a051687ac200e874cc13f Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Thu, 9 Apr 2020 16:16:27 +0200 Subject: Reorganize table API --- src/api_server.rs | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) (limited to 'src/api_server.rs') diff --git a/src/api_server.rs b/src/api_server.rs index 8acd15d8..ff7c536c 100644 --- a/src/api_server.rs +++ b/src/api_server.rs @@ -97,11 +97,9 @@ async fn handle_put(garage: Arc, None => return Err(Error::BadRequest(format!("Empty body"))), }; - let version_key = VersionMetaKey{ - bucket: bucket.to_string(), - key: key.to_string(), - }; - let mut version_value = VersionMetaValue { + let mut version = VersionMeta{ + bucket: bucket.into(), + key: key.into(), timestamp: now_msec(), uuid: version_uuid.clone(), mime_type: mime_type.to_string(), @@ -111,15 +109,15 @@ async fn handle_put(garage: Arc, }; if first_block.len() < INLINE_THRESHOLD { - version_value.data = VersionData::Inline(first_block); - version_value.is_complete = true; - garage.version_table.insert(&version_key, &version_value).await?; + version.data = VersionData::Inline(first_block); + version.is_complete = true; + garage.version_table.insert(&version).await?; return Ok(version_uuid) } let first_block_hash = hash(&first_block[..]); - version_value.data = VersionData::FirstBlock(first_block_hash); - garage.version_table.insert(&version_key, &version_value).await?; + version.data = VersionData::FirstBlock(first_block_hash); + garage.version_table.insert(&version).await?; let block_meta = BlockMeta{ version_uuid: version_uuid.clone(), @@ -145,8 +143,8 @@ async fn handle_put(garage: Arc, // TODO: if at any step we have an error, we should undo everything we did - version_value.is_complete = true; - garage.version_table.insert(&version_key, &version_value).await?; + version.is_complete = true; + garage.version_table.insert(&version).await?; Ok(version_uuid) } -- cgit v1.2.3