diff --git a/ecstore/src/disk.rs b/ecstore/src/disk.rs index e708a2a7..c8c87fd7 100644 --- a/ecstore/src/disk.rs +++ b/ecstore/src/disk.rs @@ -24,7 +24,7 @@ use crate::{ endpoint::{Endpoint, Endpoints}, file_meta::FileMeta, format::{DistributionAlgoVersion, FormatV3}, - store_api::FileInfo, + store_api::{FileInfo, RawFileInfo}, utils, }; @@ -218,6 +218,7 @@ impl LocalDisk { Ok(()) } + /// read xl.meta raw data async fn read_raw( &self, bucket: &str, @@ -480,7 +481,7 @@ impl DiskAPI for LocalDisk { fs::write(&src_file_path, fm_data).await?; - let no_inline = src_data_path.has_root() && fi.data.is_empty() && fi.size > 0; + let no_inline = src_data_path.has_root() && fi.data.is_none() && fi.size > 0; if no_inline { self.rename_all(&src_data_path, &dst_data_path, &skipParent).await?; } @@ -566,7 +567,7 @@ impl DiskAPI for LocalDisk { org_volume: &str, volume: &str, path: &str, - version_id: &str, + version_id: Uuid, opts: ReadOptions, ) -> Result { let file_path = self.get_object_path(volume, path)?; @@ -576,7 +577,18 @@ impl DiskAPI for LocalDisk { let (data, _) = self.read_raw(volume, file_dir, file_path, read_data).await?; - unimplemented!() + let meta = FileMeta::unmarshal(&data)?; + + let fi = meta.into_fileinfo(volume, path, version_id, false, true)?; + Ok(fi) + } + async fn read_xl(&self, volume: &str, path: &str, read_data: bool) -> Result { + let file_path = self.get_object_path(volume, path)?; + let file_dir = self.get_bucket_path(volume)?; + + let (buf, _) = self.read_raw(volume, file_dir, file_path, read_data).await?; + + Ok(RawFileInfo { buf }) } } diff --git a/ecstore/src/disk_api.rs b/ecstore/src/disk_api.rs index 7503acd1..486d985e 100644 --- a/ecstore/src/disk_api.rs +++ b/ecstore/src/disk_api.rs @@ -4,8 +4,9 @@ use anyhow::{Error, Result}; use bytes::Bytes; use time::OffsetDateTime; use tokio::io::DuplexStream; +use uuid::Uuid; -use crate::store_api::FileInfo; +use crate::store_api::{FileInfo, RawFileInfo}; #[async_trait::async_trait] pub trait DiskAPI: Debug + Send + Sync + 'static { @@ -34,9 +35,10 @@ pub trait DiskAPI: Debug + Send + Sync + 'static { org_volume: &str, volume: &str, path: &str, - version_id: &str, + version_id: Uuid, opts: ReadOptions, ) -> Result; + async fn read_xl(&self, volume: &str, path: &str, read_data: bool) -> Result; } pub struct VolumeInfo { diff --git a/ecstore/src/store_api.rs b/ecstore/src/store_api.rs index b24548c7..b043a827 100644 --- a/ecstore/src/store_api.rs +++ b/ecstore/src/store_api.rs @@ -13,6 +13,8 @@ pub const BLOCK_SIZE_V2: usize = 1048576; // 1M #[derive(Debug, Clone)] pub struct FileInfo { + pub name: String, + pub volume: String, pub version_id: Uuid, pub erasure: ErasureInfo, pub deleted: bool, @@ -20,7 +22,7 @@ pub struct FileInfo { pub data_dir: Uuid, pub mod_time: OffsetDateTime, pub size: usize, - pub data: Vec, + pub data: Option>, pub fresh: bool, // indicates this is a first time call to write FileInfo. } @@ -42,6 +44,8 @@ impl Default for FileInfo { size: Default::default(), data: Default::default(), fresh: Default::default(), + name: Default::default(), + volume: Default::default(), } } } @@ -62,7 +66,7 @@ impl FileInfo { }; Self { erasure: ErasureInfo { - algorithm: ERASURE_ALGORITHM, + algorithm: String::from(ERASURE_ALGORITHM), data_blocks: data_blocks, parity_blocks: parity_blocks, block_size: BLOCK_SIZE_V2, @@ -89,11 +93,15 @@ impl FileInfo { } } +pub struct RawFileInfo { + pub buf: Vec, +} + #[derive(Debug, Default, Clone)] // ErasureInfo holds erasure coding and bitrot related information. pub struct ErasureInfo { // Algorithm is the String representation of erasure-coding-algorithm - pub algorithm: &'static str, + pub algorithm: String, // DataBlocks is the number of data blocks for erasure-coding pub data_blocks: usize, // ParityBlocks is the number of parity blocks for erasure-coding