mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-31 09:18:28 +00:00
add Erasure
This commit is contained in:
+28
-17
@@ -43,7 +43,11 @@ impl Erasure {
|
|||||||
Ok(shards)
|
Ok(shards)
|
||||||
}
|
}
|
||||||
|
|
||||||
// 所需要的总长度
|
pub fn decode_data(&self, shards: &mut Vec<Option<Vec<u8>>>) -> Result<(), Error> {
|
||||||
|
self.encoder.reconstruct(shards)
|
||||||
|
}
|
||||||
|
|
||||||
|
// 每个分片长度,所需要的总长度
|
||||||
fn need_size(&self, data_size: usize) -> (usize, usize) {
|
fn need_size(&self, data_size: usize) -> (usize, usize) {
|
||||||
let shard_size = self.shard_size(data_size);
|
let shard_size = self.shard_size(data_size);
|
||||||
(shard_size, shard_size * (self.encoder.total_shard_count()))
|
(shard_size, shard_size * (self.encoder.total_shard_count()))
|
||||||
@@ -54,6 +58,16 @@ impl Erasure {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn shards_to_option_shards<T: Clone>(shards: &[Vec<T>]) -> Vec<Option<Vec<T>>> {
|
||||||
|
let mut result = Vec::with_capacity(shards.len());
|
||||||
|
|
||||||
|
for v in shards.iter() {
|
||||||
|
let inner: Vec<T> = v.clone();
|
||||||
|
result.push(Some(inner));
|
||||||
|
}
|
||||||
|
result
|
||||||
|
}
|
||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
mod test {
|
mod test {
|
||||||
|
|
||||||
@@ -68,25 +82,22 @@ mod test {
|
|||||||
let shards = ec.encode_data(data).unwrap();
|
let shards = ec.encode_data(data).unwrap();
|
||||||
println!("shards:{:?}", shards);
|
println!("shards:{:?}", shards);
|
||||||
|
|
||||||
// let (data_buffer, parity_buffer) = buf.split_at(shard_size * 3);
|
let mut s: Vec<_> = shards
|
||||||
|
.iter()
|
||||||
|
.map(|d| if d.is_empty() { None } else { Some(d.clone()) })
|
||||||
|
.collect();
|
||||||
|
|
||||||
// println!(
|
// let mut s = shards_to_option_shards(&shards);
|
||||||
// "data_buffer: {:?},parity_buffer: {:?}",
|
|
||||||
// data_buffer, parity_buffer
|
|
||||||
// );
|
|
||||||
|
|
||||||
// let data_slices: Vec<&[u8]> = data.chunks(shard_size).collect();
|
// s[0] = None;
|
||||||
// let mut parity_slices: Vec<&mut [u8]> = parity_buffer.chunks_mut(shard_size).collect();
|
s[4] = None;
|
||||||
|
s[3] = None;
|
||||||
|
|
||||||
// println!(
|
println!("sss:{:?}", &s);
|
||||||
// "data_slices: {:?},parity_slices: {:?}",
|
|
||||||
// data_slices, parity_slices
|
|
||||||
// );
|
|
||||||
|
|
||||||
// ec.encoder
|
ec.decode_data(&mut s).unwrap();
|
||||||
// .encode_sep(&data_slices, &mut parity_slices)
|
// ec.encoder.reconstruct(&mut s).unwrap();
|
||||||
// .unwrap();
|
|
||||||
// ec.encoder.encode(all_shards);
|
println!("sss:{:?}", &s);
|
||||||
// println!("shards:{:?}", shards);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user