mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-27 15:37:02 +00:00
refactor(ecstore): DiskAPI::read_all use Bytes
This commit is contained in:
+13
-13
@@ -138,7 +138,7 @@ impl LocalDisk {
|
|||||||
let mut format_last_check = None;
|
let mut format_last_check = None;
|
||||||
|
|
||||||
if !format_data.is_empty() {
|
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 fm = FormatV3::try_from(s).map_err(Error::other)?;
|
||||||
let (set_idx, disk_idx) = fm.find_disk_index_by_disk_id(fm.erasure.this)?;
|
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 {
|
let format_info = FormatInfo {
|
||||||
id,
|
id,
|
||||||
data: format_data.into(),
|
data: format_data,
|
||||||
file_info: format_meta,
|
file_info: format_meta,
|
||||||
last_check: format_last_check,
|
last_check: format_last_check,
|
||||||
};
|
};
|
||||||
@@ -980,13 +980,13 @@ fn is_root_path(path: impl AsRef<Path>) -> bool {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// 过滤 std::io::ErrorKind::NotFound
|
// 过滤 std::io::ErrorKind::NotFound
|
||||||
pub async fn read_file_exists(path: impl AsRef<Path>) -> Result<(Vec<u8>, Option<Metadata>)> {
|
pub async fn read_file_exists(path: impl AsRef<Path>) -> Result<(Bytes, Option<Metadata>)> {
|
||||||
let p = path.as_ref();
|
let p = path.as_ref();
|
||||||
let (data, meta) = match read_file_all(&p).await {
|
let (data, meta) = match read_file_all(&p).await {
|
||||||
Ok((data, meta)) => (data, Some(meta)),
|
Ok((data, meta)) => (data, Some(meta)),
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if e == Error::FileNotFound {
|
if e == Error::FileNotFound {
|
||||||
(Vec::new(), None)
|
(Bytes::new(), None)
|
||||||
} else {
|
} else {
|
||||||
return Err(e);
|
return Err(e);
|
||||||
}
|
}
|
||||||
@@ -1001,13 +1001,13 @@ pub async fn read_file_exists(path: impl AsRef<Path>) -> Result<(Vec<u8>, Option
|
|||||||
Ok((data, meta))
|
Ok((data, meta))
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn read_file_all(path: impl AsRef<Path>) -> Result<(Vec<u8>, Metadata)> {
|
pub async fn read_file_all(path: impl AsRef<Path>) -> Result<(Bytes, Metadata)> {
|
||||||
let p = path.as_ref();
|
let p = path.as_ref();
|
||||||
let meta = read_file_metadata(&path).await?;
|
let meta = read_file_metadata(&path).await?;
|
||||||
|
|
||||||
let data = fs::read(&p).await.map_err(to_file_error)?;
|
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<Path>) -> Result<Metadata> {
|
pub async fn read_file_metadata(p: impl AsRef<Path>) -> Result<Metadata> {
|
||||||
@@ -1147,11 +1147,11 @@ impl DiskAPI for LocalDisk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
async fn read_all(&self, volume: &str, path: &str) -> Result<Vec<u8>> {
|
async fn read_all(&self, volume: &str, path: &str) -> Result<Bytes> {
|
||||||
if volume == RUSTFS_META_BUCKET && path == super::FORMAT_CONFIG_FILE {
|
if volume == RUSTFS_META_BUCKET && path == super::FORMAT_CONFIG_FILE {
|
||||||
let format_info = self.format_info.read().await;
|
let format_info = self.format_info.read().await;
|
||||||
if !format_info.data.is_empty() {
|
if !format_info.data.is_empty() {
|
||||||
return Ok(format_info.data.to_vec());
|
return Ok(format_info.data.clone());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// TOFIX:
|
// 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);
|
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)?;
|
xl_meta.update_object_version(fi)?;
|
||||||
|
|
||||||
@@ -2076,7 +2076,7 @@ impl DiskAPI for LocalDisk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
res.exists = true;
|
res.exists = true;
|
||||||
res.data = data;
|
res.data = data.into();
|
||||||
res.mod_time = match meta.modified() {
|
res.mod_time = match meta.modified() {
|
||||||
Ok(md) => Some(OffsetDateTime::from(md)),
|
Ok(md) => Some(OffsetDateTime::from(md)),
|
||||||
Err(_) => {
|
Err(_) => {
|
||||||
@@ -2627,7 +2627,7 @@ mod test {
|
|||||||
|
|
||||||
// Test existing file
|
// Test existing file
|
||||||
let (data, metadata) = read_file_exists(test_file).await.unwrap();
|
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());
|
assert!(metadata.is_some());
|
||||||
|
|
||||||
// Clean up
|
// Clean up
|
||||||
@@ -2644,7 +2644,7 @@ mod test {
|
|||||||
|
|
||||||
// Test reading file
|
// Test reading file
|
||||||
let (data, metadata) = read_file_all(test_file).await.unwrap();
|
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!(metadata.is_file());
|
||||||
assert_eq!(metadata.len(), test_content.len() as u64);
|
assert_eq!(metadata.len(), test_content.len() as u64);
|
||||||
|
|
||||||
|
|||||||
@@ -372,7 +372,7 @@ impl DiskAPI for Disk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
async fn read_all(&self, volume: &str, path: &str) -> Result<Vec<u8>> {
|
async fn read_all(&self, volume: &str, path: &str) -> Result<Bytes> {
|
||||||
match self {
|
match self {
|
||||||
Disk::Local(local_disk) => local_disk.read_all(volume, path).await,
|
Disk::Local(local_disk) => local_disk.read_all(volume, path).await,
|
||||||
Disk::Remote(remote_disk) => remote_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<Vec<ReadMultipleResp>>;
|
async fn read_multiple(&self, req: ReadMultipleReq) -> Result<Vec<ReadMultipleResp>>;
|
||||||
// CleanAbandonedData
|
// CleanAbandonedData
|
||||||
async fn write_all(&self, volume: &str, path: &str, data: Bytes) -> Result<()>;
|
async fn write_all(&self, volume: &str, path: &str, data: Bytes) -> Result<()>;
|
||||||
async fn read_all(&self, volume: &str, path: &str) -> Result<Vec<u8>>;
|
async fn read_all(&self, volume: &str, path: &str) -> Result<Bytes>;
|
||||||
async fn disk_info(&self, opts: &DiskInfoOptions) -> Result<DiskInfo>;
|
async fn disk_info(&self, opts: &DiskInfoOptions) -> Result<DiskInfo>;
|
||||||
async fn ns_scanner(
|
async fn ns_scanner(
|
||||||
&self,
|
&self,
|
||||||
|
|||||||
@@ -826,7 +826,7 @@ impl DiskAPI for RemoteDisk {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
async fn read_all(&self, volume: &str, path: &str) -> Result<Vec<u8>> {
|
async fn read_all(&self, volume: &str, path: &str) -> Result<Bytes> {
|
||||||
info!("read_all {}/{}", volume, path);
|
info!("read_all {}/{}", volume, path);
|
||||||
let mut client = node_service_time_out_client(&self.addr)
|
let mut client = node_service_time_out_client(&self.addr)
|
||||||
.await
|
.await
|
||||||
@@ -843,7 +843,7 @@ impl DiskAPI for RemoteDisk {
|
|||||||
return Err(response.error.unwrap_or_default().into());
|
return Err(response.error.unwrap_or_default().into());
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(response.data.into())
|
Ok(response.data)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tracing::instrument(skip(self))]
|
#[tracing::instrument(skip(self))]
|
||||||
|
|||||||
@@ -256,7 +256,7 @@ pub async fn load_format_erasure(disk: &DiskStore, heal: bool) -> disk::error::R
|
|||||||
_ => e,
|
_ => e,
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
let mut fm = FormatV3::try_from(data.as_slice())?;
|
let mut fm = FormatV3::try_from(data.as_ref())?;
|
||||||
|
|
||||||
if heal {
|
if heal {
|
||||||
let info = disk
|
let info = disk
|
||||||
|
|||||||
+1
-1
@@ -277,7 +277,7 @@ impl Node for NodeService {
|
|||||||
match disk.read_all(&request.volume, &request.path).await {
|
match disk.read_all(&request.volume, &request.path).await {
|
||||||
Ok(data) => Ok(tonic::Response::new(ReadAllResponse {
|
Ok(data) => Ok(tonic::Response::new(ReadAllResponse {
|
||||||
success: true,
|
success: true,
|
||||||
data: data.into(),
|
data,
|
||||||
error: None,
|
error: None,
|
||||||
})),
|
})),
|
||||||
Err(err) => Ok(tonic::Response::new(ReadAllResponse {
|
Err(err) => Ok(tonic::Response::new(ReadAllResponse {
|
||||||
|
|||||||
Reference in New Issue
Block a user