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

prevent primary to remove itself in case of load error #1253

Merged
merged 1 commit into from
Mar 23, 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
16 changes: 10 additions & 6 deletions libsql-server/src/namespace/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -248,24 +248,28 @@ impl Namespace {
restore_option: RestoreOption,
resolve_attach_path: ResolveNamespacePathFn,
) -> crate::Result<Self> {
let db_path: Arc<Path> = config.base_path.join("dbs").join(name.as_str()).into();
let fresh_namespace = !db_path.try_exists()?;
// FIXME: make that truly atomic. explore the idea of using temp directories, and it's implications
match Self::try_new_primary(
config,
name.clone(),
meta_store_handle,
restore_option,
resolve_attach_path,
db_path.clone(),
)
.await
{
Ok(ns) => Ok(ns),
Err(e) => {
let path = config.base_path.join("dbs").join(name.as_str());
if let Err(e) = tokio::fs::remove_dir_all(path).await {
tracing::error!("failed to clean dirty namespace: {e}");
Ok(this) => Ok(this),
Err(e) if fresh_namespace => {
tracing::error!("an error occured while deleting creating namespace, cleaning...");
if let Err(e) = tokio::fs::remove_dir_all(&db_path).await {
tracing::error!("failed to remove dirty namespace directory: {e}")
}
Err(e)
}
Err(e) => Err(e),
}
}

Expand Down Expand Up @@ -396,9 +400,9 @@ impl Namespace {
meta_store_handle: MetaStoreHandle,
restore_option: RestoreOption,
resolve_attach_path: ResolveNamespacePathFn,
db_path: Arc<Path>,
) -> crate::Result<Self> {
let mut join_set = JoinSet::new();
let db_path = ns_config.base_path.join("dbs").join(name.as_str());

tokio::fs::create_dir_all(&db_path).await?;

Expand Down
Loading