diff --git a/Cargo.lock b/Cargo.lock index a7d6a71a5..0a9a73925 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1872,6 +1872,7 @@ checksum = "92773504d58c093f6de2459af4af33faa518c13451eb8f2b5698ed3d36e7c813" name = "e2e_test" version = "0.0.1" dependencies = [ + "common", "ecstore", "flatbuffers", "futures", @@ -2933,6 +2934,7 @@ dependencies = [ "arc-swap", "async-trait", "base64-simd", + "common", "crypto", "ecstore", "futures", diff --git a/common/common/src/error.rs b/common/common/src/error.rs index 24d2936b7..2c889053b 100644 --- a/common/common/src/error.rs +++ b/common/common/src/error.rs @@ -61,6 +61,11 @@ impl Error { pub fn downcast_mut(&mut self) -> Option<&mut T> { self.inner.downcast_mut() } + + pub fn to_io_err(&self) -> Option { + self.downcast_ref::() + .map(|e| std::io::Error::new(e.kind(), e.to_string())) + } } impl From for Error { diff --git a/e2e_test/Cargo.toml b/e2e_test/Cargo.toml index 0a8d98d5f..a519f647e 100644 --- a/e2e_test/Cargo.toml +++ b/e2e_test/Cargo.toml @@ -6,6 +6,7 @@ license.workspace = true repository.workspace = true rust-version.workspace = true + # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [lints] @@ -25,4 +26,5 @@ tonic = { version = "0.12.3", features = ["gzip"] } tokio = { workspace = true } tower.workspace = true url.workspace = true -madmin.workspace =true \ No newline at end of file +madmin.workspace =true +common.workspace = true \ No newline at end of file diff --git a/e2e_test/src/reliant/node_interact_test.rs b/e2e_test/src/reliant/node_interact_test.rs index 5bd66ce36..1752be3bb 100644 --- a/e2e_test/src/reliant/node_interact_test.rs +++ b/e2e_test/src/reliant/node_interact_test.rs @@ -125,7 +125,7 @@ async fn walk_dir() -> Result<(), Box> { println!("{}", resp.error_info.unwrap_or("".to_string())); } let entry = serde_json::from_str::(&resp.meta_cache_entry) - .map_err(|e| ecstore::error::Error::from_string(format!("Unexpected response: {:?}", response))) + .map_err(|e| common::error::Error::from_string(format!("Unexpected response: {:?}", response))) .unwrap(); out.write_obj(&entry).await.unwrap(); } diff --git a/ecstore/src/bitrot.rs b/ecstore/src/bitrot.rs index 849e54b9e..757401557 100644 --- a/ecstore/src/bitrot.rs +++ b/ecstore/src/bitrot.rs @@ -1,12 +1,12 @@ use crate::{ disk::{error::DiskError, Disk, DiskAPI}, erasure::{ReadAt, Writer}, - error::{Error, Result}, io::{FileReader, FileWriter}, store_api::BitrotAlgorithm, }; use blake2::Blake2b512; use blake2::Digest as _; +use common::error::{Error, Result}; use highway::{HighwayHash, HighwayHasher, Key}; use lazy_static::lazy_static; use sha2::{digest::core_api::BlockSizeUser, Digest, Sha256}; @@ -731,14 +731,10 @@ pub fn new_bitrot_filereader( mod test { use std::collections::HashMap; + use crate::{disk::error::DiskError, store_api::BitrotAlgorithm}; + use common::error::{Error, Result}; use hex_simd::decode_to_vec; - use crate::{ - disk::error::DiskError, - error::{Error, Result}, - store_api::BitrotAlgorithm, - }; - // use super::{bitrot_writer_sum, new_bitrot_reader}; #[test] diff --git a/ecstore/src/bucket/error.rs b/ecstore/src/bucket/error.rs index a6aa8232e..9d76e7a43 100644 --- a/ecstore/src/bucket/error.rs +++ b/ecstore/src/bucket/error.rs @@ -1,4 +1,4 @@ -use crate::error::Error; +use common::error::Error; #[derive(Debug, thiserror::Error, PartialEq, Eq)] pub enum BucketMetadataError { diff --git a/ecstore/src/bucket/metadata.rs b/ecstore/src/bucket/metadata.rs index fc97224ee..92019725f 100644 --- a/ecstore/src/bucket/metadata.rs +++ b/ecstore/src/bucket/metadata.rs @@ -16,9 +16,9 @@ use std::sync::Arc; use time::OffsetDateTime; use tracing::error; -use crate::config::common::{read_config, save_config}; -use crate::error::{Error, Result}; +use crate::config::com::{read_config, save_config}; use crate::{config, new_object_layer_fn}; +use common::error::{Error, Result}; use crate::disk::BUCKET_META_PREFIX; use crate::store::ECStore; diff --git a/ecstore/src/bucket/metadata_sys.rs b/ecstore/src/bucket/metadata_sys.rs index ef455bd9d..be43ed035 100644 --- a/ecstore/src/bucket/metadata_sys.rs +++ b/ecstore/src/bucket/metadata_sys.rs @@ -8,10 +8,10 @@ use crate::bucket::utils::is_meta_bucketname; use crate::config; use crate::config::error::ConfigError; use crate::disk::error::DiskError; -use crate::error::{Error, Result}; use crate::global::{is_dist_erasure, is_erasure, new_object_layer_fn, GLOBAL_Endpoints}; use crate::store::ECStore; use crate::utils::xml::deserialize; +use common::error::{Error, Result}; use futures::future::join_all; use s3s::dto::{ BucketLifecycleConfiguration, NotificationConfiguration, ObjectLockConfiguration, ReplicationConfiguration, diff --git a/ecstore/src/bucket/policy/bucket_policy.rs b/ecstore/src/bucket/policy/bucket_policy.rs index 2d4d183a5..fd3488b0d 100644 --- a/ecstore/src/bucket/policy/bucket_policy.rs +++ b/ecstore/src/bucket/policy/bucket_policy.rs @@ -1,4 +1,4 @@ -use crate::error::{Error, Result}; +use common::error::{Error, Result}; // use rmp_serde::Serializer as rmpSerializer; use serde::{Deserialize, Serialize}; use std::collections::HashMap; diff --git a/ecstore/src/bucket/policy/condition/key.rs b/ecstore/src/bucket/policy/condition/key.rs index b317d0a9a..faa51a189 100644 --- a/ecstore/src/bucket/policy/condition/key.rs +++ b/ecstore/src/bucket/policy/condition/key.rs @@ -1,5 +1,5 @@ use super::keyname::{KeyName, ALL_SUPPORT_KEYS}; -use crate::error::Error; +use common::error::Error; use serde::{Deserialize, Serialize}; use std::{collections::HashSet, fmt, str::FromStr}; diff --git a/ecstore/src/bucket/policy/condition/keyname.rs b/ecstore/src/bucket/policy/condition/keyname.rs index 1fc8d6602..b2fe2df91 100644 --- a/ecstore/src/bucket/policy/condition/keyname.rs +++ b/ecstore/src/bucket/policy/condition/keyname.rs @@ -3,7 +3,7 @@ use lazy_static::lazy_static; use serde::{Deserialize, Serialize}; use std::str::FromStr; -use crate::error::Error; +use common::error::Error; use super::key::Key; diff --git a/ecstore/src/bucket/policy/resource.rs b/ecstore/src/bucket/policy/resource.rs index b9c520f5e..03e15a497 100644 --- a/ecstore/src/bucket/policy/resource.rs +++ b/ecstore/src/bucket/policy/resource.rs @@ -1,8 +1,8 @@ -use crate::error::{Error, Result}; use crate::{ bucket::policy::condition::keyname::COMMOM_KEYS, utils::{self, wildcard}, }; +use common::error::{Error, Result}; use core::fmt; use serde::{Deserialize, Serialize}; use std::{ diff --git a/ecstore/src/bucket/policy_sys.rs b/ecstore/src/bucket/policy_sys.rs index b72cb333f..d14ebd30b 100644 --- a/ecstore/src/bucket/policy_sys.rs +++ b/ecstore/src/bucket/policy_sys.rs @@ -3,7 +3,7 @@ use super::{ metadata_sys::get_bucket_metadata_sys, policy::bucket_policy::{BucketPolicy, BucketPolicyArgs}, }; -use crate::error::Result; +use common::error::Result; use tracing::warn; pub struct PolicySys {} diff --git a/ecstore/src/bucket/quota/mod.rs b/ecstore/src/bucket/quota/mod.rs index a7753d85e..c3f38e84a 100644 --- a/ecstore/src/bucket/quota/mod.rs +++ b/ecstore/src/bucket/quota/mod.rs @@ -1,4 +1,4 @@ -use crate::error::Result; +use common::error::Result; use rmp_serde::Serializer as rmpSerializer; use serde::{Deserialize, Serialize}; diff --git a/ecstore/src/bucket/target/mod.rs b/ecstore/src/bucket/target/mod.rs index f830c5228..cb8797f2b 100644 --- a/ecstore/src/bucket/target/mod.rs +++ b/ecstore/src/bucket/target/mod.rs @@ -1,4 +1,4 @@ -use crate::error::Result; +use common::error::Result; use rmp_serde::Serializer as rmpSerializer; use serde::{Deserialize, Serialize}; use std::time::Duration; diff --git a/ecstore/src/bucket/utils.rs b/ecstore/src/bucket/utils.rs index 613f1b3ba..28ed670bd 100644 --- a/ecstore/src/bucket/utils.rs +++ b/ecstore/src/bucket/utils.rs @@ -1,4 +1,5 @@ -use crate::{disk::RUSTFS_META_BUCKET, error::Error}; +use crate::disk::RUSTFS_META_BUCKET; +use common::error::{Error, Result}; pub fn is_meta_bucketname(name: &str) -> bool { name.starts_with(RUSTFS_META_BUCKET) diff --git a/ecstore/src/bucket/versioning_sys.rs b/ecstore/src/bucket/versioning_sys.rs index c893b6fdb..64141f5fa 100644 --- a/ecstore/src/bucket/versioning_sys.rs +++ b/ecstore/src/bucket/versioning_sys.rs @@ -1,6 +1,6 @@ use super::{metadata_sys::get_bucket_metadata_sys, versioning::VersioningApi}; use crate::disk::RUSTFS_META_BUCKET; -use crate::error::Result; +use common::error::Result; use s3s::dto::VersioningConfiguration; use tracing::warn; diff --git a/ecstore/src/cache_value/cache.rs b/ecstore/src/cache_value/cache.rs index 96833dd96..9de88d1a9 100644 --- a/ecstore/src/cache_value/cache.rs +++ b/ecstore/src/cache_value/cache.rs @@ -14,7 +14,7 @@ use std::{ use tokio::{spawn, sync::Mutex}; -use crate::error::Result; +use common::error::Result; pub type UpdateFn = Box Pin> + Send>> + Send + Sync + 'static>; diff --git a/ecstore/src/cache_value/metacache_set.rs b/ecstore/src/cache_value/metacache_set.rs index 401561b6d..a0a6613c5 100644 --- a/ecstore/src/cache_value/metacache_set.rs +++ b/ecstore/src/cache_value/metacache_set.rs @@ -1,11 +1,9 @@ +use crate::disk::{DiskAPI, DiskStore, MetaCacheEntries, MetaCacheEntry, WalkDirOptions}; use crate::{ disk::error::{is_err_eof, is_err_file_not_found, is_err_volume_not_found, DiskError}, metacache::writer::MetacacheReader, }; -use crate::{ - disk::{DiskAPI, DiskStore, MetaCacheEntries, MetaCacheEntry, WalkDirOptions}, - error::{Error, Result}, -}; +use common::error::{Error, Result}; use futures::future::join_all; use std::{future::Future, pin::Pin, sync::Arc}; use tokio::{spawn, sync::broadcast::Receiver as B_Receiver}; @@ -140,7 +138,11 @@ pub async fn list_path_raw(mut rx: B_Receiver, opts: ListPathRawOptions) - } let revjob = spawn(async move { - let mut errs: Vec> = vec![None; readers.len()]; + let mut errs: Vec> = Vec::with_capacity(readers.len()); + for _ in 0..readers.len() { + errs.push(None); + } + loop { let mut current = MetaCacheEntry::default(); diff --git a/ecstore/src/config/common.rs b/ecstore/src/config/com.rs similarity index 99% rename from ecstore/src/config/common.rs rename to ecstore/src/config/com.rs index 837f577a8..d086f942d 100644 --- a/ecstore/src/config/common.rs +++ b/ecstore/src/config/com.rs @@ -1,10 +1,10 @@ use super::error::{is_err_config_not_found, ConfigError}; use super::{storageclass, Config, GLOBAL_StorageClass, KVS}; use crate::disk::RUSTFS_META_BUCKET; -use crate::error::{Error, Result}; use crate::store_api::{ObjectInfo, ObjectOptions, PutObjReader, StorageAPI}; use crate::store_err::is_err_object_not_found; use crate::utils::path::SLASH_SEPARATOR; +use common::error::{Error, Result}; use http::HeaderMap; use lazy_static::lazy_static; use std::collections::HashSet; diff --git a/ecstore/src/config/error.rs b/ecstore/src/config/error.rs index f734adb94..bc25d4bab 100644 --- a/ecstore/src/config/error.rs +++ b/ecstore/src/config/error.rs @@ -1,4 +1,5 @@ -use crate::{disk, error::Error, store_err::is_err_object_not_found}; +use crate::{disk, store_err::is_err_object_not_found}; +use common::error::Error; #[derive(Debug, PartialEq, thiserror::Error)] pub enum ConfigError { diff --git a/ecstore/src/config/heal.rs b/ecstore/src/config/heal.rs index 913997164..6fcaf73f7 100644 --- a/ecstore/src/config/heal.rs +++ b/ecstore/src/config/heal.rs @@ -1,9 +1,7 @@ use std::time::Duration; -use crate::{ - error::{Error, Result}, - utils::bool_flag::parse_bool, -}; +use crate::utils::bool_flag::parse_bool; +use common::error::{Error, Result}; #[derive(Debug, Default)] pub struct Config { diff --git a/ecstore/src/config/mod.rs b/ecstore/src/config/mod.rs index c4bae997a..ffe00477c 100644 --- a/ecstore/src/config/mod.rs +++ b/ecstore/src/config/mod.rs @@ -1,12 +1,12 @@ -pub mod common; +pub mod com; pub mod error; #[allow(dead_code)] pub mod heal; pub mod storageclass; -use crate::error::Result; use crate::store::ECStore; -use common::{lookup_configs, read_config_without_migrate, STORAGE_CLASS_SUB_SYS}; +use com::{lookup_configs, read_config_without_migrate, STORAGE_CLASS_SUB_SYS}; +use common::error::Result; use lazy_static::lazy_static; use serde::{Deserialize, Serialize}; use std::collections::HashMap; diff --git a/ecstore/src/config/storageclass.rs b/ecstore/src/config/storageclass.rs index 46bc0737b..3859fcb5e 100644 --- a/ecstore/src/config/storageclass.rs +++ b/ecstore/src/config/storageclass.rs @@ -1,9 +1,7 @@ use std::env; -use crate::{ - config::KV, - error::{Error, Result}, -}; +use crate::config::KV; +use common::error::{Error, Result}; use super::KVS; use lazy_static::lazy_static; diff --git a/ecstore/src/disk/endpoint.rs b/ecstore/src/disk/endpoint.rs index 6e1ac4423..d901969c2 100644 --- a/ecstore/src/disk/endpoint.rs +++ b/ecstore/src/disk/endpoint.rs @@ -1,5 +1,5 @@ -use crate::error::{Error, Result}; use crate::utils::net; +use common::error::{Error, Result}; use path_absolutize::Absolutize; use std::{fmt::Display, path::Path}; use url::{ParseError, Url}; diff --git a/ecstore/src/disk/error.rs b/ecstore/src/disk/error.rs index bdd99b84f..a0773b5e5 100644 --- a/ecstore/src/disk/error.rs +++ b/ecstore/src/disk/error.rs @@ -2,11 +2,9 @@ use std::io::{self, ErrorKind}; use tracing::error; +use crate::quorum::CheckErrorFn; use crate::utils::ERROR_TYPE_MASK; -use crate::{ - error::{Error, Result}, - quorum::CheckErrorFn, -}; +use common::error::{Error, Result}; // DiskError == StorageErr #[derive(Debug, thiserror::Error)] diff --git a/ecstore/src/disk/format.rs b/ecstore/src/disk/format.rs index 602ea629c..0a3be1b28 100644 --- a/ecstore/src/disk/format.rs +++ b/ecstore/src/disk/format.rs @@ -1,5 +1,5 @@ use super::{error::DiskError, DiskInfo}; -use crate::error::{Error, Result}; +use common::error::{Error, Result}; use serde::{Deserialize, Serialize}; use serde_json::Error as JsonError; use uuid::Uuid; diff --git a/ecstore/src/disk/local.rs b/ecstore/src/disk/local.rs index ee1a9a212..76b5f3ac3 100644 --- a/ecstore/src/disk/local.rs +++ b/ecstore/src/disk/local.rs @@ -18,7 +18,6 @@ use crate::disk::error::{ }; use crate::disk::os::{check_path_length, is_empty_dir}; use crate::disk::STORAGE_FORMAT_FILE; -use crate::error::{Error, Result}; use crate::file_meta::{get_file_info, read_xl_meta_no_data, FileInfoOpts}; use crate::global::{GLOBAL_IsErasureSD, GLOBAL_RootDiskThreshold}; use crate::heal::data_scanner::{has_active_rules, scan_data_folder, ScannerItem, ShouldSleepFn, SizeSummary}; @@ -47,6 +46,7 @@ use crate::{ utils, }; use common::defer; +use common::error::{Error, Result}; use path_absolutize::Absolutize; use std::collections::{HashMap, HashSet}; use std::fmt::Debug; diff --git a/ecstore/src/disk/mod.rs b/ecstore/src/disk/mod.rs index 380dc43a4..fd0fb89e0 100644 --- a/ecstore/src/disk/mod.rs +++ b/ecstore/src/disk/mod.rs @@ -16,7 +16,6 @@ pub const STORAGE_FORMAT_FILE_BACKUP: &str = "xl.meta.bkp"; use crate::{ bucket::{metadata_sys::get_versioning_config, versioning::VersioningApi}, - error::{Error, Result}, file_meta::{merge_file_meta_versions, FileMeta, FileMetaShallowVersion, VersionType}, heal::{ data_scanner::ShouldSleepFn, @@ -27,6 +26,7 @@ use crate::{ store_api::{FileInfo, ObjectInfo, RawFileInfo}, utils::path::SLASH_SEPARATOR, }; +use common::error::{Error, Result}; use endpoint::Endpoint; use error::DiskError; use local::LocalDisk; diff --git a/ecstore/src/disk/os.rs b/ecstore/src/disk/os.rs index bd77480de..ae88611a8 100644 --- a/ecstore/src/disk/os.rs +++ b/ecstore/src/disk/os.rs @@ -3,14 +3,13 @@ use std::{ path::{Component, Path}, }; -use tokio::fs; -use tracing::info; - use crate::{ disk::error::{is_sys_err_not_dir, is_sys_err_path_not_found, os_is_not_exist}, - error::{Error, Result}, utils::{self, os::same_disk}, }; +use common::error::{Error, Result}; +use tokio::fs; +use tracing::info; use super::error::{os_err_to_file_err, os_is_exist, DiskError}; diff --git a/ecstore/src/disk/remote.rs b/ecstore/src/disk/remote.rs index 7211e34f7..bac27b0d1 100644 --- a/ecstore/src/disk/remote.rs +++ b/ecstore/src/disk/remote.rs @@ -28,7 +28,6 @@ use super::{ }; use crate::{ disk::error::DiskError, - error::{Error, Result}, heal::{ data_scanner::ShouldSleepFn, data_usage_cache::{DataUsageCache, DataUsageEntry}, @@ -41,6 +40,7 @@ use crate::{ io::{FileReader, FileWriter, HttpFileReader, HttpFileWriter}, utils::proto_err_to_err, }; +use common::error::{Error, Result}; use protos::proto_gen::node_service::RenamePartRequst; #[derive(Debug)] diff --git a/ecstore/src/disks_layout.rs b/ecstore/src/disks_layout.rs index 62d78a910..75eab78ec 100644 --- a/ecstore/src/disks_layout.rs +++ b/ecstore/src/disks_layout.rs @@ -1,5 +1,5 @@ -use crate::error::{Error, Result}; use crate::utils::ellipses::*; +use common::error::{Error, Result}; use serde::Deserialize; use std::collections::HashSet; use std::env; diff --git a/ecstore/src/endpoints.rs b/ecstore/src/endpoints.rs index 8dbee9928..51a9c0b82 100644 --- a/ecstore/src/endpoints.rs +++ b/ecstore/src/endpoints.rs @@ -3,10 +3,10 @@ use tracing::warn; use crate::{ disk::endpoint::{Endpoint, EndpointType}, disks_layout::DisksLayout, - error::{Error, Result}, global::global_rustfs_port, utils::net::{self, XHost}, }; +use common::error::{Error, Result}; use std::{ collections::{hash_map::Entry, HashMap, HashSet}, net::IpAddr, diff --git a/ecstore/src/erasure.rs b/ecstore/src/erasure.rs index 83d1d9ae6..d4f4f1af7 100644 --- a/ecstore/src/erasure.rs +++ b/ecstore/src/erasure.rs @@ -1,6 +1,7 @@ use crate::bitrot::{BitrotReader, BitrotWriter}; -use crate::error::{Error, Result}; +use crate::error::clone_err; use crate::quorum::{object_op_ignored_errs, reduce_write_quorum_errs}; +use common::error::{Error, Result}; use futures::future::join_all; use reed_solomon_erasure::galois_8::ReedSolomon; use std::any::Any; @@ -487,7 +488,7 @@ impl Erasure { } } if !errs.is_empty() { - return Err(errs[0].clone()); + return Err(clone_err(&errs[0])); } Ok(()) diff --git a/ecstore/src/error.rs b/ecstore/src/error.rs index 3d32b495c..f3aea3374 100644 --- a/ecstore/src/error.rs +++ b/ecstore/src/error.rs @@ -1,106 +1,122 @@ use crate::disk::error::{clone_disk_err, DiskError}; +use common::error::Error; use std::io; -use tracing_error::{SpanTrace, SpanTraceStatus}; +// use tracing_error::{SpanTrace, SpanTraceStatus}; -pub type StdError = Box; +// pub type StdError = Box; -pub type Result = std::result::Result; +// pub type Result = std::result::Result; -#[derive(Debug)] -pub struct Error { - inner: Box, - span_trace: SpanTrace, -} +// #[derive(Debug)] +// pub struct Error { +// inner: Box, +// span_trace: SpanTrace, +// } -impl Error { - /// Create a new error from a `std::error::Error`. - #[must_use] - #[track_caller] - pub fn new(source: T) -> Self { - Self::from_std_error(source.into()) - } +// impl Error { +// /// Create a new error from a `std::error::Error`. +// #[must_use] +// #[track_caller] +// pub fn new(source: T) -> Self { +// Self::from_std_error(source.into()) +// } - /// Create a new error from a `std::error::Error`. - #[must_use] - #[track_caller] - pub fn from_std_error(inner: StdError) -> Self { - Self { - inner, - span_trace: SpanTrace::capture(), - } - } +// /// Create a new error from a `std::error::Error`. +// #[must_use] +// #[track_caller] +// pub fn from_std_error(inner: StdError) -> Self { +// Self { +// inner, +// span_trace: SpanTrace::capture(), +// } +// } - /// Create a new error from a string. - #[must_use] - #[track_caller] - pub fn from_string(s: impl Into) -> Self { - Self::msg(s) - } +// /// Create a new error from a string. +// #[must_use] +// #[track_caller] +// pub fn from_string(s: impl Into) -> Self { +// Self::msg(s) +// } - /// Create a new error from a string. - #[must_use] - #[track_caller] - pub fn msg(s: impl Into) -> Self { - Self::from_std_error(s.into().into()) - } +// /// Create a new error from a string. +// #[must_use] +// #[track_caller] +// pub fn msg(s: impl Into) -> Self { +// Self::from_std_error(s.into().into()) +// } - /// Returns `true` if the inner type is the same as `T`. - #[inline] - pub fn is(&self) -> bool { - self.inner.is::() - } +// /// Returns `true` if the inner type is the same as `T`. +// #[inline] +// pub fn is(&self) -> bool { +// self.inner.is::() +// } - /// Returns some reference to the inner value if it is of type `T`, or - /// `None` if it isn't. - #[inline] - pub fn downcast_ref(&self) -> Option<&T> { - self.inner.downcast_ref() - } +// /// Returns some reference to the inner value if it is of type `T`, or +// /// `None` if it isn't. +// #[inline] +// pub fn downcast_ref(&self) -> Option<&T> { +// self.inner.downcast_ref() +// } - /// Returns some mutable reference to the inner value if it is of type `T`, or - /// `None` if it isn't. - #[inline] - pub fn downcast_mut(&mut self) -> Option<&mut T> { - self.inner.downcast_mut() - } +// /// Returns some mutable reference to the inner value if it is of type `T`, or +// /// `None` if it isn't. +// #[inline] +// pub fn downcast_mut(&mut self) -> Option<&mut T> { +// self.inner.downcast_mut() +// } - pub fn to_io_err(&self) -> Option { - self.downcast_ref::() - .map(|e| io::Error::new(e.kind(), e.to_string())) - } -} +// pub fn to_io_err(&self) -> Option { +// self.downcast_ref::() +// .map(|e| io::Error::new(e.kind(), e.to_string())) +// } +// } -impl From for Error { - fn from(e: T) -> Self { - Self::new(e) - } -} +// impl From for Error { +// fn from(e: T) -> Self { +// Self::new(e) +// } +// } -impl std::fmt::Display for Error { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.inner)?; +// impl std::fmt::Display for Error { +// fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { +// write!(f, "{}", self.inner)?; - if self.span_trace.status() != SpanTraceStatus::EMPTY { - write!(f, "\nspan_trace:\n{}", self.span_trace)?; - } +// if self.span_trace.status() != SpanTraceStatus::EMPTY { +// write!(f, "\nspan_trace:\n{}", self.span_trace)?; +// } - Ok(()) - } -} +// Ok(()) +// } +// } -impl Clone for Error { - fn clone(&self) -> Self { - if let Some(e) = self.downcast_ref::() { - clone_disk_err(e) - } else if let Some(e) = self.downcast_ref::() { - if let Some(code) = e.raw_os_error() { - Error::new(io::Error::from_raw_os_error(code)) - } else { - Error::new(io::Error::new(e.kind(), e.to_string())) - } +// impl Clone for Error { +// fn clone(&self) -> Self { +// if let Some(e) = self.downcast_ref::() { +// clone_disk_err(e) +// } else if let Some(e) = self.downcast_ref::() { +// if let Some(code) = e.raw_os_error() { +// Error::new(io::Error::from_raw_os_error(code)) +// } else { +// Error::new(io::Error::new(e.kind(), e.to_string())) +// } +// } else { +// // TODO: 优化其他类型 +// Error::msg(self.to_string()) +// } +// } +// } + +pub fn clone_err(e: &Error) -> Error { + if let Some(e) = e.downcast_ref::() { + clone_disk_err(e) + } else if let Some(e) = e.downcast_ref::() { + if let Some(code) = e.raw_os_error() { + Error::new(io::Error::from_raw_os_error(code)) } else { - // TODO: 优化其他类型 - Error::msg(self.to_string()) + Error::new(io::Error::new(e.kind(), e.to_string())) } + } else { + //TODO: 优化其他类型 + Error::msg(e.to_string()) } } diff --git a/ecstore/src/file_meta.rs b/ecstore/src/file_meta.rs index bb33f8e69..c9558578e 100644 --- a/ecstore/src/file_meta.rs +++ b/ecstore/src/file_meta.rs @@ -1,4 +1,13 @@ +use crate::disk::FileInfoVersions; +use crate::file_meta_inline::InlineData; +use crate::store_api::RawFileInfo; +use crate::store_err::StorageError; +use crate::{ + disk::error::DiskError, + store_api::{ErasureInfo, FileInfo, ObjectPartInfo, ERASURE_ALGORITHM}, +}; use byteorder::ByteOrder; +use common::error::{Error, Result}; use rmp::Marker; use serde::{Deserialize, Serialize}; use std::cmp::Ordering; @@ -11,16 +20,6 @@ use tracing::{error, warn}; use uuid::Uuid; use xxhash_rust::xxh64; -use crate::disk::FileInfoVersions; -use crate::file_meta_inline::InlineData; -use crate::store_api::RawFileInfo; -use crate::store_err::StorageError; -use crate::{ - disk::error::DiskError, - error::{Error, Result}, - store_api::{ErasureInfo, FileInfo, ObjectPartInfo, ERASURE_ALGORITHM}, -}; - // XL header specifies the format pub static XL_FILE_HEADER: [u8; 4] = [b'X', b'L', b'2', b' ']; // pub static XL_FILE_VERSION_CURRENT: [u8; 4] = [0; 4]; diff --git a/ecstore/src/file_meta_inline.rs b/ecstore/src/file_meta_inline.rs index 005e18a9f..083d1b4ff 100644 --- a/ecstore/src/file_meta_inline.rs +++ b/ecstore/src/file_meta_inline.rs @@ -1,8 +1,7 @@ +use common::error::{Error, Result}; use serde::{Deserialize, Serialize}; -use uuid::Uuid; - -use crate::error::{Error, Result}; use std::io::{Cursor, Read}; +use uuid::Uuid; #[derive(Clone, Debug, Default, PartialEq, Serialize, Deserialize)] pub struct InlineData(Vec); diff --git a/ecstore/src/heal/background_heal_ops.rs b/ecstore/src/heal/background_heal_ops.rs index e096cf3eb..e0a05338e 100644 --- a/ecstore/src/heal/background_heal_ops.rs +++ b/ecstore/src/heal/background_heal_ops.rs @@ -23,7 +23,6 @@ use crate::heal::heal_ops::{HealSource, BG_HEALING_UUID}; use crate::{ config::RUSTFS_CONFIG_PREFIX, disk::{endpoint::Endpoint, error::DiskError, DiskAPI, DiskInfoOptions, BUCKET_META_PREFIX, RUSTFS_META_BUCKET}, - error::{Error, Result}, global::{GLOBAL_BackgroundHealRoutine, GLOBAL_BackgroundHealState, GLOBAL_LOCAL_DISK_MAP}, heal::{ data_usage::{DATA_USAGE_CACHE_NAME, DATA_USAGE_ROOT}, @@ -36,6 +35,7 @@ use crate::{ store_api::{BucketInfo, BucketOptions, StorageAPI}, utils::path::{path_join, SLASH_SEPARATOR}, }; +use common::error::{Error, Result}; pub static DEFAULT_MONITOR_NEW_DISK_INTERVAL: Duration = Duration::from_secs(10); diff --git a/ecstore/src/heal/data_scanner.rs b/ecstore/src/heal/data_scanner.rs index 66d796ceb..52ded12a2 100644 --- a/ecstore/src/heal/data_scanner.rs +++ b/ecstore/src/heal/data_scanner.rs @@ -12,22 +12,6 @@ use std::{ time::{Duration, SystemTime}, }; -use chrono::{DateTime, Utc}; -use lazy_static::lazy_static; -use rand::Rng; -use rmp_serde::{Deserializer, Serializer}; -use s3s::dto::{ReplicationConfiguration, ReplicationRuleStatus}; -use serde::{Deserialize, Serialize}; -use tokio::{ - sync::{ - broadcast, - mpsc::{self, Sender}, - RwLock, - }, - time::sleep, -}; -use tracing::{error, info}; - use super::{ data_scanner_metric::{globalScannerMetrics, ScannerMetric, ScannerMetrics}, data_usage::{store_data_usage_in_backend, DATA_USAGE_BLOOM_NAME_PATH}, @@ -38,11 +22,10 @@ use crate::heal::data_usage::DATA_USAGE_ROOT; use crate::{ cache_value::metacache_set::{list_path_raw, ListPathRawOptions}, config::{ - common::{read_config, save_config}, + com::{read_config, save_config}, heal::Config, }, disk::{error::DiskError, DiskInfoOptions, DiskStore, MetaCacheEntries, MetaCacheEntry, MetadataResolutionParams}, - error::{Error, Result}, global::{GLOBAL_BackgroundHealState, GLOBAL_IsErasure, GLOBAL_IsErasureSD}, heal::{ data_usage::BACKGROUND_HEAL_INFO_PATH, @@ -61,6 +44,22 @@ use crate::{ disk::DiskAPI, store_api::{FileInfo, ObjectInfo}, }; +use chrono::{DateTime, Utc}; +use common::error::{Error, Result}; +use lazy_static::lazy_static; +use rand::Rng; +use rmp_serde::{Deserializer, Serializer}; +use s3s::dto::{ReplicationConfiguration, ReplicationRuleStatus}; +use serde::{Deserialize, Serialize}; +use tokio::{ + sync::{ + broadcast, + mpsc::{self, Sender}, + RwLock, + }, + time::sleep, +}; +use tracing::{error, info}; const DATA_SCANNER_SLEEP_PER_FOLDER: Duration = Duration::from_millis(1); // Time to wait between folders. const DATA_USAGE_UPDATE_DIR_CYCLES: u32 = 16; // Visit all folders every n cycles. diff --git a/ecstore/src/heal/data_usage.rs b/ecstore/src/heal/data_usage.rs index ef569d6af..a5de85a31 100644 --- a/ecstore/src/heal/data_usage.rs +++ b/ecstore/src/heal/data_usage.rs @@ -1,22 +1,21 @@ -use lazy_static::lazy_static; -use serde::{Deserialize, Serialize}; -use std::{collections::HashMap, sync::Arc, time::SystemTime}; -use tokio::sync::mpsc::Receiver; -use tracing::{error, warn}; - use crate::{ bucket::metadata_sys::get_replication_config, config::{ - common::{read_config, save_config}, + com::{read_config, save_config}, error::is_err_config_not_found, }, disk::{BUCKET_META_PREFIX, RUSTFS_META_BUCKET}, - error::Result, new_object_layer_fn, store::ECStore, store_err::to_object_err, utils::path::SLASH_SEPARATOR, }; +use common::error::Result; +use lazy_static::lazy_static; +use serde::{Deserialize, Serialize}; +use std::{collections::HashMap, sync::Arc, time::SystemTime}; +use tokio::sync::mpsc::Receiver; +use tracing::{error, warn}; pub const DATA_USAGE_ROOT: &str = SLASH_SEPARATOR; const DATA_USAGE_OBJ_NAME: &str = ".usage.json"; diff --git a/ecstore/src/heal/data_usage_cache.rs b/ecstore/src/heal/data_usage_cache.rs index 6b3367903..7bc33df81 100644 --- a/ecstore/src/heal/data_usage_cache.rs +++ b/ecstore/src/heal/data_usage_cache.rs @@ -1,11 +1,11 @@ -use crate::config::common::save_config; +use crate::config::com::save_config; use crate::disk::error::DiskError; use crate::disk::{BUCKET_META_PREFIX, RUSTFS_META_BUCKET}; -use crate::error::{Error, Result}; use crate::new_object_layer_fn; use crate::set_disk::SetDisks; use crate::store_api::{BucketInfo, ObjectIO, ObjectOptions}; use bytesize::ByteSize; +use common::error::{Error, Result}; use http::HeaderMap; use path_clean::PathClean; use rand::Rng; diff --git a/ecstore/src/heal/heal_commands.rs b/ecstore/src/heal/heal_commands.rs index 3ff5610ef..6edd0e73a 100644 --- a/ecstore/src/heal/heal_commands.rs +++ b/ecstore/src/heal/heal_commands.rs @@ -4,22 +4,21 @@ use std::{ time::SystemTime, }; -use chrono::{DateTime, Utc}; -use lazy_static::lazy_static; -use serde::{Deserialize, Serialize}; -use time::OffsetDateTime; -use tokio::sync::RwLock; - use crate::{ config::storageclass::{RRS, STANDARD}, disk::{DeleteOptions, DiskAPI, DiskStore, BUCKET_META_PREFIX, RUSTFS_META_BUCKET}, - error::{Error, Result}, global::GLOBAL_BackgroundHealState, heal::heal_ops::HEALING_TRACKER_FILENAME, new_object_layer_fn, store_api::{BucketInfo, StorageAPI}, utils::fs::read_file, }; +use chrono::{DateTime, Utc}; +use common::error::{Error, Result}; +use lazy_static::lazy_static; +use serde::{Deserialize, Serialize}; +use time::OffsetDateTime; +use tokio::sync::RwLock; use super::{background_heal_ops::get_local_disks_to_heal, heal_ops::BG_HEALING_UUID}; diff --git a/ecstore/src/heal/heal_ops.rs b/ecstore/src/heal/heal_ops.rs index b7b694b41..d5c4544f3 100644 --- a/ecstore/src/heal/heal_ops.rs +++ b/ecstore/src/heal/heal_ops.rs @@ -6,7 +6,7 @@ use super::{ }; use crate::store_api::StorageAPI; use crate::{ - config::common::CONFIG_PREFIX, + config::com::CONFIG_PREFIX, disk::RUSTFS_META_BUCKET, global::GLOBAL_BackgroundHealRoutine, heal::{error::ERR_HEAL_STOP_SIGNALLED, heal_commands::DRIVE_STATE_OK}, @@ -14,7 +14,6 @@ use crate::{ use crate::{ disk::{endpoint::Endpoint, MetaCacheEntry}, endpoints::Endpoints, - error::{Error, Result}, global::GLOBAL_IsDistErasure, heal::heal_commands::{HealStartSuccess, HEAL_UNKNOWN_SCAN}, new_object_layer_fn, @@ -25,6 +24,7 @@ use crate::{ utils::path::path_join, }; use chrono::Utc; +use common::error::{Error, Result}; use futures::join; use lazy_static::lazy_static; use madmin::heal_commands::{HealDriveInfo, HealItemType, HealResultItem}; diff --git a/ecstore/src/metacache/writer.rs b/ecstore/src/metacache/writer.rs index bd1b576b0..e615fe3dd 100644 --- a/ecstore/src/metacache/writer.rs +++ b/ecstore/src/metacache/writer.rs @@ -1,6 +1,6 @@ use crate::disk::MetaCacheEntry; -use crate::error::Error; -use crate::error::Result; +use crate::error::clone_err; +use common::error::{Error, Result}; use rmp::Marker; use std::str::from_utf8; use tokio::io::AsyncRead; @@ -246,7 +246,7 @@ impl MetacacheReader { self.check_init().await?; if let Some(err) = &self.err { - return Err(err.clone()); + return Err(clone_err(err)); } let mut n = size; @@ -285,7 +285,7 @@ impl MetacacheReader { self.check_init().await?; if let Some(err) = &self.err { - return Err(err.clone()); + return Err(clone_err(err)); } match rmp::decode::read_bool(&mut self.read_more(1).await?) { diff --git a/ecstore/src/notification_sys.rs b/ecstore/src/notification_sys.rs index 37b234899..017e346c3 100644 --- a/ecstore/src/notification_sys.rs +++ b/ecstore/src/notification_sys.rs @@ -1,8 +1,8 @@ use crate::endpoints::EndpointServerPools; -use crate::error::{Error, Result}; use crate::global::get_global_endpoints; use crate::peer_rest_client::PeerRestClient; use crate::StorageAPI; +use common::error::{Error, Result}; use futures::future::join_all; use lazy_static::lazy_static; use madmin::{ItemState, ServerProperties}; diff --git a/ecstore/src/peer.rs b/ecstore/src/peer.rs index 13df3a7e0..ce153d042 100644 --- a/ecstore/src/peer.rs +++ b/ecstore/src/peer.rs @@ -1,18 +1,6 @@ -use async_trait::async_trait; -use futures::future::join_all; -use madmin::heal_commands::{HealDriveInfo, HealResultItem}; -use protos::node_service_time_out_client; -use protos::proto_gen::node_service::{ - DeleteBucketRequest, GetBucketInfoRequest, HealBucketRequest, ListBucketRequest, MakeBucketRequest, -}; -use regex::Regex; -use std::{collections::HashMap, fmt::Debug, sync::Arc}; -use tokio::sync::RwLock; -use tonic::Request; -use tracing::info; - use crate::disk::error::is_all_buckets_not_found; use crate::disk::{DiskAPI, DiskStore}; +use crate::error::clone_err; use crate::global::GLOBAL_LOCAL_DISK_MAP; use crate::heal::heal_commands::{ HealOpts, DRIVE_STATE_CORRUPT, DRIVE_STATE_MISSING, DRIVE_STATE_OFFLINE, DRIVE_STATE_OK, HEAL_ITEM_BUCKET, @@ -25,9 +13,21 @@ use crate::utils::wildcard::is_rustfs_meta_bucket_name; use crate::{ disk::{self, error::DiskError, VolumeInfo}, endpoints::{EndpointServerPools, Node}, - error::{Error, Result}, store_api::{BucketInfo, BucketOptions, DeleteBucketOptions, MakeBucketOptions}, }; +use async_trait::async_trait; +use common::error::{Error, Result}; +use futures::future::join_all; +use madmin::heal_commands::{HealDriveInfo, HealResultItem}; +use protos::node_service_time_out_client; +use protos::proto_gen::node_service::{ + DeleteBucketRequest, GetBucketInfoRequest, HealBucketRequest, ListBucketRequest, MakeBucketRequest, +}; +use regex::Regex; +use std::{collections::HashMap, fmt::Debug, sync::Arc}; +use tokio::sync::RwLock; +use tonic::Request; +use tracing::info; type Client = Arc>; @@ -95,7 +95,7 @@ impl S3PeerSys { for (i, client) in self.clients.iter().enumerate() { if let Some(v) = client.get_pools() { if v.contains(&pool_idx) { - per_pool_errs.push(errs[i].clone()); + per_pool_errs.push(errs[i].as_ref().map(|e| clone_err(e))); } } } @@ -130,7 +130,7 @@ impl S3PeerSys { for (i, client) in self.clients.iter().enumerate() { if let Some(v) = client.get_pools() { if v.contains(&pool_idx) { - per_pool_errs.push(errs[i].clone()); + per_pool_errs.push(errs[i].as_ref().map(|e| clone_err(e))); } } } @@ -781,7 +781,7 @@ pub async fn heal_bucket_local(bucket: &str, opts: &HealOpts) -> Result>(); futures.push(async move { if bs_clone.read().await[idx] == DRIVE_STATE_MISSING { info!("bucket not find, will recreate"); @@ -795,7 +795,7 @@ pub async fn heal_bucket_local(bucket: &str, opts: &HealOpts) -> Result bool; @@ -106,7 +107,7 @@ fn reduce_errs(errs: &[Option], ignored_errs: &[Box]) - if let Some(&c) = error_counts.get(&max_err) { if let Some(&err_idx) = error_map.get(&max_err) { - let err = errs[err_idx].clone(); + let err = errs[err_idx].as_ref().map(|e| clone_err(e)); return (c, err); } diff --git a/ecstore/src/set_disk.rs b/ecstore/src/set_disk.rs index c163bd36b..142accb98 100644 --- a/ecstore/src/set_disk.rs +++ b/ecstore/src/set_disk.rs @@ -1,12 +1,3 @@ -use std::{ - collections::{HashMap, HashSet}, - io::{Cursor, Write}, - mem::replace, - path::Path, - sync::Arc, - time::Duration, -}; - use crate::{ bitrot::{bitrot_verify, close_bitrot_writers, new_bitrot_filereader, new_bitrot_filewriter, BitrotFileWriter}, cache_value::metacache_set::{list_path_raw, ListPathRawOptions}, @@ -20,7 +11,7 @@ use crate::{ UpdateMetadataOpts, RUSTFS_META_BUCKET, RUSTFS_META_MULTIPART_BUCKET, RUSTFS_META_TMP_BUCKET, }, erasure::Erasure, - error::{Error, Result}, + error::clone_err, file_meta::{merge_file_meta_versions, FileMeta, FileMetaShallowVersion}, global::{ get_global_deployment_id, is_dist_erasure, GLOBAL_BackgroundHealState, GLOBAL_LOCAL_DISK_MAP, @@ -64,6 +55,7 @@ use crate::{ }; use bytesize::ByteSize; use chrono::Utc; +use common::error::{Error, Result}; use futures::future::join_all; use glob::Pattern; use http::HeaderMap; @@ -82,6 +74,14 @@ use rand::{ use sha2::{Digest, Sha256}; use std::hash::Hash; use std::time::SystemTime; +use std::{ + collections::{HashMap, HashSet}, + io::{Cursor, Write}, + mem::replace, + path::Path, + sync::Arc, + time::Duration, +}; use time::OffsetDateTime; use tokio::{ io::{empty, AsyncWrite}, @@ -320,7 +320,7 @@ impl SetDisks { } Err(e) => { // ress.push(None); - errs.push(Some(e.clone())); + errs.push(Some(clone_err(e))); } } } @@ -1242,7 +1242,7 @@ impl SetDisks { Err(err) => { for item in errs.iter_mut() { if item.is_none() { - *item = Some(err.clone()) + *item = Some(clone_err(&err)); } } @@ -2292,7 +2292,7 @@ impl SetDisks { "file({} : {}) part corrupt too much, can not to fix, disks_to_heal_count: {}, parity_blocks: {}", bucket, object, disks_to_heal_count, lastest_meta.erasure.parity_blocks ); - let mut t_errs = vec![None; errs.len()]; + // Allow for dangling deletes, on versions that have DataDir missing etc. // this would end up restoring the correct readable versions. match self @@ -2315,13 +2315,22 @@ impl SetDisks { } else { Error::new(DiskError::FileNotFound) }; + let mut t_errs = Vec::with_capacity(errs.len()); + for _ in 0..errs.len() { + t_errs.push(None); + } return Ok(( self.default_heal_result(m, &t_errs, bucket, object, version_id).await, Some(derr), )); } Err(err) => { - t_errs = vec![Some(err.clone()); errs.len()]; + // t_errs = vec![Some(err.clone()); errs.len()]; + let mut t_errs = Vec::with_capacity(errs.len()); + for _ in 0..errs.len() { + t_errs.push(Some(clone_err(&err))); + } + return Ok(( self.default_heal_result(FileInfo::default(), &t_errs, bucket, object, version_id) .await, @@ -3521,7 +3530,7 @@ impl SetDisks { } if let Some(err) = ret_err.as_ref() { - return Err(err.clone()); + return Err(clone_err(err)); } if !tracker.read().await.queue_buckets.is_empty() { return Err(Error::from_string(format!( @@ -4438,7 +4447,7 @@ impl StorageAPI for SetDisks { } }; - let mut upload_ids = Vec::new(); + let mut upload_ids: Vec = Vec::new(); for disk in disks.iter().flatten() { if !disk.is_online().await { @@ -5227,7 +5236,10 @@ async fn disks_with_all_parts( let erasure_distribution_reliable = inconsistent <= parts_metadata.len() / 2; - let mut meta_errs = vec![None; errs.len()]; + let mut meta_errs = Vec::with_capacity(errs.len()); + for _ in 0..errs.len() { + meta_errs.push(None); + } for (index, disk) in online_disks.iter().enumerate() { let disk = if let Some(disk) = disk { @@ -5237,8 +5249,8 @@ async fn disks_with_all_parts( continue; }; - if let Some(err) = errs[index].clone() { - meta_errs[index] = Some(err); + if let Some(err) = &errs[index] { + meta_errs[index] = Some(clone_err(err)); continue; } if !disk.is_online().await { @@ -5394,7 +5406,7 @@ pub fn should_heal_object_on_disk( match err { Some(err) => match err.downcast_ref::() { Some(DiskError::FileNotFound) | Some(DiskError::FileVersionNotFound) | Some(DiskError::FileCorrupt) => { - return (true, Some(err.clone())); + return (true, Some(clone_err(err))); } _ => {} }, @@ -5417,7 +5429,7 @@ pub fn should_heal_object_on_disk( } } } - (false, err.clone()) + (false, err.as_ref().map(|e| clone_err(e))) } async fn get_disks_info(disks: &[Option], eps: &[Endpoint]) -> Vec { diff --git a/ecstore/src/sets.rs b/ecstore/src/sets.rs index 149c0e62f..0a2e716fa 100644 --- a/ecstore/src/sets.rs +++ b/ecstore/src/sets.rs @@ -1,14 +1,6 @@ #![allow(clippy::map_entry)] use std::{collections::HashMap, sync::Arc}; -use common::globals::GLOBAL_Local_Node_Name; -use futures::future::join_all; -use http::HeaderMap; -use lock::{namespace_lock::NsLockMap, new_lock_api, LockApi}; -use madmin::heal_commands::{HealDriveInfo, HealResultItem}; -use tokio::sync::RwLock; -use uuid::Uuid; - use crate::{ disk::{ error::{is_unformatted_disk, DiskError}, @@ -16,7 +8,6 @@ use crate::{ new_disk, DiskAPI, DiskInfo, DiskOption, DiskStore, }, endpoints::{Endpoints, PoolEndpoints}, - error::{Error, Result}, global::{is_dist_erasure, GLOBAL_LOCAL_DISK_SET_DRIVES}, heal::heal_commands::{ HealOpts, DRIVE_STATE_CORRUPT, DRIVE_STATE_MISSING, DRIVE_STATE_OFFLINE, DRIVE_STATE_OK, HEAL_ITEM_METADATA, @@ -31,6 +22,14 @@ use crate::{ store_init::{check_format_erasure_values, get_format_erasure_in_quorum, load_format_erasure_all, save_format_file}, utils::{hash, path::path_join_buf}, }; +use common::error::{Error, Result}; +use common::globals::GLOBAL_Local_Node_Name; +use futures::future::join_all; +use http::HeaderMap; +use lock::{namespace_lock::NsLockMap, new_lock_api, LockApi}; +use madmin::heal_commands::{HealDriveInfo, HealResultItem}; +use tokio::sync::RwLock; +use uuid::Uuid; use crate::heal::heal_ops::HealSequence; use tokio::time::Duration; @@ -767,30 +766,50 @@ async fn init_storage_disks_with_errors( opts: &DiskOption, ) -> (Vec>, Vec>) { // Bootstrap disks. - let disks = Arc::new(RwLock::new(vec![None; endpoints.as_ref().len()])); - let errs = Arc::new(RwLock::new(vec![None; endpoints.as_ref().len()])); + // let disks = Arc::new(RwLock::new(vec![None; endpoints.as_ref().len()])); + // let errs = Arc::new(RwLock::new(vec![None; endpoints.as_ref().len()])); let mut futures = Vec::with_capacity(endpoints.as_ref().len()); - for (index, endpoint) in endpoints.as_ref().iter().enumerate() { - let ep = endpoint.clone(); - let opt = opts.clone(); - let disks_clone = disks.clone(); - let errs_clone = errs.clone(); - futures.push(tokio::spawn(async move { - match new_disk(&ep, &opt).await { - Ok(disk) => { - disks_clone.write().await[index] = Some(disk); - errs_clone.write().await[index] = None; - } - Err(err) => { - disks_clone.write().await[index] = None; - errs_clone.write().await[index] = Some(err); - } - } - })); + for endpoint in endpoints.as_ref().iter() { + futures.push(new_disk(endpoint, opts)); + + // let ep = endpoint.clone(); + // let opt = opts.clone(); + // let disks_clone = disks.clone(); + // let errs_clone = errs.clone(); + // futures.push(tokio::spawn(async move { + // match new_disk(&ep, &opt).await { + // Ok(disk) => { + // disks_clone.write().await[index] = Some(disk); + // errs_clone.write().await[index] = None; + // } + // Err(err) => { + // disks_clone.write().await[index] = None; + // errs_clone.write().await[index] = Some(err); + // } + // } + // })); } - let _ = join_all(futures).await; - let disks = disks.read().await.clone(); - let errs = errs.read().await.clone(); + // let _ = join_all(futures).await; + // let disks = disks.read().await.clone(); + // let errs = errs.read().await.clone(); + + let mut disks = Vec::with_capacity(endpoints.as_ref().len()); + let mut errs = Vec::with_capacity(endpoints.as_ref().len()); + + let results = join_all(futures).await; + for result in results { + match result { + Ok(disk) => { + disks.push(Some(disk)); + errs.push(None); + } + Err(err) => { + disks.push(None); + errs.push(Some(err)); + } + } + } + (disks, errs) } diff --git a/ecstore/src/store.rs b/ecstore/src/store.rs index 8a95edefc..4c86bd1c5 100644 --- a/ecstore/src/store.rs +++ b/ecstore/src/store.rs @@ -6,6 +6,7 @@ use crate::config::GLOBAL_StorageClass; use crate::config::{self, storageclass, GLOBAL_ConfigSys}; use crate::disk::endpoint::{Endpoint, EndpointType}; use crate::disk::{DiskAPI, DiskInfo, DiskInfoOptions, MetaCacheEntry}; +use crate::error::clone_err; use crate::global::{ is_dist_erasure, is_erasure_sd, set_global_deployment_id, set_object_layer, DISK_ASSUME_UNKNOWN_SIZE, DISK_FILL_FRACTION, DISK_MIN_INODES, DISK_RESERVE_FRACTION, GLOBAL_LOCAL_DISK_MAP, GLOBAL_LOCAL_DISK_SET_DRIVES, @@ -30,7 +31,6 @@ use crate::{ bucket::metadata::BucketMetadata, disk::{error::DiskError, new_disk, DiskOption, DiskStore, BUCKET_META_PREFIX, RUSTFS_META_BUCKET}, endpoints::EndpointServerPools, - error::{Error, Result}, peer::S3PeerSys, sets::Sets, store_api::{ @@ -40,6 +40,7 @@ use crate::{ }, store_init, utils, }; +use common::error::{Error, Result}; use common::globals::{GLOBAL_Local_Node_Name, GLOBAL_Rustfs_Host, GLOBAL_Rustfs_Port}; use futures::future::join_all; use glob::Pattern; @@ -664,7 +665,7 @@ impl ECStore { has_def_pool = true; if !is_err_object_not_found(err) && !is_err_version_not_found(err) { - return Err(err.clone()); + return Err(clone_err(&err)); } if pinfo.object_info.delete_marker && !pinfo.object_info.name.is_empty() { @@ -802,7 +803,7 @@ impl ECStore { } let _ = task.await; if let Some(err) = first_err.read().await.as_ref() { - return Err(err.clone()); + return Err(clone_err(&err)); } Ok(()) } @@ -932,8 +933,8 @@ impl ECStore { } } - if derrs[0].is_some() { - return Err(derrs[0].as_ref().unwrap().clone()); + if let Some(e) = &derrs[0] { + return Err(clone_err(e)); } Ok(objs[0].as_ref().unwrap().clone()) @@ -1056,13 +1057,23 @@ struct PoolErr { err: Option, } -#[derive(Debug, Default, Clone)] +#[derive(Debug, Default)] pub struct PoolObjInfo { pub index: usize, pub object_info: ObjectInfo, pub err: Option, } +impl Clone for PoolObjInfo { + fn clone(&self) -> Self { + Self { + index: self.index, + object_info: self.object_info.clone(), + err: self.err.as_ref().map(|e| clone_err(e)), + } + } +} + // #[derive(Debug, Default, Clone)] // pub struct ListPathOptions { // pub id: String, @@ -2037,45 +2048,59 @@ impl StorageAPI for ECStore { ) -> Result<(HealResultItem, Option)> { info!("ECStore heal_object"); let object = utils::path::encode_dir_object(object); - let errs = Arc::new(RwLock::new(vec![None; self.pools.len()])); - let results = Arc::new(RwLock::new(vec![HealResultItem::default(); self.pools.len()])); - let mut futures = Vec::with_capacity(self.pools.len()); - for (idx, pool) in self.pools.iter().enumerate() { - //TODO: IsSuspended - let object = object.clone(); - let results = results.clone(); - let errs = errs.clone(); - futures.push(async move { - match pool.heal_object(bucket, &object, version_id, opts).await { - Ok((mut result, err)) => { - result.object = utils::path::decode_dir_object(&result.object); - results.write().await.insert(idx, result); - errs.write().await[idx] = err; - } - Err(err) => { - errs.write().await[idx] = Some(err); - } - } - }); - } - let _ = join_all(futures).await; - // Return the first nil error - for (index, err) in errs.read().await.iter().enumerate() { + let mut futures = Vec::with_capacity(self.pools.len()); + for pool in self.pools.iter() { + //TODO: IsSuspended + futures.push(pool.heal_object(bucket, &object, version_id, opts)); + // futures.push(async move { + // match pool.heal_object(bucket, &object, version_id, opts).await { + // Ok((mut result, err)) => { + // result.object = utils::path::decode_dir_object(&result.object); + // results.write().await.insert(idx, result); + // errs.write().await[idx] = err; + // } + // Err(err) => { + // errs.write().await[idx] = Some(err); + // } + // } + // }); + } + let results = join_all(futures).await; + + let mut errs = Vec::with_capacity(self.pools.len()); + let mut ress = Vec::with_capacity(self.pools.len()); + + for res in results.into_iter() { + match res { + Ok((result, err)) => { + let mut result = result; + result.object = utils::path::decode_dir_object(&result.object); + ress.push(result); + errs.push(err); + } + Err(err) => { + errs.push(Some(err)); + ress.push(HealResultItem::default()); + } + } + } + + for (idx, err) in errs.iter().enumerate() { if err.is_none() { - return Ok((results.write().await.remove(index), None)); + return Ok((ress.remove(idx), None)); } } // No pool returned a nil error, return the first non 'not found' error - for (index, err) in errs.read().await.iter().enumerate() { + for (index, err) in errs.iter().enumerate() { match err { Some(err) => match err.downcast_ref::() { Some(DiskError::FileNotFound) | Some(DiskError::FileVersionNotFound) => {} - _ => return Ok((results.write().await.remove(index), Some(err.clone()))), + _ => return Ok((ress.remove(index), Some(clone_err(err)))), }, None => { - return Ok((results.write().await.remove(index), None)); + return Ok((ress.remove(index), None)); } } } @@ -2227,7 +2252,7 @@ impl StorageAPI for ECStore { } if !errs.is_empty() { - return Err(errs[0].clone()); + return Err(clone_err(&errs[0])); } Ok(()) diff --git a/ecstore/src/store_api.rs b/ecstore/src/store_api.rs index 69299616d..476fc2d69 100644 --- a/ecstore/src/store_api.rs +++ b/ecstore/src/store_api.rs @@ -1,13 +1,8 @@ use crate::heal::heal_ops::HealSequence; use crate::io::FileReader; use crate::store_utils::clean_metadata; -use crate::{ - disk::DiskStore, - error::{Error, Result}, - heal::heal_commands::HealOpts, - utils::path::decode_dir_object, - xhttp, -}; +use crate::{disk::DiskStore, heal::heal_commands::HealOpts, utils::path::decode_dir_object, xhttp}; +use common::error::{Error, Result}; use http::{HeaderMap, HeaderValue}; use madmin::heal_commands::HealResultItem; use rmp_serde::Serializer; diff --git a/ecstore/src/store_err.rs b/ecstore/src/store_err.rs index 74498c174..b6b3532eb 100644 --- a/ecstore/src/store_err.rs +++ b/ecstore/src/store_err.rs @@ -1,8 +1,8 @@ use crate::{ disk::error::{is_err_file_not_found, DiskError}, - error::Error, utils::path::decode_dir_object, }; +use common::error::Error; #[derive(Debug, thiserror::Error, PartialEq, Eq)] pub enum StorageError { diff --git a/ecstore/src/store_init.rs b/ecstore/src/store_init.rs index 00f93d111..2e44db00f 100644 --- a/ecstore/src/store_init.rs +++ b/ecstore/src/store_init.rs @@ -7,9 +7,9 @@ use crate::{ new_disk, DiskInfoOptions, DiskOption, DiskStore, FORMAT_CONFIG_FILE, RUSTFS_META_BUCKET, }, endpoints::Endpoints, - error::{Error, Result}, heal::heal_commands::init_healing_tracker, }; +use common::error::{Error, Result}; use futures::future::join_all; use std::{ collections::{hash_map::Entry, HashMap}, diff --git a/ecstore/src/store_list_objects.rs b/ecstore/src/store_list_objects.rs index 58b8a7408..4ebd42e4f 100644 --- a/ecstore/src/store_list_objects.rs +++ b/ecstore/src/store_list_objects.rs @@ -6,7 +6,7 @@ use crate::disk::{ DiskInfo, DiskStore, MetaCacheEntries, MetaCacheEntriesSorted, MetaCacheEntriesSortedResult, MetaCacheEntry, MetadataResolutionParams, }; -use crate::error::{Error, Result}; +use crate::error::clone_err; use crate::file_meta::merge_file_meta_versions; use crate::peer::is_reserved_or_invalid_bucket; use crate::set_disk::SetDisks; @@ -16,6 +16,7 @@ use crate::store_err::{is_err_bucket_not_found, to_object_err, StorageError}; use crate::utils::path::{self, base_dir_from_prefix, SLASH_SEPARATOR}; use crate::StorageAPI; use crate::{store::ECStore, store_api::ListObjectsV2Info}; +use common::error::{Error, Result}; use futures::future::join_all; use rand::seq::SliceRandom; use rand::thread_rng; @@ -508,7 +509,7 @@ impl ECStore { // cancel channel let (cancel_tx, cancel_rx) = broadcast::channel(1); - let (err_tx, mut err_rx) = broadcast::channel::(1); + let (err_tx, mut err_rx) = broadcast::channel::>(1); let (sender, recv) = mpsc::channel(o.limit as usize); @@ -521,7 +522,7 @@ impl ECStore { opts.stop_disk_at_limit = true; if let Err(err) = store.list_merged(cancel_rx1, opts, sender).await { error!("list_merged err {:?}", err); - let _ = err_tx1.send(err); + let _ = err_tx1.send(Arc::new(err)); } }); @@ -533,7 +534,7 @@ impl ECStore { let job2 = tokio::spawn(async move { if let Err(err) = gather_results(cancel_rx2, opts, recv, result_tx).await { error!("gather_results err {:?}", err); - let _ = err_tx2.send(err); + let _ = err_tx2.send(Arc::new(err)); } }); @@ -545,7 +546,7 @@ impl ECStore { match res{ Ok(o) => { error!("list_path err_rx.recv() ok {:?}", &o); - MetaCacheEntriesSortedResult{ entries: None, err: Some(o) } + MetaCacheEntriesSortedResult{ entries: None, err: Some(clone_err(o.as_ref())) } }, Err(err) => { error!("list_path err_rx.recv() err {:?}", &err); @@ -659,7 +660,7 @@ impl ECStore { continue; } - return Err(err.clone()); + return Err(clone_err(err)); } else { all_at_eof = false; continue; diff --git a/ecstore/src/utils/bool_flag.rs b/ecstore/src/utils/bool_flag.rs index 45f4a4b11..1a042af2d 100644 --- a/ecstore/src/utils/bool_flag.rs +++ b/ecstore/src/utils/bool_flag.rs @@ -1,4 +1,4 @@ -use crate::error::{Error, Result}; +use common::error::{Error, Result}; pub fn parse_bool(str: &str) -> Result { match str { diff --git a/ecstore/src/utils/ellipses.rs b/ecstore/src/utils/ellipses.rs index 07c33c1cf..f052236ae 100644 --- a/ecstore/src/utils/ellipses.rs +++ b/ecstore/src/utils/ellipses.rs @@ -1,4 +1,4 @@ -use crate::error::{Error, Result}; +use common::error::{Error, Result}; use lazy_static::*; use regex::Regex; diff --git a/ecstore/src/utils/mod.rs b/ecstore/src/utils/mod.rs index b45790abd..d5aa9c2fe 100644 --- a/ecstore/src/utils/mod.rs +++ b/ecstore/src/utils/mod.rs @@ -1,10 +1,10 @@ use crate::bucket::error::BucketMetadataError; use crate::config::error::ConfigError; use crate::disk::error::DiskError; -use crate::error::Error; use crate::quorum::QuorumError; use crate::store_err::StorageError; use crate::store_init::ErasureError; +use common::error::Error; use protos::proto_gen::node_service::Error as Proto_Error; pub mod bool_flag; diff --git a/ecstore/src/utils/net.rs b/ecstore/src/utils/net.rs index c2de72e19..e892dce37 100644 --- a/ecstore/src/utils/net.rs +++ b/ecstore/src/utils/net.rs @@ -1,4 +1,4 @@ -use crate::error::{Error, Result}; +use common::error::{Error, Result}; use lazy_static::lazy_static; use std::{ collections::HashSet, diff --git a/ecstore/src/utils/os/unix.rs b/ecstore/src/utils/os/unix.rs index bee857150..d710a7709 100644 --- a/ecstore/src/utils/os/unix.rs +++ b/ecstore/src/utils/os/unix.rs @@ -1,5 +1,6 @@ use super::IOStats; -use crate::{disk::Info, error::Result}; +use crate::disk::Info; +use common::error::Result; use nix::sys::{stat::stat, statfs::statfs}; use std::io::{Error, ErrorKind}; use std::path::Path; diff --git a/iam/Cargo.toml b/iam/Cargo.toml index 6c66d8f6e..fd4e85c47 100644 --- a/iam/Cargo.toml +++ b/iam/Cargo.toml @@ -31,6 +31,7 @@ tracing.workspace = true madmin.workspace = true lazy_static.workspace = true regex = "1.11.1" +common.workspace = true [dev-dependencies] test-case.workspace = true diff --git a/iam/src/arn.rs b/iam/src/arn.rs index c633fadc4..2337208ac 100644 --- a/iam/src/arn.rs +++ b/iam/src/arn.rs @@ -1,4 +1,4 @@ -use ecstore::error::{Error, Result}; +use common::error::{Error, Result}; use regex::Regex; const ARN_PREFIX_ARN: &str = "arn"; diff --git a/iam/src/auth/credentials.rs b/iam/src/auth/credentials.rs index 905c17713..2313b10d4 100644 --- a/iam/src/auth/credentials.rs +++ b/iam/src/auth/credentials.rs @@ -3,7 +3,7 @@ use crate::policy::Policy; use crate::sys::{iam_policy_claim_name_sa, Validator, INHERITED_POLICY_TYPE}; use crate::utils; use crate::utils::extract_claims; -use ecstore::error::{Error, Result}; +use common::error::{Error, Result}; use serde::de::DeserializeOwned; use serde::{Deserialize, Serialize}; use serde_json::{json, Value}; diff --git a/iam/src/error.rs b/iam/src/error.rs index 4c4ff0a64..f13b0da97 100644 --- a/iam/src/error.rs +++ b/iam/src/error.rs @@ -1,3 +1,6 @@ +use ecstore::disk::error::clone_disk_err; +use ecstore::disk::error::DiskError; + use crate::policy; #[derive(thiserror::Error, Debug)] @@ -6,7 +9,7 @@ pub enum Error { PolicyError(#[from] policy::Error), #[error("ecsotre error: {0}")] - EcstoreError(ecstore::error::Error), + EcstoreError(common::error::Error), #[error("{0}")] StringError(String), @@ -96,7 +99,7 @@ pub enum Error { // matches!(e, Error::NoSuchUser(_)) // } -pub fn is_err_no_such_policy(err: &ecstore::error::Error) -> bool { +pub fn is_err_no_such_policy(err: &common::error::Error) -> bool { if let Some(e) = err.downcast_ref::() { matches!(e, Error::NoSuchPolicy) } else { @@ -104,7 +107,7 @@ pub fn is_err_no_such_policy(err: &ecstore::error::Error) -> bool { } } -pub fn is_err_no_such_user(err: &ecstore::error::Error) -> bool { +pub fn is_err_no_such_user(err: &common::error::Error) -> bool { if let Some(e) = err.downcast_ref::() { matches!(e, Error::NoSuchUser(_)) } else { @@ -112,7 +115,7 @@ pub fn is_err_no_such_user(err: &ecstore::error::Error) -> bool { } } -pub fn is_err_no_such_account(err: &ecstore::error::Error) -> bool { +pub fn is_err_no_such_account(err: &common::error::Error) -> bool { if let Some(e) = err.downcast_ref::() { matches!(e, Error::NoSuchAccount(_)) } else { @@ -120,7 +123,7 @@ pub fn is_err_no_such_account(err: &ecstore::error::Error) -> bool { } } -pub fn is_err_no_such_temp_account(err: &ecstore::error::Error) -> bool { +pub fn is_err_no_such_temp_account(err: &common::error::Error) -> bool { if let Some(e) = err.downcast_ref::() { matches!(e, Error::NoSuchTempAccount(_)) } else { @@ -128,7 +131,7 @@ pub fn is_err_no_such_temp_account(err: &ecstore::error::Error) -> bool { } } -pub fn is_err_no_such_group(err: &ecstore::error::Error) -> bool { +pub fn is_err_no_such_group(err: &common::error::Error) -> bool { if let Some(e) = err.downcast_ref::() { matches!(e, Error::NoSuchGroup(_)) } else { @@ -136,10 +139,25 @@ pub fn is_err_no_such_group(err: &ecstore::error::Error) -> bool { } } -pub fn is_err_no_such_service_account(err: &ecstore::error::Error) -> bool { +pub fn is_err_no_such_service_account(err: &common::error::Error) -> bool { if let Some(e) = err.downcast_ref::() { matches!(e, Error::NoSuchServiceAccount(_)) } else { false } } + +pub fn clone_err(e: &common::error::Error) -> common::error::Error { + if let Some(e) = e.downcast_ref::() { + clone_disk_err(e) + } else if let Some(e) = e.downcast_ref::() { + if let Some(code) = e.raw_os_error() { + common::error::Error::new(std::io::Error::from_raw_os_error(code)) + } else { + common::error::Error::new(std::io::Error::new(e.kind(), e.to_string())) + } + } else { + //TODO: 优化其他类型 + common::error::Error::msg(e.to_string()) + } +} diff --git a/iam/src/lib.rs b/iam/src/lib.rs index 65484724c..f0844c227 100644 --- a/iam/src/lib.rs +++ b/iam/src/lib.rs @@ -1,5 +1,5 @@ use auth::Credentials; -use ecstore::error::{Error, Result}; +use common::error::{Error, Result}; use ecstore::store::ECStore; use error::Error as IamError; use log::debug; diff --git a/iam/src/manager.rs b/iam/src/manager.rs index d257b49ea..89cbec47f 100644 --- a/iam/src/manager.rs +++ b/iam/src/manager.rs @@ -12,11 +12,9 @@ use crate::{ MAX_SVCSESSION_POLICY_SIZE, SESSION_POLICY_NAME, SESSION_POLICY_NAME_EXTRACTED, STATUS_DISABLED, STATUS_ENABLED, }, }; +use common::error::{Error, Result}; +use ecstore::config::error::is_err_config_not_found; use ecstore::utils::{crypto::base64_encode, path::path_join_buf}; -use ecstore::{ - config::error::is_err_config_not_found, - error::{Error, Result}, -}; use log::{debug, warn}; use madmin::{AccountStatus, AddOrUpdateUserReq, GroupDesc}; use serde::{Deserialize, Serialize}; diff --git a/iam/src/policy/action.rs b/iam/src/policy/action.rs index 03204aae9..8061c8d42 100644 --- a/iam/src/policy/action.rs +++ b/iam/src/policy/action.rs @@ -1,4 +1,4 @@ -use ecstore::error::{Error, Result}; +use common::error::{Error, Result}; use serde::{Deserialize, Serialize}; use std::{collections::HashSet, ops::Deref}; use strum::{EnumString, IntoStaticStr}; diff --git a/iam/src/policy/effect.rs b/iam/src/policy/effect.rs index 67cc38c34..e815fa4ff 100644 --- a/iam/src/policy/effect.rs +++ b/iam/src/policy/effect.rs @@ -1,4 +1,4 @@ -use ecstore::error::{Error, Result}; +use common::error::{Error, Result}; use serde::{Deserialize, Serialize}; use strum::{EnumString, IntoStaticStr}; diff --git a/iam/src/policy/function/key.rs b/iam/src/policy/function/key.rs index 73e0ae182..1f674b972 100644 --- a/iam/src/policy/function/key.rs +++ b/iam/src/policy/function/key.rs @@ -1,6 +1,6 @@ use super::key_name::KeyName; use crate::{policy::Error as PolicyError, sys::Validator}; -use ecstore::error::Error; +use common::error::Error; use serde::{Deserialize, Serialize}; #[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)] diff --git a/iam/src/policy/id.rs b/iam/src/policy/id.rs index d31f0dfd8..19a589907 100644 --- a/iam/src/policy/id.rs +++ b/iam/src/policy/id.rs @@ -1,4 +1,4 @@ -use ecstore::error::{Error, Result}; +use common::error::{Error, Result}; use serde::{Deserialize, Serialize}; use std::ops::Deref; diff --git a/iam/src/policy/policy.rs b/iam/src/policy/policy.rs index bec599838..19f329480 100644 --- a/iam/src/policy/policy.rs +++ b/iam/src/policy/policy.rs @@ -1,6 +1,6 @@ use super::{Effect, Error as IamError, Statement, ID}; use crate::sys::{Args, Validator, DEFAULT_VERSION}; -use ecstore::error::{Error, Result}; +use common::error::{Error, Result}; use serde::{Deserialize, Serialize}; use std::collections::HashSet; @@ -323,7 +323,7 @@ pub mod default { #[cfg(test)] mod test { use super::*; - use ecstore::error::Result; + use common::error::{Error, Result}; #[tokio::test] async fn test_parse_policy() -> Result<()> { diff --git a/iam/src/policy/resource.rs b/iam/src/policy/resource.rs index 9c33e8d5e..6ea279e29 100644 --- a/iam/src/policy/resource.rs +++ b/iam/src/policy/resource.rs @@ -1,4 +1,4 @@ -use ecstore::error::{Error, Result}; +use common::error::{Error, Result}; use serde::{Deserialize, Serialize}; use std::{ collections::{HashMap, HashSet}, diff --git a/iam/src/policy/statement.rs b/iam/src/policy/statement.rs index 142d19fd4..fcd9b8a17 100644 --- a/iam/src/policy/statement.rs +++ b/iam/src/policy/statement.rs @@ -1,7 +1,7 @@ use crate::sys::{Args, Validator}; use super::{action::Action, ActionSet, Effect, Error as IamError, Functions, ResourceSet, ID}; -use ecstore::error::{Error, Result}; +use common::error::{Error, Result}; use serde::{Deserialize, Serialize}; #[derive(Serialize, Deserialize, Clone, Default, Debug)] diff --git a/iam/src/store.rs b/iam/src/store.rs index 946a88023..d993a2fb7 100644 --- a/iam/src/store.rs +++ b/iam/src/store.rs @@ -1,7 +1,7 @@ pub mod object; use crate::{auth::UserIdentity, cache::Cache, policy::PolicyDoc}; -use ecstore::error::Result; +use common::error::Result; use serde::{de::DeserializeOwned, Deserialize, Serialize}; use std::collections::{HashMap, HashSet}; use time::OffsetDateTime; diff --git a/iam/src/store/object.rs b/iam/src/store/object.rs index 40c9e97a4..d4469abdd 100644 --- a/iam/src/store/object.rs +++ b/iam/src/store/object.rs @@ -7,13 +7,13 @@ use crate::{ manager::{extract_jwt_claims, get_default_policyes}, policy::PolicyDoc, }; +use common::error::{Error, Result}; use ecstore::{ config::{ - common::{delete_config, read_config, read_config_with_metadata, save_config}, + com::{delete_config, read_config, read_config_with_metadata, save_config}, error::is_err_config_not_found, RUSTFS_CONFIG_PREFIX, }, - error::{Error, Result}, store::ECStore, store_api::{ObjectInfo, ObjectOptions}, store_list_objects::{ObjectInfoOrErr, WalkOptions}, diff --git a/iam/src/sys.rs b/iam/src/sys.rs index c22a9d56f..8d83141a0 100644 --- a/iam/src/sys.rs +++ b/iam/src/sys.rs @@ -24,7 +24,7 @@ use crate::policy::PolicyDoc; use crate::store::MappedPolicy; use crate::store::Store; use crate::store::UserType; -use ecstore::error::{Error, Result}; +use common::error::{Error, Result}; use ecstore::utils::crypto::base64_decode; use ecstore::utils::crypto::base64_encode; use madmin::AddOrUpdateUserReq; diff --git a/iam/src/utils.rs b/iam/src/utils.rs index 2d301bb9a..80447d8a2 100644 --- a/iam/src/utils.rs +++ b/iam/src/utils.rs @@ -1,4 +1,4 @@ -use ecstore::error::{Error, Result}; +use common::error::{Error, Result}; use jsonwebtoken::{Algorithm, DecodingKey, EncodingKey, Header}; use rand::{Rng, RngCore}; use serde::{de::DeserializeOwned, Serialize}; diff --git a/rustfs/src/admin/handlers.rs b/rustfs/src/admin/handlers.rs index 88a551f75..e5de35749 100644 --- a/rustfs/src/admin/handlers.rs +++ b/rustfs/src/admin/handlers.rs @@ -1,12 +1,12 @@ use super::router::Operation; use crate::storage::error::to_s3_error; use bytes::Bytes; +use common::error::Error as ec_Error; use ecstore::admin_server_info::get_server_info; use ecstore::bucket::policy::action::{Action, ActionSet}; use ecstore::bucket::policy::bucket_policy::{BPStatement, BucketPolicy}; use ecstore::bucket::policy::effect::Effect; use ecstore::bucket::policy::resource::{Resource, ResourceSet}; -use ecstore::error::Error as ec_Error; use ecstore::global::GLOBAL_ALlHealState; use ecstore::heal::data_usage::load_data_usage_from_backend; use ecstore::heal::heal_commands::HealOpts; diff --git a/rustfs/src/grpc.rs b/rustfs/src/grpc.rs index 7c944ee16..5c8e1012f 100644 --- a/rustfs/src/grpc.rs +++ b/rustfs/src/grpc.rs @@ -1,12 +1,12 @@ use std::{collections::HashMap, io::Cursor, pin::Pin}; +use common::error::Error as EcsError; use ecstore::{ admin_server_info::get_local_server_property, bucket::{metadata::load_bucket_metadata, metadata_sys}, disk::{ DeleteOptions, DiskAPI, DiskInfoOptions, DiskStore, FileInfoVersions, ReadMultipleReq, ReadOptions, UpdateMetadataOpts, }, - error::Error as EcsError, heal::{ data_usage_cache::DataUsageCache, heal_commands::{get_local_background_heal_status, HealOpts}, diff --git a/rustfs/src/storage/error.rs b/rustfs/src/storage/error.rs index 459a1b292..c902390e3 100644 --- a/rustfs/src/storage/error.rs +++ b/rustfs/src/storage/error.rs @@ -1,6 +1,6 @@ -use ecstore::{disk::error::is_err_file_not_found, error::Error, store_err::StorageError}; +use common::error::Error; +use ecstore::{disk::error::is_err_file_not_found, store_err::StorageError}; use s3s::{s3_error, S3Error, S3ErrorCode}; - pub fn to_s3_error(err: Error) -> S3Error { if let Some(storage_err) = err.downcast_ref::() { return match storage_err { diff --git a/rustfs/src/storage/options.rs b/rustfs/src/storage/options.rs index 847d67791..18a13974a 100644 --- a/rustfs/src/storage/options.rs +++ b/rustfs/src/storage/options.rs @@ -1,5 +1,5 @@ +use common::error::{Error, Result}; use ecstore::bucket::versioning_sys::BucketVersioningSys; -use ecstore::error::{Error, Result}; use ecstore::store_api::ObjectOptions; use ecstore::store_err::StorageError; use ecstore::utils::path::is_dir_object;