Revert "Use Rust erasure library and turn on erasure (#3768)" (#3827)

This reverts commit b9bb5af4a5.
This commit is contained in:
sakridge
2019-04-17 12:52:12 -07:00
committed by GitHub
parent 2518e95fb0
commit 4b8cb72977
12 changed files with 758 additions and 631 deletions

View File

@@ -1,3 +1,4 @@
#[cfg(feature = "erasure")]
use crate::erasure::{NUM_CODING, NUM_DATA};
#[derive(Clone, Debug, Default, Deserialize, Serialize, Eq, PartialEq)]
@@ -58,6 +59,7 @@ impl SlotMeta {
}
}
#[cfg(feature = "erasure")]
#[derive(Clone, Debug, Default, Deserialize, Serialize, Eq, PartialEq)]
/// Erasure coding information
pub struct ErasureMeta {
@@ -69,6 +71,7 @@ pub struct ErasureMeta {
pub coding: u64,
}
#[cfg(feature = "erasure")]
impl ErasureMeta {
pub fn new(set_index: u64) -> ErasureMeta {
ErasureMeta {
@@ -88,56 +91,36 @@ impl ErasureMeta {
}
pub fn is_coding_present(&self, index: u64) -> bool {
let start = self.start_index();
let end = start + NUM_CODING as u64;
let set_index = Self::set_index_for(index);
let position = index - self.start_index();
if start <= index && index < end {
let position = index - start;
self.coding & (1 << position) != 0
} else {
false
}
set_index == self.set_index && self.coding & (1 << position) != 0
}
pub fn set_coding_present(&mut self, index: u64, present: bool) {
pub fn set_coding_present(&mut self, index: u64) {
let set_index = Self::set_index_for(index);
if set_index as u64 == self.set_index {
let position = index - self.start_index();
if present {
self.coding |= 1 << position;
} else {
self.coding &= !(1 << position);
}
self.coding |= 1 << position;
}
}
pub fn is_data_present(&self, index: u64) -> bool {
let start = self.start_index();
let end = start + NUM_DATA as u64;
let set_index = Self::set_index_for(index);
let position = index - self.start_index();
if start <= index && index < end {
let position = index - start;
self.data & (1 << position) != 0
} else {
false
}
set_index == self.set_index && self.data & (1 << position) != 0
}
pub fn set_data_present(&mut self, index: u64, present: bool) {
pub fn set_data_present(&mut self, index: u64) {
let set_index = Self::set_index_for(index);
if set_index as u64 == self.set_index {
let position = index - self.start_index();
if present {
self.data |= 1 << position;
} else {
self.data &= !(1 << position);
}
self.data |= 1 << position;
}
}
@@ -156,29 +139,7 @@ impl ErasureMeta {
}
}
#[test]
fn test_meta_indexes() {
use rand::{thread_rng, Rng};
let mut rng = thread_rng();
for _ in 0..100 {
let set_index = rng.gen_range(0, 1_000);
let blob_index = (set_index * NUM_DATA as u64) + rng.gen_range(0, 16);
assert_eq!(set_index, ErasureMeta::set_index_for(blob_index));
let e_meta = ErasureMeta::new(set_index);
assert_eq!(e_meta.start_index(), set_index * NUM_DATA as u64);
let (data_end_idx, coding_end_idx) = e_meta.end_indexes();
assert_eq!(data_end_idx, (set_index + 1) * NUM_DATA as u64);
assert_eq!(
coding_end_idx,
set_index * NUM_DATA as u64 + NUM_CODING as u64
);
}
}
#[cfg(feature = "erasure")]
#[test]
fn test_meta_coding_present() {
let set_index = 0;
@@ -189,7 +150,7 @@ fn test_meta_coding_present() {
};
for i in 0..NUM_CODING as u64 {
e_meta.set_coding_present(i, true);
e_meta.set_coding_present(i);
assert_eq!(e_meta.is_coding_present(i), true);
}
for i in NUM_CODING as u64..NUM_DATA as u64 {
@@ -199,7 +160,7 @@ fn test_meta_coding_present() {
e_meta.set_index = ErasureMeta::set_index_for((NUM_DATA * 17) as u64);
for i in (NUM_DATA * 17) as u64..((NUM_DATA * 17) + NUM_CODING) as u64 {
e_meta.set_coding_present(i, true);
e_meta.set_coding_present(i);
assert_eq!(e_meta.is_coding_present(i), true);
}
for i in (NUM_DATA * 17 + NUM_CODING) as u64..((NUM_DATA * 17) + NUM_DATA) as u64 {
@@ -207,6 +168,7 @@ fn test_meta_coding_present() {
}
}
#[cfg(feature = "erasure")]
#[test]
fn test_can_recover() {
let set_index = 0;
@@ -249,31 +211,3 @@ fn test_can_recover() {
e_meta.data = 0b1111_1111_1111_1000;
assert!(e_meta.can_recover());
}
#[test]
fn test_meta_data_present() {
let set_index = 0;
let mut e_meta = ErasureMeta {
set_index,
data: 0,
coding: 0,
};
for i in 0..NUM_DATA as u64 {
e_meta.set_data_present(i, true);
assert_eq!(e_meta.is_data_present(i), true);
}
for i in NUM_DATA as u64..2 * NUM_DATA as u64 {
assert_eq!(e_meta.is_data_present(i), false);
}
e_meta.set_index = ErasureMeta::set_index_for((NUM_DATA * 23) as u64);
for i in (NUM_DATA * 23) as u64..(NUM_DATA * 24) as u64 {
e_meta.set_data_present(i, true);
assert_eq!(e_meta.is_data_present(i), true);
}
for i in (NUM_DATA * 22) as u64..(NUM_DATA * 23) as u64 {
assert_eq!(e_meta.is_data_present(i), false);
}
}