From d4236e7d6667003f4be4c8c596a8d3f651a1dfdb Mon Sep 17 00:00:00 2001 From: gabriele-0201 Date: Tue, 11 Feb 2025 09:09:07 +0100 Subject: [PATCH] refactor: avoid new thread for writeout_start Within the `rollback` module, `SyncController::writeout_start` does not need to be spawned within another thread. --- nomt/src/rollback/mod.rs | 27 +++++---------------------- nomt/src/store/sync.rs | 11 ++++------- 2 files changed, 9 insertions(+), 29 deletions(-) diff --git a/nomt/src/rollback/mod.rs b/nomt/src/rollback/mod.rs index 7e26ade9..3af1e65d 100644 --- a/nomt/src/rollback/mod.rs +++ b/nomt/src/rollback/mod.rs @@ -293,10 +293,6 @@ impl Rollback { pub struct SyncController { rollback: Rollback, writeout_data: Option, - // The channel to send the result of the writeout task. Option is to allow `take`. - writeout_result_tx: Option>>, - // The channel to receive the result of the writeout task. - writeout_result_rx: Receiver>, // The channel to send the result of the post meta task. Option is to allow `take`. post_meta_result_tx: Option>>>, // The channel to receive the result of the post meta task. @@ -305,13 +301,10 @@ pub struct SyncController { impl SyncController { fn new(rollback: Rollback) -> Self { - let (writeout_result_tx, writeout_result_rx) = crossbeam_channel::bounded(1); let (post_meta_result_tx, post_meta_result_rx) = crossbeam_channel::bounded(1); Self { rollback, writeout_data: None, - writeout_result_tx: Some(writeout_result_tx), - writeout_result_rx, post_meta_result_tx: Some(post_meta_result_tx), post_meta_result_rx, } @@ -320,22 +313,12 @@ impl SyncController { /// Begins the sync process. /// /// This function doesn't block. - pub fn begin_sync(&mut self) { - let tp = self.rollback.shared.sync_tp.clone(); - let rollback = self.rollback.clone(); - // UNWRAP: safe because begin_sync is called only once. - let writeout_result_tx = self.writeout_result_tx.take().unwrap(); - spawn_task(&tp, move || rollback.writeout_start(), writeout_result_tx); - } - - /// Wait for the rollback writeout to complete. Returns the new rollback live range - /// `(start_live, end_live)`. /// - /// This should be called by the sync thread. Blocking. - pub fn wait_pre_meta(&mut self) -> (u64, u64) { - let wd_result = join_task(&self.writeout_result_rx); - let res = (wd_result.rollback_start_live, wd_result.rollback_end_live); - self.writeout_data.replace(wd_result); + /// Returns the new rollback live range `(start_live, end_live)`. + pub fn begin_sync(&mut self) -> (u64, u64) { + let wa = self.rollback.writeout_start(); + let res = (wa.rollback_start_live, wa.rollback_end_live); + self.writeout_data.replace(wa); res } diff --git a/nomt/src/store/sync.rs b/nomt/src/store/sync.rs index f0f0681b..3879581b 100644 --- a/nomt/src/store/sync.rs +++ b/nomt/src/store/sync.rs @@ -47,17 +47,14 @@ impl Sync { bitbox_sync.begin_sync(sync_seqn, page_cache, updated_pages); beatree_sync.begin_sync(value_tx); - if let Some(ref mut rollback) = rollback_sync { - rollback.begin_sync(); - } - - bitbox_sync.wait_pre_meta()?; - let beatree_meta_wd = beatree_sync.wait_pre_meta()?; let (rollback_start_live, rollback_end_live) = match rollback_sync { - Some(ref mut rollback) => rollback.wait_pre_meta(), + Some(ref mut rollback) => rollback.begin_sync(), None => (0, 0), }; + bitbox_sync.wait_pre_meta()?; + let beatree_meta_wd = beatree_sync.wait_pre_meta()?; + if let Some(PanicOnSyncMode::PostWal) = self.panic_on_sync { panic!("panic_on_sync is true (post-wal)") }