From b394c6f6fa85cbc8d37e4341f448c88a11ca55ed Mon Sep 17 00:00:00 2001 From: Dennis Zhuang Date: Thu, 12 Oct 2023 15:18:15 +0800 Subject: [PATCH] fix: ensure data_home directory created before creating metadata store, #2587 --- src/cmd/src/error.rs | 7 +++++++ src/cmd/src/standalone.rs | 10 ++++++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/cmd/src/error.rs b/src/cmd/src/error.rs index df8468f92b85..d8b748029213 100644 --- a/src/cmd/src/error.rs +++ b/src/cmd/src/error.rs @@ -180,6 +180,12 @@ pub enum Error { error: serde_json::error::Error, location: Location, }, + #[snafu(display("Failed to create directory {}", dir))] + CreateDir { + dir: String, + #[snafu(source)] + error: std::io::Error, + }, } pub type Result = std::result::Result; @@ -202,6 +208,7 @@ impl ErrorExt for Error { | Error::LoadLayeredConfig { .. } | Error::IllegalConfig { .. } | Error::InvalidReplCommand { .. } + | Error::CreateDir { .. } | Error::ConnectEtcd { .. } => StatusCode::InvalidArguments, Error::ReplCreation { .. } | Error::Readline { .. } => StatusCode::Internal, diff --git a/src/cmd/src/standalone.rs b/src/cmd/src/standalone.rs index a1f9695dd368..c5c703059025 100644 --- a/src/cmd/src/standalone.rs +++ b/src/cmd/src/standalone.rs @@ -13,6 +13,7 @@ // limitations under the License. use std::sync::Arc; +use std::{fs, path}; use catalog::kvbackend::KvBackendCatalogManager; use catalog::CatalogManagerRef; @@ -41,8 +42,8 @@ use servers::Mode; use snafu::ResultExt; use crate::error::{ - IllegalConfigSnafu, InitMetadataSnafu, Result, ShutdownDatanodeSnafu, ShutdownFrontendSnafu, - StartDatanodeSnafu, StartFrontendSnafu, + CreateDirSnafu, IllegalConfigSnafu, InitMetadataSnafu, Result, ShutdownDatanodeSnafu, + ShutdownFrontendSnafu, StartDatanodeSnafu, StartFrontendSnafu, }; use crate::options::{MixOptions, Options, TopLevelOptions}; @@ -310,6 +311,11 @@ impl StartCommand { fe_opts, dn_opts ); + // Ensure the data_home directory exists. + fs::create_dir_all(path::Path::new(&opts.data_home)).context(CreateDirSnafu { + dir: &opts.data_home, + })?; + let metadata_dir = metadata_store_dir(&opts.data_home); let (kv_store, procedure_manager) = FeInstance::try_build_standalone_components( metadata_dir,