diff --git a/crates/types/src/config/mod.rs b/crates/types/src/config/mod.rs index dd809f48af..f0ad30edfe 100644 --- a/crates/types/src/config/mod.rs +++ b/crates/types/src/config/mod.rs @@ -68,24 +68,34 @@ static NODE_BASE_DIR: Lazy> = pub type UpdateableConfiguration = Arc>; #[cfg(not(any(test, feature = "test-util")))] -fn data_dir(dir: &str) -> PathBuf { +pub fn node_dir() -> PathBuf { NODE_BASE_DIR .get() .expect("base_dir is initialized") - .join(dir) + .clone() +} + +#[cfg(not(any(test, feature = "test-util")))] +fn data_dir(dir: &str) -> PathBuf { + node_dir().join(dir) } #[cfg(any(test, feature = "test-util"))] -pub fn data_dir(dir: &str) -> PathBuf { +pub fn node_dir() -> PathBuf { let guard = NODE_BASE_DIR.read().unwrap(); match &*guard { - TempOrPath::Temp(temp) => temp.path().join(dir), - TempOrPath::Path(path) => path.join(dir), + TempOrPath::Temp(temp) => temp.path().to_path_buf(), + TempOrPath::Path(path) => path.clone(), } } +#[cfg(any(test, feature = "test-util"))] +pub fn data_dir(dir: &str) -> PathBuf { + node_dir().join(dir) +} + pub fn node_filepath(filename: &str) -> PathBuf { - data_dir(filename) + node_dir().join(filename) } #[cfg(any(test, feature = "test-util"))] diff --git a/server/src/main.rs b/server/src/main.rs index efe2d42b80..c433201b1c 100644 --- a/server/src/main.rs +++ b/server/src/main.rs @@ -31,7 +31,7 @@ use restate_tracing_instrumentation::init_tracing_and_logging; use restate_tracing_instrumentation::TracingGuard; use restate_types::art::render_restate_logo; use restate_types::config::CommonOptionCliOverride; -use restate_types::config::Configuration; +use restate_types::config::{node_dir, Configuration}; mod signal; @@ -84,29 +84,21 @@ enum WipeMode { } impl WipeMode { - async fn wipe( - mode: Option<&WipeMode>, - worker_storage_dir: PathBuf, - local_loglet_storage_dir: PathBuf, - local_metadata_store_storage_dir: PathBuf, - ) -> io::Result<()> { - let (wipe_worker, wipe_local_loglet, wipe_local_metadata_store) = match mode { - Some(WipeMode::Worker) => (true, true, false), - Some(WipeMode::LocalLoglet) => (false, true, false), - Some(WipeMode::LocalMetadataStore) => (false, false, true), - Some(WipeMode::All) => (true, true, true), - None => (false, false, false), - }; - - if wipe_worker { - restate_fs_util::remove_dir_all_if_exists(worker_storage_dir).await?; - } - if wipe_local_loglet { - restate_fs_util::remove_dir_all_if_exists(local_loglet_storage_dir).await?; - } - if wipe_local_metadata_store { - restate_fs_util::remove_dir_all_if_exists(local_metadata_store_storage_dir).await? + async fn wipe(mode: Option<&WipeMode>, config: &Configuration) -> io::Result<()> { + match mode { + Some(WipeMode::Worker) => { + restate_fs_util::remove_dir_all_if_exists(config.worker.storage.data_dir()).await? + } + Some(WipeMode::LocalLoglet) => { + restate_fs_util::remove_dir_all_if_exists(config.bifrost.local.data_dir()).await? + } + Some(WipeMode::LocalMetadataStore) => { + restate_fs_util::remove_dir_all_if_exists(config.metadata_store.data_dir()).await? + } + Some(WipeMode::All) => restate_fs_util::remove_dir_all_if_exists(node_dir()).await?, + _ => {} } + Ok(()) } } @@ -209,14 +201,9 @@ fn main() { { let config = Configuration::pinned(); - WipeMode::wipe( - cli_args.wipe.as_ref(), - config.worker.storage.data_dir(), - config.bifrost.local.data_dir(), - config.metadata_store.data_dir(), - ) - .await - .expect("Error when trying to wipe the configured storage path"); + WipeMode::wipe(cli_args.wipe.as_ref(), &config) + .await + .expect("Error when trying to wipe the configured storage path"); } let node = Node::create(Configuration::current().clone()).await;