aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAlex Auvolat <alex@adnab.me>2024-02-23 12:26:35 +0100
committerAlex Auvolat <alex@adnab.me>2024-02-23 12:50:10 +0100
commit6ee691e65f2c6f7b337a62cbfacaddb9ba9cd61a (patch)
tree0a8c9c8d57abfa084188873dab2987ecfe93c0d7 /src
parente9c42bca347e3a67f8d6bae953bdf0b53ce37d00 (diff)
downloadgarage-6ee691e65f2c6f7b337a62cbfacaddb9ba9cd61a.tar.gz
garage-6ee691e65f2c6f7b337a62cbfacaddb9ba9cd61a.zip
[refactor-block] simplify some morerefactor-block
Diffstat (limited to 'src')
-rw-r--r--src/block/block.rs21
-rw-r--r--src/block/manager.rs6
2 files changed, 5 insertions, 22 deletions
diff --git a/src/block/block.rs b/src/block/block.rs
index 3f5c4f94..504d11f8 100644
--- a/src/block/block.rs
+++ b/src/block/block.rs
@@ -62,20 +62,9 @@ impl<T> DataBlockElem<T> {
pub fn as_parts_ref(&self) -> (DataBlockHeader, &T) {
(self.header, &self.elem)
}
-
- /// Query whether this block is compressed
- pub fn is_compressed(&self) -> bool {
- self.header.is_compressed()
- }
}
impl DataBlock {
- /// Get the inner, possibly compressed buffer. You should probably use [`DataBlock::verify_get`]
- /// instead
- pub fn inner_buffer(&self) -> &[u8] {
- &self.elem
- }
-
/// Verify data integrity. Does not return the buffer content.
pub fn verify(&self, hash: Hash) -> Result<(), Error> {
match self.header {
@@ -97,16 +86,10 @@ impl DataBlock {
tokio::task::spawn_blocking(move || {
if let Some(level) = level {
if let Ok(data_compressed) = zstd_encode(&data[..], level) {
- return DataBlock {
- header: DataBlockHeader::Compressed,
- elem: data_compressed.into(),
- };
+ return DataBlock::compressed(data_compressed.into());
}
}
- DataBlock {
- header: DataBlockHeader::Plain,
- elem: data.into(),
- }
+ DataBlock::plain(data.into())
})
.await
.unwrap()
diff --git a/src/block/manager.rs b/src/block/manager.rs
index 6773dfd1..817866f6 100644
--- a/src/block/manager.rs
+++ b/src/block/manager.rs
@@ -690,8 +690,8 @@ impl BlockManagerLocked {
mgr: &BlockManager,
existing_path: Option<DataBlockPath>,
) -> Result<(), Error> {
- let compressed = data.is_compressed();
- let data = data.inner_buffer();
+ let (header, data) = data.as_parts_ref();
+ let compressed = header.is_compressed();
let directory = mgr.data_layout.load().primary_block_dir(hash);
@@ -805,7 +805,7 @@ impl BlockManagerLocked {
let data = mgr.read_block_from(hash, &wrong_path).await?;
self.write_block_inner(hash, &data, mgr, Some(wrong_path))
.await?;
- Ok(data.inner_buffer().len())
+ Ok(data.as_parts_ref().1.len())
}
}