Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Coalesce data and coding index #7765

Merged
merged 1 commit into from
Jan 13, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions ledger/src/blocktree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,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();
Expand Down Expand Up @@ -907,7 +907,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());
Expand Down Expand Up @@ -965,7 +965,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<()> {
Expand Down Expand Up @@ -5117,7 +5117,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
Expand All @@ -5130,7 +5130,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);
}
}
59 changes: 12 additions & 47 deletions ledger/src/blocktree_meta.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>,
}

Expand Down Expand Up @@ -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()
}

Expand Down