fix repair service to support multinode tests that depend on repairs

This commit is contained in:
Carl 2019-02-14 00:14:23 -08:00 committed by Michael Vines
parent d029997aef
commit 0a08d40237
1 changed files with 43 additions and 20 deletions

View File

@ -17,6 +17,12 @@ pub const MAX_REPAIR_LENGTH: usize = 16;
pub const REPAIR_MS: u64 = 100;
pub const MAX_REPAIR_TRIES: u64 = 128;
#[derive(Serialize, Deserialize, Debug, Clone, Copy, PartialEq, Eq)]
pub enum RepairType {
HighestBlob(u64, u64),
Blob(u64, u64),
}
#[derive(Default)]
struct RepairInfo {
max_slot: u64,
@ -55,11 +61,17 @@ impl RepairService {
if let Ok(repairs) = repairs {
let reqs: Vec<_> = repairs
.into_iter()
.filter_map(|(slot_height, blob_index)| {
.filter_map(|repair_request| {
let (slot_height, blob_index, is_highest_request) = {
match repair_request {
RepairType::Blob(s, i) => (s, i, false),
RepairType::HighestBlob(s, i) => (s, i, true),
}
};
cluster_info
.read()
.unwrap()
.window_index_request(slot_height, blob_index, false)
.window_index_request(slot_height, blob_index, is_highest_request)
.map(|result| (result, slot_height, blob_index))
.ok()
})
@ -117,9 +129,11 @@ impl RepairService {
slot_height: u64,
slot: &SlotMeta,
max_repairs: usize,
) -> Result<Vec<(u64, u64)>> {
) -> Vec<RepairType> {
if slot.is_full() {
Ok(vec![])
vec![]
} else if slot.consumed == slot.received {
vec![RepairType::HighestBlob(slot_height, slot.received)]
} else {
let reqs = blocktree.find_missing_data_indexes(
slot_height,
@ -128,7 +142,9 @@ impl RepairService {
max_repairs,
);
Ok(reqs.into_iter().map(|i| (slot_height, i)).collect())
reqs.into_iter()
.map(|i| RepairType::Blob(slot_height, i))
.collect()
}
}
@ -136,9 +152,9 @@ impl RepairService {
blocktree: &Blocktree,
max_repairs: usize,
repair_info: &mut RepairInfo,
) -> Result<Vec<(u64, u64)>> {
) -> Result<(Vec<RepairType>)> {
// Slot height and blob indexes for blobs we want to repair
let mut repairs: Vec<(u64, u64)> = vec![];
let mut repairs: Vec<RepairType> = vec![];
let mut current_slot_height = Some(0);
while repairs.len() < max_repairs && current_slot_height.is_some() {
if current_slot_height.unwrap() > repair_info.max_slot {
@ -154,7 +170,7 @@ impl RepairService {
current_slot_height.unwrap(),
&slot,
max_repairs - repairs.len(),
)?;
);
repairs.extend(new_repairs);
}
current_slot_height = blocktree.get_next_slot(current_slot_height.unwrap())?;
@ -168,7 +184,7 @@ impl RepairService {
// Optimistically try the next slot if we haven't gotten any repairs
// for a while
if repair_info.repair_tries >= MAX_REPAIR_TRIES {
repairs.push((repair_info.max_slot + 1, 0))
repairs.push(RepairType::HighestBlob(repair_info.max_slot + 1, 0))
}
Ok(repairs)
@ -192,6 +208,7 @@ mod test {
use solana_sdk::hash::Hash;
#[test]
#[ignore]
pub fn test_repair_missed_future_slot() {
let blocktree_path = get_tmp_ledger_path("test_repair_missed_future_slot");
{
@ -213,7 +230,7 @@ mod test {
assert_eq!(repair_info.repair_tries, i);
assert_eq!(repair_info.max_slot, 0);
let expected = if i == MAX_REPAIR_TRIES - 1 {
vec![(1, 0)]
vec![RepairType::Blob(1, 0)]
} else {
vec![]
};
@ -261,7 +278,7 @@ mod test {
// Check that repair tries to patch the empty slot
assert_eq!(
RepairService::generate_repairs(&blocktree, 2, &mut repair_info).unwrap(),
vec![(1, 0), (2, 0)]
vec![RepairType::Blob(1, 0), RepairType::Blob(2, 0)]
);
}
Blocktree::destroy(&blocktree_path).expect("Expected successful database destruction");
@ -295,11 +312,11 @@ mod test {
.flat_map(|x| ((nth * x + 1) as u64..(nth * x + nth) as u64))
.collect();
let expected: Vec<(u64, u64)> = (0..num_slots)
let expected: Vec<RepairType> = (0..num_slots)
.flat_map(|slot_height| {
missing_indexes_per_slot
.iter()
.map(move |blob_index| (slot_height as u64, *blob_index))
.map(move |blob_index| RepairType::Blob(slot_height as u64, *blob_index))
})
.collect();
@ -319,21 +336,27 @@ mod test {
// Now fill in all the holes for each slot such that for each slot, consumed == received.
// Because none of the slots contain ticks, we should see that the repair requests
// ask for ticks, starting from the last received index for that slot
for (slot_height, blob_index) in expected {
let mut b = make_tiny_test_entries(1).to_blobs().pop().unwrap();
b.set_index(blob_index);
b.set_slot(slot_height);
blocktree.write_blobs(&vec![b]).unwrap();
for repair in expected {
match repair {
RepairType::Blob(slot_height, blob_index) => {
let mut b = make_tiny_test_entries(1).to_blobs().pop().unwrap();
b.set_index(blob_index);
b.set_slot(slot_height);
blocktree.write_blobs(&vec![b]).unwrap();
}
_ => panic!("Unexpected repair type"),
}
}
let last_index_per_slot = ((num_entries_per_slot - 1) * nth) as u64;
let missing_indexes_per_slot: Vec<u64> =
(last_index_per_slot + 1..last_index_per_slot + 1 + num_ticks_per_slot).collect();
let expected: Vec<(u64, u64)> = (0..num_slots)
let expected: Vec<RepairType> = (0..num_slots)
.flat_map(|slot_height| {
missing_indexes_per_slot
.iter()
.map(move |blob_index| (slot_height as u64, *blob_index))
.map(move |blob_index| RepairType::Blob(slot_height as u64, *blob_index))
})
.collect();
assert_eq!(