mirror of
https://github.com/rustfs/rustfs.git
synced 2026-11-30 20:57:35 +00:00
perf(s3-client): stream composite checksums and borrow error bodies (#9752)
This commit is contained in:
committed by
GitHub
parent
1e1e9ddbf7
commit
798391899c
@@ -88,15 +88,10 @@ impl Display for ErrorResponse {
|
||||
}
|
||||
|
||||
pub fn to_error_response(err: &std::io::Error) -> ErrorResponse {
|
||||
if let Some(err) = err.get_ref() {
|
||||
if err.is::<ErrorResponse>() {
|
||||
err.downcast_ref::<ErrorResponse>().expect("err!").clone()
|
||||
} else {
|
||||
ErrorResponse::default()
|
||||
}
|
||||
} else {
|
||||
ErrorResponse::default()
|
||||
}
|
||||
err.get_ref()
|
||||
.and_then(|err| err.downcast_ref::<ErrorResponse>())
|
||||
.cloned()
|
||||
.unwrap_or_default()
|
||||
}
|
||||
|
||||
pub fn http_resp_to_error_response(
|
||||
@@ -106,7 +101,6 @@ pub fn http_resp_to_error_response(
|
||||
bucket_name: &str,
|
||||
object_name: &str,
|
||||
) -> ErrorResponse {
|
||||
let err_body = String::from_utf8_lossy(&b).to_string();
|
||||
if h.is_empty() || !(resp_status.is_client_error() || resp_status.is_server_error()) {
|
||||
return ErrorResponse {
|
||||
status_code: resp_status,
|
||||
@@ -117,6 +111,7 @@ pub fn http_resp_to_error_response(
|
||||
..Default::default()
|
||||
};
|
||||
}
|
||||
let err_body = String::from_utf8_lossy(&b);
|
||||
let err_resp_ = quick_xml::de::from_str::<ErrorResponse>(&err_body);
|
||||
let mut err_resp = ErrorResponse::default();
|
||||
if err_resp_.is_err() {
|
||||
@@ -171,10 +166,11 @@ pub fn http_resp_to_error_response(
|
||||
};
|
||||
}
|
||||
_ => {
|
||||
let mut msg = resp_status.to_string();
|
||||
if err_body.len() > 0 {
|
||||
msg = err_body;
|
||||
}
|
||||
let msg = if err_body.is_empty() {
|
||||
resp_status.to_string()
|
||||
} else {
|
||||
err_body.into_owned()
|
||||
};
|
||||
err_resp = ErrorResponse {
|
||||
status_code: resp_status,
|
||||
code: RemoteErrorCode::custom(resp_status.to_string()),
|
||||
|
||||
@@ -143,7 +143,8 @@ impl GetObjectOptions {
|
||||
}
|
||||
|
||||
pub fn to_query_values(&self) -> HashMap<String, String> {
|
||||
let mut url_values = HashMap::new();
|
||||
let extra = usize::from(!self.version_id.is_empty()) + usize::from(self.part_number > 0);
|
||||
let mut url_values = HashMap::with_capacity(self.req_params.len() + extra);
|
||||
if self.version_id != "" {
|
||||
url_values.insert("versionId".to_string(), self.version_id.clone());
|
||||
}
|
||||
|
||||
@@ -205,9 +205,8 @@ async fn process_bucket_location_response<C: crate::transition_api::TransitionCo
|
||||
//if resp != nil {
|
||||
if resp.status() != StatusCode::OK {
|
||||
let resp_status = resp.status();
|
||||
let h = resp.headers().clone();
|
||||
|
||||
let err_resp = http_resp_to_error_response(resp_status, &h, vec![], bucket_name, "");
|
||||
let err_resp = http_resp_to_error_response(resp_status, resp.headers(), vec![], bucket_name, "");
|
||||
match err_resp.code {
|
||||
RemoteErrorCode::NOT_IMPLEMENTED => {
|
||||
match err_resp.server.as_str() {
|
||||
|
||||
@@ -138,13 +138,11 @@ impl ChecksumMode {
|
||||
}
|
||||
p.sort_by_key(|part| part.part_num);
|
||||
let c = self.base();
|
||||
let mut crc_bytes = Vec::<u8>::with_capacity(p.len() * self.raw_byte_len());
|
||||
let mut h = self.hasher()?;
|
||||
for part in p.iter() {
|
||||
let part_checksum = part.checksum_raw(&c)?;
|
||||
crc_bytes.extend(part_checksum);
|
||||
h.update(&part_checksum);
|
||||
}
|
||||
h.update(crc_bytes.as_ref());
|
||||
let hash = h.finalize();
|
||||
Ok(Checksum {
|
||||
checksum_type: *self,
|
||||
|
||||
Reference in New Issue
Block a user