mirror of
https://github.com/rustfs/rustfs.git
synced 2026-08-29 16:37:07 +00:00
8f0d4a20d1
The storage engine embedded a ~8.4K-line hand-written S3 HTTP client under crates/ecstore/src/client (rustfs/backlog#1842). That client is a legitimate engine capability — it consumes remote S3-compatible endpoints for ILM tier warm backends and transition targets — but it was misfiled inside the engine, dragging s3s/hyper wire types into ecstore and blocking ARCHITECTURE.md invariant 4. This PR is the pure-move step: 21 modules move verbatim to the new crates/s3-client crate (rustfs-s3-client), and crates/ecstore/src/client/mod.rs becomes a re-export shim so every in-crate crate::client:: path keeps working. The two server-side modules that were historically misfiled under client/ — object_api_utils.rs and object_handlers_common.rs — stay in ecstore. Three reverse dependencies from the client into engine internals are severed so the move can be pure: - transition_api::ReaderImpl::ObjectBody held ecstore's GetObjectReader; the client only ever reads the body, so the variant now holds an ObjectReader newtype over Box<dyn AsyncRead + Send + Sync + Unpin> with the same read_all() surface. The single production construction site (set_disk transition upload) and the two engine-side consumers were adjusted. - api_list/api_remove used ecstore's storage_api_contracts / object_api types; api_list now imports BucketInfo from rustfs-storage-api directly, and api_remove uses the client's own transition_api::ObjectInfo (only .name/.version_id were read; the error-path bucket name is now threaded as a parameter instead of read from the deleted objects). - the api_put_object_streaming regression tests built a GetObjectReader by hand; they now wrap the duplex stream in ObjectReader::new. Guard updates: the s3s footprint ratchet gains an ecstore-scoped counter (42 files, shrink-only, per rustfs/backlog#1842), the ecstore module-lint-blanket register follows the moved files into crates/s3-client so the blanket ratchet keeps covering them, the logging guardrail path pin follows transition_api.rs, and the ::other(format!) baseline is regenerated (moved call sites left ecstore). Verification: cargo check -p rustfs-s3-client -p rustfs-ecstore; cargo nextest run -p rustfs-s3-client (43 passed) and -p rustfs-ecstore (4515/4523; the 8 failures reproduce identically on pristine origin/main on the same machine); cargo clippy --all-targets; scripts/check_layer_dependencies.sh, check_architecture_migration_rules.sh, check_s3s_footprint.sh, check_logging_guardrails.sh, check_error_other_format_ratchet.sh, check_doc_paths.sh, check_ci_paths_sync.sh all pass.
109 lines
3.8 KiB
Rust
109 lines
3.8 KiB
Rust
#![allow(clippy::map_entry)]
|
|
// Copyright 2024 RustFS Team
|
|
//
|
|
// Licensed under the Apache License, Version 2.0 (the "License");
|
|
// you may not use this file except in compliance with the License.
|
|
// You may obtain a copy of the License at
|
|
//
|
|
// http://www.apache.org/licenses/LICENSE-2.0
|
|
//
|
|
// Unless required by applicable law or agreed to in writing, software
|
|
// distributed under the License is distributed on an "AS IS" BASIS,
|
|
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
// See the License for the specific language governing permissions and
|
|
// limitations under the License.
|
|
#![allow(unused_variables)]
|
|
#![allow(unused_mut)]
|
|
#![allow(unused_assignments)]
|
|
#![allow(unused_must_use)]
|
|
#![allow(clippy::all)]
|
|
|
|
use crate::{
|
|
api_error_response::{err_entity_too_large, err_invalid_argument},
|
|
api_put_object::PutObjectOptions,
|
|
constants::{ABS_MIN_PART_SIZE, MAX_MULTIPART_PUT_OBJECT_SIZE, MAX_PART_SIZE, MAX_PARTS_COUNT, MIN_PART_SIZE},
|
|
transition_api::ReaderImpl,
|
|
transition_api::TransitionClient,
|
|
};
|
|
|
|
pub fn is_object(reader: &ReaderImpl) -> bool {
|
|
matches!(reader, ReaderImpl::ObjectBody(_))
|
|
}
|
|
|
|
pub fn optimal_part_info(object_size: i64, configured_part_size: u64) -> Result<(i64, i64, i64), std::io::Error> {
|
|
let unknown_size;
|
|
let mut object_size = object_size;
|
|
if object_size == -1 {
|
|
unknown_size = true;
|
|
object_size = MAX_MULTIPART_PUT_OBJECT_SIZE;
|
|
} else {
|
|
unknown_size = false;
|
|
}
|
|
|
|
if object_size > MAX_MULTIPART_PUT_OBJECT_SIZE {
|
|
return Err(std::io::Error::other(err_entity_too_large(
|
|
object_size,
|
|
MAX_MULTIPART_PUT_OBJECT_SIZE,
|
|
"",
|
|
"",
|
|
)));
|
|
}
|
|
|
|
let mut part_size_flt: f64;
|
|
if configured_part_size > 0 {
|
|
if configured_part_size as i64 > object_size {
|
|
return Err(std::io::Error::other(err_entity_too_large(
|
|
configured_part_size as i64,
|
|
object_size,
|
|
"",
|
|
"",
|
|
)));
|
|
}
|
|
|
|
if !unknown_size && object_size > (configured_part_size as i64 * MAX_PARTS_COUNT) {
|
|
return Err(std::io::Error::other(err_invalid_argument(
|
|
"Part size * max_parts(10000) is lesser than input objectSize.",
|
|
)));
|
|
}
|
|
|
|
if (configured_part_size as i64) < ABS_MIN_PART_SIZE {
|
|
return Err(std::io::Error::other(err_invalid_argument(
|
|
"Input part size is smaller than allowed minimum of 5MiB.",
|
|
)));
|
|
}
|
|
|
|
if configured_part_size as i64 > MAX_PART_SIZE {
|
|
return Err(std::io::Error::other(err_invalid_argument(
|
|
"Input part size is bigger than allowed maximum of 5GiB.",
|
|
)));
|
|
}
|
|
|
|
part_size_flt = configured_part_size as f64;
|
|
if unknown_size {
|
|
object_size = configured_part_size as i64 * MAX_PARTS_COUNT;
|
|
}
|
|
} else {
|
|
let min_part = MIN_PART_SIZE as f64;
|
|
part_size_flt = (object_size as f64 / MAX_PARTS_COUNT as f64).ceil();
|
|
part_size_flt = part_size_flt.max(min_part);
|
|
part_size_flt = (part_size_flt / min_part).ceil() * min_part;
|
|
}
|
|
|
|
let total_parts_count = (object_size as f64 / part_size_flt).ceil() as i64;
|
|
let part_size = part_size_flt as i64;
|
|
let last_part_size = object_size - (total_parts_count - 1) * part_size;
|
|
Ok((total_parts_count, part_size, last_part_size))
|
|
}
|
|
|
|
impl TransitionClient {
|
|
pub async fn new_upload_id(
|
|
&self,
|
|
bucket_name: &str,
|
|
object_name: &str,
|
|
opts: &PutObjectOptions,
|
|
) -> Result<String, std::io::Error> {
|
|
let init_multipart_upload_result = self.initiate_multipart_upload(bucket_name, object_name, opts).await?;
|
|
Ok(init_multipart_upload_result.upload_id)
|
|
}
|
|
}
|