Skip to content

Commit

Permalink
refactor: OnDisk ensures dir
Browse files Browse the repository at this point in the history
  • Loading branch information
drmingdrmer committed Nov 7, 2024
1 parent 449204c commit 9ef7883
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/meta/binaries/metactl/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ use databend_common_base::base::tokio;
use databend_common_meta_client::MetaGrpcClient;
use databend_common_meta_kvapi::kvapi::KVApi;
use databend_common_meta_raft_store::config::RaftConfig;
use databend_common_meta_raft_store::ondisk::OnDisk;
use databend_common_meta_sled_store::init_sled_db;
use databend_common_tracing::init_logging;
use databend_common_tracing::Config as LogConfig;
Expand Down Expand Up @@ -362,6 +363,10 @@ async fn main() -> anyhow::Result<()> {
};
let _guards = init_logging("metactl", &log_config, BTreeMap::new());

if let Some(raft_dir) = &app.globals.raft_dir {
OnDisk::ensure_dirs(raft_dir)?;
}

match app.command {
Some(ref cmd) => match cmd {
CtlCommand::Status(args) => {
Expand Down
20 changes: 20 additions & 0 deletions src/meta/raft-store/src/ondisk/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,26 @@ impl fmt::Display for OnDisk {
impl OnDisk {
pub const KEY_HEADER: &'static str = "header";

pub fn ensure_dirs(raft_dir: &str) -> Result<(), io::Error> {
let raft_dir = Path::new(raft_dir);
let version_dir = raft_dir.join("df_meta").join(format!("{}", DATA_VERSION));

let log_dir = version_dir.join("log");

if !log_dir.exists() {
fs::create_dir_all(&log_dir)
.context(format!("creating dir {}", log_dir.as_path().display()))?;
}

let snapshot_dir = version_dir.join("snapshot");
if !snapshot_dir.exists() {
fs::create_dir_all(&snapshot_dir)
.context(format!("creating dir {}", snapshot_dir.as_path().display()))?;
}

Ok(())
}

/// Initialize data version for local store, returns the loaded version.
#[fastrace::trace]
pub async fn open(db: &sled::Db, config: &RaftConfig) -> Result<OnDisk, MetaStorageError> {
Expand Down

0 comments on commit 9ef7883

Please # to comment.