From 47182c054401e48efac75bc18971f025ca17ef40 Mon Sep 17 00:00:00 2001 From: weisd Date: Tue, 24 Sep 2024 16:21:02 +0800 Subject: [PATCH] fix: #23 need test reduce_read_quorum_errs --- ecstore/src/disk/local.rs | 20 ++++++++++---------- ecstore/src/disk/remote.rs | 10 +++++----- ecstore/src/quorum.rs | 9 +++------ ecstore/src/sets.rs | 4 ++-- ecstore/src/store.rs | 4 ++-- ecstore/src/store_api.rs | 14 ++++++++++++-- ecstore/src/utils/fs.rs | 4 ++-- 7 files changed, 36 insertions(+), 29 deletions(-) diff --git a/ecstore/src/disk/local.rs b/ecstore/src/disk/local.rs index 9cd6a70f..7bf5cb5e 100644 --- a/ecstore/src/disk/local.rs +++ b/ecstore/src/disk/local.rs @@ -113,9 +113,9 @@ impl LocalDisk { Ok(disk) } - fn check_path_length(path_name: &str) -> Result<()> { - unimplemented!() - } + // fn check_path_length(_path_name: &str) -> Result<()> { + // unimplemented!() + // } fn is_valid_volname(volname: &str) -> bool { if volname.len() < 3 { @@ -1000,10 +1000,10 @@ impl DiskAPI for LocalDisk { created: modtime, }) } - async fn delete_paths(&self, volume: &str, paths: &[&str]) -> Result<()> { + async fn delete_paths(&self, _volume: &str, _paths: &[&str]) -> Result<()> { unimplemented!() } - async fn update_metadata(&self, volume: &str, path: &str, fi: FileInfo, opts: UpdateMetadataOpts) { + async fn update_metadata(&self, _volume: &str, _path: &str, _fi: FileInfo, _opts: UpdateMetadataOpts) { unimplemented!() } async fn write_metadata(&self, _org_volume: &str, volume: &str, path: &str, fi: FileInfo) -> Result<()> { @@ -1062,11 +1062,11 @@ impl DiskAPI for LocalDisk { } async fn delete_version( &self, - volume: &str, - path: &str, - fi: FileInfo, - force_del_marker: bool, - opts: DeleteOptions, + _volume: &str, + _path: &str, + _fi: FileInfo, + _force_del_marker: bool, + _opts: DeleteOptions, ) -> Result { unimplemented!() } diff --git a/ecstore/src/disk/remote.rs b/ecstore/src/disk/remote.rs index 82723e1f..b3360f13 100644 --- a/ecstore/src/disk/remote.rs +++ b/ecstore/src/disk/remote.rs @@ -482,11 +482,11 @@ impl DiskAPI for RemoteDisk { } async fn delete_version( &self, - volume: &str, - path: &str, - fi: FileInfo, - force_del_marker: bool, - opts: DeleteOptions, + _volume: &str, + _path: &str, + _fi: FileInfo, + _force_del_marker: bool, + _opts: DeleteOptions, ) -> Result { unimplemented!() } diff --git a/ecstore/src/quorum.rs b/ecstore/src/quorum.rs index 72e33109..a3850077 100644 --- a/ecstore/src/quorum.rs +++ b/ecstore/src/quorum.rs @@ -1,7 +1,4 @@ -use crate::{ - disk::error::DiskError, - error::{Error, Result}, -}; +use crate::{disk::error::DiskError, error::Error}; use std::{collections::HashMap, fmt::Debug}; // pub type CheckErrorFn = fn(e: &Error) -> bool; @@ -11,7 +8,7 @@ pub trait CheckErrorFn: Debug + Send + Sync + 'static { } #[derive(Debug, thiserror::Error)] -enum QuorumError { +pub enum QuorumError { #[error("Read quorum not met")] Read, #[error("disk not found")] @@ -112,7 +109,7 @@ fn reduce_quorum_errs( // 根据读quorum验证错误数量 // 返回最大错误数量的下标,或QuorumError pub fn reduce_read_quorum_errs( - errs: &mut Vec>, + errs: &Vec>, ignored_errs: &Vec>, read_quorum: usize, ) -> Option { diff --git a/ecstore/src/sets.rs b/ecstore/src/sets.rs index 319a04c3..7853c5df 100644 --- a/ecstore/src/sets.rs +++ b/ecstore/src/sets.rs @@ -98,7 +98,7 @@ impl Sets { let set_disks = SetDisks { disks: RwLock::new(set_drive), set_drive_count, - parity_count: partiy_count, + default_parity_count: partiy_count, set_index: i, pool_index: pool_idx, set_endpoints, @@ -343,7 +343,7 @@ impl StorageAPI for Sets { .get_object_reader(bucket, object, range, h, opts) .await } - async fn put_object(&self, bucket: &str, object: &str, data: PutObjReader, opts: &ObjectOptions) -> Result<()> { + async fn put_object(&self, bucket: &str, object: &str, data: PutObjReader, opts: &ObjectOptions) -> Result { self.get_disks_by_key(object).put_object(bucket, object, data, opts).await } diff --git a/ecstore/src/store.rs b/ecstore/src/store.rs index c99c7ba3..caa21174 100644 --- a/ecstore/src/store.rs +++ b/ecstore/src/store.rs @@ -314,7 +314,7 @@ impl ECStore { if entry.is_object() { let fi = entry.to_fileinfo(&opts.bucket)?; if fi.is_some() { - ress.push(fi.unwrap().into_object_info(&opts.bucket, &entry.name, false)); + ress.push(fi.unwrap().to_object_info(&opts.bucket, &entry.name, false)); } continue; } @@ -738,7 +738,7 @@ impl StorageAPI for ECStore { unimplemented!() } - async fn put_object(&self, bucket: &str, object: &str, data: PutObjReader, opts: &ObjectOptions) -> Result<()> { + async fn put_object(&self, bucket: &str, object: &str, data: PutObjReader, opts: &ObjectOptions) -> Result { // checkPutObjectArgs let object = utils::path::encode_dir_object(object); diff --git a/ecstore/src/store_api.rs b/ecstore/src/store_api.rs index 49bc7dd2..12710705 100644 --- a/ecstore/src/store_api.rs +++ b/ecstore/src/store_api.rs @@ -29,6 +29,8 @@ pub struct FileInfo { pub is_latest: bool, #[serde(skip_serializing_if = "Option::is_none", default)] pub tags: Option>, + pub metadata: Option>, + pub num_versions: usize, } // impl Default for FileInfo { @@ -96,6 +98,14 @@ impl FileInfo { false } + pub fn get_etag(&self) -> Option { + if let Some(meta) = &self.metadata { + meta.get("etag").cloned() + } else { + None + } + } + pub fn write_quorum(&self, quorum: usize) -> usize { if self.deleted { return quorum; @@ -141,7 +151,7 @@ impl FileInfo { self.parts.sort_by(|a, b| a.number.cmp(&b.number)); } - pub fn into_object_info(&self, bucket: &str, object: &str, _versioned: bool) -> ObjectInfo { + pub fn to_object_info(&self, bucket: &str, object: &str, _versioned: bool) -> ObjectInfo { ObjectInfo { bucket: bucket.to_string(), name: object.to_string(), @@ -533,7 +543,7 @@ pub trait StorageAPI { h: HeaderMap, opts: &ObjectOptions, ) -> Result; - async fn put_object(&self, bucket: &str, object: &str, data: PutObjReader, opts: &ObjectOptions) -> Result<()>; + async fn put_object(&self, bucket: &str, object: &str, data: PutObjReader, opts: &ObjectOptions) -> Result; async fn put_object_part( &self, bucket: &str, diff --git a/ecstore/src/utils/fs.rs b/ecstore/src/utils/fs.rs index 1e1cae40..41c7e486 100644 --- a/ecstore/src/utils/fs.rs +++ b/ecstore/src/utils/fs.rs @@ -2,7 +2,7 @@ use std::{fs::Metadata, path::Path}; use tokio::{fs, io}; -#[cfg(not(target_os = "windows"))] +#[cfg(not(windows))] pub fn same_file(f1: &Metadata, f2: &Metadata) -> bool { use std::os::unix::fs::MetadataExt; @@ -28,7 +28,7 @@ pub fn same_file(f1: &Metadata, f2: &Metadata) -> bool { true } -#[cfg(target_os = "windows")] +#[cfg(windows)] pub fn same_file(f1: &Metadata, f2: &Metadata) -> bool { if f1.permissions() != f2.permissions() { return false;