fix errors/delete_object

This commit is contained in:
weisd
2024-11-19 16:59:51 +08:00
parent 706fce49b9
commit 2ea2fd4308
4 changed files with 443 additions and 129 deletions
+121 -1
View File
@@ -1,9 +1,20 @@
use crate::{disk::error::is_err_file_not_found, error::Error};
use crate::{
disk::error::{is_err_file_not_found, DiskError},
error::Error,
utils::path::decode_dir_object,
};
#[derive(Debug, thiserror::Error, PartialEq, Eq)]
pub enum StorageError {
#[error("Invalid arguments provided for {0}/{1}-{2}")]
InvalidArgument(String, String, String),
#[error("Bucket not found: {0}")]
BucketNotFound(String),
#[error("Bucket not empty: {0}")]
BucketNotEmpty(String),
#[error("Bucket name invalid: {0}")]
BucketNameInvalid(String),
@@ -12,6 +23,13 @@ pub enum StorageError {
#[error("Bucket exists: {0}")]
BucketExists(String),
#[error("Storage reached its minimum free drive threshold.")]
StorageFull,
#[error("Please reduce your request rate")]
SlowDown,
#[error("Prefix access is denied:{0}/{1}")]
PrefixAccessDenied(String, String),
#[error("Invalid UploadID KeyCombination: {0}/{1}")]
InvalidUploadIDKeyCombination(String, String),
@@ -38,6 +56,108 @@ pub enum StorageError {
InvalidVersionID(String, String, String),
#[error("invalid data movement operation, source and destination pool are the same for : {0}/{1}-{2}")]
DataMovementOverwriteErr(String, String, String),
#[error("Object exists on :{0} as directory {1}")]
ObjectExistsAsDirectory(String, String),
#[error("Storage resources are insufficient for the read operation")]
InsufficientReadQuorum,
#[error("Storage resources are insufficient for the write operation")]
InsufficientWriteQuorum,
}
pub fn to_object_err(err: Error, params: Vec<&str>) -> Error {
if let Some(e) = err.downcast_ref::<DiskError>() {
match e {
DiskError::DiskFull => {
return Error::new(StorageError::StorageFull);
}
DiskError::FileNotFound => {
let bucket = params.get(0).cloned().unwrap_or_default().to_owned();
let object = params.get(1).cloned().map(|v| decode_dir_object(v)).unwrap_or_default();
return Error::new(StorageError::ObjectNotFound(bucket, object));
}
DiskError::FileVersionNotFound => {
let bucket = params.get(0).cloned().unwrap_or_default().to_owned();
let object = params.get(1).cloned().map(|v| decode_dir_object(v)).unwrap_or_default();
let version = params.get(2).cloned().unwrap_or_default().to_owned();
return Error::new(StorageError::VersionNotFound(bucket, object, version));
}
DiskError::TooManyOpenFiles => {
return Error::new(StorageError::SlowDown);
}
DiskError::FileNameTooLong => {
let bucket = params.get(0).cloned().unwrap_or_default().to_owned();
let object = params.get(1).cloned().map(|v| decode_dir_object(v)).unwrap_or_default();
return Error::new(StorageError::ObjectNameInvalid(bucket, object));
}
DiskError::VolumeExists => {
let bucket = params.get(0).cloned().unwrap_or_default().to_owned();
return Error::new(StorageError::BucketExists(bucket));
}
DiskError::IsNotRegular => {
let bucket = params.get(0).cloned().unwrap_or_default().to_owned();
let object = params.get(1).cloned().map(|v| decode_dir_object(v)).unwrap_or_default();
return Error::new(StorageError::ObjectExistsAsDirectory(bucket, object));
}
DiskError::VolumeNotFound => {
let bucket = params.get(0).cloned().unwrap_or_default().to_owned();
return Error::new(StorageError::BucketNotFound(bucket));
}
DiskError::VolumeNotEmpty => {
let bucket = params.get(0).cloned().unwrap_or_default().to_owned();
return Error::new(StorageError::BucketNotEmpty(bucket));
}
DiskError::FileAccessDenied => {
let bucket = params.get(0).cloned().unwrap_or_default().to_owned();
let object = params.get(1).cloned().map(|v| decode_dir_object(v)).unwrap_or_default();
return Error::new(StorageError::PrefixAccessDenied(bucket, object));
}
// DiskError::MaxVersionsExceeded => todo!(),
// DiskError::Unexpected => todo!(),
// DiskError::CorruptedFormat => todo!(),
// DiskError::CorruptedBackend => todo!(),
// DiskError::UnformattedDisk => todo!(),
// DiskError::InconsistentDisk => todo!(),
// DiskError::UnsupportedDisk => todo!(),
// DiskError::DiskNotDir => todo!(),
// DiskError::DiskNotFound => todo!(),
// DiskError::DiskOngoingReq => todo!(),
// DiskError::DriveIsRoot => todo!(),
// DiskError::FaultyRemoteDisk => todo!(),
// DiskError::FaultyDisk => todo!(),
// DiskError::DiskAccessDenied => todo!(),
// DiskError::FileCorrupt => todo!(),
// DiskError::BitrotHashAlgoInvalid => todo!(),
// DiskError::CrossDeviceLink => todo!(),
// DiskError::LessData => todo!(),
// DiskError::MoreData => todo!(),
// DiskError::OutdatedXLMeta => todo!(),
// DiskError::PartMissingOrCorrupt => todo!(),
// DiskError::PathNotFound => todo!(),
// DiskError::VolumeAccessDenied => todo!(),
_ => (),
}
}
err
}
pub fn is_err_read_quorum(err: &Error) -> bool {
if let Some(e) = err.downcast_ref::<StorageError>() {
matches!(e, StorageError::InsufficientReadQuorum)
} else {
false
}
}
pub fn is_err_invalid_upload_id(err: &Error) -> bool {