diff options
author | Alex Auvolat <alex@adnab.me> | 2020-04-10 23:11:52 +0200 |
---|---|---|
committer | Alex Auvolat <alex@adnab.me> | 2020-04-10 23:11:52 +0200 |
commit | cf8fd948fc4bb6a9f48100ebf89df3752371805d (patch) | |
tree | 77fcb45f80ab75da2e5cdf520a50ab7192f9e25c /src/api_server.rs | |
parent | ff4fb9756810abeff17c360f3055c3865160b240 (diff) | |
download | garage-cf8fd948fc4bb6a9f48100ebf89df3752371805d.tar.gz garage-cf8fd948fc4bb6a9f48100ebf89df3752371805d.zip |
Add block ref table
Diffstat (limited to 'src/api_server.rs')
-rw-r--r-- | src/api_server.rs | 29 |
1 files changed, 20 insertions, 9 deletions
diff --git a/src/api_server.rs b/src/api_server.rs index 024da7d5..153991b2 100644 --- a/src/api_server.rs +++ b/src/api_server.rs @@ -133,7 +133,7 @@ async fn handle_put( } let version = Version { - version: version_uuid.clone(), + uuid: version_uuid.clone(), deleted: false, blocks: Vec::new(), bucket: bucket.into(), @@ -146,7 +146,7 @@ async fn handle_put( let mut next_offset = first_block.len(); let mut put_curr_version_block = - put_version_block(garage.clone(), &version, 0, first_block_hash.clone()); + put_block_meta(garage.clone(), &version, 0, first_block_hash.clone()); let mut put_curr_block = put_block(garage.clone(), first_block_hash, first_block); loop { @@ -155,7 +155,7 @@ async fn handle_put( if let Some(block) = next_block { let block_hash = hash(&block[..]); let block_len = block.len(); - put_curr_version_block = put_version_block( + put_curr_version_block = put_block_meta( garage.clone(), &version, next_offset as u64, @@ -176,15 +176,28 @@ async fn handle_put( Ok(version_uuid) } -async fn put_version_block( +async fn put_block_meta( garage: Arc<Garage>, version: &Version, offset: u64, hash: Hash, ) -> Result<(), Error> { let mut version = version.clone(); - version.blocks.push(VersionBlock { offset, hash }); - garage.version_table.insert(&version).await?; + version.blocks.push(VersionBlock { + offset, + hash: hash.clone(), + }); + + let block_ref = BlockRef { + block: hash, + version: version.uuid.clone(), + deleted: false, + }; + + futures::try_join!( + garage.version_table.insert(&version), + garage.block_ref_table.insert(&block_ref), + )?; Ok(()) } @@ -308,9 +321,7 @@ async fn handle_get( } }) .buffered(2); - let body: BodyType = Box::new(StreamBody::new( - Box::pin(body_stream), - )); + let body: BodyType = Box::new(StreamBody::new(Box::pin(body_stream))); Ok(resp_builder.body(body)?) } } |