Hoist repair_window() branches

This probably would have been done if repair_window() was unit-tested.
This commit is contained in:
Greg Fitzgerald
2018-09-07 11:29:04 -06:00
parent d77699c126
commit 78b3a8f7f9

View File

@ -113,30 +113,16 @@ fn repair_backoff(last: &mut u64, times: &mut usize, consumed: u64) -> bool {
} }
fn repair_window( fn repair_window(
id: &Pubkey,
window: &SharedWindow, window: &SharedWindow,
crdt: &Arc<RwLock<Crdt>>, crdt: &Arc<RwLock<Crdt>>,
recycler: &BlobRecycler, recycler: &BlobRecycler,
last: &mut u64, id: &Pubkey,
times: &mut usize, times: usize,
consumed: u64, consumed: u64,
received: u64, received: u64,
) -> Option<Vec<(SocketAddr, Vec<u8>)>> { ) -> Vec<(SocketAddr, Vec<u8>)> {
if received <= consumed { let num_peers = crdt.read().unwrap().table.len() as u64;
return None; let highest_lost = calculate_highest_lost_blob_index(num_peers, consumed, received);
}
//exponential backoff
if !repair_backoff(last, times, consumed) {
trace!("{} !repair_backoff() times = {}", id, times);
return None;
}
let highest_lost = calculate_highest_lost_blob_index(
crdt.read().unwrap().table.len() as u64,
consumed,
received,
);
let mut window = window.write().unwrap(); let mut window = window.write().unwrap();
let idxs = clear_window_slots(&mut window, recycler, consumed, highest_lost); let idxs = clear_window_slots(&mut window, recycler, consumed, highest_lost);
@ -150,7 +136,7 @@ fn repair_window(
trace!( trace!(
"{}: repair_window counter times: {} consumed: {} highest_lost: {} missing: {}", "{}: repair_window counter times: {} consumed: {} highest_lost: {} missing: {}",
id, id,
*times, times,
consumed, consumed,
highest_lost, highest_lost,
reqs.len() reqs.len()
@ -160,7 +146,7 @@ fn repair_window(
trace!("{}: repair_window request to {}", id, to); trace!("{}: repair_window request to {}", id, to);
} }
} }
Some(reqs) reqs
} }
fn add_block_to_retransmit_queue( fn add_block_to_retransmit_queue(
@ -662,9 +648,18 @@ pub fn window(
} }
} }
} }
if let Some(reqs) = repair_window(
&id, &window, &crdt, &recycler, &mut last, &mut times, consumed, received, if received <= consumed {
) { continue;
}
//exponential backoff
if !repair_backoff(&mut last, &mut times, consumed) {
trace!("{} !repair_backoff() times = {}", id, times);
continue;
}
let reqs = repair_window(&window, &crdt, &recycler, &id, times, consumed, received);
for (to, req) in reqs { for (to, req) in reqs {
repair_socket.send_to(&req, to).unwrap_or_else(|e| { repair_socket.send_to(&req, to).unwrap_or_else(|e| {
info!("{} repair req send_to({}) error {:?}", id, to, e); info!("{} repair req send_to({}) error {:?}", id, to, e);
@ -672,7 +667,6 @@ pub fn window(
}); });
} }
} }
}
}) })
.unwrap() .unwrap()
} }