添加 自定义MetaObject marshal

This commit is contained in:
weisd
2024-08-13 14:32:32 +08:00
parent d1b1e896f6
commit 278aae8fff
5 changed files with 81 additions and 77 deletions
+12 -12
View File
@@ -10,24 +10,24 @@ pub const BUCKET_METADATA_FILE: &str = ".metadata.bin";
pub const BUCKET_METADATA_FORMAT: u16 = 1; pub const BUCKET_METADATA_FORMAT: u16 = 1;
pub const BUCKET_METADATA_VERSION: u16 = 1; pub const BUCKET_METADATA_VERSION: u16 = 1;
#[derive(Debug, PartialEq, Deserialize, Serialize)] #[derive(Debug, PartialEq, Deserialize, Serialize, Default)]
pub struct BucketMetadata { pub struct BucketMetadata {
format: u16, format: u16,
version: u16, version: u16,
pub name: String, pub name: String,
pub created: OffsetDateTime, pub created: Option<OffsetDateTime>,
} }
impl Default for BucketMetadata { // impl Default for BucketMetadata {
fn default() -> Self { // fn default() -> Self {
Self { // Self {
format: Default::default(), // format: Default::default(),
version: Default::default(), // version: Default::default(),
name: Default::default(), // name: Default::default(),
created: OffsetDateTime::now_utc(), // created: OffsetDateTime::now_utc(),
} // }
} // }
} // }
impl BucketMetadata { impl BucketMetadata {
pub fn new(name: &str) -> Self { pub fn new(name: &str) -> Self {
+18 -9
View File
@@ -28,7 +28,7 @@ pub struct LocalDisk {
pub _format_meta: Option<Metadata>, pub _format_meta: Option<Metadata>,
pub _format_path: PathBuf, pub _format_path: PathBuf,
// pub format_legacy: bool, // drop // pub format_legacy: bool, // drop
pub _format_last_check: OffsetDateTime, pub _format_last_check: Option<OffsetDateTime>,
} }
impl LocalDisk { impl LocalDisk {
@@ -48,7 +48,7 @@ impl LocalDisk {
let mut id = Uuid::nil(); let mut id = Uuid::nil();
// let mut format_legacy = false; // let mut format_legacy = false;
let mut format_last_check = OffsetDateTime::UNIX_EPOCH; 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_slice();
@@ -61,7 +61,7 @@ impl LocalDisk {
id = fm.erasure.this; id = fm.erasure.this;
// format_legacy = fm.erasure.distribution_algo == DistributionAlgoVersion::V1; // format_legacy = fm.erasure.distribution_algo == DistributionAlgoVersion::V1;
format_last_check = OffsetDateTime::now_utc(); format_last_check = Some(OffsetDateTime::now_utc());
} }
let disk = Self { let disk = Self {
@@ -619,8 +619,11 @@ impl DiskAPI for LocalDisk {
let name = entry.file_name().to_string_lossy().to_string(); let name = entry.file_name().to_string_lossy().to_string();
let created = match metadata.created() { let created = match metadata.created() {
Ok(md) => OffsetDateTime::from(md), Ok(md) => Some(OffsetDateTime::from(md)),
Err(_) => return Err(Error::msg("Not supported created on this platform")), Err(_) => {
warn!("Not supported created on this platform");
None
}
}; };
volumes.push(VolumeInfo { name, created }); volumes.push(VolumeInfo { name, created });
@@ -634,8 +637,11 @@ impl DiskAPI for LocalDisk {
let m = read_file_metadata(&p).await?; let m = read_file_metadata(&p).await?;
let modtime = match m.modified() { let modtime = match m.modified() {
Ok(md) => OffsetDateTime::from(md), Ok(md) => Some(OffsetDateTime::from(md)),
Err(_) => return Err(Error::msg("Not supported modified on this platform")), Err(_) => {
warn!("Not supported modified on this platform");
None
}
}; };
Ok(VolumeInfo { Ok(VolumeInfo {
@@ -722,8 +728,11 @@ impl DiskAPI for LocalDisk {
res.exists = true; res.exists = true;
res.data = data; res.data = data;
res.mod_time = match meta.modified() { res.mod_time = match meta.modified() {
Ok(md) => OffsetDateTime::from(md), Ok(md) => Some(OffsetDateTime::from(md)),
Err(_) => return Err(Error::msg("Not supported modified on this platform")), Err(_) => {
warn!("Not supported modified on this platform");
None
}
}; };
results.push(res); results.push(res);
+16 -16
View File
@@ -107,7 +107,7 @@ pub struct ReadMultipleReq {
pub max_results: usize, pub max_results: usize,
} }
#[derive(Debug, Clone)] #[derive(Debug, Clone, Default)]
pub struct ReadMultipleResp { pub struct ReadMultipleResp {
pub bucket: String, pub bucket: String,
pub prefix: String, pub prefix: String,
@@ -115,26 +115,26 @@ pub struct ReadMultipleResp {
pub exists: bool, pub exists: bool,
pub error: String, pub error: String,
pub data: Vec<u8>, pub data: Vec<u8>,
pub mod_time: OffsetDateTime, pub mod_time: Option<OffsetDateTime>,
} }
impl Default for ReadMultipleResp { // impl Default for ReadMultipleResp {
fn default() -> Self { // fn default() -> Self {
Self { // Self {
bucket: String::new(), // bucket: String::new(),
prefix: String::new(), // prefix: String::new(),
file: String::new(), // file: String::new(),
exists: false, // exists: false,
error: String::new(), // error: String::new(),
data: Vec::new(), // data: Vec::new(),
mod_time: OffsetDateTime::UNIX_EPOCH, // mod_time: OffsetDateTime::UNIX_EPOCH,
} // }
} // }
} // }
pub struct VolumeInfo { pub struct VolumeInfo {
pub name: String, pub name: String,
pub created: OffsetDateTime, pub created: Option<OffsetDateTime>,
} }
pub struct ReadOptions { pub struct ReadOptions {
+29 -29
View File
@@ -19,7 +19,7 @@ pub struct FileInfo {
pub deleted: bool, pub deleted: bool,
// DataDir of the file // DataDir of the file
pub data_dir: Uuid, pub data_dir: Uuid,
pub mod_time: OffsetDateTime, pub mod_time: Option<OffsetDateTime>,
pub size: usize, pub size: usize,
pub data: Option<Vec<u8>>, pub data: Option<Vec<u8>>,
pub fresh: bool, // indicates this is a first time call to write FileInfo. pub fresh: bool, // indicates this is a first time call to write FileInfo.
@@ -58,7 +58,7 @@ impl FileInfo {
Ok(t) Ok(t)
} }
pub fn add_object_part(&mut self, num: usize, part_size: usize, mod_time: OffsetDateTime, actual_size: usize) { pub fn add_object_part(&mut self, num: usize, part_size: usize, mod_time: Option<OffsetDateTime>, actual_size: usize) {
let part = ObjectPartInfo { let part = ObjectPartInfo {
number: num, number: num,
size: part_size, size: part_size,
@@ -120,7 +120,7 @@ impl Default for FileInfo {
erasure: Default::default(), erasure: Default::default(),
deleted: Default::default(), deleted: Default::default(),
data_dir: Uuid::nil(), data_dir: Uuid::nil(),
mod_time: OffsetDateTime::UNIX_EPOCH, mod_time: None,
size: Default::default(), size: Default::default(),
data: Default::default(), data: Default::default(),
fresh: Default::default(), fresh: Default::default(),
@@ -175,27 +175,27 @@ impl FileInfo {
} }
} }
#[derive(Serialize, Deserialize, Debug, PartialEq, Clone)] #[derive(Serialize, Deserialize, Debug, PartialEq, Clone, Default)]
pub struct ObjectPartInfo { pub struct ObjectPartInfo {
// pub etag: Option<String>, // pub etag: Option<String>,
pub number: usize, pub number: usize,
pub size: usize, pub size: usize,
pub actual_size: usize, // 源数据大小 pub actual_size: usize, // 源数据大小
pub mod_time: OffsetDateTime, pub mod_time: Option<OffsetDateTime>,
// pub index: Option<Vec<u8>>, // pub index: Option<Vec<u8>>,
// pub checksums: Option<std::collections::HashMap<String, String>>, // pub checksums: Option<std::collections::HashMap<String, String>>,
} }
impl Default for ObjectPartInfo { // impl Default for ObjectPartInfo {
fn default() -> Self { // fn default() -> Self {
Self { // Self {
number: Default::default(), // number: Default::default(),
size: Default::default(), // size: Default::default(),
mod_time: OffsetDateTime::UNIX_EPOCH, // mod_time: OffsetDateTime::UNIX_EPOCH,
actual_size: Default::default(), // actual_size: Default::default(),
} // }
} // }
} // }
pub struct RawFileInfo { pub struct RawFileInfo {
pub buf: Vec<u8>, pub buf: Vec<u8>,
@@ -358,30 +358,30 @@ impl HTTPRangeSpec {
} }
} }
#[derive(Debug)] #[derive(Debug, Default)]
pub struct ObjectOptions { pub struct ObjectOptions {
// Use the maximum parity (N/2), used when saving server configuration files // Use the maximum parity (N/2), used when saving server configuration files
pub max_parity: bool, pub max_parity: bool,
pub mod_time: OffsetDateTime, pub mod_time: Option<OffsetDateTime>,
pub part_number: usize, pub part_number: usize,
} }
impl Default for ObjectOptions { // impl Default for ObjectOptions {
fn default() -> Self { // fn default() -> Self {
Self { // Self {
max_parity: Default::default(), // max_parity: Default::default(),
mod_time: OffsetDateTime::UNIX_EPOCH, // mod_time: OffsetDateTime::UNIX_EPOCH,
part_number: Default::default(), // part_number: Default::default(),
} // }
} // }
} // }
pub struct BucketOptions {} pub struct BucketOptions {}
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct BucketInfo { pub struct BucketInfo {
pub name: String, pub name: String,
pub created: OffsetDateTime, pub created: Option<OffsetDateTime>,
} }
pub struct MultipartUploadResult { pub struct MultipartUploadResult {
@@ -390,7 +390,7 @@ pub struct MultipartUploadResult {
pub struct PartInfo { pub struct PartInfo {
pub part_num: usize, pub part_num: usize,
pub last_mod: OffsetDateTime, pub last_mod: Option<OffsetDateTime>,
pub size: usize, pub size: usize,
} }
@@ -415,7 +415,7 @@ pub struct ObjectInfo {
pub data_blocks: usize, pub data_blocks: usize,
pub version_id: Uuid, pub version_id: Uuid,
pub deleted: bool, pub deleted: bool,
pub mod_time: OffsetDateTime, pub mod_time: Option<OffsetDateTime>,
pub size: usize, pub size: usize,
pub parts: Vec<ObjectPartInfo>, pub parts: Vec<ObjectPartInfo>,
pub is_latest: bool, pub is_latest: bool,
+6 -11
View File
@@ -20,7 +20,6 @@ use s3s::S3;
use s3s::{S3Request, S3Response}; use s3s::{S3Request, S3Response};
use std::fmt::Debug; use std::fmt::Debug;
use std::str::FromStr; use std::str::FromStr;
use time::OffsetDateTime;
use transform_stream::AsyncTryStream; use transform_stream::AsyncTryStream;
use ecstore::error::Result; use ecstore::error::Result;
@@ -145,11 +144,7 @@ impl S3 for FS {
let range = HTTPRangeSpec::nil(); let range = HTTPRangeSpec::nil();
let h = HeaderMap::new(); let h = HeaderMap::new();
let opts = &ObjectOptions { let opts = &ObjectOptions::default();
max_parity: false,
mod_time: OffsetDateTime::UNIX_EPOCH,
part_number: 0,
};
let reader = try_!( let reader = try_!(
self.store self.store
@@ -160,12 +155,12 @@ impl S3 for FS {
let info = reader.object_info; let info = reader.object_info;
let content_type = try_!(ContentType::from_str("application/x-msdownload")); let content_type = try_!(ContentType::from_str("application/x-msdownload"));
let last_modified = Timestamp::from(info.mod_time); let last_modified = info.mod_time.map(|v| Timestamp::from(v));
let output = GetObjectOutput { let output = GetObjectOutput {
body: Some(reader.stream), body: Some(reader.stream),
content_length: Some(info.size as i64), content_length: Some(info.size as i64),
last_modified: Some(last_modified), last_modified: last_modified,
content_type: Some(content_type), content_type: Some(content_type),
..Default::default() ..Default::default()
}; };
@@ -199,12 +194,12 @@ impl S3 for FS {
debug!("info {:?}", info); debug!("info {:?}", info);
let content_type = try_!(ContentType::from_str("application/x-msdownload")); let content_type = try_!(ContentType::from_str("application/x-msdownload"));
let last_modified = Timestamp::from(info.mod_time); let last_modified = info.mod_time.map(|v| Timestamp::from(v));
let output = HeadObjectOutput { let output = HeadObjectOutput {
content_length: Some(try_!(i64::try_from(info.size))), content_length: Some(try_!(i64::try_from(info.size))),
content_type: Some(content_type), content_type: Some(content_type),
last_modified: Some(last_modified), last_modified: last_modified,
// metadata: object_metadata, // metadata: object_metadata,
..Default::default() ..Default::default()
}; };
@@ -220,7 +215,7 @@ impl S3 for FS {
let buckets: Vec<Bucket> = bucket_infos let buckets: Vec<Bucket> = bucket_infos
.iter() .iter()
.map(|v| Bucket { .map(|v| Bucket {
creation_date: Some(Timestamp::from(v.created)), creation_date: v.created.map(|v| Timestamp::from(v)),
name: Some(v.name.clone()), name: Some(v.name.clone()),
}) })
.collect(); .collect();