From 83408fe9d23e651767a69e90cc51d4fe4d0e3551 Mon Sep 17 00:00:00 2001 From: Ron Kuris Date: Thu, 27 Apr 2023 14:23:28 +0000 Subject: [PATCH] 2/3: Postpone cloning the db_path Want access to it after the last init_wal for better errors --- firewood/src/db.rs | 4 ++-- firewood/src/storage/buffer.rs | 12 ++++++------ 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/firewood/src/db.rs b/firewood/src/db.rs index 379e94429..6493830f0 100644 --- a/firewood/src/db.rs +++ b/firewood/src/db.rs @@ -664,8 +664,8 @@ impl Db { }; let root_hash_staging = StoreRevMut::new(root_hash_cache); - // recover from Wal - disk_requester.init_wal("wal", db_path); + // recover from WAL + disk_requester.init_wal("wal", &db_path); // set up the storage layout diff --git a/firewood/src/storage/buffer.rs b/firewood/src/storage/buffer.rs index 131516309..821d5263d 100644 --- a/firewood/src/storage/buffer.rs +++ b/firewood/src/storage/buffer.rs @@ -1,6 +1,6 @@ //! Disk buffer for staging in memory pages and flushing them to disk. use std::fmt::Debug; -use std::path::PathBuf; +use std::path::{Path, PathBuf}; use std::rc::Rc; use std::sync::Arc; use std::{cell::RefCell, collections::HashMap}; @@ -452,10 +452,10 @@ impl DiskBufferRequester { self.sender.blocking_send(BufferCmd::Shutdown).ok().unwrap() } - /// Initialize the Wal. - pub fn init_wal(&self, waldir: &str, rootpath: PathBuf) { + /// Initialize the WAL. + pub fn init_wal(&self, waldir: &str, rootpath: &Path) { self.sender - .blocking_send(BufferCmd::InitWal(rootpath, waldir.to_string())) + .blocking_send(BufferCmd::InitWal(rootpath.to_path_buf(), waldir.to_string())) .map_err(StoreError::Send) .ok(); } @@ -517,7 +517,7 @@ mod tests { let state_path = file::touch_dir("state", &root_db_path).unwrap(); assert!(reset); // create a new wal directory on top of root_db_fd - disk_requester.init_wal("wal", root_db_path); + disk_requester.init_wal("wal", &root_db_path); // create a new state cache which tracks on disk state. let state_cache = Rc::new( @@ -605,7 +605,7 @@ mod tests { let state_path = file::touch_dir("state", &root_db_path).unwrap(); assert!(reset); // create a new wal directory on top of root_db_fd - disk_requester.init_wal("wal", root_db_path); + disk_requester.init_wal("wal", &root_db_path); // create a new state cache which tracks on disk state. let state_cache = Rc::new(