Skip to content

Commit 32defd3

Browse files
fix for #573 corrected error message in case of deployment mismatch
data directory creation should not happen in case of deployment mismatch staging should be overwritten in case of new staging default staging and data directory should not be created if env var has different path
1 parent bcf8e4b commit 32defd3

File tree

6 files changed

+34
-17
lines changed

6 files changed

+34
-17
lines changed

Cargo.lock

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

server/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ url = "2.4.0"
102102
http-auth-basic = "0.3.3"
103103
serde_repr = "0.1.17"
104104
hashlru = { version = "0.11.0", features = ["serde"] }
105+
path-clean = "1.0.1"
105106

106107
[build-dependencies]
107108
cargo_toml = "0.15"

server/src/main.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,9 @@ use crate::localcache::LocalCacheManager;
5555
async fn main() -> anyhow::Result<()> {
5656
env_logger::init();
5757
let storage = CONFIG.storage().get_object_store();
58-
CONFIG.validate_staging()?;
5958
migration::run_metadata_migration(&CONFIG).await?;
6059
let metadata = storage::resolve_parseable_metadata().await?;
61-
60+
CONFIG.validate_staging()?;
6261
banner::print(&CONFIG, &metadata).await;
6362
rbac::map::init(&metadata);
6463
metadata.set_global();

server/src/option.rs

Lines changed: 20 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ use clap::{command, value_parser, Arg, ArgGroup, Args, Command, FromArgMatches};
2121

2222
use once_cell::sync::Lazy;
2323
use parquet::basic::{BrotliLevel, GzipLevel, ZstdLevel};
24-
use std::path::{Path, PathBuf};
24+
use std::path::PathBuf;
25+
use std::env;
2526
use std::sync::Arc;
2627
use url::Url;
2728

@@ -107,7 +108,7 @@ impl Config {
107108
self.storage.clone()
108109
}
109110

110-
pub fn staging_dir(&self) -> &Path {
111+
pub fn staging_dir(&self) -> &PathBuf {
111112
&self.parseable.local_staging_path
112113
}
113114

@@ -610,12 +611,14 @@ impl From<Compression> for parquet::basic::Compression {
610611

611612
pub mod validation {
612613
use std::{
613-
fs::{canonicalize, create_dir_all},
614614
net::ToSocketAddrs,
615-
path::PathBuf,
615+
path::{PathBuf, Path},
616616
str::FromStr,
617+
env,io
617618
};
618619

620+
use path_clean::PathClean;
621+
619622
use crate::option::MIN_CACHE_SIZE_BYTES;
620623
use crate::storage::LOCAL_SYNC_INTERVAL;
621624
use human_size::{multiples, SpecificSize};
@@ -633,16 +636,22 @@ pub mod validation {
633636

634637
Ok(path)
635638
}
639+
pub fn absolute_path(path: impl AsRef<Path>) -> io::Result<PathBuf> {
640+
let path = path.as_ref();
641+
642+
let absolute_path = if path.is_absolute() {
643+
path.to_path_buf()
644+
} else {
645+
env::current_dir()?.join(path)
646+
}.clean();
647+
648+
Ok(absolute_path)
649+
}
636650

637651
pub fn canonicalize_path(s: &str) -> Result<PathBuf, String> {
638652
let path = PathBuf::from(s);
639-
640-
create_dir_all(&path)
641-
.map_err(|err| err.to_string())
642-
.and_then(|_| {
643-
canonicalize(&path)
644-
.map_err(|_| "Cannot use the path provided as an absolute path".to_string())
645-
})
653+
let absolute_path = absolute_path(&path);
654+
Ok(absolute_path.unwrap())
646655
}
647656

648657
pub fn socket_addr(s: &str) -> Result<String, String> {

server/src/storage/localfs.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ use tokio::fs::{self, DirEntry};
3232
use tokio_stream::wrappers::ReadDirStream;
3333

3434
use crate::metrics::storage::{localfs::REQUEST_RESPONSE_TIME, StorageMetrics};
35-
use crate::utils::validate_path_is_writeable;
35+
use crate::{option::validation, utils::validate_path_is_writeable};
3636

3737
use super::{object_storage, LogStream, ObjectStorage, ObjectStorageError, ObjectStorageProvider};
3838

@@ -49,7 +49,8 @@ pub struct FSConfig {
4949
#[arg(
5050
env = "P_FS_DIR",
5151
value_name = "filesystem path",
52-
default_value = "./data"
52+
default_value = "./data",
53+
value_parser = validation::canonicalize_path
5354
)]
5455
pub root: PathBuf,
5556
}

server/src/storage/store_metadata.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl StorageMetadata {
6666
Self {
6767
version: "v3".to_string(),
6868
mode: CONFIG.storage_name.to_owned(),
69-
staging: CONFIG.staging_dir().canonicalize().unwrap(),
69+
staging: CONFIG.staging_dir().to_path_buf(),
7070
storage: CONFIG.storage().get_endpoint(),
7171
deployment_id: uid::gen(),
7272
users: Vec::new(),
@@ -130,7 +130,7 @@ pub async fn resolve_parseable_metadata() -> Result<StorageMetadata, ObjectStora
130130
}
131131
EnvChange::CreateBoth => {
132132
create_dir_all(CONFIG.staging_dir())?;
133-
let metadata = StorageMetadata::new();
133+
let metadata = StorageMetadata::new();
134134
// new metadata needs to be set on both staging and remote
135135
overwrite_remote = true;
136136
overwrite_staging = true;

0 commit comments

Comments
 (0)