From 07c78959480327af3709dc0e7b6c8f798cef9c92 Mon Sep 17 00:00:00 2001 From: Alex Auvolat Date: Fri, 23 Feb 2024 11:47:44 +0100 Subject: [refactor-block] simplify rpc_get_block --- src/block/block.rs | 23 ++--------------------- src/block/manager.rs | 5 ++--- 2 files changed, 4 insertions(+), 24 deletions(-) (limited to 'src') diff --git a/src/block/block.rs b/src/block/block.rs index 20f57aa5..34afea5d 100644 --- a/src/block/block.rs +++ b/src/block/block.rs @@ -2,7 +2,7 @@ use std::path::PathBuf; use bytes::Bytes; use serde::{Deserialize, Serialize}; -use zstd::stream::{decode_all as zstd_decode, Encoder}; +use zstd::stream::Encoder; use garage_util::data::*; use garage_util::error::*; @@ -43,26 +43,7 @@ impl DataBlock { res } - /// Get the buffer, possibly decompressing it, and verify it's integrity. - /// For Plain block, data is compared to hash, for Compressed block, zstd checksumming system - /// is used instead. - pub fn verify_get(self, hash: Hash) -> Result { - match self { - DataBlock::Plain(data) => { - if blake2sum(&data) == hash { - Ok(data) - } else { - Err(Error::CorruptData(hash)) - } - } - DataBlock::Compressed(data) => zstd_decode(&data[..]) - .map_err(|_| Error::CorruptData(hash)) - .map(Bytes::from), - } - } - - /// Verify data integrity. Allocate less than [`DataBlock::verify_get`] and don't consume self, but - /// does not return the buffer content. + /// Verify data integrity. Does not return the buffer content. pub fn verify(&self, hash: Hash) -> Result<(), Error> { match self { DataBlock::Plain(data) => { diff --git a/src/block/manager.rs b/src/block/manager.rs index 54290888..64e2ea27 100644 --- a/src/block/manager.rs +++ b/src/block/manager.rs @@ -342,9 +342,8 @@ impl BlockManager { hash: &Hash, order_tag: Option, ) -> Result { - self.rpc_get_raw_block(hash, order_tag) - .await? - .verify_get(*hash) + let stream = self.rpc_get_block_streaming(hash, order_tag).await?; + Ok(read_stream_to_end(stream).await?.into_bytes()) } /// Send block to nodes that should have it -- cgit v1.2.3