diff --git a/ecstore/src/disk/local.rs b/ecstore/src/disk/local.rs index 004aaa61d..1cfd28e2a 100644 --- a/ecstore/src/disk/local.rs +++ b/ecstore/src/disk/local.rs @@ -138,7 +138,7 @@ impl LocalDisk { let mut format_last_check = None; if !format_data.is_empty() { - let s = format_data.as_slice(); + let s = format_data.as_ref(); let fm = FormatV3::try_from(s).map_err(Error::other)?; let (set_idx, disk_idx) = fm.find_disk_index_by_disk_id(fm.erasure.this)?; @@ -153,7 +153,7 @@ impl LocalDisk { let format_info = FormatInfo { id, - data: format_data.into(), + data: format_data, file_info: format_meta, last_check: format_last_check, }; @@ -980,13 +980,13 @@ fn is_root_path(path: impl AsRef) -> bool { } // 过滤 std::io::ErrorKind::NotFound -pub async fn read_file_exists(path: impl AsRef) -> Result<(Vec, Option)> { +pub async fn read_file_exists(path: impl AsRef) -> Result<(Bytes, Option)> { let p = path.as_ref(); let (data, meta) = match read_file_all(&p).await { Ok((data, meta)) => (data, Some(meta)), Err(e) => { if e == Error::FileNotFound { - (Vec::new(), None) + (Bytes::new(), None) } else { return Err(e); } @@ -1001,13 +1001,13 @@ pub async fn read_file_exists(path: impl AsRef) -> Result<(Vec, Option Ok((data, meta)) } -pub async fn read_file_all(path: impl AsRef) -> Result<(Vec, Metadata)> { +pub async fn read_file_all(path: impl AsRef) -> Result<(Bytes, Metadata)> { let p = path.as_ref(); let meta = read_file_metadata(&path).await?; let data = fs::read(&p).await.map_err(to_file_error)?; - Ok((data, meta)) + Ok((data.into(), meta)) } pub async fn read_file_metadata(p: impl AsRef) -> Result { @@ -1147,11 +1147,11 @@ impl DiskAPI for LocalDisk { } #[tracing::instrument(skip(self))] - async fn read_all(&self, volume: &str, path: &str) -> Result> { + async fn read_all(&self, volume: &str, path: &str) -> Result { if volume == RUSTFS_META_BUCKET && path == super::FORMAT_CONFIG_FILE { let format_info = self.format_info.read().await; if !format_info.data.is_empty() { - return Ok(format_info.data.to_vec()); + return Ok(format_info.data.clone()); } } // TOFIX: @@ -1866,11 +1866,11 @@ impl DiskAPI for LocalDisk { } })?; - if !FileMeta::is_xl2_v1_format(buf.as_slice()) { + if !FileMeta::is_xl2_v1_format(buf.as_ref()) { return Err(DiskError::FileVersionNotFound); } - let mut xl_meta = FileMeta::load(buf.as_slice())?; + let mut xl_meta = FileMeta::load(buf.as_ref())?; xl_meta.update_object_version(fi)?; @@ -2076,7 +2076,7 @@ impl DiskAPI for LocalDisk { } res.exists = true; - res.data = data; + res.data = data.into(); res.mod_time = match meta.modified() { Ok(md) => Some(OffsetDateTime::from(md)), Err(_) => { @@ -2627,7 +2627,7 @@ mod test { // Test existing file let (data, metadata) = read_file_exists(test_file).await.unwrap(); - assert_eq!(data, b"test content"); + assert_eq!(data.as_ref(), b"test content"); assert!(metadata.is_some()); // Clean up @@ -2644,7 +2644,7 @@ mod test { // Test reading file let (data, metadata) = read_file_all(test_file).await.unwrap(); - assert_eq!(data, test_content); + assert_eq!(data.as_ref(), test_content); assert!(metadata.is_file()); assert_eq!(metadata.len(), test_content.len() as u64); diff --git a/ecstore/src/disk/mod.rs b/ecstore/src/disk/mod.rs index 821e362f3..a345732f9 100644 --- a/ecstore/src/disk/mod.rs +++ b/ecstore/src/disk/mod.rs @@ -372,7 +372,7 @@ impl DiskAPI for Disk { } #[tracing::instrument(skip(self))] - async fn read_all(&self, volume: &str, path: &str) -> Result> { + async fn read_all(&self, volume: &str, path: &str) -> Result { match self { Disk::Local(local_disk) => local_disk.read_all(volume, path).await, Disk::Remote(remote_disk) => remote_disk.read_all(volume, path).await, @@ -505,7 +505,7 @@ pub trait DiskAPI: Debug + Send + Sync + 'static { async fn read_multiple(&self, req: ReadMultipleReq) -> Result>; // CleanAbandonedData async fn write_all(&self, volume: &str, path: &str, data: Bytes) -> Result<()>; - async fn read_all(&self, volume: &str, path: &str) -> Result>; + async fn read_all(&self, volume: &str, path: &str) -> Result; async fn disk_info(&self, opts: &DiskInfoOptions) -> Result; async fn ns_scanner( &self, diff --git a/ecstore/src/disk/remote.rs b/ecstore/src/disk/remote.rs index eb3794a47..9495a14ea 100644 --- a/ecstore/src/disk/remote.rs +++ b/ecstore/src/disk/remote.rs @@ -826,7 +826,7 @@ impl DiskAPI for RemoteDisk { } #[tracing::instrument(skip(self))] - async fn read_all(&self, volume: &str, path: &str) -> Result> { + async fn read_all(&self, volume: &str, path: &str) -> Result { info!("read_all {}/{}", volume, path); let mut client = node_service_time_out_client(&self.addr) .await @@ -843,7 +843,7 @@ impl DiskAPI for RemoteDisk { return Err(response.error.unwrap_or_default().into()); } - Ok(response.data.into()) + Ok(response.data) } #[tracing::instrument(skip(self))] diff --git a/ecstore/src/store_init.rs b/ecstore/src/store_init.rs index 9cb781b1e..97c23cb02 100644 --- a/ecstore/src/store_init.rs +++ b/ecstore/src/store_init.rs @@ -256,7 +256,7 @@ pub async fn load_format_erasure(disk: &DiskStore, heal: bool) -> disk::error::R _ => e, })?; - let mut fm = FormatV3::try_from(data.as_slice())?; + let mut fm = FormatV3::try_from(data.as_ref())?; if heal { let info = disk diff --git a/rustfs/src/grpc.rs b/rustfs/src/grpc.rs index ee7bd1366..95ca12c2e 100644 --- a/rustfs/src/grpc.rs +++ b/rustfs/src/grpc.rs @@ -277,7 +277,7 @@ impl Node for NodeService { match disk.read_all(&request.volume, &request.path).await { Ok(data) => Ok(tonic::Response::new(ReadAllResponse { success: true, - data: data.into(), + data, error: None, })), Err(err) => Ok(tonic::Response::new(ReadAllResponse {