merge main

This commit is contained in:
weisd
2024-09-23 17:20:28 +08:00
42 changed files with 7017 additions and 301 deletions
+12 -7
View File
@@ -4,7 +4,7 @@ use bytes::Bytes;
use futures::future::join_all;
use futures::{Stream, StreamExt};
use reed_solomon_erasure::galois_8::ReedSolomon;
use tokio::io::AsyncWrite;
use std::fmt::Debug;
use tokio::io::AsyncWriteExt;
use tokio::io::DuplexStream;
use tracing::debug;
@@ -14,7 +14,7 @@ use uuid::Uuid;
use crate::chunk_stream::ChunkedStream;
use crate::disk::error::DiskError;
use crate::disk::FileReader;
use crate::disk::{FileReader, FileWriter};
pub struct Erasure {
data_shards: usize,
@@ -44,17 +44,16 @@ impl Erasure {
}
}
pub async fn encode<S, W>(
pub async fn encode<S>(
&self,
body: S,
writers: &mut [W],
writers: &mut [FileWriter],
// block_size: usize,
total_size: usize,
write_quorum: usize,
) -> Result<usize>
where
S: Stream<Item = Result<Bytes, StdError>> + Send + Sync + 'static,
W: AsyncWrite + Unpin,
{
let mut stream = ChunkedStream::new(body, total_size, self.block_size, false);
let mut total: usize = 0;
@@ -86,9 +85,9 @@ impl Erasure {
let mut errs = Vec::new();
for (i, w) in writers.iter_mut().enumerate() {
match w.write_all(blocks[i].as_ref()).await {
match w.write(blocks[i].as_ref()).await {
Ok(_) => errs.push(None),
Err(e) => errs.push(Some(Error::new(e))),
Err(e) => errs.push(Some(e)),
}
}
@@ -319,6 +318,12 @@ impl Erasure {
}
}
#[async_trait::async_trait]
pub trait Write {
async fn write(&mut self, buf: &[u8]) -> Result<()>;
}
#[async_trait::async_trait]
pub trait ReadAt {
async fn read_at(&mut self, offset: usize, length: usize) -> Result<(Vec<u8>, usize)>;
}