Skip to content

Commit

Permalink
fix: ensure data_home directory created (GreptimeTeam#2588)
Browse files Browse the repository at this point in the history
fix: ensure data_home directory created before creating metadata store, GreptimeTeam#2587
  • Loading branch information
killme2008 authored and paomian committed Oct 19, 2023
1 parent d478a0c commit fb602d9
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
7 changes: 7 additions & 0 deletions src/cmd/src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<T> = std::result::Result<T, Error>;
Expand All @@ -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,
Expand Down
10 changes: 8 additions & 2 deletions src/cmd/src/standalone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
// limitations under the License.

use std::sync::Arc;
use std::{fs, path};

use catalog::kvbackend::KvBackendCatalogManager;
use catalog::CatalogManagerRef;
Expand Down Expand Up @@ -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};

Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit fb602d9

Please sign in to comment.