Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Delete the node dir when wiping all #1630

Merged
merged 1 commit into from
Jun 20, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 16 additions & 6 deletions crates/types/src/config/mod.rs
Original file line number Diff line number Diff line change
@@ -68,24 +68,34 @@ static NODE_BASE_DIR: Lazy<std::sync::RwLock<TempOrPath>> =
pub type UpdateableConfiguration = Arc<ArcSwap<Configuration>>;

#[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"))]
49 changes: 18 additions & 31 deletions server/src/main.rs
Original file line number Diff line number Diff line change
@@ -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;