coalesce data and coding index (#7765)

This commit is contained in:
carllin
2020-01-13 12:03:19 -08:00
committed by GitHub
parent a17d5795fb
commit 8f7ded33e0
2 changed files with 17 additions and 52 deletions

View File

@ -867,7 +867,7 @@ impl Blocktree {
fn should_insert_coding_shred(
shred: &Shred,
coding_index: &CodingIndex,
coding_index: &ShredIndex,
last_root: &RwLock<u64>,
) -> bool {
let slot = shred.slot();
@ -909,7 +909,7 @@ impl Blocktree {
fn should_insert_data_shred(
shred: &Shred,
slot_meta: &SlotMeta,
data_index: &DataIndex,
data_index: &ShredIndex,
last_root: &RwLock<u64>,
) -> bool {
let shred_index = u64::from(shred.index());
@ -967,7 +967,7 @@ impl Blocktree {
fn insert_data_shred(
&self,
slot_meta: &mut SlotMeta,
data_index: &mut DataIndex,
data_index: &mut ShredIndex,
shred: &Shred,
write_batch: &mut WriteBatch,
) -> Result<()> {
@ -5157,7 +5157,7 @@ pub mod tests {
}
// Test the data index doesn't have anything extra
let num_data_in_index = index.data().num_data();
let num_data_in_index = index.data().num_shreds();
assert_eq!(num_data_in_index, num_data);
// Test the set of coding shreds in the index and in the coding column
@ -5170,7 +5170,7 @@ pub mod tests {
}
// Test the data index doesn't have anything extra
let num_coding_in_index = index.coding().num_coding();
let num_coding_in_index = index.coding().num_shreds();
assert_eq!(num_coding_in_index, num_coding);
}
}

View File

@ -37,20 +37,13 @@ pub struct SlotMeta {
/// Index recording presence/absence of shreds
pub struct Index {
pub slot: Slot,
data: DataIndex,
coding: CodingIndex,
data: ShredIndex,
coding: ShredIndex,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
pub struct DataIndex {
/// Map representing presence/absence of data shreds
index: BTreeSet<u64>,
}
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
/// Erasure coding information
pub struct CodingIndex {
/// Map from set index, to hashmap from shred index to presence bool
pub struct ShredIndex {
/// Map representing presence/absence of shreds
index: BTreeSet<u64>,
}
@ -78,56 +71,28 @@ impl Index {
pub(crate) fn new(slot: Slot) -> Self {
Index {
slot,
data: DataIndex::default(),
coding: CodingIndex::default(),
data: ShredIndex::default(),
coding: ShredIndex::default(),
}
}
pub fn data(&self) -> &DataIndex {
pub fn data(&self) -> &ShredIndex {
&self.data
}
pub fn coding(&self) -> &CodingIndex {
pub fn coding(&self) -> &ShredIndex {
&self.coding
}
pub fn data_mut(&mut self) -> &mut DataIndex {
pub fn data_mut(&mut self) -> &mut ShredIndex {
&mut self.data
}
pub fn coding_mut(&mut self) -> &mut CodingIndex {
pub fn coding_mut(&mut self) -> &mut ShredIndex {
&mut self.coding
}
}
impl CodingIndex {
pub fn num_coding(&self) -> usize {
self.index.len()
}
pub fn present_in_bounds(&self, bounds: impl RangeBounds<u64>) -> usize {
self.index.range(bounds).count()
}
pub fn is_present(&self, index: u64) -> bool {
self.index.contains(&index)
}
pub fn set_present(&mut self, index: u64, presence: bool) {
if presence {
self.index.insert(index);
} else {
self.index.remove(&index);
}
}
pub fn set_many_present(&mut self, presence: impl IntoIterator<Item = (u64, bool)>) {
for (idx, present) in presence.into_iter() {
self.set_present(idx, present);
}
}
}
impl DataIndex {
pub fn num_data(&self) -> usize {
impl ShredIndex {
pub fn num_shreds(&self) -> usize {
self.index.len()
}