Merge pull request #169 from rustfs/refactor-err

Refactor err
This commit is contained in:
junxiangMu
2024-12-19 17:21:21 +08:00
committed by GitHub
14 changed files with 1016 additions and 283 deletions
@@ -1,6 +1,13 @@
// This file is @generated by prost-build. // This file is @generated by prost-build.
/// -------------------------------------------------------------------- /// --------------------------------------------------------------------
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct Error {
#[prost(uint32, tag = "1")]
pub code: u32,
#[prost(string, tag = "2")]
pub error_info: ::prost::alloc::string::String,
}
#[derive(Clone, PartialEq, ::prost::Message)]
pub struct PingRequest { pub struct PingRequest {
#[prost(uint64, tag = "1")] #[prost(uint64, tag = "1")]
pub version: u64, pub version: u64,
@@ -25,8 +32,8 @@ pub struct HealBucketRequest {
pub struct HealBucketResponse { pub struct HealBucketResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
#[prost(string, optional, tag = "2")] #[prost(message, optional, tag = "2")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct ListBucketRequest { pub struct ListBucketRequest {
@@ -39,8 +46,8 @@ pub struct ListBucketResponse {
pub success: bool, pub success: bool,
#[prost(string, repeated, tag = "2")] #[prost(string, repeated, tag = "2")]
pub bucket_infos: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, pub bucket_infos: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
#[prost(string, optional, tag = "3")] #[prost(message, optional, tag = "3")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct MakeBucketRequest { pub struct MakeBucketRequest {
@@ -53,8 +60,8 @@ pub struct MakeBucketRequest {
pub struct MakeBucketResponse { pub struct MakeBucketResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
#[prost(string, optional, tag = "2")] #[prost(message, optional, tag = "2")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct GetBucketInfoRequest { pub struct GetBucketInfoRequest {
@@ -69,8 +76,8 @@ pub struct GetBucketInfoResponse {
pub success: bool, pub success: bool,
#[prost(string, tag = "2")] #[prost(string, tag = "2")]
pub bucket_info: ::prost::alloc::string::String, pub bucket_info: ::prost::alloc::string::String,
#[prost(string, optional, tag = "3")] #[prost(message, optional, tag = "3")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct DeleteBucketRequest { pub struct DeleteBucketRequest {
@@ -81,8 +88,8 @@ pub struct DeleteBucketRequest {
pub struct DeleteBucketResponse { pub struct DeleteBucketResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
#[prost(string, optional, tag = "2")] #[prost(message, optional, tag = "2")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct ReadAllRequest { pub struct ReadAllRequest {
@@ -100,8 +107,8 @@ pub struct ReadAllResponse {
pub success: bool, pub success: bool,
#[prost(bytes = "vec", tag = "2")] #[prost(bytes = "vec", tag = "2")]
pub data: ::prost::alloc::vec::Vec<u8>, pub data: ::prost::alloc::vec::Vec<u8>,
#[prost(string, optional, tag = "3")] #[prost(message, optional, tag = "3")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct WriteAllRequest { pub struct WriteAllRequest {
@@ -119,8 +126,8 @@ pub struct WriteAllRequest {
pub struct WriteAllResponse { pub struct WriteAllResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
#[prost(string, optional, tag = "2")] #[prost(message, optional, tag = "2")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct DeleteRequest { pub struct DeleteRequest {
@@ -138,8 +145,8 @@ pub struct DeleteRequest {
pub struct DeleteResponse { pub struct DeleteResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
#[prost(string, optional, tag = "2")] #[prost(message, optional, tag = "2")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct VerifyFileRequest { pub struct VerifyFileRequest {
@@ -159,8 +166,8 @@ pub struct VerifyFileResponse {
pub success: bool, pub success: bool,
#[prost(string, tag = "2")] #[prost(string, tag = "2")]
pub check_parts_resp: ::prost::alloc::string::String, pub check_parts_resp: ::prost::alloc::string::String,
#[prost(string, optional, tag = "3")] #[prost(message, optional, tag = "3")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct CheckPartsRequest { pub struct CheckPartsRequest {
@@ -180,8 +187,8 @@ pub struct CheckPartsResponse {
pub success: bool, pub success: bool,
#[prost(string, tag = "2")] #[prost(string, tag = "2")]
pub check_parts_resp: ::prost::alloc::string::String, pub check_parts_resp: ::prost::alloc::string::String,
#[prost(string, optional, tag = "3")] #[prost(message, optional, tag = "3")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct RenamePartRequst { pub struct RenamePartRequst {
@@ -202,8 +209,8 @@ pub struct RenamePartRequst {
pub struct RenamePartResponse { pub struct RenamePartResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
#[prost(string, optional, tag = "2")] #[prost(message, optional, tag = "2")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct RenameFileRequst { pub struct RenameFileRequst {
@@ -222,8 +229,8 @@ pub struct RenameFileRequst {
pub struct RenameFileResponse { pub struct RenameFileResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
#[prost(string, optional, tag = "2")] #[prost(message, optional, tag = "2")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct WriteRequest { pub struct WriteRequest {
@@ -243,8 +250,8 @@ pub struct WriteRequest {
pub struct WriteResponse { pub struct WriteResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
#[prost(string, optional, tag = "2")] #[prost(message, optional, tag = "2")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct ReadAtRequest { pub struct ReadAtRequest {
@@ -268,8 +275,8 @@ pub struct ReadAtResponse {
pub data: ::prost::alloc::vec::Vec<u8>, pub data: ::prost::alloc::vec::Vec<u8>,
#[prost(int64, tag = "3")] #[prost(int64, tag = "3")]
pub read_size: i64, pub read_size: i64,
#[prost(string, optional, tag = "4")] #[prost(message, optional, tag = "4")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct ListDirRequest { pub struct ListDirRequest {
@@ -285,8 +292,8 @@ pub struct ListDirResponse {
pub success: bool, pub success: bool,
#[prost(string, repeated, tag = "2")] #[prost(string, repeated, tag = "2")]
pub volumes: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, pub volumes: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
#[prost(string, optional, tag = "3")] #[prost(message, optional, tag = "3")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct WalkDirRequest { pub struct WalkDirRequest {
@@ -302,8 +309,8 @@ pub struct WalkDirResponse {
pub success: bool, pub success: bool,
#[prost(string, repeated, tag = "2")] #[prost(string, repeated, tag = "2")]
pub meta_cache_entry: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, pub meta_cache_entry: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
#[prost(string, optional, tag = "3")] #[prost(message, optional, tag = "3")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct RenameDataRequest { pub struct RenameDataRequest {
@@ -327,8 +334,8 @@ pub struct RenameDataResponse {
pub success: bool, pub success: bool,
#[prost(string, tag = "2")] #[prost(string, tag = "2")]
pub rename_data_resp: ::prost::alloc::string::String, pub rename_data_resp: ::prost::alloc::string::String,
#[prost(string, optional, tag = "3")] #[prost(message, optional, tag = "3")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct MakeVolumesRequest { pub struct MakeVolumesRequest {
@@ -342,8 +349,8 @@ pub struct MakeVolumesRequest {
pub struct MakeVolumesResponse { pub struct MakeVolumesResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
#[prost(string, optional, tag = "2")] #[prost(message, optional, tag = "2")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct MakeVolumeRequest { pub struct MakeVolumeRequest {
@@ -357,8 +364,8 @@ pub struct MakeVolumeRequest {
pub struct MakeVolumeResponse { pub struct MakeVolumeResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
#[prost(string, optional, tag = "2")] #[prost(message, optional, tag = "2")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct ListVolumesRequest { pub struct ListVolumesRequest {
@@ -372,8 +379,8 @@ pub struct ListVolumesResponse {
pub success: bool, pub success: bool,
#[prost(string, repeated, tag = "2")] #[prost(string, repeated, tag = "2")]
pub volume_infos: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, pub volume_infos: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
#[prost(string, optional, tag = "3")] #[prost(message, optional, tag = "3")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct StatVolumeRequest { pub struct StatVolumeRequest {
@@ -389,8 +396,8 @@ pub struct StatVolumeResponse {
pub success: bool, pub success: bool,
#[prost(string, tag = "2")] #[prost(string, tag = "2")]
pub volume_info: ::prost::alloc::string::String, pub volume_info: ::prost::alloc::string::String,
#[prost(string, optional, tag = "3")] #[prost(message, optional, tag = "3")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct DeletePathsRequest { pub struct DeletePathsRequest {
@@ -405,8 +412,8 @@ pub struct DeletePathsRequest {
pub struct DeletePathsResponse { pub struct DeletePathsResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
#[prost(string, optional, tag = "2")] #[prost(message, optional, tag = "2")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct UpdateMetadataRequest { pub struct UpdateMetadataRequest {
@@ -425,8 +432,8 @@ pub struct UpdateMetadataRequest {
pub struct UpdateMetadataResponse { pub struct UpdateMetadataResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
#[prost(string, optional, tag = "2")] #[prost(message, optional, tag = "2")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct WriteMetadataRequest { pub struct WriteMetadataRequest {
@@ -444,8 +451,8 @@ pub struct WriteMetadataRequest {
pub struct WriteMetadataResponse { pub struct WriteMetadataResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
#[prost(string, optional, tag = "2")] #[prost(message, optional, tag = "2")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct ReadVersionRequest { pub struct ReadVersionRequest {
@@ -466,8 +473,8 @@ pub struct ReadVersionResponse {
pub success: bool, pub success: bool,
#[prost(string, tag = "2")] #[prost(string, tag = "2")]
pub file_info: ::prost::alloc::string::String, pub file_info: ::prost::alloc::string::String,
#[prost(string, optional, tag = "3")] #[prost(message, optional, tag = "3")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct ReadXlRequest { pub struct ReadXlRequest {
@@ -486,8 +493,8 @@ pub struct ReadXlResponse {
pub success: bool, pub success: bool,
#[prost(string, tag = "2")] #[prost(string, tag = "2")]
pub raw_file_info: ::prost::alloc::string::String, pub raw_file_info: ::prost::alloc::string::String,
#[prost(string, optional, tag = "3")] #[prost(message, optional, tag = "3")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct DeleteVersionRequest { pub struct DeleteVersionRequest {
@@ -510,8 +517,8 @@ pub struct DeleteVersionResponse {
pub success: bool, pub success: bool,
#[prost(string, tag = "2")] #[prost(string, tag = "2")]
pub raw_file_info: ::prost::alloc::string::String, pub raw_file_info: ::prost::alloc::string::String,
#[prost(string, optional, tag = "3")] #[prost(message, optional, tag = "3")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct DeleteVersionsRequest { pub struct DeleteVersionsRequest {
@@ -530,8 +537,8 @@ pub struct DeleteVersionsResponse {
pub success: bool, pub success: bool,
#[prost(string, repeated, tag = "2")] #[prost(string, repeated, tag = "2")]
pub errors: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, pub errors: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
#[prost(string, optional, tag = "3")] #[prost(message, optional, tag = "3")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct ReadMultipleRequest { pub struct ReadMultipleRequest {
@@ -546,8 +553,8 @@ pub struct ReadMultipleResponse {
pub success: bool, pub success: bool,
#[prost(string, repeated, tag = "2")] #[prost(string, repeated, tag = "2")]
pub read_multiple_resps: ::prost::alloc::vec::Vec<::prost::alloc::string::String>, pub read_multiple_resps: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
#[prost(string, optional, tag = "3")] #[prost(message, optional, tag = "3")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct DeleteVolumeRequest { pub struct DeleteVolumeRequest {
@@ -560,8 +567,8 @@ pub struct DeleteVolumeRequest {
pub struct DeleteVolumeResponse { pub struct DeleteVolumeResponse {
#[prost(bool, tag = "1")] #[prost(bool, tag = "1")]
pub success: bool, pub success: bool,
#[prost(string, optional, tag = "2")] #[prost(message, optional, tag = "2")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct DiskInfoRequest { pub struct DiskInfoRequest {
@@ -576,8 +583,8 @@ pub struct DiskInfoResponse {
pub success: bool, pub success: bool,
#[prost(string, tag = "2")] #[prost(string, tag = "2")]
pub disk_info: ::prost::alloc::string::String, pub disk_info: ::prost::alloc::string::String,
#[prost(string, optional, tag = "3")] #[prost(message, optional, tag = "3")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
pub struct NsScannerRequest { pub struct NsScannerRequest {
@@ -596,8 +603,8 @@ pub struct NsScannerResponse {
pub update: ::prost::alloc::string::String, pub update: ::prost::alloc::string::String,
#[prost(string, tag = "3")] #[prost(string, tag = "3")]
pub data_usage_cache: ::prost::alloc::string::String, pub data_usage_cache: ::prost::alloc::string::String,
#[prost(string, optional, tag = "4")] #[prost(message, optional, tag = "4")]
pub error_info: ::core::option::Option<::prost::alloc::string::String>, pub error: ::core::option::Option<Error>,
} }
/// lock api have same argument type /// lock api have same argument type
#[derive(Clone, PartialEq, ::prost::Message)] #[derive(Clone, PartialEq, ::prost::Message)]
+38 -33
View File
@@ -2,6 +2,11 @@ syntax = "proto3";
package node_service; package node_service;
/* -------------------------------------------------------------------- */ /* -------------------------------------------------------------------- */
message Error {
uint32 code = 1;
string error_info = 2;
}
message PingRequest { message PingRequest {
uint64 version = 1; uint64 version = 1;
bytes body = 2; bytes body = 2;
@@ -19,7 +24,7 @@ message HealBucketRequest {
message HealBucketResponse { message HealBucketResponse {
bool success = 1; bool success = 1;
optional string error_info = 2; optional Error error = 2;
} }
message ListBucketRequest { message ListBucketRequest {
@@ -29,7 +34,7 @@ message ListBucketRequest {
message ListBucketResponse { message ListBucketResponse {
bool success = 1; bool success = 1;
repeated string bucket_infos = 2; repeated string bucket_infos = 2;
optional string error_info = 3; optional Error error = 3;
} }
message MakeBucketRequest { message MakeBucketRequest {
@@ -39,7 +44,7 @@ message MakeBucketRequest {
message MakeBucketResponse { message MakeBucketResponse {
bool success = 1; bool success = 1;
optional string error_info = 2; optional Error error = 2;
} }
message GetBucketInfoRequest { message GetBucketInfoRequest {
@@ -50,7 +55,7 @@ message GetBucketInfoRequest {
message GetBucketInfoResponse { message GetBucketInfoResponse {
bool success = 1; bool success = 1;
string bucket_info = 2; string bucket_info = 2;
optional string error_info = 3; optional Error error = 3;
} }
message DeleteBucketRequest { message DeleteBucketRequest {
@@ -59,7 +64,7 @@ message DeleteBucketRequest {
message DeleteBucketResponse { message DeleteBucketResponse {
bool success = 1; bool success = 1;
optional string error_info = 2; optional Error error = 2;
} }
message ReadAllRequest { message ReadAllRequest {
@@ -71,7 +76,7 @@ message ReadAllRequest {
message ReadAllResponse { message ReadAllResponse {
bool success = 1; bool success = 1;
bytes data = 2; bytes data = 2;
optional string error_info = 3; optional Error error = 3;
} }
message WriteAllRequest { message WriteAllRequest {
@@ -83,7 +88,7 @@ message WriteAllRequest {
message WriteAllResponse { message WriteAllResponse {
bool success = 1; bool success = 1;
optional string error_info = 2; optional Error error = 2;
} }
message DeleteRequest { message DeleteRequest {
@@ -95,7 +100,7 @@ message DeleteRequest {
message DeleteResponse { message DeleteResponse {
bool success = 1; bool success = 1;
optional string error_info = 2; optional Error error = 2;
} }
message VerifyFileRequest { message VerifyFileRequest {
@@ -108,7 +113,7 @@ message VerifyFileRequest {
message VerifyFileResponse { message VerifyFileResponse {
bool success = 1; bool success = 1;
string check_parts_resp = 2; string check_parts_resp = 2;
optional string error_info = 3; optional Error error = 3;
} }
message CheckPartsRequest { message CheckPartsRequest {
@@ -121,7 +126,7 @@ message CheckPartsRequest {
message CheckPartsResponse { message CheckPartsResponse {
bool success = 1; bool success = 1;
string check_parts_resp = 2; string check_parts_resp = 2;
optional string error_info = 3; optional Error error = 3;
} }
message RenamePartRequst { message RenamePartRequst {
@@ -135,7 +140,7 @@ message RenamePartRequst {
message RenamePartResponse { message RenamePartResponse {
bool success = 1; bool success = 1;
optional string error_info = 2; optional Error error = 2;
} }
message RenameFileRequst { message RenameFileRequst {
@@ -148,7 +153,7 @@ message RenameFileRequst {
message RenameFileResponse { message RenameFileResponse {
bool success = 1; bool success = 1;
optional string error_info = 2; optional Error error = 2;
} }
message WriteRequest { message WriteRequest {
@@ -161,7 +166,7 @@ message WriteRequest {
message WriteResponse { message WriteResponse {
bool success = 1; bool success = 1;
optional string error_info = 2; optional Error error = 2;
} }
// message AppendRequest { // message AppendRequest {
@@ -173,7 +178,7 @@ message WriteResponse {
// //
// message AppendResponse { // message AppendResponse {
// bool success = 1; // bool success = 1;
// optional string error_info = 2; // optional Error error = 2;
// } // }
message ReadAtRequest { message ReadAtRequest {
@@ -188,7 +193,7 @@ message ReadAtResponse {
bool success = 1; bool success = 1;
bytes data = 2; bytes data = 2;
int64 read_size = 3; int64 read_size = 3;
optional string error_info = 4; optional Error error = 4;
} }
message ListDirRequest { message ListDirRequest {
@@ -199,7 +204,7 @@ message ListDirRequest {
message ListDirResponse { message ListDirResponse {
bool success = 1; bool success = 1;
repeated string volumes = 2; repeated string volumes = 2;
optional string error_info = 3; optional Error error = 3;
} }
message WalkDirRequest { message WalkDirRequest {
@@ -210,7 +215,7 @@ message WalkDirRequest {
message WalkDirResponse { message WalkDirResponse {
bool success = 1; bool success = 1;
repeated string meta_cache_entry = 2; repeated string meta_cache_entry = 2;
optional string error_info = 3; optional Error error = 3;
} }
message RenameDataRequest { message RenameDataRequest {
@@ -225,7 +230,7 @@ message RenameDataRequest {
message RenameDataResponse { message RenameDataResponse {
bool success = 1; bool success = 1;
string rename_data_resp = 2; string rename_data_resp = 2;
optional string error_info = 3; optional Error error = 3;
} }
message MakeVolumesRequest { message MakeVolumesRequest {
@@ -235,7 +240,7 @@ message MakeVolumesRequest {
message MakeVolumesResponse { message MakeVolumesResponse {
bool success = 1; bool success = 1;
optional string error_info = 2; optional Error error = 2;
} }
message MakeVolumeRequest { message MakeVolumeRequest {
@@ -245,7 +250,7 @@ message MakeVolumeRequest {
message MakeVolumeResponse { message MakeVolumeResponse {
bool success = 1; bool success = 1;
optional string error_info = 2; optional Error error = 2;
} }
message ListVolumesRequest { message ListVolumesRequest {
@@ -255,7 +260,7 @@ message ListVolumesRequest {
message ListVolumesResponse { message ListVolumesResponse {
bool success = 1; bool success = 1;
repeated string volume_infos = 2; repeated string volume_infos = 2;
optional string error_info = 3; optional Error error = 3;
} }
message StatVolumeRequest { message StatVolumeRequest {
@@ -266,7 +271,7 @@ message StatVolumeRequest {
message StatVolumeResponse { message StatVolumeResponse {
bool success = 1; bool success = 1;
string volume_info = 2; string volume_info = 2;
optional string error_info = 3; optional Error error = 3;
} }
message DeletePathsRequest { message DeletePathsRequest {
@@ -277,7 +282,7 @@ message DeletePathsRequest {
message DeletePathsResponse { message DeletePathsResponse {
bool success = 1; bool success = 1;
optional string error_info = 2; optional Error error = 2;
} }
message UpdateMetadataRequest { message UpdateMetadataRequest {
@@ -290,7 +295,7 @@ message UpdateMetadataRequest {
message UpdateMetadataResponse { message UpdateMetadataResponse {
bool success = 1; bool success = 1;
optional string error_info = 2; optional Error error = 2;
} }
message WriteMetadataRequest { message WriteMetadataRequest {
@@ -302,7 +307,7 @@ message WriteMetadataRequest {
message WriteMetadataResponse { message WriteMetadataResponse {
bool success = 1; bool success = 1;
optional string error_info = 2; optional Error error = 2;
} }
message ReadVersionRequest { message ReadVersionRequest {
@@ -316,7 +321,7 @@ message ReadVersionRequest {
message ReadVersionResponse { message ReadVersionResponse {
bool success = 1; bool success = 1;
string file_info = 2; string file_info = 2;
optional string error_info = 3; optional Error error = 3;
} }
message ReadXLRequest { message ReadXLRequest {
@@ -329,7 +334,7 @@ message ReadXLRequest {
message ReadXLResponse { message ReadXLResponse {
bool success = 1; bool success = 1;
string raw_file_info = 2; string raw_file_info = 2;
optional string error_info = 3; optional Error error = 3;
} }
message DeleteVersionRequest { message DeleteVersionRequest {
@@ -344,7 +349,7 @@ message DeleteVersionRequest {
message DeleteVersionResponse { message DeleteVersionResponse {
bool success = 1; bool success = 1;
string raw_file_info = 2; string raw_file_info = 2;
optional string error_info = 3; optional Error error = 3;
} }
message DeleteVersionsRequest { message DeleteVersionsRequest {
@@ -357,7 +362,7 @@ message DeleteVersionsRequest {
message DeleteVersionsResponse { message DeleteVersionsResponse {
bool success = 1; bool success = 1;
repeated string errors = 2; repeated string errors = 2;
optional string error_info = 3; optional Error error = 3;
} }
message ReadMultipleRequest { message ReadMultipleRequest {
@@ -368,7 +373,7 @@ message ReadMultipleRequest {
message ReadMultipleResponse { message ReadMultipleResponse {
bool success = 1; bool success = 1;
repeated string read_multiple_resps = 2; repeated string read_multiple_resps = 2;
optional string error_info = 3; optional Error error = 3;
} }
message DeleteVolumeRequest { message DeleteVolumeRequest {
@@ -378,7 +383,7 @@ message DeleteVolumeRequest {
message DeleteVolumeResponse { message DeleteVolumeResponse {
bool success = 1; bool success = 1;
optional string error_info = 2; optional Error error = 2;
} }
message DiskInfoRequest { message DiskInfoRequest {
@@ -389,7 +394,7 @@ message DiskInfoRequest {
message DiskInfoResponse { message DiskInfoResponse {
bool success = 1; bool success = 1;
string disk_info = 2; string disk_info = 2;
optional string error_info = 3; optional Error error = 3;
} }
message NsScannerRequest { message NsScannerRequest {
@@ -402,7 +407,7 @@ message NsScannerResponse {
bool success = 1; bool success = 1;
string update = 2; string update = 2;
string data_usage_cache = 3; string data_usage_cache = 3;
optional string error_info = 4; optional Error error = 4;
} }
// lock api have same argument type // lock api have same argument type
+29
View File
@@ -29,3 +29,32 @@ impl BucketMetadataError {
} }
} }
} }
impl BucketMetadataError {
pub fn to_u32(&self) -> u32 {
match self {
BucketMetadataError::TaggingNotFound => 0x01,
BucketMetadataError::BucketPolicyNotFound => 0x02,
BucketMetadataError::BucketObjectLockConfigNotFound => 0x03,
BucketMetadataError::BucketLifecycleNotFound => 0x04,
BucketMetadataError::BucketSSEConfigNotFound => 0x05,
BucketMetadataError::BucketQuotaConfigNotFound => 0x06,
BucketMetadataError::BucketReplicationConfigNotFound => 0x07,
BucketMetadataError::BucketRemoteTargetNotFound => 0x08,
}
}
pub fn from_u32(error: u32) -> Option<Self> {
match error {
0x01 => Some(BucketMetadataError::TaggingNotFound),
0x02 => Some(BucketMetadataError::BucketPolicyNotFound),
0x03 => Some(BucketMetadataError::BucketObjectLockConfigNotFound),
0x04 => Some(BucketMetadataError::BucketLifecycleNotFound),
0x05 => Some(BucketMetadataError::BucketSSEConfigNotFound),
0x06 => Some(BucketMetadataError::BucketQuotaConfigNotFound),
0x07 => Some(BucketMetadataError::BucketReplicationConfigNotFound),
0x08 => Some(BucketMetadataError::BucketRemoteTargetNotFound),
_ => None,
}
}
}
+17 -1
View File
@@ -1,6 +1,6 @@
use crate::{disk, error::Error}; use crate::{disk, error::Error};
#[derive(Debug, thiserror::Error)] #[derive(Debug, PartialEq, thiserror::Error)]
pub enum ConfigError { pub enum ConfigError {
#[error("config not found")] #[error("config not found")]
NotFound, NotFound,
@@ -15,6 +15,22 @@ impl ConfigError {
matches!(self, Self::NotFound) matches!(self, Self::NotFound)
} }
} }
impl ConfigError {
pub fn to_u32(&self) -> u32 {
match self {
ConfigError::NotFound => 0x01,
}
}
pub fn from_u32(error: u32) -> Option<Self> {
match error {
0x01 => Some(Self::NotFound),
_ => None,
}
}
}
pub fn is_not_found(err: &Error) -> bool { pub fn is_not_found(err: &Error) -> bool {
if let Some(e) = err.downcast_ref::<ConfigError>() { if let Some(e) = err.downcast_ref::<ConfigError>() {
ConfigError::is_not_found(e) ConfigError::is_not_found(e)
+82
View File
@@ -2,6 +2,7 @@ use std::io::{self, ErrorKind};
use tracing::error; use tracing::error;
use crate::utils::ERROR_TYPE_MASK;
use crate::{ use crate::{
error::{Error, Result}, error::{Error, Result},
quorum::CheckErrorFn, quorum::CheckErrorFn,
@@ -167,6 +168,87 @@ impl DiskError {
} }
} }
impl DiskError {
pub fn to_u32(&self) -> u32 {
match self {
DiskError::MaxVersionsExceeded => 0x01,
DiskError::Unexpected => 0x02,
DiskError::CorruptedFormat => 0x03,
DiskError::CorruptedBackend => 0x04,
DiskError::UnformattedDisk => 0x05,
DiskError::InconsistentDisk => 0x06,
DiskError::UnsupportedDisk => 0x07,
DiskError::DiskFull => 0x08,
DiskError::DiskNotDir => 0x09,
DiskError::DiskNotFound => 0x0A,
DiskError::DiskOngoingReq => 0x0B,
DiskError::DriveIsRoot => 0x0C,
DiskError::FaultyRemoteDisk => 0x0D,
DiskError::FaultyDisk => 0x0E,
DiskError::DiskAccessDenied => 0x0F,
DiskError::FileNotFound => 0x10,
DiskError::FileVersionNotFound => 0x11,
DiskError::TooManyOpenFiles => 0x12,
DiskError::FileNameTooLong => 0x13,
DiskError::VolumeExists => 0x14,
DiskError::IsNotRegular => 0x15,
DiskError::PathNotFound => 0x16,
DiskError::VolumeNotFound => 0x17,
DiskError::VolumeNotEmpty => 0x18,
DiskError::VolumeAccessDenied => 0x19,
DiskError::FileAccessDenied => 0x1A,
DiskError::FileCorrupt => 0x1B,
DiskError::BitrotHashAlgoInvalid => 0x1C,
DiskError::CrossDeviceLink => 0x1D,
DiskError::LessData => 0x1E,
DiskError::MoreData => 0x1F,
DiskError::OutdatedXLMeta => 0x20,
DiskError::PartMissingOrCorrupt => 0x21,
DiskError::NoHealRequired => 0x22,
}
}
pub fn from_u32(error: u32) -> Option<Self> {
match error & ERROR_TYPE_MASK {
0x01 => Some(DiskError::MaxVersionsExceeded),
0x02 => Some(DiskError::Unexpected),
0x03 => Some(DiskError::CorruptedFormat),
0x04 => Some(DiskError::CorruptedBackend),
0x05 => Some(DiskError::UnformattedDisk),
0x06 => Some(DiskError::InconsistentDisk),
0x07 => Some(DiskError::UnsupportedDisk),
0x08 => Some(DiskError::DiskFull),
0x09 => Some(DiskError::DiskNotDir),
0x0A => Some(DiskError::DiskNotFound),
0x0B => Some(DiskError::DiskOngoingReq),
0x0C => Some(DiskError::DriveIsRoot),
0x0D => Some(DiskError::FaultyRemoteDisk),
0x0E => Some(DiskError::FaultyDisk),
0x0F => Some(DiskError::DiskAccessDenied),
0x10 => Some(DiskError::FileNotFound),
0x11 => Some(DiskError::FileVersionNotFound),
0x12 => Some(DiskError::TooManyOpenFiles),
0x13 => Some(DiskError::FileNameTooLong),
0x14 => Some(DiskError::VolumeExists),
0x15 => Some(DiskError::IsNotRegular),
0x16 => Some(DiskError::PathNotFound),
0x17 => Some(DiskError::VolumeNotFound),
0x18 => Some(DiskError::VolumeNotEmpty),
0x19 => Some(DiskError::VolumeAccessDenied),
0x1A => Some(DiskError::FileAccessDenied),
0x1B => Some(DiskError::FileCorrupt),
0x1C => Some(DiskError::BitrotHashAlgoInvalid),
0x1D => Some(DiskError::CrossDeviceLink),
0x1E => Some(DiskError::LessData),
0x1F => Some(DiskError::MoreData),
0x20 => Some(DiskError::OutdatedXLMeta),
0x21 => Some(DiskError::PartMissingOrCorrupt),
0x22 => Some(DiskError::NoHealRequired),
_ => None,
}
}
}
impl PartialEq for DiskError { impl PartialEq for DiskError {
fn eq(&self, other: &Self) -> bool { fn eq(&self, other: &Self) -> bool {
core::mem::discriminant(self) == core::mem::discriminant(other) core::mem::discriminant(self) == core::mem::discriminant(other)
+11 -6
View File
@@ -14,6 +14,7 @@ pub const FORMAT_CONFIG_FILE: &str = "format.json";
pub const STORAGE_FORMAT_FILE: &str = "xl.meta"; pub const STORAGE_FORMAT_FILE: &str = "xl.meta";
pub const STORAGE_FORMAT_FILE_BACKUP: &str = "xl.meta.bkp"; pub const STORAGE_FORMAT_FILE_BACKUP: &str = "xl.meta.bkp";
use crate::utils::proto_err_to_err;
use crate::{ use crate::{
erasure::Writer, erasure::Writer,
error::{Error, Result}, error::{Error, Result},
@@ -1109,9 +1110,11 @@ impl Writer for RemoteFileWriter {
if resp.success { if resp.success {
info!("write stream success"); info!("write stream success");
} else { } else {
let error_info = resp.error_info.unwrap_or("".to_string()); return if let Some(err) = &resp.error {
info!("write stream failed: {}", error_info); Err(proto_err_to_err(err))
return Err(Error::from_string(error_info)); } else {
Err(Error::from_string(""))
};
} }
} else { } else {
let error_info = "can not get response"; let error_info = "can not get response";
@@ -1287,9 +1290,11 @@ impl Reader for RemoteFileReader {
Ok(resp.read_size.try_into().unwrap()) Ok(resp.read_size.try_into().unwrap())
} else { } else {
let error_info = resp.error_info.unwrap_or("".to_string()); return if let Some(err) = &resp.error {
info!("read at stream failed: {}", error_info); Err(proto_err_to_err(err))
Err(Error::from_string(error_info)) } else {
Err(Error::from_string(""))
};
} }
} else { } else {
let error_info = "can not get response"; let error_info = "can not get response";
+116 -26
View File
@@ -21,6 +21,7 @@ use super::{
FileInfoVersions, FileReader, FileWriter, MetaCacheEntry, ReadMultipleReq, ReadMultipleResp, ReadOptions, RemoteFileReader, FileInfoVersions, FileReader, FileWriter, MetaCacheEntry, ReadMultipleReq, ReadMultipleResp, ReadOptions, RemoteFileReader,
RemoteFileWriter, RenameDataResp, UpdateMetadataOpts, VolumeInfo, WalkDirOptions, RemoteFileWriter, RenameDataResp, UpdateMetadataOpts, VolumeInfo, WalkDirOptions,
}; };
use crate::utils::proto_err_to_err;
use crate::{ use crate::{
disk::error::DiskError, disk::error::DiskError,
error::{Error, Result}, error::{Error, Result},
@@ -161,7 +162,11 @@ impl DiskAPI for RemoteDisk {
let response = client.write_all(request).await?.into_inner(); let response = client.write_all(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
Ok(()) Ok(())
@@ -183,7 +188,11 @@ impl DiskAPI for RemoteDisk {
let response = client.delete(request).await?.into_inner(); let response = client.delete(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
Ok(()) Ok(())
@@ -205,7 +214,11 @@ impl DiskAPI for RemoteDisk {
let response = client.verify_file(request).await?.into_inner(); let response = client.verify_file(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
let check_parts_resp = serde_json::from_str::<CheckPartsResp>(&response.check_parts_resp)?; let check_parts_resp = serde_json::from_str::<CheckPartsResp>(&response.check_parts_resp)?;
@@ -229,7 +242,11 @@ impl DiskAPI for RemoteDisk {
let response = client.check_parts(request).await?.into_inner(); let response = client.check_parts(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
let check_parts_resp = serde_json::from_str::<CheckPartsResp>(&response.check_parts_resp)?; let check_parts_resp = serde_json::from_str::<CheckPartsResp>(&response.check_parts_resp)?;
@@ -254,7 +271,11 @@ impl DiskAPI for RemoteDisk {
let response = client.rename_part(request).await?.into_inner(); let response = client.rename_part(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
Ok(()) Ok(())
@@ -275,7 +296,11 @@ impl DiskAPI for RemoteDisk {
let response = client.rename_file(request).await?.into_inner(); let response = client.rename_file(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
Ok(()) Ok(())
@@ -341,7 +366,11 @@ impl DiskAPI for RemoteDisk {
let response = client.list_dir(request).await?.into_inner(); let response = client.list_dir(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
Ok(response.volumes) Ok(response.volumes)
@@ -361,7 +390,11 @@ impl DiskAPI for RemoteDisk {
let response = client.walk_dir(request).await?.into_inner(); let response = client.walk_dir(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
let entries = response let entries = response
@@ -398,7 +431,11 @@ impl DiskAPI for RemoteDisk {
let response = client.rename_data(request).await?.into_inner(); let response = client.rename_data(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
let rename_data_resp = serde_json::from_str::<RenameDataResp>(&response.rename_data_resp)?; let rename_data_resp = serde_json::from_str::<RenameDataResp>(&response.rename_data_resp)?;
@@ -419,7 +456,11 @@ impl DiskAPI for RemoteDisk {
let response = client.make_volumes(request).await?.into_inner(); let response = client.make_volumes(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
Ok(()) Ok(())
@@ -438,7 +479,11 @@ impl DiskAPI for RemoteDisk {
let response = client.make_volume(request).await?.into_inner(); let response = client.make_volume(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
Ok(()) Ok(())
@@ -456,7 +501,11 @@ impl DiskAPI for RemoteDisk {
let response = client.list_volumes(request).await?.into_inner(); let response = client.list_volumes(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
let infos = response let infos = response
@@ -481,7 +530,11 @@ impl DiskAPI for RemoteDisk {
let response = client.stat_volume(request).await?.into_inner(); let response = client.stat_volume(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
let volume_info = serde_json::from_str::<VolumeInfo>(&response.volume_info)?; let volume_info = serde_json::from_str::<VolumeInfo>(&response.volume_info)?;
@@ -504,7 +557,11 @@ impl DiskAPI for RemoteDisk {
let response = client.delete_paths(request).await?.into_inner(); let response = client.delete_paths(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
Ok(()) Ok(())
@@ -528,7 +585,11 @@ impl DiskAPI for RemoteDisk {
let response = client.update_metadata(request).await?.into_inner(); let response = client.update_metadata(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
Ok(()) Ok(())
@@ -550,7 +611,11 @@ impl DiskAPI for RemoteDisk {
let response = client.write_metadata(request).await?.into_inner(); let response = client.write_metadata(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
Ok(()) Ok(())
@@ -580,7 +645,11 @@ impl DiskAPI for RemoteDisk {
let response = client.read_version(request).await?.into_inner(); let response = client.read_version(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
let file_info = serde_json::from_str::<FileInfo>(&response.file_info)?; let file_info = serde_json::from_str::<FileInfo>(&response.file_info)?;
@@ -603,7 +672,11 @@ impl DiskAPI for RemoteDisk {
let response = client.read_xl(request).await?.into_inner(); let response = client.read_xl(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
let raw_file_info = serde_json::from_str::<RawFileInfo>(&response.raw_file_info)?; let raw_file_info = serde_json::from_str::<RawFileInfo>(&response.raw_file_info)?;
@@ -637,7 +710,11 @@ impl DiskAPI for RemoteDisk {
let response = client.delete_version(request).await?.into_inner(); let response = client.delete_version(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
// let raw_file_info = serde_json::from_str::<RawFileInfo>(&response.raw_file_info)?; // let raw_file_info = serde_json::from_str::<RawFileInfo>(&response.raw_file_info)?;
@@ -668,10 +745,11 @@ impl DiskAPI for RemoteDisk {
let response = client.delete_versions(request).await?.into_inner(); let response = client.delete_versions(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(format!( return if let Some(err) = &response.error {
"delete versions remote err: {}", Err(proto_err_to_err(err))
response.error_info.unwrap_or("None".to_string()) } else {
))); Err(Error::from_string(""))
};
} }
let errors = response let errors = response
.errors .errors
@@ -702,7 +780,11 @@ impl DiskAPI for RemoteDisk {
let response = client.read_multiple(request).await?.into_inner(); let response = client.read_multiple(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
let read_multiple_resps = response let read_multiple_resps = response
@@ -727,7 +809,11 @@ impl DiskAPI for RemoteDisk {
let response = client.delete_volume(request).await?.into_inner(); let response = client.delete_volume(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
Ok(()) Ok(())
@@ -747,7 +833,11 @@ impl DiskAPI for RemoteDisk {
let response = client.disk_info(request).await?.into_inner(); let response = client.disk_info(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or("".to_string()))); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
let disk_info = serde_json::from_str::<DiskInfo>(&response.disk_info)?; let disk_info = serde_json::from_str::<DiskInfo>(&response.disk_info)?;
+33 -3
View File
@@ -20,6 +20,7 @@ use crate::heal::heal_commands::{
use crate::heal::heal_ops::RUESTFS_RESERVED_BUCKET; use crate::heal::heal_ops::RUESTFS_RESERVED_BUCKET;
use crate::quorum::{bucket_op_ignored_errs, reduce_write_quorum_errs}; use crate::quorum::{bucket_op_ignored_errs, reduce_write_quorum_errs};
use crate::store::all_local_disk; use crate::store::all_local_disk;
use crate::utils::proto_err_to_err;
use crate::utils::wildcard::is_rustfs_meta_bucket_name; use crate::utils::wildcard::is_rustfs_meta_bucket_name;
use crate::{ use crate::{
disk::{self, error::DiskError, VolumeInfo}, disk::{self, error::DiskError, VolumeInfo},
@@ -523,7 +524,11 @@ impl PeerS3Client for RemotePeerS3Client {
}); });
let response = client.heal_bucket(request).await?.into_inner(); let response = client.heal_bucket(request).await?.into_inner();
if !response.success { if !response.success {
return Err(Error::from_string(response.error_info.unwrap_or_default())); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
Ok(HealResultItem { Ok(HealResultItem {
@@ -541,6 +546,13 @@ impl PeerS3Client for RemotePeerS3Client {
.map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?; .map_err(|err| Error::from_string(format!("can not get client, err: {}", err)))?;
let request = Request::new(ListBucketRequest { options }); let request = Request::new(ListBucketRequest { options });
let response = client.list_bucket(request).await?.into_inner(); let response = client.list_bucket(request).await?.into_inner();
if !response.success {
return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
}
let bucket_infos = response let bucket_infos = response
.bucket_infos .bucket_infos
.into_iter() .into_iter()
@@ -562,7 +574,11 @@ impl PeerS3Client for RemotePeerS3Client {
// TODO: deal with error // TODO: deal with error
if !response.success { if !response.success {
warn!("make bucket error: {:?}", response.error_info); return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
} }
Ok(()) Ok(())
@@ -577,6 +593,13 @@ impl PeerS3Client for RemotePeerS3Client {
options, options,
}); });
let response = client.get_bucket_info(request).await?.into_inner(); let response = client.get_bucket_info(request).await?.into_inner();
if !response.success {
return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
}
let bucket_info = serde_json::from_str::<BucketInfo>(&response.bucket_info)?; let bucket_info = serde_json::from_str::<BucketInfo>(&response.bucket_info)?;
Ok(bucket_info) Ok(bucket_info)
@@ -590,7 +613,14 @@ impl PeerS3Client for RemotePeerS3Client {
let request = Request::new(DeleteBucketRequest { let request = Request::new(DeleteBucketRequest {
bucket: bucket.to_string(), bucket: bucket.to_string(),
}); });
let _response = client.delete_bucket(request).await?.into_inner(); let response = client.delete_bucket(request).await?.into_inner();
if !response.success {
return if let Some(err) = &response.error {
Err(proto_err_to_err(err))
} else {
Err(Error::from_string(""))
};
}
Ok(()) Ok(())
} }
+1 -1
View File
@@ -53,7 +53,7 @@ impl PeerRestClient {
let eps = eps.clone(); let eps = eps.clone();
let hosts = eps.hosts_sorted(); let hosts = eps.hosts_sorted();
let mut remote = vec![None; hosts.len()]; let mut remote = vec![None; hosts.len()];
let mut all = Vec::with_capacity(hosts.len()); let mut all = vec![None; hosts.len()];
for (i, hs_host) in hosts.iter().enumerate() { for (i, hs_host) in hosts.iter().enumerate() {
if let Some(host) = hs_host { if let Some(host) = hs_host {
if let Some(grid_host) = eps.find_grid_hosts_from_peer(host) { if let Some(grid_host) = eps.find_grid_hosts_from_peer(host) {
+19 -2
View File
@@ -1,13 +1,13 @@
use crate::config::error::ConfigError;
use crate::{disk::error::DiskError, error::Error}; use crate::{disk::error::DiskError, error::Error};
use std::{collections::HashMap, fmt::Debug}; use std::{collections::HashMap, fmt::Debug};
// pub type CheckErrorFn = fn(e: &Error) -> bool; // pub type CheckErrorFn = fn(e: &Error) -> bool;
pub trait CheckErrorFn: Debug + Send + Sync + 'static { pub trait CheckErrorFn: Debug + Send + Sync + 'static {
fn is(&self, e: &Error) -> bool; fn is(&self, e: &Error) -> bool;
} }
#[derive(Debug, thiserror::Error)] #[derive(Debug, PartialEq, thiserror::Error)]
pub enum QuorumError { pub enum QuorumError {
#[error("Read quorum not met")] #[error("Read quorum not met")]
Read, Read,
@@ -15,6 +15,23 @@ pub enum QuorumError {
Write, Write,
} }
impl QuorumError {
pub fn to_u32(&self) -> u32 {
match self {
QuorumError::Read => 0x01,
QuorumError::Write => 0x02,
}
}
pub fn from_u32(error: u32) -> Option<Self> {
match error {
0x01 => Some(QuorumError::Read),
0x02 => Some(QuorumError::Write),
_ => None,
}
}
}
pub fn base_ignored_errs() -> Vec<Box<dyn CheckErrorFn>> { pub fn base_ignored_errs() -> Vec<Box<dyn CheckErrorFn>> {
vec![ vec![
Box::new(DiskError::DiskNotFound), Box::new(DiskError::DiskNotFound),
+65
View File
@@ -76,6 +76,71 @@ pub enum StorageError {
DecommissionNotStarted, DecommissionNotStarted,
} }
impl StorageError {
pub fn to_u32(&self) -> u32 {
match self {
StorageError::NotImplemented => 0x01,
StorageError::InvalidArgument(_, _, _) => 0x02,
StorageError::MethodNotAllowed => 0x03,
StorageError::BucketNotFound(_) => 0x04,
StorageError::BucketNotEmpty(_) => 0x05,
StorageError::BucketNameInvalid(_) => 0x06,
StorageError::ObjectNameInvalid(_, _) => 0x07,
StorageError::BucketExists(_) => 0x08,
StorageError::StorageFull => 0x09,
StorageError::SlowDown => 0x0A,
StorageError::PrefixAccessDenied(_, _) => 0x0B,
StorageError::InvalidUploadIDKeyCombination(_, _) => 0x0C,
StorageError::MalformedUploadID(_) => 0x0D,
StorageError::ObjectNameTooLong(_, _) => 0x0E,
StorageError::ObjectNamePrefixAsSlash(_, _) => 0x0F,
StorageError::ObjectNotFound(_, _) => 0x10,
StorageError::VersionNotFound(_, _, _) => 0x11,
StorageError::InvalidUploadID(_, _, _) => 0x12,
StorageError::InvalidVersionID(_, _, _) => 0x13,
StorageError::DataMovementOverwriteErr(_, _, _) => 0x14,
StorageError::ObjectExistsAsDirectory(_, _) => 0x15,
StorageError::InsufficientReadQuorum => 0x16,
StorageError::InsufficientWriteQuorum => 0x17,
StorageError::DecommissionNotStarted => 0x18,
}
}
pub fn from_u32(error: u32) -> Option<Self> {
match error {
0x01 => Some(StorageError::NotImplemented),
0x02 => Some(StorageError::InvalidArgument(Default::default(), Default::default(), Default::default())),
0x03 => Some(StorageError::MethodNotAllowed),
0x04 => Some(StorageError::BucketNotFound(Default::default())),
0x05 => Some(StorageError::BucketNotEmpty(Default::default())),
0x06 => Some(StorageError::BucketNameInvalid(Default::default())),
0x07 => Some(StorageError::ObjectNameInvalid(Default::default(), Default::default())),
0x08 => Some(StorageError::BucketExists(Default::default())),
0x09 => Some(StorageError::StorageFull),
0x0A => Some(StorageError::SlowDown),
0x0B => Some(StorageError::PrefixAccessDenied(Default::default(), Default::default())),
0x0C => Some(StorageError::InvalidUploadIDKeyCombination(Default::default(), Default::default())),
0x0D => Some(StorageError::MalformedUploadID(Default::default())),
0x0E => Some(StorageError::ObjectNameTooLong(Default::default(), Default::default())),
0x0F => Some(StorageError::ObjectNamePrefixAsSlash(Default::default(), Default::default())),
0x10 => Some(StorageError::ObjectNotFound(Default::default(), Default::default())),
0x11 => Some(StorageError::VersionNotFound(Default::default(), Default::default(), Default::default())),
0x12 => Some(StorageError::InvalidUploadID(Default::default(), Default::default(), Default::default())),
0x13 => Some(StorageError::InvalidVersionID(Default::default(), Default::default(), Default::default())),
0x14 => Some(StorageError::DataMovementOverwriteErr(
Default::default(),
Default::default(),
Default::default(),
)),
0x15 => Some(StorageError::ObjectExistsAsDirectory(Default::default(), Default::default())),
0x16 => Some(StorageError::InsufficientReadQuorum),
0x17 => Some(StorageError::InsufficientWriteQuorum),
0x18 => Some(StorageError::DecommissionNotStarted),
_ => None,
}
}
}
pub fn to_object_err(err: Error, params: Vec<&str>) -> Error { pub fn to_object_err(err: Error, params: Vec<&str>) -> Error {
if let Some(e) = err.downcast_ref::<DiskError>() { if let Some(e) = err.downcast_ref::<DiskError>() {
match e { match e {
+24
View File
@@ -16,6 +16,7 @@ use std::{
fmt::Debug, fmt::Debug,
}; };
use crate::config::error::ConfigError;
use tracing::{debug, warn}; use tracing::{debug, warn};
use uuid::Uuid; use uuid::Uuid;
@@ -330,3 +331,26 @@ impl ErasureError {
false false
} }
} }
impl ErasureError {
pub fn to_u32(&self) -> u32 {
match self {
ErasureError::ErasureReadQuorum => 0x01,
ErasureError::_ErasureWriteQuorum => 0x02,
ErasureError::NotFirstDisk => 0x03,
ErasureError::FirstDiskWait => 0x04,
ErasureError::InvalidPart(_) => 0x05,
}
}
pub fn from_u32(error: u32) -> Option<Self> {
match error {
0x01 => Some(ErasureError::ErasureReadQuorum),
0x02 => Some(ErasureError::_ErasureWriteQuorum),
0x03 => Some(ErasureError::NotFirstDisk),
0x04 => Some(ErasureError::FirstDiskWait),
0x05 => Some(ErasureError::InvalidPart(Default::default())),
_ => None,
}
}
}
+110
View File
@@ -1,3 +1,12 @@
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 protos::proto_gen::node_service::Error as Proto_Error;
pub mod bool_flag; pub mod bool_flag;
pub mod crypto; pub mod crypto;
pub mod ellipses; pub mod ellipses;
@@ -8,3 +17,104 @@ pub mod os;
pub mod path; pub mod path;
pub mod wildcard; pub mod wildcard;
pub mod xml; pub mod xml;
const ERROR_MODULE_MASK: u32 = 0xFF00;
pub const ERROR_TYPE_MASK: u32 = 0x00FF;
const DISK_ERROR_MASK: u32 = 0x0100;
const STORAGE_ERROR_MASK: u32 = 0x0200;
const BUCKET_METADATA_ERROR_MASK: u32 = 0x0300;
const CONFIG_ERROR_MASK: u32 = 0x04000;
const QUORUM_ERROR_MASK: u32 = 0x0500;
const ERASURE_ERROR_MASK: u32 = 0x0600;
// error to u8
pub fn error_to_u32(err: &Error) -> u32 {
if let Some(e) = err.downcast_ref::<DiskError>() {
DISK_ERROR_MASK | e.to_u32()
} else if let Some(e) = err.downcast_ref::<StorageError>() {
STORAGE_ERROR_MASK | e.to_u32()
} else if let Some(e) = err.downcast_ref::<BucketMetadataError>() {
BUCKET_METADATA_ERROR_MASK | e.to_u32()
} else if let Some(e) = err.downcast_ref::<ConfigError>() {
CONFIG_ERROR_MASK | e.to_u32()
} else if let Some(e) = err.downcast_ref::<QuorumError>() {
QUORUM_ERROR_MASK | e.to_u32()
} else if let Some(e) = err.downcast_ref::<ErasureError>() {
ERASURE_ERROR_MASK | e.to_u32()
} else {
0
}
}
pub fn u32_to_error(e: u32) -> Option<Error> {
match e & ERROR_MODULE_MASK {
DISK_ERROR_MASK => DiskError::from_u32(e & ERROR_TYPE_MASK).map(|e| Error::new(e)),
STORAGE_ERROR_MASK => StorageError::from_u32(e & ERROR_TYPE_MASK).map(|e| Error::new(e)),
BUCKET_METADATA_ERROR_MASK => BucketMetadataError::from_u32(e & ERROR_TYPE_MASK).map(|e| Error::new(e)),
CONFIG_ERROR_MASK => ConfigError::from_u32(e & ERROR_TYPE_MASK).map(|e| Error::new(e)),
QUORUM_ERROR_MASK => QuorumError::from_u32(e & ERROR_TYPE_MASK).map(|e| Error::new(e)),
ERASURE_ERROR_MASK => ErasureError::from_u32(e & ERROR_TYPE_MASK).map(|e| Error::new(e)),
_ => None,
}
}
pub fn err_to_proto_err(err: &Error, msg: &str) -> Proto_Error {
let num = error_to_u32(err);
Proto_Error {
code: num,
error_info: msg.to_string(),
}
}
pub fn proto_err_to_err(err: &Proto_Error) -> Error {
if let Some(e) = u32_to_error(err.code) {
e
} else {
Error::from_string(err.error_info.clone())
}
}
#[test]
fn test_u32_to_error() {
let error = Error::new(DiskError::FileCorrupt);
let num = error_to_u32(&error);
let new_error = u32_to_error(num);
assert!(new_error.is_some());
assert_eq!(new_error.unwrap().downcast_ref::<DiskError>(), Some(&DiskError::FileCorrupt));
let error = Error::new(StorageError::BucketNotEmpty(Default::default()));
let num = error_to_u32(&error);
let new_error = u32_to_error(num);
assert!(new_error.is_some());
assert_eq!(
new_error.unwrap().downcast_ref::<StorageError>(),
Some(&StorageError::BucketNotEmpty(Default::default()))
);
let error = Error::new(BucketMetadataError::BucketObjectLockConfigNotFound);
let num = error_to_u32(&error);
let new_error = u32_to_error(num);
assert!(new_error.is_some());
assert_eq!(
new_error.unwrap().downcast_ref::<BucketMetadataError>(),
Some(&BucketMetadataError::BucketObjectLockConfigNotFound)
);
let error = Error::new(ConfigError::NotFound);
let num = error_to_u32(&error);
let new_error = u32_to_error(num);
assert!(new_error.is_some());
assert_eq!(new_error.unwrap().downcast_ref::<ConfigError>(), Some(&ConfigError::NotFound));
let error = Error::new(QuorumError::Read);
let num = error_to_u32(&error);
let new_error = u32_to_error(num);
assert!(new_error.is_some());
assert_eq!(new_error.unwrap().downcast_ref::<QuorumError>(), Some(&QuorumError::Read));
let error = Error::new(ErasureError::ErasureReadQuorum);
let num = error_to_u32(&error);
let new_error = u32_to_error(num);
assert!(new_error.is_some());
assert_eq!(new_error.unwrap().downcast_ref::<ErasureError>(), Some(&ErasureError::ErasureReadQuorum));
}
+400 -147
View File
File diff suppressed because it is too large Load Diff