Skip to content

Commit

Permalink
2/3: Postpone cloning the db_path
Browse files Browse the repository at this point in the history
Want access to it after the last init_wal for better errors
  • Loading branch information
rkuris committed Aug 1, 2023
1 parent b6c84b8 commit 79aad05
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 14 deletions.
5 changes: 4 additions & 1 deletion firewood/src/db.rs
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,9 @@ impl Db<CompactSpace<Node, StoreRevMut>> {
disk_requester.reg_cached_space(cached_space.id(), cached_space.clone_files());
});

// recover from WAL
disk_requester.init_wal("wal", &db_path);

// set up the storage layout

let db_header: ObjPtr<DbHeader> = ObjPtr::new_from_addr(offset);
Expand Down Expand Up @@ -712,7 +715,7 @@ impl Db<CompactSpace<Node, StoreRevMut>> {
let root_hash_staging = StoreRevMut::new(root_hash_cache);

// recover from Wal
disk_requester.init_wal("wal", db_path);
disk_requester.init_wal("wal", &db_path);

let (mut db_header_ref, merkle_payload_header_ref, _blob_payload_header_ref) = {
let merkle_meta_ref = data_staging.merkle.meta.as_ref();
Expand Down
27 changes: 14 additions & 13 deletions firewood/src/storage/buffer.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,11 @@
//! Disk buffer for staging in memory pages and flushing them to disk.
use std::fmt::Debug;
use std::ops::IndexMut;
use std::path::{Path, PathBuf};
use std::rc::Rc;
use std::sync::Arc;
use std::{cell::RefCell, collections::HashMap};

use super::{AshRecord, FilePool, Page, StoreDelta, StoreError, WalConfig, PAGE_SIZE_NBIT};
use crate::storage::DeltaPage;
use aiofut::{AioBuilder, AioError, AioManager};
Expand All @@ -9,15 +16,6 @@ use growthring::{
WalFileImpl, WalStoreImpl,
};
use shale::SpaceId;
use std::{
cell::RefCell,
collections::HashMap,
fmt::Debug,
ops::IndexMut,
path::{Path, PathBuf},
rc::Rc,
sync::Arc,
};
use tokio::{
sync::{
mpsc,
Expand Down Expand Up @@ -581,9 +579,12 @@ impl DiskBufferRequester {
}

/// Initialize the Wal.
pub fn init_wal(&self, waldir: &str, rootpath: PathBuf) {
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();
}
Expand Down Expand Up @@ -645,7 +646,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 = Arc::new(
Expand Down Expand Up @@ -733,7 +734,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 = Arc::new(
Expand Down

0 comments on commit 79aad05

Please sign in to comment.