aboutsummaryrefslogtreecommitdiff
path: root/src/api
diff options
context:
space:
mode:
authorTrinity Pointard <trinity.pointard@gmail.com>2021-03-17 01:31:35 +0100
committerTrinity Pointard <trinity.pointard@gmail.com>2021-04-06 02:50:07 +0200
commit47d0aee9f807e0ded10a01d045a8930ff112224b (patch)
treeece47de34a21387da1f97a2ee304f23f11aa55c1 /src/api
parent6e0cb2dfb6db182a07debe4f7b89f7780bcdf5e4 (diff)
downloadgarage-47d0aee9f807e0ded10a01d045a8930ff112224b.tar.gz
garage-47d0aee9f807e0ded10a01d045a8930ff112224b.zip
change crate used for cdc
previous one seemed to output incorrect results
Diffstat (limited to 'src/api')
-rw-r--r--src/api/Cargo.toml2
-rw-r--r--src/api/s3_put.rs24
2 files changed, 15 insertions, 11 deletions
diff --git a/src/api/Cargo.toml b/src/api/Cargo.toml
index 5bc170a3..b328f671 100644
--- a/src/api/Cargo.toml
+++ b/src/api/Cargo.toml
@@ -22,7 +22,7 @@ bytes = "1.0"
chrono = "0.4"
crypto-mac = "0.10"
err-derive = "0.3"
-hash-roll = "0.3.0"
+fastcdc = "1.0.5"
hex = "0.4"
hmac = "0.10"
log = "0.4"
diff --git a/src/api/s3_put.rs b/src/api/s3_put.rs
index e2a1b54d..f5607c9f 100644
--- a/src/api/s3_put.rs
+++ b/src/api/s3_put.rs
@@ -2,8 +2,8 @@ use std::collections::{BTreeMap, VecDeque};
use std::fmt::Write;
use std::sync::Arc;
+use fastcdc::{Chunk, FastCDC};
use futures::stream::*;
-use hash_roll::{ChunkIncr, fastcdc::{FastCdc, FastCdcIncr}, gear_table::GEAR_64};
use hyper::{Body, Request, Response};
use md5::{digest::generic_array::*, Digest as Md5Digest, Md5};
use sha2::Sha256;
@@ -269,22 +269,24 @@ async fn put_block_meta(
struct BodyChunker {
body: Body,
read_all: bool,
+ min_block_size: usize,
+ avg_block_size: usize,
max_block_size: usize,
buf: VecDeque<u8>,
- chunker: FastCdcIncr<'static>,
}
impl BodyChunker {
fn new(body: Body, block_size: usize) -> Self {
+ let min_block_size = block_size / 4 * 3;
+ let avg_block_size = block_size;
let max_block_size = block_size * 2;
- let chunker = FastCdc::new(&GEAR_64, block_size as u64 / 2, block_size as u64, max_block_size as u64);
- let chunker = (&chunker).into();
Self {
body,
read_all: false,
+ min_block_size,
+ avg_block_size,
max_block_size,
buf: VecDeque::with_capacity(2 * max_block_size),
- chunker,
}
}
async fn next(&mut self) -> Result<Option<Vec<u8>>, GarageError> {
@@ -299,12 +301,14 @@ impl BodyChunker {
}
if self.buf.len() == 0 {
Ok(None)
- } else if let Some(index) = self.chunker.push(self.buf.make_contiguous()) {
- let block = self.buf.drain(..index).collect::<Vec<u8>>();
- Ok(Some(block))
} else {
- let block = self.buf.drain(..).collect::<Vec<u8>>();
- Ok(Some(block))
+ let mut iter = FastCDC::with_eof(self.buf.make_contiguous(), self.min_block_size, self.avg_block_size, self.max_block_size, self.read_all);
+ if let Some(Chunk {length, ..}) = iter.next() {
+ let block = self.buf.drain(..length).collect::<Vec<u8>>();
+ Ok(Some(block))
+ } else {
+ Ok(None)
+ }
}
}
}