coalesce data and coding index (#7765)
This commit is contained in:
@ -867,7 +867,7 @@ impl Blocktree {
|
|||||||
|
|
||||||
fn should_insert_coding_shred(
|
fn should_insert_coding_shred(
|
||||||
shred: &Shred,
|
shred: &Shred,
|
||||||
coding_index: &CodingIndex,
|
coding_index: &ShredIndex,
|
||||||
last_root: &RwLock<u64>,
|
last_root: &RwLock<u64>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let slot = shred.slot();
|
let slot = shred.slot();
|
||||||
@ -909,7 +909,7 @@ impl Blocktree {
|
|||||||
fn should_insert_data_shred(
|
fn should_insert_data_shred(
|
||||||
shred: &Shred,
|
shred: &Shred,
|
||||||
slot_meta: &SlotMeta,
|
slot_meta: &SlotMeta,
|
||||||
data_index: &DataIndex,
|
data_index: &ShredIndex,
|
||||||
last_root: &RwLock<u64>,
|
last_root: &RwLock<u64>,
|
||||||
) -> bool {
|
) -> bool {
|
||||||
let shred_index = u64::from(shred.index());
|
let shred_index = u64::from(shred.index());
|
||||||
@ -967,7 +967,7 @@ impl Blocktree {
|
|||||||
fn insert_data_shred(
|
fn insert_data_shred(
|
||||||
&self,
|
&self,
|
||||||
slot_meta: &mut SlotMeta,
|
slot_meta: &mut SlotMeta,
|
||||||
data_index: &mut DataIndex,
|
data_index: &mut ShredIndex,
|
||||||
shred: &Shred,
|
shred: &Shred,
|
||||||
write_batch: &mut WriteBatch,
|
write_batch: &mut WriteBatch,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
@ -5157,7 +5157,7 @@ pub mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Test the data index doesn't have anything extra
|
// 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);
|
assert_eq!(num_data_in_index, num_data);
|
||||||
|
|
||||||
// Test the set of coding shreds in the index and in the coding column
|
// 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
|
// 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);
|
assert_eq!(num_coding_in_index, num_coding);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -37,20 +37,13 @@ pub struct SlotMeta {
|
|||||||
/// Index recording presence/absence of shreds
|
/// Index recording presence/absence of shreds
|
||||||
pub struct Index {
|
pub struct Index {
|
||||||
pub slot: Slot,
|
pub slot: Slot,
|
||||||
data: DataIndex,
|
data: ShredIndex,
|
||||||
coding: CodingIndex,
|
coding: ShredIndex,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
|
#[derive(Clone, Debug, Default, Deserialize, Serialize, PartialEq)]
|
||||||
pub struct DataIndex {
|
pub struct ShredIndex {
|
||||||
/// Map representing presence/absence of data shreds
|
/// Map representing presence/absence of 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
|
|
||||||
index: BTreeSet<u64>,
|
index: BTreeSet<u64>,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -78,56 +71,28 @@ impl Index {
|
|||||||
pub(crate) fn new(slot: Slot) -> Self {
|
pub(crate) fn new(slot: Slot) -> Self {
|
||||||
Index {
|
Index {
|
||||||
slot,
|
slot,
|
||||||
data: DataIndex::default(),
|
data: ShredIndex::default(),
|
||||||
coding: CodingIndex::default(),
|
coding: ShredIndex::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn data(&self) -> &DataIndex {
|
pub fn data(&self) -> &ShredIndex {
|
||||||
&self.data
|
&self.data
|
||||||
}
|
}
|
||||||
pub fn coding(&self) -> &CodingIndex {
|
pub fn coding(&self) -> &ShredIndex {
|
||||||
&self.coding
|
&self.coding
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn data_mut(&mut self) -> &mut DataIndex {
|
pub fn data_mut(&mut self) -> &mut ShredIndex {
|
||||||
&mut self.data
|
&mut self.data
|
||||||
}
|
}
|
||||||
pub fn coding_mut(&mut self) -> &mut CodingIndex {
|
pub fn coding_mut(&mut self) -> &mut ShredIndex {
|
||||||
&mut self.coding
|
&mut self.coding
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl CodingIndex {
|
impl ShredIndex {
|
||||||
pub fn num_coding(&self) -> usize {
|
pub fn num_shreds(&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 {
|
|
||||||
self.index.len()
|
self.index.len()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user