diff --git a/ecstore/src/config/com.rs b/ecstore/src/config/com.rs index 43e48c6d2..d08b0da27 100644 --- a/ecstore/src/config/com.rs +++ b/ecstore/src/config/com.rs @@ -12,25 +12,54 @@ use std::io::Cursor; use std::sync::Arc; use tracing::{error, warn}; +/// * config prefix pub const CONFIG_PREFIX: &str = "config"; +/// * config file const CONFIG_FILE: &str = "config.json"; +/// * config class sub system pub const STORAGE_CLASS_SUB_SYS: &str = "storage_class"; +/// * config class sub system pub const DEFAULT_KV_KEY: &str = "_"; lazy_static! { + /// * config bucket static ref CONFIG_BUCKET: String = format!("{}{}{}", RUSTFS_META_BUCKET, SLASH_SEPARATOR, CONFIG_PREFIX); + /// * config file static ref SubSystemsDynamic: HashSet = { let mut h = HashSet::new(); h.insert(STORAGE_CLASS_SUB_SYS.to_owned()); h }; } + +/// * read config +/// +/// * @param api +/// * @param file +/// +/// * @return +/// * @description +/// * read config +/// * @error +/// * * ConfigError::NotFound pub async fn read_config(api: Arc, file: &str) -> Result> { let (data, _obj) = read_config_with_metadata(api, file, &ObjectOptions::default()).await?; Ok(data) } +/// * read_config_with_metadata +/// read config with metadata +/// +/// * @param api +/// * @param file +/// * @param opts +/// +/// * @return +/// * @description +/// * read config with metadata +/// * @error +/// * * ConfigError::NotFound pub async fn read_config_with_metadata( api: Arc, file: &str, @@ -57,6 +86,15 @@ pub async fn read_config_with_metadata( Ok((data, rd.object_info)) } +/// * save_config +/// +/// * @param api +/// * @param file +/// * @param data +/// +/// * @return +/// * @description +/// * save config pub async fn save_config(api: Arc, file: &str, data: Vec) -> Result<()> { save_config_with_opts( api, @@ -70,6 +108,13 @@ pub async fn save_config(api: Arc, file: &str, data: Vec) .await } +/// * delete_config +/// +/// * @param api +/// * @param file +/// * @return +/// * @description +/// * delete config pub async fn delete_config(api: Arc, file: &str) -> Result<()> { match api .delete_object( @@ -94,6 +139,15 @@ pub async fn delete_config(api: Arc, file: &str) -> Result<()> } } +/// * save_config_with_opts +/// save config with opts +/// * @param api +/// * @param file +/// * @param data +/// * @param opts +/// * @return +/// * @description +/// * save config with opts pub async fn save_config_with_opts(api: Arc, file: &str, data: Vec, opts: &ObjectOptions) -> Result<()> { let size = data.len(); let _ = api @@ -114,19 +168,20 @@ async fn new_and_save_server_config(api: Arc) -> Result(api: Arc) -> Result { let config_file = format!("{}{}{}", CONFIG_PREFIX, SLASH_SEPARATOR, CONFIG_FILE); let data = match read_config(api.clone(), config_file.as_str()).await { Ok(res) => res, Err(err) => { - if is_err_config_not_found(&err) { + return if is_err_config_not_found(&err) { warn!("config not found, start to init"); let cfg = new_and_save_server_config(api).await?; warn!("config init done"); - return Ok(cfg); + Ok(cfg) } else { error!("read config err {:?}", &err); - return Err(err); + Err(err) } } }; @@ -141,14 +196,14 @@ async fn read_server_config(api: Arc, data: &[u8]) -> Result res, Err(err) => { - if is_err_config_not_found(&err) { + return if is_err_config_not_found(&err) { warn!("config not found init start"); let cfg = new_and_save_server_config(api).await?; warn!("config not found init done"); - return Ok(cfg); + Ok(cfg) } else { error!("read config err {:?}", &err); - return Err(err); + Err(err) } } }; @@ -171,6 +226,7 @@ async fn save_server_config(api: Arc, cfg: &Config) -> Result< save_config(api, &config_file, data).await } +/// * lookup_configs pub async fn lookup_configs(cfg: &mut Config, api: Arc) { // TODO: from etcd if let Err(err) = apply_dynamic_config(cfg, api).await { @@ -186,13 +242,12 @@ async fn apply_dynamic_config(cfg: &mut Config, api: Arc) -> R Ok(()) } -async fn apply_dynamic_config_for_sub_sys(cfg: &mut Config, api: Arc, subsys: &str) -> Result<()> { +async fn apply_dynamic_config_for_sub_sys(cfg: &mut Config, api: Arc, sub_sys: &str) -> Result<()> { let set_drive_counts = api.set_drive_counts(); - if subsys == STORAGE_CLASS_SUB_SYS { - let kvs = match cfg.get_value(STORAGE_CLASS_SUB_SYS, DEFAULT_KV_KEY) { - Some(res) => res, - None => KVS::new(), - }; + if sub_sys == STORAGE_CLASS_SUB_SYS { + let kvs = cfg + .get_value(STORAGE_CLASS_SUB_SYS, DEFAULT_KV_KEY) + .unwrap_or_else(|| KVS::new()); for (i, count) in set_drive_counts.iter().enumerate() { match storageclass::lookup_config(&kvs, *count) { diff --git a/ecstore/src/disk/error.rs b/ecstore/src/disk/error.rs index 0d422b106..549ad3873 100644 --- a/ecstore/src/disk/error.rs +++ b/ecstore/src/disk/error.rs @@ -341,7 +341,7 @@ pub fn os_err_to_file_err(e: io::Error) -> Error { // io::ErrorKind::UnexpectedEof => todo!(), // io::ErrorKind::OutOfMemory => todo!(), // io::ErrorKind::Other => todo!(), - // TODO: 把不支持的king用字符串处理 + // TODO: 把不支持的 king 用字符串处理 _ => Error::new(e), } } @@ -355,7 +355,7 @@ pub struct FileAccessDeniedWithContext { impl std::fmt::Display for FileAccessDeniedWithContext { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "访问文件 '{}' 被拒绝: {}", self.path.display(), self.source) + write!(f, "Access files '{}' denied: {}", self.path.display(), self.source) } } diff --git a/rustfs/src/storage/ecfs.rs b/rustfs/src/storage/ecfs.rs index 44b00072a..32d838c78 100644 --- a/rustfs/src/storage/ecfs.rs +++ b/rustfs/src/storage/ecfs.rs @@ -129,7 +129,7 @@ impl FS { let ext = ext.to_owned(); - // TODO: spport zip + // TODO: support zip let decoder = CompressionFormat::from_extension(&ext).get_decoder(body).map_err(|e| { error!("get_decoder err {:?}", e); s3_error!(InvalidArgument, "get_decoder err")