diff --git a/ecstore/src/disk/local.rs b/ecstore/src/disk/local.rs index 9eb470bae..73139387a 100644 --- a/ecstore/src/disk/local.rs +++ b/ecstore/src/disk/local.rs @@ -26,7 +26,7 @@ use std::{ use time::OffsetDateTime; use tokio::fs::{self, File}; use tokio::io::{AsyncReadExt, AsyncWriteExt, ErrorKind}; -use tokio::sync::Mutex; +use tokio::sync::RwLock; use tracing::{debug, warn}; use uuid::Uuid; @@ -52,7 +52,7 @@ impl FormatInfo { pub struct LocalDisk { pub root: PathBuf, pub format_path: PathBuf, - pub format_info: Mutex, + pub format_info: RwLock, pub endpoint: Endpoint, // pub id: Mutex>, // pub format_data: Mutex>, @@ -106,7 +106,7 @@ impl LocalDisk { root, endpoint: ep.clone(), format_path: format_path, - format_info: Mutex::new(format_info), + format_info: RwLock::new(format_info), // // format_legacy, // format_file_info: Mutex::new(format_meta), // format_data: Mutex::new(format_data), @@ -499,7 +499,7 @@ impl LocalDisk { // write_all_public for trail async fn write_all_public(&self, volume: &str, path: &str, data: Vec) -> Result<()> { if volume == super::RUSTFS_META_BUCKET && path == super::FORMAT_CONFIG_FILE { - let mut format_info = self.format_info.lock().await; + let mut format_info = self.format_info.write().await; format_info.data = data.clone(); } @@ -685,8 +685,7 @@ impl DiskAPI for LocalDisk { } async fn get_disk_id(&self) -> Result> { - // TODO: check format file - let mut format_info = self.format_info.lock().await; + let mut format_info = self.format_info.write().await; let id = format_info.id.clone(); @@ -737,18 +736,24 @@ impl DiskAPI for LocalDisk { format_info.last_check = Some(OffsetDateTime::now_utc()); Ok(Some(disk_id)) - // TODO: 判断源文件id,是否有效 } async fn set_disk_id(&self, id: Option) -> Result<()> { // 本地不需要设置 - let mut format_info = self.format_info.lock().await; + // TODO: add check_id_store + let mut format_info = self.format_info.write().await; format_info.id = id; Ok(()) } #[must_use] async fn read_all(&self, volume: &str, path: &str) -> Result> { + if volume == super::RUSTFS_META_BUCKET && path == super::FORMAT_CONFIG_FILE { + let format_info = self.format_info.read().await; + if format_info.data.len() > 0 { + return Ok(format_info.data.clone()); + } + } // TOFIX: let p = self.get_object_path(volume, path)?; let (data, _) = read_file_all(&p).await?; diff --git a/ecstore/src/disk/os.rs b/ecstore/src/disk/os.rs index 78d0ada5c..eea5e0fcd 100644 --- a/ecstore/src/disk/os.rs +++ b/ecstore/src/disk/os.rs @@ -208,12 +208,3 @@ pub async fn os_mkdir_all(dir_path: impl AsRef, base_dir: impl AsRef Ok(()) } - -#[cfg(test)] -mod test { - - use super::*; - - #[tokio::test] - async fn test_make_dir() {} -} diff --git a/ecstore/src/error.rs b/ecstore/src/error.rs index 1fc8dfabf..db5b27561 100644 --- a/ecstore/src/error.rs +++ b/ecstore/src/error.rs @@ -98,7 +98,11 @@ impl Clone for Error { if let Some(e) = self.downcast_ref::() { clone_disk_err(e) } else if let Some(e) = self.downcast_ref::() { - Error::new(io::Error::new(e.kind(), e.to_string())) + if let Some(code) = e.raw_os_error() { + Error::new(io::Error::from_raw_os_error(code)) + } else { + Error::new(io::Error::new(e.kind(), e.to_string())) + } } else { // TODO: 优化其他类型 Error::msg(self.to_string())