From e4de25442a34d77d660f23879740a9676f880053 Mon Sep 17 00:00:00 2001 From: Greg Fitzgerald Date: Fri, 7 Sep 2018 09:47:13 -0600 Subject: [PATCH] Hoist write lock It needed to be passed the lock before, because it contained a branch where one side didn't require locking. Now that that defensive programming was hoisted, we can hoist the write lock as well, leaving a simpler function for unit testing. --- src/window.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/window.rs b/src/window.rs index 2ea366f1e9..7eb6c313f1 100644 --- a/src/window.rs +++ b/src/window.rs @@ -31,7 +31,8 @@ pub struct WindowSlot { pub leader_unknown: bool, } -pub type SharedWindow = Arc>>; +type Window = Vec; +pub type SharedWindow = Arc>; #[derive(Debug)] pub struct WindowIndex { @@ -40,13 +41,12 @@ pub struct WindowIndex { } fn find_next_missing( - window: &SharedWindow, + window: &mut Window, crdt: &Arc>, recycler: &BlobRecycler, consumed: u64, received: u64, ) -> Vec<(SocketAddr, Vec)> { - let mut window = window.write().unwrap(); (consumed..received) .filter_map(|pix| { let i = (pix % WINDOW_SIZE) as usize; @@ -132,7 +132,8 @@ fn repair_window( return None; } - let reqs = find_next_missing(window, crdt, recycler, consumed, highest_lost); + let mut window = window.write().unwrap(); + let reqs = find_next_missing(&mut window, crdt, recycler, consumed, highest_lost); inc_new_counter_info!("streamer-repair_window-repair", reqs.len()); if log_enabled!(Level::Trace) { trace!(