mirror of
https://github.com/rustfs/rustfs.git
synced 2026-11-16 04:52:36 +00:00
Compare commits
27 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 278a7ed84b | |||
| 02c25a577e | |||
| 279228f796 | |||
| c46963f21d | |||
| 476376fb3d | |||
| eed3768e66 | |||
| 06077d1ca8 | |||
| af502d24b9 | |||
| e6f9d55c65 | |||
| debe7cfd60 | |||
| 2ab3ace01d | |||
| 20c3ea7469 | |||
| 0c6516d94c | |||
| 9efa398852 | |||
| c91158b2db | |||
| 7abd301724 | |||
| 85aea95afb | |||
| 314efb725e | |||
| 1ebcdc9130 | |||
| f019a54485 | |||
| fd9441a905 | |||
| 98feedc8e5 | |||
| 4fa6331ae2 | |||
| 28d761e15b | |||
| 2a78431bf8 | |||
| 89bf6aa4c9 | |||
| 7b76ed9514 |
@@ -42,6 +42,7 @@ script-tests: ## Run shell script tests
|
||||
$(RUSTFS_PYTHON_BIN) ./scripts/test_internode_msgpack_peer_canary.py
|
||||
./scripts/test_internode_msgpack_peer_canary_runner.sh
|
||||
./scripts/test_object_batch_bench_enhanced.sh
|
||||
$(RUSTFS_PYTHON_BIN) ./scripts/test_inline_docker_lab.py
|
||||
./scripts/test_package_service_scripts.sh
|
||||
./scripts/test_hotpath_warp_ab_gate.sh
|
||||
./scripts/test_hotpath_warp_abba.sh
|
||||
|
||||
@@ -22,7 +22,7 @@ rustfs-connect-symbol-catalog 6 0
|
||||
rustfs-credentials 24 0
|
||||
rustfs-crypto 67 0
|
||||
rustfs-data-usage 58 0
|
||||
rustfs-ecstore 7858 2
|
||||
rustfs-ecstore 7858 3
|
||||
rustfs-extension-schema 23 0
|
||||
rustfs-filemeta 361 0
|
||||
rustfs-gateway-adapter 74 0
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
# syntax=docker/dockerfile:1.6
|
||||
# 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.
|
||||
|
||||
# Server-only Linux validation image. The build context supplies a Git bundle.
|
||||
FROM rust:1.100.0-trixie AS build-tools
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates clang lld libssl-dev pkg-config protobuf-compiler python3 python3-boto3 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
ENV RUSTUP_TOOLCHAIN=1.100.0 \
|
||||
CARGO_BUILD_JOBS=4 \
|
||||
CARGO_NET_GIT_FETCH_WITH_CLI=true \
|
||||
CARGO_TARGET_DIR=/work/rustfs/target \
|
||||
RUSTFLAGS="-C link-arg=-fuse-ld=lld"
|
||||
|
||||
FROM build-tools AS build
|
||||
ARG SOURCE_REVISION
|
||||
COPY repository.bundle /tmp/repository.bundle
|
||||
COPY inspect_geometry.rs /tmp/inspect_geometry.rs
|
||||
RUN git clone /tmp/repository.bundle /work/rustfs \
|
||||
&& git -C /work/rustfs checkout --detach "$SOURCE_REVISION" \
|
||||
&& test "$(git -C /work/rustfs rev-parse HEAD)" = "$SOURCE_REVISION"
|
||||
WORKDIR /work/rustfs
|
||||
RUN --mount=type=cache,id=rustfs-inline-registry,target=/usr/local/cargo/registry \
|
||||
--mount=type=cache,id=rustfs-inline-git,target=/usr/local/cargo/git \
|
||||
--mount=type=cache,id=rustfs-inline-linux-target,target=/work/rustfs/target \
|
||||
cargo build --locked --release --bin rustfs \
|
||||
&& install -Dm755 target/release/rustfs /out/rustfs
|
||||
|
||||
# Build the diagnostic tool after preserving the clean-source server binary.
|
||||
RUN cp /tmp/inspect_geometry.rs crates/filemeta/examples/inline_lab_inspect.rs
|
||||
RUN --mount=type=cache,id=rustfs-inline-registry,target=/usr/local/cargo/registry \
|
||||
--mount=type=cache,id=rustfs-inline-git,target=/usr/local/cargo/git \
|
||||
--mount=type=cache,id=rustfs-inline-linux-target,target=/work/rustfs/target \
|
||||
cargo build --locked --release -p rustfs-filemeta --example inline_lab_inspect \
|
||||
&& install -Dm755 target/release/examples/inline_lab_inspect /out/inline_lab_inspect
|
||||
|
||||
FROM debian:trixie-slim AS runtime
|
||||
RUN apt-get update && apt-get install -y --no-install-recommends \
|
||||
ca-certificates curl libssl3t64 \
|
||||
&& rm -rf /var/lib/apt/lists/*
|
||||
ARG SOURCE_REVISION
|
||||
LABEL org.opencontainers.image.revision="$SOURCE_REVISION" \
|
||||
rustfs.validation="inline"
|
||||
COPY --from=build /out/rustfs /usr/local/bin/rustfs
|
||||
COPY --from=build /out/inline_lab_inspect /usr/local/bin/inline_lab_inspect
|
||||
ENTRYPOINT ["/usr/local/bin/rustfs"]
|
||||
@@ -0,0 +1,5 @@
|
||||
FROM debian:trixie-slim
|
||||
COPY mc /usr/bin/mc
|
||||
RUN chmod 0755 /usr/bin/mc && /usr/bin/mc --version
|
||||
LABEL rustfs.validation="inline"
|
||||
ENTRYPOINT ["/usr/bin/mc"]
|
||||
@@ -0,0 +1,133 @@
|
||||
# Inline geometry Linux lab
|
||||
|
||||
**Use this when** validating inline placement, block geometry, Range reads and reader rollback in a task-owned local Docker cluster.
|
||||
|
||||
The adapter reuses the repository's four-node compose topology with 16 logical Docker volumes and EC12+4. It binds one S3 port to loopback, keeps strict durability and checks running binary hashes and persisted object geometry. Docker volumes share the host storage substrate. Performance observations describe this local virtualized lab.
|
||||
|
||||
## Build a frozen server image
|
||||
|
||||
Use the current stable toolchain pinned in the lab Dockerfile. Supply a Git bundle and the metadata inspector source as the build context. The server is compiled from a clean checkout before the diagnostic example is added.
|
||||
|
||||
```bash
|
||||
set -euo pipefail
|
||||
LAB_BUILD_DIR="$(mktemp -d)"
|
||||
LAB_REVISION="$(git rev-parse HEAD)"
|
||||
git bundle create "$LAB_BUILD_DIR/repository.bundle" HEAD
|
||||
cp crates/filemeta/examples/inline_lab_inspect.rs "$LAB_BUILD_DIR/inspect_geometry.rs"
|
||||
docker --context "$LAB_CONTEXT" build --target build-tools \
|
||||
-t rustfs-inline-build-tools:1.100 \
|
||||
-f .docker/inline-lab/Dockerfile .docker/inline-lab
|
||||
docker --context "$LAB_CONTEXT" build \
|
||||
--build-arg SOURCE_REVISION="$LAB_REVISION" \
|
||||
-t rustfs-inline-validation:local \
|
||||
-f .docker/inline-lab/Dockerfile "$LAB_BUILD_DIR"
|
||||
LAB_EXPORT_ID="$(docker --context "$LAB_CONTEXT" create \
|
||||
--label rustfs.validation=inline rustfs-inline-validation:local)"
|
||||
docker --context "$LAB_CONTEXT" cp \
|
||||
"$LAB_EXPORT_ID:/usr/local/bin/rustfs" "$LAB_BUILD_DIR/rustfs-linux"
|
||||
docker --context "$LAB_CONTEXT" rm "$LAB_EXPORT_ID"
|
||||
```
|
||||
|
||||
## Configure and probe
|
||||
|
||||
Select a new compose project and a private state directory. The adapter generates test credentials there. Existing resources require matching ownership labels. Configure checks the image's source revision and pins immutable image IDs. Each operation takes an exclusive state lock. Deployment waits for `/health/ready` on every node, covering storage, IAM, lock quorum and peer dependencies.
|
||||
|
||||
```bash
|
||||
scripts/python_bin.sh scripts/inline_docker_lab.py --state-dir "$LAB_STATE" configure \
|
||||
--context "$LAB_CONTEXT" --project "$LAB_PROJECT" \
|
||||
--image rustfs-inline-validation:local --revision "$LAB_REVISION" \
|
||||
--binary "$LAB_BUILD_DIR/rustfs-linux" --port 19080
|
||||
scripts/python_bin.sh scripts/inline_docker_lab.py --state-dir "$LAB_STATE" deploy \
|
||||
--bucket inline-geometry-probe --shard-bytes 0
|
||||
scripts/python_bin.sh scripts/inline_docker_lab.py --state-dir "$LAB_STATE" probe \
|
||||
--bucket inline-geometry-probe
|
||||
```
|
||||
|
||||
The probe verifies complete bytes, HEAD sizes, Range contents, EC12+4 and the actual persisted block. It records inline markers for 4 KiB, 1 MiB, 1 MiB + 1 byte, 1.25 MiB, 1,572,856 bytes, 1,572,857 bytes and 1.5 MiB objects in `probe.json`. The server-only image includes the existing filemeta decoder through a small geometry inspector. Console assets and the administration CLI are outside this lab image.
|
||||
|
||||
## ABBA deployment hook
|
||||
|
||||
Use `inline_docker_lab.py ... deploy` in the existing `run_hotpath_warp_abba.sh` external deploy hook. Export `RUSTFS_ERASURE_SHARD_BYTES` according to `HOTPATH_ABBA_PHASE`. The adapter uses the supplied leg, phase, bucket, binary and evidence-file context, resets only owned lab volumes, checks running configuration and binary hashes, creates the fresh bucket and writes the runner's deployment evidence.
|
||||
|
||||
Use the same frozen binary for both sides of a geometry experiment. Fix the inline budget and encoding mode, then compare zero with one candidate shard value. Include the CPU, memory and image identities from every node in each result. The state `config.json` supplies the generated test credentials for the load driver. Set `DOCKER_CONTEXT` to the selected context when the driver captures Docker resource snapshots.
|
||||
|
||||
For content compatibility across an image or geometry change, configure the next selected image and artifact using the same state, then deploy with `--keep-data` and an existing bucket. This retains owned volumes. Compare existing objects and version IDs with the manifest prepared before the change.
|
||||
|
||||
## Cleanup
|
||||
|
||||
```bash
|
||||
scripts/python_bin.sh scripts/inline_docker_lab.py --state-dir "$LAB_STATE" down --purge
|
||||
```
|
||||
|
||||
Cleanup checks ownership for containers, volumes and networks. A configuration cannot adopt another project's resources. Raw measurements, state, Git bundles and build outputs stay in task artifact directories.
|
||||
|
||||
Unit checks run with `scripts/python_bin.sh scripts/test_inline_docker_lab.py` and are included in `make script-tests`.
|
||||
|
||||
## Linux content-probe client
|
||||
|
||||
The PUT after-probe requires a working `mc`. For a macOS client affected by cgo initialization failures, compile the same frozen public mc module for Linux with CGO disabled, build it with `Dockerfile.mc`, and use `scripts/inline_docker_mc.sh` as the process-local `mc` command. Record the module version, checksum and resulting image ID with the run.
|
||||
|
||||
The adapter rewrites only the lab loopback alias endpoint to the private `node1` endpoint. Alias configuration stays in the probe's own `MC_CONFIG_DIR`, and `cat` streams raw bytes. The existing HEAD, GET and hash checks continue to execute.
|
||||
|
||||
```bash
|
||||
export RUSTFS_INLINE_LAB_STATE="$LAB_STATE"
|
||||
export RUSTFS_INLINE_MC_IMAGE="$LAB_MC_IMAGE"
|
||||
mkdir -p "$LAB_TOOLS"
|
||||
ln -s "$PWD/scripts/inline_docker_mc.sh" "$LAB_TOOLS/mc"
|
||||
export PATH="$LAB_TOOLS:$PATH"
|
||||
```
|
||||
|
||||
## Compare transport and placement independently
|
||||
|
||||
`deploy --rpc-mode json-compat` explicitly clears both MessagePack-only flags on every node. `deploy --rpc-mode msgpack-only` enables both flags for the selected homogeneous lab fleet. Deployment evidence records the mode and checks both running flags. The default is `json-compat`. The ABBA hook may select the same mode through `RUSTFS_INLINE_LAB_RPC_MODE`.
|
||||
|
||||
First compare the base and bounded-multi-block binaries at `--shard-bytes 0` in JSON compatibility mode. Then repeat with MessagePack-only on both sides. A same-binary transport ABBA isolates the encoding effect. Keep the 128 KiB budget, CPU sets, strict durability, load and object set fixed. Check actual markers and block sizes at the boundary sizes before timing. Retain baseline-drift and candidate gates, error logs and raw request distributions.
|
||||
|
||||
For a rolling downgrade, redeploy the current binary with `--keep-data --rpc-mode json-compat` before introducing an older node. Check old and new reads, version IDs and batch deletes against the persisted manifest. A running MessagePack-only flag pair establishes the lab configuration. Compatibility with a particular old reader requires the explicit reader test.
|
||||
|
||||
## Preserve a compatibility manifest
|
||||
|
||||
Run the seed once in a fresh lab bucket. It records full byte oracles and the observed version inventory, including any additional version matching a known body, and leaves a 5 MiB multipart part ready for the next reader. Each bucket has its own private `compat-<bucket>.json` manifest. Keep the same state and volumes across image changes. A fresh deployment or cleanup that resets volumes moves existing compatibility manifests into `compat-history`. Retained-data deployments preserve the active manifests.
|
||||
|
||||
```bash
|
||||
scripts/python_bin.sh scripts/inline_docker_lab.py --state-dir "$LAB_STATE" compat-seed --bucket inline-compat
|
||||
scripts/python_bin.sh scripts/inline_docker_lab.py --state-dir "$LAB_STATE" compat-check --bucket inline-compat
|
||||
# Configure the next frozen image and binary, then retain the data.
|
||||
scripts/python_bin.sh scripts/inline_docker_lab.py --state-dir "$LAB_STATE" deploy \
|
||||
--bucket inline-compat --shard-bytes 0 --rpc-mode json-compat --keep-data
|
||||
scripts/python_bin.sh scripts/inline_docker_lab.py --state-dir "$LAB_STATE" compat-check --bucket inline-compat
|
||||
scripts/python_bin.sh scripts/inline_docker_lab.py --state-dir "$LAB_STATE" compat-finish-mpu --bucket inline-compat
|
||||
```
|
||||
|
||||
The check compares every persisted version ID, HEAD length, complete SHA256, cross-block Range and per-version geometry from `xl.meta`. The seed includes zero-length objects, null versions, the 192 KiB versioned admission boundary and the accumulated 128 KiB shard boundary. Seed a second bucket on the new writer before the downgrade, then check both manifests using the selected old reader. Complete an old upload on the new binary and a new upload on the old binary. After returning to the current fleet, `compat-delete --bucket <bucket>` deletes the recorded versions in one S3 batch and checks the exact remaining inventory and bytes.
|
||||
|
||||
Successful multipart-completion and batch-delete receipts are saved before subsequent content and geometry checks. If either check fails, rerun the same command with the same state directory to resume verification from the saved completion state. After a seed check fails with a saved manifest, use `compat-check` to resume verification.
|
||||
|
||||
For mixed-version testing, retain JSON compatibility mode throughout the rolling replacement. Verify each node's immutable image and binary, then perform manifest checks and new writes through both coordinator versions using `--coordinator node1` and `--coordinator node4`. The manifest records the actual writer coordinator revision from the running image. Stop one owned node to check read availability at EC12+4, restore it and check the manifests again. Record the exact oldest tested source revision, toolchain and build profile with the evidence. The version boundary is established by these executed cells.
|
||||
|
||||
An owned lab can replace just its fourth node through a compose image override. Select the frozen old image first and verify its revision label. Keep `compose.json` in JSON compatibility mode for this cell.
|
||||
|
||||
```bash
|
||||
set -euo pipefail
|
||||
OLD_IMAGE_ID="$(docker --context "$LAB_CONTEXT" image inspect "$OLD_IMAGE" --format '{{.Id}}')"
|
||||
test "$(docker --context "$LAB_CONTEXT" image inspect "$OLD_IMAGE_ID" --format '{{index .Config.Labels "org.opencontainers.image.revision"}}')" = "$OLD_REVISION"
|
||||
INLINE_OLD_IMAGE_ID="$OLD_IMAGE_ID" scripts/python_bin.sh - <<'PYTHON' > "$LAB_STATE/mixed-image.json"
|
||||
import json
|
||||
import os
|
||||
import sys
|
||||
|
||||
override = {"services": {"node4": {"image": os.environ["INLINE_OLD_IMAGE_ID"]}}}
|
||||
json.dump(override, sys.stdout)
|
||||
PYTHON
|
||||
docker --context "$LAB_CONTEXT" compose --project-name "$LAB_PROJECT" \
|
||||
--file "$LAB_STATE/compose.json" --file "$LAB_STATE/mixed-image.json" \
|
||||
up --detach --no-deps --no-build --pull never node4
|
||||
scripts/python_bin.sh scripts/inline_docker_lab.py --state-dir "$LAB_STATE" compat-check \
|
||||
--bucket inline-compat --coordinator node4
|
||||
scripts/python_bin.sh scripts/inline_docker_lab.py --state-dir "$LAB_STATE" compat-seed \
|
||||
--bucket inline-mixed-writer --coordinator node4
|
||||
scripts/python_bin.sh scripts/inline_docker_lab.py --state-dir "$LAB_STATE" compat-check \
|
||||
--bucket inline-mixed-writer --coordinator node1
|
||||
```
|
||||
|
||||
Inspect all four running image IDs and binary hashes before recording the mixed-fleet result. Redeploy the configured current image with `--keep-data --rpc-mode json-compat` to restore a homogeneous fleet. The same manifest checks apply after stopping and restarting one owned node through the base compose file.
|
||||
@@ -2559,9 +2559,44 @@ fn encode_file_info_versions_msgpack(value: &FileInfoVersions) -> Result<Vec<u8>
|
||||
encode_msgpack_with_capacity(value, capacity)
|
||||
}
|
||||
|
||||
/// JSON compatibility string for a dual-encoded (`_bin` + text) request field. Returns an empty
|
||||
/// string only when msgpack-only mode and its explicit fleet confirmation guard are both enabled;
|
||||
/// otherwise the legacy JSON encoding is retained for old peers.
|
||||
fn encode_delete_versions_request(
|
||||
disk: String,
|
||||
volume: &str,
|
||||
versions: &[FileInfoVersions],
|
||||
opts: &DeleteOptions,
|
||||
) -> Result<DeleteVersionsRequest> {
|
||||
// Binary-only batches require fleet-confirmed receivers that traverse the
|
||||
// binary list. Capture that policy for the complete batch and its options.
|
||||
let msgpack_only = rustfs_protos::internode_rpc_msgpack_only();
|
||||
let opts_json = if msgpack_only {
|
||||
String::new()
|
||||
} else {
|
||||
serde_json::to_string(opts)?
|
||||
};
|
||||
let mut versions_json = if msgpack_only {
|
||||
Vec::new()
|
||||
} else {
|
||||
Vec::with_capacity(versions.len())
|
||||
};
|
||||
let mut versions_bin = Vec::with_capacity(versions.len());
|
||||
for version in versions {
|
||||
if !msgpack_only {
|
||||
versions_json.push(serde_json::to_string(version)?);
|
||||
}
|
||||
versions_bin.push(encode_file_info_versions_msgpack(version)?.into());
|
||||
}
|
||||
Ok(DeleteVersionsRequest {
|
||||
disk,
|
||||
volume: volume.to_owned(),
|
||||
versions: versions_json,
|
||||
opts: opts_json,
|
||||
versions_bin,
|
||||
opts_bin: encode_delete_options_msgpack(opts)?.into(),
|
||||
})
|
||||
}
|
||||
|
||||
/// JSON compatibility string for a dual-encoded request field. The captured
|
||||
/// send policy selects the encoding, and its generation guard binds dispatch.
|
||||
fn compat_json<T: Serialize>(value: &T, policy: &MsgpackSendPolicy) -> Result<String> {
|
||||
if policy.omit_eligible_json() {
|
||||
return Ok(String::new());
|
||||
@@ -3547,52 +3582,10 @@ impl DiskAPI for RemoteDisk {
|
||||
return vec![Some(DiskError::FaultyDisk); versions.len()];
|
||||
}
|
||||
|
||||
// `_bin` support for DeleteVersions is new (grpc-optimization P2); always dual-write JSON +
|
||||
// msgpack until its fallback counter has read zero across a release window.
|
||||
let opts_bin = match encode_delete_options_msgpack(&opts) {
|
||||
Ok(opts_bin) => opts_bin,
|
||||
Err(err) => {
|
||||
let mut errors = Vec::with_capacity(versions.len());
|
||||
for _ in 0..versions.len() {
|
||||
errors.push(Some(Error::other(err.to_string())));
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
let request = match encode_delete_versions_request(self.endpoint.to_string(), volume, &versions, &opts) {
|
||||
Ok(request) => request,
|
||||
Err(err) => return vec![Some(Error::other(err.to_string())); versions.len()],
|
||||
};
|
||||
let opts = match serde_json::to_string(&opts) {
|
||||
Ok(opts) => opts,
|
||||
Err(err) => {
|
||||
let mut errors = Vec::with_capacity(versions.len());
|
||||
for _ in 0..versions.len() {
|
||||
errors.push(Some(Error::other(err.to_string())));
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
};
|
||||
let mut versions_str = Vec::with_capacity(versions.len());
|
||||
let mut versions_bin = Vec::with_capacity(versions.len());
|
||||
for file_info_versions in versions.iter() {
|
||||
versions_str.push(match serde_json::to_string(file_info_versions) {
|
||||
Ok(versions_str) => versions_str,
|
||||
Err(err) => {
|
||||
let mut errors = Vec::with_capacity(versions.len());
|
||||
for _ in 0..versions.len() {
|
||||
errors.push(Some(Error::other(err.to_string())));
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
});
|
||||
versions_bin.push(match encode_file_info_versions_msgpack(file_info_versions) {
|
||||
Ok(versions_bin) => Bytes::from(versions_bin),
|
||||
Err(err) => {
|
||||
let mut errors = Vec::with_capacity(versions.len());
|
||||
for _ in 0..versions.len() {
|
||||
errors.push(Some(Error::other(err.to_string())));
|
||||
}
|
||||
return errors;
|
||||
}
|
||||
});
|
||||
}
|
||||
let mut client = match self.get_client().await {
|
||||
Ok(client) => client,
|
||||
Err(err) => {
|
||||
@@ -3604,14 +3597,7 @@ impl DiskAPI for RemoteDisk {
|
||||
}
|
||||
};
|
||||
|
||||
let mut request = Request::new(DeleteVersionsRequest {
|
||||
disk: self.endpoint.to_string(),
|
||||
volume: volume.to_string(),
|
||||
versions: versions_str,
|
||||
opts,
|
||||
versions_bin,
|
||||
opts_bin: opts_bin.into(),
|
||||
});
|
||||
let mut request = Request::new(request);
|
||||
let canonical_body = rustfs_protos::canonical_delete_versions_request_body(request.get_ref());
|
||||
if let Err(err) = attach_mutation_body_digest(&mut request, canonical_body, "delete_versions") {
|
||||
let mut errors = Vec::with_capacity(versions.len());
|
||||
@@ -6337,6 +6323,94 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete_versions_request_encoding_preserves_batches_and_fleet_guards() {
|
||||
use tonic_prost::prost::Message;
|
||||
let groups: Vec<_> = ["first", "second"]
|
||||
.into_iter()
|
||||
.map(|name| FileInfoVersions {
|
||||
volume: "bucket".to_owned(),
|
||||
name: name.to_owned(),
|
||||
versions: vec![sample_rename_data_file_info()],
|
||||
..Default::default()
|
||||
})
|
||||
.collect();
|
||||
let opts = DeleteOptions {
|
||||
undo_write: true,
|
||||
old_data_dir: Some(Uuid::from_u128(7)),
|
||||
..Default::default()
|
||||
};
|
||||
let mut binary_wire_size = 0;
|
||||
let mut compat_wire_size = 0;
|
||||
for (requested, confirmed, peer_capability, binary_only) in [
|
||||
(None, None, None, false),
|
||||
(Some("true"), None, None, false),
|
||||
(Some("false"), Some("true"), None, false),
|
||||
(Some("true"), Some("false"), None, false),
|
||||
(Some("true"), None, Some("true"), false),
|
||||
(Some("true"), Some("false"), Some("true"), false),
|
||||
(Some("true"), Some("true"), None, true),
|
||||
(Some("true"), Some("true"), Some("true"), true),
|
||||
] {
|
||||
with_internode_msgpack_env(
|
||||
[
|
||||
(rustfs_config::ENV_INTERNODE_RPC_MSGPACK_ONLY, requested),
|
||||
(rustfs_config::ENV_INTERNODE_RPC_MSGPACK_ONLY_FLEET_CONFIRMED, confirmed),
|
||||
(rustfs_config::ENV_INTERNODE_RPC_MSGPACK_PEER_CAPABILITY, peer_capability),
|
||||
],
|
||||
|| {
|
||||
for batch in [&groups[..], &[]] {
|
||||
let disk = "disk".to_owned();
|
||||
let disk_buffer = disk.as_ptr();
|
||||
let request = encode_delete_versions_request(disk, "bucket", batch, &opts).expect("encode batch");
|
||||
assert_eq!(request.disk, "disk");
|
||||
assert_eq!(request.disk.as_ptr(), disk_buffer, "move the prepared endpoint into the request");
|
||||
assert_eq!(request.volume, "bucket");
|
||||
assert_eq!(request.versions_bin.len(), batch.len());
|
||||
assert_eq!(request.opts.is_empty(), binary_only);
|
||||
let decoded_opts: DeleteOptions = rmp_serde::from_slice(&request.opts_bin).expect("binary options");
|
||||
assert!(decoded_opts.undo_write);
|
||||
assert_eq!(decoded_opts.old_data_dir, opts.old_data_dir);
|
||||
for (encoded, expected) in request.versions_bin.iter().zip(batch) {
|
||||
let decoded: FileInfoVersions = rmp_serde::from_slice(encoded).expect("binary batch item");
|
||||
assert_eq!(decoded.name, expected.name);
|
||||
assert_eq!(decoded.versions, expected.versions);
|
||||
}
|
||||
if binary_only {
|
||||
assert!(request.versions.is_empty());
|
||||
} else {
|
||||
assert_eq!(request.opts, serde_json::to_string(&opts).expect("legacy options"));
|
||||
assert_eq!(request.versions.len(), batch.len());
|
||||
for (encoded, expected) in request.versions.iter().zip(batch) {
|
||||
let decoded: FileInfoVersions = serde_json::from_str(encoded).expect("legacy batch item");
|
||||
assert_eq!(decoded.name, expected.name);
|
||||
assert_eq!(decoded.versions, expected.versions);
|
||||
}
|
||||
}
|
||||
let canonical = rustfs_protos::canonical_delete_versions_request_body(&request).expect("bound batch");
|
||||
let mut modified = request.clone();
|
||||
modified.opts_bin = encode_delete_options_msgpack(&DeleteOptions::default())
|
||||
.expect("other options")
|
||||
.into();
|
||||
assert_ne!(
|
||||
canonical,
|
||||
rustfs_protos::canonical_delete_versions_request_body(&modified).expect("other bound batch")
|
||||
);
|
||||
if !batch.is_empty() {
|
||||
if binary_only {
|
||||
binary_wire_size = request.encoded_len();
|
||||
} else {
|
||||
compat_wire_size = request.encoded_len();
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
assert!(binary_wire_size > 0 && binary_wire_size < compat_wire_size);
|
||||
println!("delete batch encoded bytes compat={compat_wire_size} msgpack_only={binary_wire_size}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn msgpack_eligible_requests_bind_one_policy_and_bounded_local_retry() {
|
||||
let source = rustfs_protos::compat_manifest::production_source(include_str!("remote_disk.rs"), "remote_disk.rs");
|
||||
@@ -7287,7 +7361,10 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
fn with_internode_msgpack_env<R>(vars: [(&'static str, Option<&'static str>); 2], f: impl FnOnce() -> R) -> R {
|
||||
fn with_internode_msgpack_env<R, const N: usize>(
|
||||
vars: [(&'static str, Option<&'static str>); N],
|
||||
f: impl FnOnce() -> R,
|
||||
) -> R {
|
||||
temp_env::with_vars(vars, || {
|
||||
rustfs_protos::reset_internode_rpc_msgpack_only_cache();
|
||||
let result = f();
|
||||
|
||||
@@ -101,7 +101,6 @@ const DEFAULT_RRS_STORAGE_CLASS: &str = "EC:1";
|
||||
const ZERO_SET_DRIVE_COUNT_ERROR: &str = "set drive count must be greater than zero";
|
||||
|
||||
pub static DEFAULT_INLINE_BLOCK: usize = 128 * 1024;
|
||||
const DEFAULT_INLINE_OBJECT_BUDGET: usize = 2 * DEFAULT_INLINE_BLOCK;
|
||||
|
||||
pub static DEFAULT_KVS: LazyLock<KVS> = LazyLock::new(|| {
|
||||
let kvs = vec![
|
||||
@@ -152,6 +151,7 @@ pub struct Config {
|
||||
inline_block: usize,
|
||||
initialized: bool,
|
||||
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
|
||||
// Preserve the explicit-limit marker when configurations round-trip through older readers.
|
||||
inline_block_explicit: bool,
|
||||
#[serde(skip)]
|
||||
standard_parities: Vec<PoolParity>,
|
||||
@@ -245,8 +245,10 @@ impl Config {
|
||||
return false;
|
||||
}
|
||||
|
||||
let shard_size = shard_size as usize;
|
||||
let inline_block = self.effective_inline_block(data_shards);
|
||||
let Ok(shard_size) = usize::try_from(shard_size) else {
|
||||
return false;
|
||||
};
|
||||
let inline_block = self.inline_block();
|
||||
|
||||
if versioned {
|
||||
shard_size <= inline_block / 8
|
||||
@@ -255,27 +257,7 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the per-shard inline budget used by both write admission and
|
||||
/// legacy read fallback.
|
||||
///
|
||||
/// The default budget is scaled by the number of data shards so a wider EC
|
||||
/// layout does not silently increase the maximum inline object size. An
|
||||
/// explicitly configured `inline_block` remains a fixed per-shard limit for
|
||||
/// compatibility with deployments that opted into the historical policy.
|
||||
pub(crate) fn effective_inline_block(&self, data_shards: usize) -> usize {
|
||||
if data_shards == 0 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if self.initialized && self.inline_block_explicit {
|
||||
self.inline_block
|
||||
} else {
|
||||
// Keep the historical two-data-shard object budget while preventing
|
||||
// wider EC layouts from multiplying the maximum inline object size.
|
||||
DEFAULT_INLINE_OBJECT_BUDGET.div_ceil(data_shards).min(DEFAULT_INLINE_BLOCK)
|
||||
}
|
||||
}
|
||||
|
||||
/// Per-shard inline data budget, defaulting to 128 KiB across EC layouts.
|
||||
pub fn inline_block(&self) -> usize {
|
||||
if !self.initialized {
|
||||
DEFAULT_INLINE_BLOCK
|
||||
@@ -567,7 +549,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_inline_scales_default_threshold_by_data_shards() {
|
||||
fn should_inline_uses_fixed_default_threshold_for_every_ec_layout() {
|
||||
let config = lookup_config_for_pools_with_env(&KVS::new(), &[3, 12], no_env_overrides())
|
||||
.expect("default inline policy should resolve for EC2+1 and EC8+4");
|
||||
|
||||
@@ -576,10 +558,14 @@ mod tests {
|
||||
("EC2+1 unversioned above", 128 * 1024 + 1, 2, false, false),
|
||||
("EC2+1 versioned exact", 16 * 1024, 2, true, true),
|
||||
("EC2+1 versioned above", 16 * 1024 + 1, 2, true, false),
|
||||
("EC8+4 unversioned exact", 32 * 1024, 8, false, true),
|
||||
("EC8+4 unversioned above", 32 * 1024 + 1, 8, false, false),
|
||||
("EC8+4 versioned exact", 4 * 1024, 8, true, true),
|
||||
("EC8+4 versioned above", 4 * 1024 + 1, 8, true, false),
|
||||
("EC8+4 unversioned exact", 128 * 1024, 8, false, true),
|
||||
("EC8+4 unversioned above", 128 * 1024 + 1, 8, false, false),
|
||||
("EC8+4 versioned exact", 16 * 1024, 8, true, true),
|
||||
("EC8+4 versioned above", 16 * 1024 + 1, 8, true, false),
|
||||
("EC12+4 unversioned exact", 128 * 1024, 12, false, true),
|
||||
("EC12+4 unversioned above", 128 * 1024 + 1, 12, false, false),
|
||||
("EC12+4 versioned exact", 16 * 1024, 12, true, true),
|
||||
("EC12+4 versioned above", 16 * 1024 + 1, 12, true, false),
|
||||
("negative", -1, 2, false, false),
|
||||
("zero data shards", 0, 0, false, false),
|
||||
] {
|
||||
@@ -626,37 +612,35 @@ mod tests {
|
||||
let shard_size = erasure.shard_file_size(object_size);
|
||||
let inline = config.should_inline(shard_size, data_shards, false);
|
||||
|
||||
// The effective policy is monotonic across object sizes. This
|
||||
// table covers the boundaries that previously exposed the
|
||||
// fixed-shard read-ahead mismatch, including the 1 MiB case.
|
||||
// The per-shard budget stays monotonic across object sizes.
|
||||
// PUT separately bounds inline body materialization.
|
||||
assert!(!inline || previous, "inline decision must not re-enable at {object_size} bytes");
|
||||
previous = inline;
|
||||
}
|
||||
|
||||
assert!(
|
||||
!config.should_inline(erasure.shard_file_size(1024 * 1024), data_shards, false),
|
||||
"1 MiB must use the non-inline path for EC{data_shards}+{parity_shards}"
|
||||
config.should_inline(erasure.shard_file_size(1024 * 1024), data_shards, false),
|
||||
"1 MiB fits the per-shard budget for EC{data_shards}+{parity_shards}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn effective_inline_block_scales_default_budget_and_preserves_explicit_limit() {
|
||||
fn inline_block_preserves_fixed_default_and_explicit_limits() {
|
||||
let config = Config::default();
|
||||
assert_eq!(config.effective_inline_block(8), 32 * 1024);
|
||||
assert_eq!(config.effective_inline_block(12), 21_846);
|
||||
assert_eq!(config.effective_inline_block(0), 0);
|
||||
assert_eq!(config.inline_block(), 128 * 1024);
|
||||
assert!(!config.should_inline(0, 0, false));
|
||||
|
||||
let explicit = lookup_config_for_pools_with_env(
|
||||
&KVS::new(),
|
||||
&[12],
|
||||
StorageClassEnvOverrides {
|
||||
inline_block: Some("128KiB".to_string()),
|
||||
inline_block: Some("32KiB".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.expect("explicit inline block should resolve");
|
||||
assert_eq!(explicit.effective_inline_block(12), 128 * 1024);
|
||||
assert_eq!(explicit.inline_block(), 32 * 1024);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -905,6 +889,21 @@ mod tests {
|
||||
assert!(decoded.should_inline(100 * 1024, 8, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_scalar_inline_config_preserves_limit_without_explicit_marker() {
|
||||
let cfg = lookup_config_for_pools_with_env(&KVS::new(), &[12], no_env_overrides())
|
||||
.expect("default storage class should resolve");
|
||||
let mut legacy = serde_json::to_value(cfg).expect("serialize scalar config");
|
||||
legacy["inline_block"] = serde_json::json!(64 * 1024);
|
||||
legacy.as_object_mut().expect("config object").remove("inline_block_explicit");
|
||||
let decoded: Config = serde_json::from_value(legacy).expect("read historical scalar config");
|
||||
|
||||
assert!(decoded.should_inline(64 * 1024, 8, false));
|
||||
assert!(!decoded.should_inline(64 * 1024 + 1, 8, false));
|
||||
assert!(decoded.should_inline(8 * 1024, 8, true));
|
||||
assert!(!decoded.should_inline(8 * 1024 + 1, 8, true));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn lookup_config_reads_rrs_from_class_rrs_key() {
|
||||
// Regression: kvs.get(RRS) used RRS="REDUCED_REDUNDANCY" instead of
|
||||
|
||||
@@ -17643,12 +17643,9 @@ impl DiskAPI for LocalDisk {
|
||||
fi.data = None;
|
||||
}
|
||||
|
||||
// Keep this compatibility read-ahead decision on the same policy
|
||||
// as PUT's inline admission. In particular, do not use the old
|
||||
// fixed 128 KiB shard limit: a non-inline object in a wider EC
|
||||
// layout can have a smaller shard and would otherwise be copied
|
||||
// out of part.1 during every metadata read. Such objects remain
|
||||
// fully readable through the normal EC reader below.
|
||||
// Keep legacy external prefetch within one block during metadata
|
||||
// fanout. Persisted inline payloads are loaded by their marker and
|
||||
// can contain several frames without reading external part files.
|
||||
let storage_class_config = runtime_sources::storage_class_config_snapshot();
|
||||
if should_read_legacy_inline_part(&fi, storage_class_config.as_ref()) {
|
||||
let part_path = path_join_buf(&[
|
||||
@@ -17921,6 +17918,9 @@ fn should_read_legacy_inline_part(fi: &FileInfo, storage_class_config: &crate::c
|
||||
}
|
||||
|
||||
let part = &fi.parts[0];
|
||||
if !usize::try_from(part.actual_size).is_ok_and(|size| size <= fi.erasure.block_size) {
|
||||
return false;
|
||||
}
|
||||
let shard_size = fi.shard_file_size(part.actual_size);
|
||||
let versioned = fi.versioned || fi.version_id.is_some_and(|version_id| !version_id.is_nil());
|
||||
storage_class_config.should_inline(shard_size, fi.erasure.data_blocks, versioned)
|
||||
@@ -18643,9 +18643,16 @@ mod test {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_inline_read_ahead_matches_writer_policy_for_ec_layouts() {
|
||||
fn legacy_inline_read_ahead_stays_single_block_for_ec_layouts() {
|
||||
let config = crate::config::storageclass::Config::default();
|
||||
let object_sizes = [128 * 1024_i64, 256 * 1024, 512 * 1024, 1024 * 1024, 4 * 1024 * 1024];
|
||||
let object_sizes = [
|
||||
128 * 1024_i64,
|
||||
256 * 1024,
|
||||
512 * 1024,
|
||||
1024 * 1024,
|
||||
1024 * 1024 + 1,
|
||||
4 * 1024 * 1024,
|
||||
];
|
||||
|
||||
for (data_shards, parity_shards) in [(8, 4), (12, 4)] {
|
||||
for object_size in object_sizes {
|
||||
@@ -18658,7 +18665,8 @@ mod test {
|
||||
..Default::default()
|
||||
}];
|
||||
|
||||
let writer_decision = config.should_inline(fi.shard_file_size(object_size), data_shards, false);
|
||||
let writer_decision = config.should_inline(fi.shard_file_size(object_size), data_shards, false)
|
||||
&& usize::try_from(object_size).expect("test size") <= fi.erasure.block_size;
|
||||
assert_eq!(
|
||||
should_read_legacy_inline_part(&fi, &config),
|
||||
writer_decision,
|
||||
@@ -18671,13 +18679,13 @@ mod test {
|
||||
ec12.data_dir = Some(Uuid::from_u128(1));
|
||||
ec12.parts = vec![ObjectPartInfo {
|
||||
number: 1,
|
||||
size: 1024 * 1024,
|
||||
actual_size: 1024 * 1024,
|
||||
size: 1024 * 1024 + 1,
|
||||
actual_size: 1024 * 1024 + 1,
|
||||
..Default::default()
|
||||
}];
|
||||
assert!(
|
||||
ec12.shard_file_size(1024 * 1024) < crate::config::storageclass::DEFAULT_INLINE_BLOCK as i64,
|
||||
"the regression guard must exercise the old fixed 128 KiB read-ahead boundary"
|
||||
ec12.shard_file_size(1024 * 1024 + 1) < 128 * 1024,
|
||||
"a multi-block external object can still fit the per-shard budget"
|
||||
);
|
||||
assert!(!should_read_legacy_inline_part(&ec12, &config));
|
||||
}
|
||||
|
||||
@@ -303,6 +303,24 @@ fn log_read_error(error: &std::io::Error) {
|
||||
}
|
||||
}
|
||||
|
||||
/// Verify one borrowed `[hash][data]` frame before exposing its payload.
|
||||
/// A short digest prefix and a digest mismatch both fail without copying data.
|
||||
pub(crate) fn verified_bitrot_frame<'a>(
|
||||
hash_algo: &HashAlgorithm,
|
||||
skip_verify: bool,
|
||||
block: &'a [u8],
|
||||
) -> std::io::Result<&'a [u8]> {
|
||||
let hash_size = hash_algo.size();
|
||||
if block.len() < hash_size {
|
||||
return Err(std::io::Error::new(std::io::ErrorKind::UnexpectedEof, "truncated bitrot frame digest"));
|
||||
}
|
||||
let (hash, data) = block.split_at(hash_size);
|
||||
if !skip_verify && hash_algo.hash_encode(data).as_ref() != hash {
|
||||
return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, DiskError::FileCorrupt));
|
||||
}
|
||||
Ok(data)
|
||||
}
|
||||
|
||||
/// Split a `[hash][data]` block, verify the hash (unless `skip_verify`), and
|
||||
/// return the data slice plus the time spent hashing. The caller writes `data`
|
||||
/// into its sink **only after** this returns `Ok`, so a shard that fails the
|
||||
@@ -310,17 +328,13 @@ fn log_read_error(error: &std::io::Error) {
|
||||
/// rather than stored so this stays a free function usable while `self` is
|
||||
/// borrowed for the block.
|
||||
fn split_and_verify<'a>(hash_algo: &HashAlgorithm, skip_verify: bool, block: &'a [u8]) -> std::io::Result<(&'a [u8], Duration)> {
|
||||
let (hash, data) = block.split_at(hash_algo.size());
|
||||
if skip_verify {
|
||||
return Ok((data, Duration::ZERO));
|
||||
}
|
||||
let verify_start = std::time::Instant::now();
|
||||
let actual_hash = hash_algo.hash_encode(data);
|
||||
let verify = verify_start.elapsed();
|
||||
if actual_hash.as_ref() != hash {
|
||||
log_hash_mismatch(data.len());
|
||||
return Err(std::io::Error::new(std::io::ErrorKind::InvalidData, DiskError::FileCorrupt));
|
||||
}
|
||||
let verify_start = (!skip_verify).then(std::time::Instant::now);
|
||||
let data = verified_bitrot_frame(hash_algo, skip_verify, block).inspect_err(|err| {
|
||||
if err.kind() == std::io::ErrorKind::InvalidData {
|
||||
log_hash_mismatch(block.len().saturating_sub(hash_algo.size()));
|
||||
}
|
||||
})?;
|
||||
let verify = verify_start.map_or(Duration::ZERO, |start| start.elapsed());
|
||||
Ok((data, verify))
|
||||
}
|
||||
|
||||
@@ -965,10 +979,11 @@ pub struct InlineBuffer {
|
||||
foreground: Vec<u8>,
|
||||
background: Option<crate::disk::background_memory::BackgroundBuffer>,
|
||||
filled: usize,
|
||||
max_len: Option<usize>,
|
||||
}
|
||||
|
||||
impl InlineBuffer {
|
||||
fn new() -> Self {
|
||||
fn new(max_len: Option<usize>) -> Self {
|
||||
let background = crate::disk::current_resource_unit()
|
||||
.and_then(|unit| unit.memory_budget())
|
||||
.map(|budget| crate::disk::background_memory::BackgroundBuffer::new(Some(budget)));
|
||||
@@ -976,6 +991,7 @@ impl InlineBuffer {
|
||||
foreground: Vec::new(),
|
||||
background,
|
||||
filled: 0,
|
||||
max_len,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -990,10 +1006,22 @@ impl InlineBuffer {
|
||||
let total = bufs
|
||||
.iter()
|
||||
.try_fold(0usize, |length, buf| length.checked_add(buf.len()).ok_or(std::io::ErrorKind::OutOfMemory))?;
|
||||
let length = self
|
||||
.as_slice()
|
||||
.len()
|
||||
.checked_add(total)
|
||||
.ok_or(std::io::ErrorKind::OutOfMemory)?;
|
||||
if self.max_len.is_some_and(|limit| length > limit) {
|
||||
return Err(std::io::Error::new(
|
||||
std::io::ErrorKind::InvalidData,
|
||||
"inline shard exceeds its admitted buffer limit",
|
||||
));
|
||||
}
|
||||
if let Some(buffer) = &mut self.background {
|
||||
let length = self.filled.checked_add(total).ok_or(std::io::ErrorKind::OutOfMemory)?;
|
||||
if length > buffer.as_slice().len() {
|
||||
let capacity = buffer.as_slice().len().checked_mul(2).unwrap_or(length).max(length);
|
||||
let capacity = self
|
||||
.max_len
|
||||
.unwrap_or_else(|| buffer.as_slice().len().checked_mul(2).unwrap_or(length).max(length));
|
||||
// Admission includes both allocations until the prefix has been copied.
|
||||
buffer.grow(capacity, self.filled)?;
|
||||
}
|
||||
@@ -1004,6 +1032,13 @@ impl InlineBuffer {
|
||||
}
|
||||
self.filled = length;
|
||||
} else {
|
||||
if let Some(limit) = self.max_len
|
||||
&& length > self.foreground.capacity()
|
||||
{
|
||||
self.foreground
|
||||
.try_reserve_exact(limit - self.foreground.len())
|
||||
.map_err(std::io::Error::other)?;
|
||||
}
|
||||
for buf in bufs {
|
||||
self.foreground.extend_from_slice(buf);
|
||||
}
|
||||
@@ -1022,7 +1057,11 @@ impl InlineBuffer {
|
||||
impl CustomWriter {
|
||||
/// Create a new inline buffer writer
|
||||
pub fn new_inline_buffer() -> Self {
|
||||
Self::InlineBuffer(InlineBuffer::new())
|
||||
Self::InlineBuffer(InlineBuffer::new(None))
|
||||
}
|
||||
|
||||
pub(crate) fn new_bounded_inline_buffer(max_len: usize) -> Self {
|
||||
Self::InlineBuffer(InlineBuffer::new(Some(max_len)))
|
||||
}
|
||||
|
||||
/// Create a new disk writer from any AsyncWrite implementation
|
||||
@@ -1475,6 +1514,80 @@ mod tests {
|
||||
use std::time::Duration;
|
||||
use tokio::io::{AsyncRead, AsyncWrite, AsyncWriteExt, ReadBuf};
|
||||
|
||||
#[test]
|
||||
fn borrowed_bitrot_frame_verification_preserves_slices_and_rejects_short_prefixes() {
|
||||
for algo in [
|
||||
HashAlgorithm::HighwayHash256S,
|
||||
HashAlgorithm::HighwayHash256SLegacy,
|
||||
HashAlgorithm::SHA256,
|
||||
HashAlgorithm::None,
|
||||
] {
|
||||
let payload = b"borrowed frame";
|
||||
let mut frame = algo.hash_encode(payload).as_ref().to_vec();
|
||||
frame.extend_from_slice(payload);
|
||||
let verified = super::verified_bitrot_frame(&algo, false, &frame).expect("valid borrowed frame");
|
||||
assert_eq!(verified, payload);
|
||||
assert_eq!(verified.as_ptr(), frame[algo.size()..].as_ptr());
|
||||
for prefix_len in 0..algo.size() {
|
||||
for skip_verify in [false, true] {
|
||||
assert_eq!(
|
||||
super::split_and_verify(&algo, skip_verify, &frame[..prefix_len])
|
||||
.expect_err("short prefix must be an error")
|
||||
.kind(),
|
||||
io::ErrorKind::UnexpectedEof
|
||||
);
|
||||
}
|
||||
}
|
||||
if algo.size() != 0 {
|
||||
frame[0] ^= 1;
|
||||
assert_eq!(
|
||||
super::verified_bitrot_frame(&algo, false, &frame)
|
||||
.expect_err("damaged digest")
|
||||
.kind(),
|
||||
io::ErrorKind::InvalidData
|
||||
);
|
||||
assert_eq!(
|
||||
super::verified_bitrot_frame(&algo, true, &frame).expect("explicit diagnostic skip"),
|
||||
payload
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[ignore = "manual ABBA comparison of borrowed and streaming verification kernels"]
|
||||
async fn inline_bitrot_borrowed_verification_benchmark() {
|
||||
let algo = HashAlgorithm::HighwayHash256S;
|
||||
for (part_size, shard_size, iterations) in [(4096, 4096, 20_000), (128 * 1024, 64 * 1024, 2000)] {
|
||||
let data = vec![0x7b; part_size];
|
||||
let mut encoded = Vec::new();
|
||||
for part in data.chunks(shard_size) {
|
||||
encoded.extend_from_slice(algo.hash_encode(part).as_ref());
|
||||
encoded.extend_from_slice(part);
|
||||
}
|
||||
for borrowed in [false, true, true, false] {
|
||||
let start = std::time::Instant::now();
|
||||
for _ in 0..iterations {
|
||||
let encoded = std::hint::black_box(encoded.as_slice());
|
||||
if borrowed {
|
||||
for frame in encoded.chunks(shard_size + algo.size()) {
|
||||
std::hint::black_box(super::verified_bitrot_frame(&algo, false, frame).expect("borrowed frame"));
|
||||
}
|
||||
} else {
|
||||
bitrot_verify(Cursor::new(encoded), encoded.len(), part_size, algo.clone(), shard_size)
|
||||
.await
|
||||
.expect("streamed frame");
|
||||
}
|
||||
}
|
||||
println!(
|
||||
"inline_verify debug={} size={part_size} borrowed={borrowed} iterations={iterations} elapsed_ns={}",
|
||||
cfg!(debug_assertions),
|
||||
start.elapsed().as_nanos()
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bitrot_damage_preserves_typed_repair_evidence() {
|
||||
use crate::disk::error::Error as DiskError;
|
||||
@@ -2943,6 +3056,25 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn bounded_inline_buffer_rejects_vectored_overflow_atomically() {
|
||||
use tokio::io::AsyncWriteExt;
|
||||
let mut writer = CustomWriter::new_bounded_inline_buffer(64);
|
||||
writer.write_all(&[7; 32]).await.expect("initial inline prefix");
|
||||
let error = writer
|
||||
.write_vectored(&[IoSlice::new(&[8; 16]), IoSlice::new(&[9; 17])])
|
||||
.await
|
||||
.expect_err("combined vectored data exceeds the bound");
|
||||
assert_eq!(error.kind(), io::ErrorKind::InvalidData);
|
||||
assert_eq!(writer.get_inline_data(), Some(&[7; 32][..]));
|
||||
writer.write_all(&[8; 32]).await.expect("fill exactly to the bound");
|
||||
assert!(writer.write_all(&[1]).await.is_err());
|
||||
if let CustomWriter::InlineBuffer(buffer) = &writer {
|
||||
assert!(buffer.foreground.capacity() <= 64);
|
||||
}
|
||||
assert_eq!(writer.into_inline_data().expect("export bounded bytes").len(), 64);
|
||||
}
|
||||
|
||||
mod inline_memory_regressions {
|
||||
use super::*;
|
||||
use crate::disk::background_memory::is_memory_pressure;
|
||||
@@ -2957,6 +3089,25 @@ mod tests {
|
||||
.await
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn bounded_inline_writer_retains_its_memory_receipt() {
|
||||
let memory = BackgroundMemoryBudget::new();
|
||||
memory.set_sampled_limit(256, Duration::from_secs(30));
|
||||
let (resources, _) = test_resource_units(1);
|
||||
let mut writer = with_optional_resource_unit(Some(resources.with_memory_budget(Arc::clone(&memory))), async {
|
||||
CustomWriter::new_bounded_inline_buffer(64)
|
||||
})
|
||||
.await;
|
||||
writer.write_all(&[3; 32]).await.expect("bounded background write");
|
||||
let bytes = writer.into_inline_data().expect("bounded bytes");
|
||||
let clone = bytes.clone();
|
||||
assert_eq!(memory.snapshot().used, 64);
|
||||
drop(bytes);
|
||||
assert_eq!(memory.snapshot().used, 64);
|
||||
drop(clone);
|
||||
assert_eq!(memory.snapshot().used, 0);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn inline_writer_rejects_closed_and_expired_owners_before_first_allocation() {
|
||||
for expired in [false, true] {
|
||||
|
||||
@@ -812,12 +812,20 @@ pub(crate) fn create_deferred_bitrot_reader_with_stripe_handle(
|
||||
/// a fixed body length when locating the authenticated trailer. Clamping it
|
||||
/// to `0` would claim an empty body and misframe the stream. `0` stays `0`
|
||||
/// because a genuinely empty object still means an empty body.
|
||||
fn bitrot_create_file_size(length: i64, shard_size: usize, checksum_algo: &HashAlgorithm) -> i64 {
|
||||
fn bitrot_create_file_size(length: i64, shard_size: usize, checksum_algo: &HashAlgorithm) -> disk::error::Result<i64> {
|
||||
if length <= 0 {
|
||||
return length;
|
||||
return Ok(length);
|
||||
}
|
||||
let length = length as usize;
|
||||
(length.div_ceil(shard_size) * checksum_algo.size() + length) as i64
|
||||
if shard_size == 0 {
|
||||
return Err(DiskError::other("bitrot shard size is zero"));
|
||||
}
|
||||
let payload = usize::try_from(length).map_err(|_| DiskError::other("bitrot shard length exceeds usize"))?;
|
||||
let framed = payload
|
||||
.div_ceil(shard_size)
|
||||
.checked_mul(checksum_algo.size())
|
||||
.and_then(|overhead| payload.checked_add(overhead))
|
||||
.ok_or_else(|| DiskError::other("bitrot framed length overflows"))?;
|
||||
i64::try_from(framed).map_err(|_| DiskError::other("bitrot framed length exceeds i64"))
|
||||
}
|
||||
|
||||
pub async fn create_bitrot_writer(
|
||||
@@ -843,12 +851,16 @@ pub async fn create_bitrot_writer_with_orig_volume(
|
||||
shard_size: usize,
|
||||
checksum_algo: HashAlgorithm,
|
||||
) -> disk::error::Result<BitrotWriterWrapper> {
|
||||
let framed_length = bitrot_create_file_size(length, shard_size, &checksum_algo)?;
|
||||
let writer = if is_inline_buffer {
|
||||
CustomWriter::new_inline_buffer()
|
||||
if framed_length < 0 {
|
||||
CustomWriter::new_inline_buffer()
|
||||
} else {
|
||||
let limit = usize::try_from(framed_length).map_err(|_| DiskError::other("inline buffer limit exceeds usize"))?;
|
||||
CustomWriter::new_bounded_inline_buffer(limit)
|
||||
}
|
||||
} else if let Some(disk) = disk {
|
||||
let length = bitrot_create_file_size(length, shard_size, &checksum_algo);
|
||||
|
||||
let file = disk.create_file(origvolume, volume, path, length).await?;
|
||||
let file = disk.create_file(origvolume, volume, path, framed_length).await?;
|
||||
#[cfg(feature = "hotpath")]
|
||||
let file = instrument_raw_shard_writer(file, disk.is_local());
|
||||
CustomWriter::from_file_writer(file)
|
||||
@@ -867,23 +879,41 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn bitrot_create_file_size_grows_known_length_by_checksums() {
|
||||
// 10 bytes over 4-byte shards = 3 shards, each followed by a 32-byte hash.
|
||||
assert_eq!(bitrot_create_file_size(10, 4, &HashAlgorithm::HighwayHash256), 10 + 3 * 32);
|
||||
assert_eq!(bitrot_create_file_size(10, 4, &HashAlgorithm::None), 10);
|
||||
// 10 bytes over 4-byte shards = 3 frames with a 32-byte prefix each.
|
||||
assert_eq!(
|
||||
bitrot_create_file_size(10, 4, &HashAlgorithm::HighwayHash256).expect("known frame size"),
|
||||
10 + 3 * 32
|
||||
);
|
||||
assert_eq!(bitrot_create_file_size(10, 4, &HashAlgorithm::None).expect("unhashed frame size"), 10);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bitrot_create_file_size_keeps_empty_and_unknown_distinct() {
|
||||
assert_eq!(bitrot_create_file_size(0, 4, &HashAlgorithm::HighwayHash256), 0);
|
||||
assert_eq!(
|
||||
bitrot_create_file_size(0, 4, &HashAlgorithm::HighwayHash256).expect("empty frame size"),
|
||||
0
|
||||
);
|
||||
// SSE/compression streams advertise SIZE_PRESERVE_LAYER (-1); the remote
|
||||
// put_file_stream receiver relies on a non-positive size to parse the auth
|
||||
// trailer from the stream tail, so the sentinel must survive untouched.
|
||||
assert_eq!(
|
||||
bitrot_create_file_size(rustfs_rio::HashReader::SIZE_PRESERVE_LAYER, 4, &HashAlgorithm::HighwayHash256),
|
||||
bitrot_create_file_size(rustfs_rio::HashReader::SIZE_PRESERVE_LAYER, 4, &HashAlgorithm::HighwayHash256)
|
||||
.expect("unknown length sentinel"),
|
||||
rustfs_rio::HashReader::SIZE_PRESERVE_LAYER
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bitrot_create_file_size_rejects_invalid_geometry_and_overflow() {
|
||||
assert!(bitrot_create_file_size(1, 0, &HashAlgorithm::HighwayHash256S).is_err());
|
||||
assert!(bitrot_create_file_size(i64::MAX, 1, &HashAlgorithm::HighwayHash256S).is_err());
|
||||
assert_eq!(
|
||||
bitrot_create_file_size(-7, 0, &HashAlgorithm::HighwayHash256S).expect("negative sentinel"),
|
||||
-7
|
||||
);
|
||||
assert_eq!(bitrot_create_file_size(0, 0, &HashAlgorithm::HighwayHash256S).expect("empty body"), 0);
|
||||
}
|
||||
|
||||
struct TestChunkReader {
|
||||
chunks: VecDeque<Bytes>,
|
||||
}
|
||||
@@ -1762,6 +1792,28 @@ mod tests {
|
||||
assert!(result.unwrap().is_none());
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn bounded_inline_bitrot_writer_counts_each_frame_header() {
|
||||
let mut writer = create_bitrot_writer(true, None, "bucket", "object", 6, 4, HashAlgorithm::HighwayHash256S)
|
||||
.await
|
||||
.expect("bounded inline writer");
|
||||
writer.write(b"abcd").await.expect("first full frame");
|
||||
writer.write(b"ef").await.expect("final partial frame");
|
||||
let raw = writer.into_inline_data().expect("export framed bytes");
|
||||
assert_eq!(raw.len(), 6 + 2 * 32);
|
||||
let mut exact = create_bitrot_writer(true, None, "bucket", "object", 4, 4, HashAlgorithm::HighwayHash256S)
|
||||
.await
|
||||
.expect("exact bounded writer");
|
||||
exact.write(b"abcd").await.expect("fill admitted frame");
|
||||
assert!(exact.write(b"e").await.is_err());
|
||||
assert_eq!(exact.into_inline_data().expect("intact first frame").len(), 4 + 32);
|
||||
assert!(
|
||||
create_bitrot_writer(true, None, "bucket", "object", 1, 0, HashAlgorithm::HighwayHash256S)
|
||||
.await
|
||||
.is_err()
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_create_bitrot_writer_inline() {
|
||||
use rustfs_utils::HashAlgorithm;
|
||||
|
||||
@@ -9903,6 +9903,19 @@ mod tests {
|
||||
("RUSTFS_GET_METADATA_EARLY_STOP_BOUNDED_FANOUT", Some("true")),
|
||||
],
|
||||
async {
|
||||
let fanout_order = bounded_metadata_fanout_order(bucket, &object, DISKS, 2);
|
||||
let distribution = FileInfo::new(&metadata_distribution_key(bucket, &object), 2, 2)
|
||||
.erasure
|
||||
.distribution;
|
||||
let initial_parity_disk = *fanout_order
|
||||
.iter()
|
||||
.take(3)
|
||||
.find(|disk_index| distribution[**disk_index] > 2)
|
||||
.expect("initial fanout should include one parity shard");
|
||||
// Hold the initial parity response so the single-pending-read
|
||||
// hedge is exercised independently of task completion order.
|
||||
let initial_barrier =
|
||||
rename_fanout_barrier::arm(&object, initial_parity_disk, rename_fanout_barrier::PHASE_READ_VERSION);
|
||||
let spare_disk = bounded_spare_disk_index(bucket, &object, 2, 2);
|
||||
let barrier = rename_fanout_barrier::arm(&object, spare_disk, rename_fanout_barrier::PHASE_READ_VERSION);
|
||||
let tracker = rename_fanout_barrier::observe_tasks(&object);
|
||||
@@ -9925,9 +9938,13 @@ mod tests {
|
||||
.await
|
||||
});
|
||||
|
||||
tokio::time::timeout(BARRIER_PAUSE_GUARD, initial_barrier.wait_until_paused())
|
||||
.await
|
||||
.expect("initial parity response should pause before quorum");
|
||||
tokio::time::timeout(BARRIER_PAUSE_GUARD, barrier.wait_until_paused())
|
||||
.await
|
||||
.expect("bounded fanout should hedge and pause the spare disk");
|
||||
initial_barrier.release();
|
||||
let (parts_metadata, errs, diagnostics) = tokio::time::timeout(BARRIER_PAUSE_GUARD, &mut read)
|
||||
.await
|
||||
.expect("verified inline quorum should return without the paused spare")
|
||||
@@ -10221,6 +10238,15 @@ mod tests {
|
||||
data_read_early_stop_inline_body_miss_reason(bucket, object, &candidate, &corrupt, &disks).await,
|
||||
Some(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_BODY_VERIFY)
|
||||
);
|
||||
|
||||
let mut trailing = parts_metadata.clone();
|
||||
let mut inline_data = trailing[data_disk].data.as_ref().expect("fixture inline bytes").to_vec();
|
||||
inline_data.push(0x7b);
|
||||
trailing[data_disk].data = Some(Bytes::from(inline_data));
|
||||
assert_eq!(
|
||||
data_read_early_stop_inline_body_miss_reason(bucket, object, &candidate, &trailing, &disks).await,
|
||||
Some(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_BODY_VERIFY)
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -36,12 +36,12 @@ use crate::disk::{
|
||||
self, BATCH_READ_VERSION_MAX_ITEMS, BatchReadVersionItem, BatchReadVersionReq, BatchReadVersionResp, Disk, DiskAPI,
|
||||
};
|
||||
use crate::set_disk::{
|
||||
DiskError, DiskStore, FileInfo, HashAlgorithm, ReadOptions, SetDisks, can_try_inline_data_shards_direct,
|
||||
codec_streaming_rollout_applies, collect_inline_data_shard_fileinfos_from_observations, file_info_is_valid_for_metadata,
|
||||
get_metadata_slowtail_fault_request, inline_erasure_shard_file_offset, inline_erasure_shard_size,
|
||||
is_get_metadata_data_read_early_stop_enabled, is_get_metadata_early_stop_bounded_fanout_enabled,
|
||||
is_get_metadata_early_stop_enabled, is_get_metadata_non_inline_data_read_early_stop_enabled, is_version_early_stop_enabled,
|
||||
object_fits_single_block,
|
||||
DiskError, DiskStore, FileInfo, ReadOptions, SetDisks, codec_streaming_rollout_applies,
|
||||
collect_inline_data_shard_fileinfos_from_observations, file_info_is_valid_for_metadata, get_metadata_slowtail_fault_request,
|
||||
inline_body_buffering_miss_reason, is_get_metadata_data_read_early_stop_enabled,
|
||||
is_get_metadata_early_stop_bounded_fanout_enabled, is_get_metadata_early_stop_enabled,
|
||||
is_get_metadata_non_inline_data_read_early_stop_enabled, is_version_early_stop_enabled, object_fits_single_block,
|
||||
try_decode_inline_data_shards,
|
||||
};
|
||||
use futures::future::join_all;
|
||||
use metrics::counter;
|
||||
@@ -656,68 +656,8 @@ fn verify_inline_body_from_observations<'a>(
|
||||
disks.get(index).is_some_and(Option::is_some)
|
||||
})?;
|
||||
|
||||
let Some(part) = candidate.parts.first() else {
|
||||
return Err(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_PART_SHAPE);
|
||||
};
|
||||
let Ok(object_size) = usize::try_from(candidate.size) else {
|
||||
return Err(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_SIZE);
|
||||
};
|
||||
let checksum_info = candidate.erasure.get_checksum_info(part.number);
|
||||
let checksum_algo = if candidate.uses_legacy_checksum && checksum_info.algorithm == HashAlgorithm::HighwayHash256S {
|
||||
HashAlgorithm::HighwayHash256SLegacy
|
||||
} else {
|
||||
checksum_info.algorithm
|
||||
};
|
||||
let read_length = inline_erasure_shard_file_offset(
|
||||
0,
|
||||
object_size,
|
||||
object_size,
|
||||
candidate.erasure.block_size,
|
||||
data_shards,
|
||||
candidate.uses_legacy_checksum,
|
||||
);
|
||||
let shard_size = inline_erasure_shard_size(candidate.erasure.block_size, data_shards, candidate.uses_legacy_checksum);
|
||||
if object_size == 0 || read_length == 0 || read_length > shard_size || data_files.len() < data_shards {
|
||||
return Err(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_BODY_VERIFY);
|
||||
}
|
||||
let shards_needed = object_size.div_ceil(read_length);
|
||||
if shards_needed > data_shards {
|
||||
return Err(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_BODY_VERIFY);
|
||||
}
|
||||
let Some(encoded_capacity) = read_length.checked_mul(shards_needed) else {
|
||||
return Err(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_BODY_VERIFY);
|
||||
};
|
||||
#[cfg(test)]
|
||||
{
|
||||
for file in &data_files {
|
||||
if file.data.is_some() {
|
||||
crate::set_disk::disk_call_counters::record_shard_open(_object, true);
|
||||
}
|
||||
}
|
||||
crate::set_disk::disk_call_counters::record(_object, crate::set_disk::disk_call_counters::KIND_BODY_DECODE, 0);
|
||||
}
|
||||
|
||||
let hash_size = checksum_algo.size();
|
||||
let need = hash_size + read_length;
|
||||
let mut body = Vec::with_capacity(encoded_capacity);
|
||||
for file in data_files.iter().take(shards_needed) {
|
||||
let Some(raw) = file.data.as_deref() else {
|
||||
return Err(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_BODY_VERIFY);
|
||||
};
|
||||
let Some(block) = raw.get(..need) else {
|
||||
return Err(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_BODY_VERIFY);
|
||||
};
|
||||
let (hash, data) = block.split_at(hash_size);
|
||||
if hash_size > 0 && checksum_algo.hash_encode(data).as_ref() != hash {
|
||||
return Err(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_BODY_VERIFY);
|
||||
}
|
||||
body.extend_from_slice(data);
|
||||
if body.len() >= object_size {
|
||||
body.truncate(object_size);
|
||||
return Ok(bytes::Bytes::from(body));
|
||||
}
|
||||
}
|
||||
Err(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_BODY_VERIFY)
|
||||
try_decode_inline_data_shards(_object, candidate, &data_files, false)
|
||||
.ok_or(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_BODY_VERIFY)
|
||||
}
|
||||
|
||||
fn data_read_early_stop_inline_candidate_miss_reason(candidate: &FileInfo) -> Option<&'static str> {
|
||||
@@ -755,10 +695,7 @@ fn data_read_early_stop_inline_candidate_miss_reason(candidate: &FileInfo) -> Op
|
||||
if candidate.parts.first().is_none_or(|part| part.size != object_size) {
|
||||
return Some(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_PART_SHAPE);
|
||||
}
|
||||
if !can_try_inline_data_shards_direct(object_size, candidate.erasure.block_size) {
|
||||
return Some(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_SIZE);
|
||||
}
|
||||
None
|
||||
inline_body_buffering_miss_reason(candidate)
|
||||
}
|
||||
|
||||
pub(in crate::set_disk) fn non_inline_data_read_candidate_is_safe(candidate: &FileInfo) -> bool {
|
||||
|
||||
+319
-164
@@ -51,12 +51,13 @@ use crate::bucket::replication::{ReplicateDecision, ReplicationObjectBridge, Rep
|
||||
use crate::cluster::rpc::heal_bucket_local_on_disks;
|
||||
use crate::data_usage::record_compression_total_memory;
|
||||
use crate::diagnostics::get::{
|
||||
GET_CODEC_STREAMING_OBJECT_CLASS_PLAIN_SINGLE_PART, GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_GEOMETRY,
|
||||
GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_IDENTITY_MISMATCH,
|
||||
GET_CODEC_STREAMING_OBJECT_CLASS_PLAIN_SINGLE_PART, GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_BODY_VERIFY,
|
||||
GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_GEOMETRY, GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_IDENTITY_MISMATCH,
|
||||
GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_MISSING_PAYLOAD,
|
||||
GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_MISSING_SHARD, GET_OBJECT_PATH_BODY_CACHE, GET_OBJECT_PATH_CODEC_STREAMING,
|
||||
GET_OBJECT_PATH_CODEC_STREAMING_LEGACY_ENGINE, GET_OBJECT_PATH_CODEC_STREAMING_RUSTFS_ENGINE, GET_OBJECT_PATH_DIRECT_MEMORY,
|
||||
GET_OBJECT_PATH_EMPTY, GET_OBJECT_PATH_INLINE_DIRECT, GET_OBJECT_PATH_INTERNAL_META, GET_OBJECT_PATH_LEGACY_DUPLEX,
|
||||
GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_MISSING_SHARD, GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_SIZE,
|
||||
GET_OBJECT_PATH_BODY_CACHE, GET_OBJECT_PATH_CODEC_STREAMING, GET_OBJECT_PATH_CODEC_STREAMING_LEGACY_ENGINE,
|
||||
GET_OBJECT_PATH_CODEC_STREAMING_RUSTFS_ENGINE, GET_OBJECT_PATH_DIRECT_MEMORY, GET_OBJECT_PATH_EMPTY,
|
||||
GET_OBJECT_PATH_INLINE_DIRECT, GET_OBJECT_PATH_INTERNAL_META, GET_OBJECT_PATH_LEGACY_DUPLEX,
|
||||
GET_OBJECT_PATH_REMOTE_TRANSITION, GET_OBJECT_PATH_SET_DISK, GET_STAGE_DECODE, GET_STAGE_EMIT, GET_STAGE_INLINE_PREPARE,
|
||||
GET_STAGE_LOCK_ACQUIRE, GET_STAGE_METADATA, GET_STAGE_OBJECT_INFO, GET_STAGE_PATH_DECISION, GET_STAGE_READER_SETUP,
|
||||
classify_storage_error, get_stage_timer_if_enabled, record_get_object_pipeline_failure,
|
||||
@@ -787,7 +788,8 @@ const DEFAULT_RUSTFS_GET_SMALL_OBJECT_DIRECT_MEMORY_THRESHOLD: usize = 128 * 102
|
||||
// Bound the in-memory inline decoder independently from the configurable
|
||||
// storage-class admission policy. This protects its Vec allocation while
|
||||
// allowing explicitly configured EC layouts to inline objects above 128 KiB.
|
||||
const INLINE_FAST_PATH_MAX_OBJECT_SIZE: i64 = 1024 * 1024;
|
||||
const INLINE_FAST_PATH_MAX_OBJECT_SIZE: usize = 2 * 1024 * 1024;
|
||||
const INLINE_FAST_PATH_MAX_BLOCKS: usize = 32;
|
||||
|
||||
// --- Metadata Early-Stop Configuration ---
|
||||
|
||||
@@ -6049,6 +6051,51 @@ fn should_use_inline_fast_path(
|
||||
should_use_inline_fast_path_with_plan(range, object_info, fi, opts, ReadPathPlan::new(object_info, fi))
|
||||
}
|
||||
|
||||
fn inline_body_fits_buffer(size: usize, block_size: usize) -> bool {
|
||||
size > 0
|
||||
&& size <= INLINE_FAST_PATH_MAX_OBJECT_SIZE
|
||||
&& block_size != 0
|
||||
&& size.div_ceil(block_size) <= INLINE_FAST_PATH_MAX_BLOCKS
|
||||
}
|
||||
|
||||
fn should_inline_put(
|
||||
storage_class: &crate::config::storageclass::Config,
|
||||
erasure: &coding::Erasure,
|
||||
stored_size: i64,
|
||||
actual_size: i64,
|
||||
versioned: bool,
|
||||
protected: bool,
|
||||
) -> bool {
|
||||
let admission_size = if stored_size >= 0 {
|
||||
stored_size
|
||||
} else if !protected && actual_size > 0 {
|
||||
actual_size
|
||||
} else {
|
||||
return false;
|
||||
};
|
||||
let Ok(size) = usize::try_from(admission_size) else {
|
||||
return false;
|
||||
};
|
||||
if size > erasure.block_size && (stored_size < 0 || protected || !inline_body_fits_buffer(size, erasure.block_size)) {
|
||||
return false;
|
||||
}
|
||||
storage_class.should_inline(erasure.shard_file_size(admission_size), erasure.data_shards, versioned)
|
||||
}
|
||||
|
||||
fn inline_body_buffering_miss_reason(fi: &FileInfo) -> Option<&'static str> {
|
||||
let Ok(size) = usize::try_from(fi.size) else {
|
||||
return Some(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_SIZE);
|
||||
};
|
||||
if !inline_body_fits_buffer(size, fi.erasure.block_size) {
|
||||
return Some(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_SIZE);
|
||||
}
|
||||
// Proof-protected parts use the readers that bind their PartProofReader.
|
||||
if fi.parts.iter().any(|part| part.integrity.is_some()) {
|
||||
return Some(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_BODY_VERIFY);
|
||||
}
|
||||
None
|
||||
}
|
||||
|
||||
fn should_use_inline_fast_path_with_plan(
|
||||
range: &Option<HTTPRangeSpec>,
|
||||
object_info: &ObjectInfo,
|
||||
@@ -6060,18 +6107,12 @@ fn should_use_inline_fast_path_with_plan(
|
||||
return false;
|
||||
}
|
||||
|
||||
let Some(shape) = plan.shape() else {
|
||||
if plan.shape().is_none() {
|
||||
return false;
|
||||
};
|
||||
// The persisted marker is authoritative for the storage decision, but it
|
||||
// is still untrusted metadata at this boundary. Revalidate its geometry so
|
||||
// a stale/corrupt marker cannot route an oversized payload into the
|
||||
// in-memory decoder. The independent direct-memory reader remains capped
|
||||
// at 128 KiB below.
|
||||
plan.is_plain()
|
||||
&& shape.object_size <= usize::try_from(INLINE_FAST_PATH_MAX_OBJECT_SIZE).expect("inline fast path limit fits usize")
|
||||
&& fi.erasure.data_blocks != 0
|
||||
&& fi.erasure.block_size != 0
|
||||
}
|
||||
// Apply the same materialization contract as metadata pre-verification.
|
||||
// The independent direct-memory reader retains its 128 KiB gate.
|
||||
plan.is_plain() && inline_body_buffering_miss_reason(fi).is_none() && fi.erasure.data_blocks != 0
|
||||
}
|
||||
|
||||
enum SmallWritePath {
|
||||
@@ -6160,27 +6201,9 @@ fn known_put_object_storage_size(data_size: i64) -> i64 {
|
||||
}
|
||||
}
|
||||
|
||||
/// Shard size the inline admission check evaluates for a single PUT.
|
||||
///
|
||||
/// A compressed or encrypted stream reports `SIZE_PRESERVE_LAYER` as its
|
||||
/// stored size because the transformed length is only known after the write.
|
||||
/// MinIO's `putObject` sizes such objects for inline admission by their
|
||||
/// plaintext `ActualSize`; without that fallback every transformed object,
|
||||
/// however small, lands in `part.1` files. A stream with neither size known
|
||||
/// yields a negative shard size, which `should_inline` rejects.
|
||||
fn inline_admission_shard_size(erasure: &coding::Erasure, stored_size: i64, actual_size: i64) -> i64 {
|
||||
if stored_size >= 0 {
|
||||
return erasure.shard_file_size(stored_size);
|
||||
}
|
||||
if actual_size > 0 {
|
||||
return erasure.shard_file_size(actual_size);
|
||||
}
|
||||
HashReader::SIZE_PRESERVE_LAYER
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn build_inline_bitrot_readers(
|
||||
files: &[FileInfo],
|
||||
async fn build_inline_bitrot_readers<'a>(
|
||||
files: impl Iterator<Item = &'a FileInfo> + Send,
|
||||
total_shards: usize,
|
||||
bucket: &str,
|
||||
object: &str,
|
||||
@@ -6190,7 +6213,7 @@ async fn build_inline_bitrot_readers(
|
||||
skip_verify_bitrot: bool,
|
||||
) -> disk::error::Result<Vec<Option<InlineBitrotReader>>> {
|
||||
let mut readers = Vec::with_capacity(total_shards);
|
||||
for file in files.iter().take(total_shards) {
|
||||
for file in files.take(total_shards) {
|
||||
let reader = if let Some(data) = &file.data {
|
||||
create_bitrot_reader_from_bytes(
|
||||
Some(data.clone()),
|
||||
@@ -6213,38 +6236,83 @@ async fn build_inline_bitrot_readers(
|
||||
Ok(readers)
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
async fn build_inline_bitrot_readers_from_refs(
|
||||
files: &[&FileInfo],
|
||||
bucket: &str,
|
||||
object: &str,
|
||||
read_length: usize,
|
||||
shard_size: usize,
|
||||
checksum_algo: &HashAlgorithm,
|
||||
skip_verify_bitrot: bool,
|
||||
) -> disk::error::Result<Vec<Option<InlineBitrotReader>>> {
|
||||
let mut readers = Vec::with_capacity(files.len());
|
||||
for file in files {
|
||||
let reader = if let Some(data) = &file.data {
|
||||
create_bitrot_reader_from_bytes(
|
||||
Some(data.clone()),
|
||||
None,
|
||||
bucket,
|
||||
object,
|
||||
0,
|
||||
read_length,
|
||||
shard_size,
|
||||
checksum_algo.clone(),
|
||||
skip_verify_bitrot,
|
||||
false,
|
||||
)
|
||||
.await?
|
||||
} else {
|
||||
None
|
||||
};
|
||||
readers.push(reader);
|
||||
/// Resolve the bitrot checksum algorithm for one part, honoring the legacy
|
||||
/// HighwayHash flag.
|
||||
fn part_checksum_algorithm(fi: &FileInfo, part_number: usize) -> HashAlgorithm {
|
||||
let checksum_info = fi.erasure.get_checksum_info(part_number);
|
||||
if fi.uses_legacy_checksum && checksum_info.algorithm == HashAlgorithm::HighwayHash256S {
|
||||
HashAlgorithm::HighwayHash256SLegacy
|
||||
} else {
|
||||
checksum_info.algorithm
|
||||
}
|
||||
Ok(readers)
|
||||
}
|
||||
|
||||
/// Decode already identity-checked data shards without reader wrappers or RS.
|
||||
/// A failed frame leaves recovery to the caller's ordinary erasure reader.
|
||||
fn try_decode_inline_data_shards(
|
||||
_object: &str,
|
||||
fi: &FileInfo,
|
||||
data_files: &[&FileInfo],
|
||||
skip_verify_bitrot: bool,
|
||||
) -> Option<Bytes> {
|
||||
if inline_body_buffering_miss_reason(fi).is_some() {
|
||||
return None;
|
||||
}
|
||||
let object_size = usize::try_from(fi.size).ok()?;
|
||||
let part = fi.parts.first()?;
|
||||
let data_shards = fi.erasure.data_blocks;
|
||||
if fi.parts.len() != 1 || part.size != object_size || data_files.len() < data_shards {
|
||||
return None;
|
||||
}
|
||||
let shard_size = inline_erasure_shard_size(fi.erasure.block_size, data_shards, fi.uses_legacy_checksum);
|
||||
if shard_size == 0 {
|
||||
return None;
|
||||
}
|
||||
let checksum_algo = part_checksum_algorithm(fi, part.number);
|
||||
let hash_size = checksum_algo.size();
|
||||
let stride = shard_size.checked_add(hash_size)?;
|
||||
let part_size = inline_erasure_shard_file_size(part.size, fi.erasure.block_size, data_shards, fi.uses_legacy_checksum);
|
||||
let encoded_size = part_size
|
||||
.div_ceil(shard_size)
|
||||
.checked_mul(hash_size)?
|
||||
.checked_add(part_size)?;
|
||||
// Metadata early-stop can cache this body, so require exact framing even
|
||||
// when the caller explicitly skips bitrot digest verification.
|
||||
for file in data_files.iter().take(data_shards) {
|
||||
if file.data.as_ref()?.len() != encoded_size {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
#[cfg(test)]
|
||||
{
|
||||
for _ in data_files.iter().take(data_shards) {
|
||||
disk_call_counters::record_shard_open(_object, true);
|
||||
}
|
||||
disk_call_counters::record(_object, disk_call_counters::KIND_BODY_DECODE, 0);
|
||||
}
|
||||
let mut body = Vec::with_capacity(object_size);
|
||||
for (frame, offset) in (0..object_size).step_by(fi.erasure.block_size).enumerate() {
|
||||
let block_length = fi.erasure.block_size.min(object_size - offset);
|
||||
let read_length =
|
||||
inline_erasure_shard_file_size(block_length, fi.erasure.block_size, data_shards, fi.uses_legacy_checksum);
|
||||
if read_length == 0 || read_length > shard_size {
|
||||
return None;
|
||||
}
|
||||
let start = frame.checked_mul(stride)?;
|
||||
let end = start.checked_add(hash_size)?.checked_add(read_length)?;
|
||||
let mut remaining = block_length;
|
||||
for file in data_files.iter().take(block_length.div_ceil(read_length)) {
|
||||
let block = file.data.as_deref()?.get(start..end)?;
|
||||
let data = coding::verified_bitrot_frame(&checksum_algo, skip_verify_bitrot, block).ok()?;
|
||||
let take = remaining.min(data.len());
|
||||
body.extend_from_slice(&data[..take]);
|
||||
remaining -= take;
|
||||
}
|
||||
if remaining != 0 {
|
||||
return None;
|
||||
}
|
||||
}
|
||||
Some(Bytes::from(body))
|
||||
}
|
||||
|
||||
async fn try_read_inline_data_shards_direct(
|
||||
@@ -6285,10 +6353,6 @@ async fn try_read_inline_data_shards_direct(
|
||||
None
|
||||
}
|
||||
|
||||
fn can_try_inline_data_shards_direct(object_size: usize, block_size: usize) -> bool {
|
||||
object_size > 0 && object_size <= block_size
|
||||
}
|
||||
|
||||
fn inline_erasure_shard_size(block_size: usize, data_shards: usize, uses_legacy: bool) -> usize {
|
||||
if block_size == 0 || data_shards == 0 {
|
||||
return 0;
|
||||
@@ -6317,31 +6381,14 @@ fn inline_erasure_shard_file_size(total_length: usize, block_size: usize, data_s
|
||||
num_shards * shard_size + last_shard_size
|
||||
}
|
||||
|
||||
fn inline_erasure_shard_file_offset(
|
||||
start_offset: usize,
|
||||
length: usize,
|
||||
total_length: usize,
|
||||
block_size: usize,
|
||||
data_shards: usize,
|
||||
uses_legacy: bool,
|
||||
) -> usize {
|
||||
if block_size == 0 || data_shards == 0 {
|
||||
return 0;
|
||||
}
|
||||
|
||||
let shard_size = inline_erasure_shard_size(block_size, data_shards, uses_legacy);
|
||||
let shard_file_size = inline_erasure_shard_file_size(total_length, block_size, data_shards, uses_legacy);
|
||||
let end_shard = (start_offset + length) / block_size;
|
||||
let till_offset = end_shard * shard_size + shard_size;
|
||||
till_offset.min(shard_file_size)
|
||||
}
|
||||
type InlineDataShardFiles<'a> = smallvec::SmallVec<[&'a FileInfo; shard_source::INLINE_SHARD_SLOTS]>;
|
||||
|
||||
fn collect_inline_data_shard_fileinfos_by_index<'a>(
|
||||
parts_metadata: &'a [FileInfo],
|
||||
fi: &FileInfo,
|
||||
data_shards: usize,
|
||||
disk_is_online: impl FnMut(usize) -> bool,
|
||||
) -> Option<Vec<&'a FileInfo>> {
|
||||
) -> Option<InlineDataShardFiles<'a>> {
|
||||
collect_inline_data_shard_fileinfos_by_index_or_reason(parts_metadata, fi, data_shards, disk_is_online).ok()
|
||||
}
|
||||
|
||||
@@ -6350,7 +6397,7 @@ fn collect_inline_data_shard_fileinfos_by_index_or_reason<'a>(
|
||||
fi: &FileInfo,
|
||||
data_shards: usize,
|
||||
disk_is_online: impl FnMut(usize) -> bool,
|
||||
) -> std::result::Result<Vec<&'a FileInfo>, &'static str> {
|
||||
) -> std::result::Result<InlineDataShardFiles<'a>, &'static str> {
|
||||
collect_inline_data_shard_fileinfos_from_observations(
|
||||
parts_metadata
|
||||
.iter()
|
||||
@@ -6367,9 +6414,13 @@ fn collect_inline_data_shard_fileinfos_from_observations<'a>(
|
||||
fi: &FileInfo,
|
||||
data_shards: usize,
|
||||
mut disk_is_online: impl FnMut(usize) -> bool,
|
||||
) -> std::result::Result<Vec<&'a FileInfo>, &'static str> {
|
||||
) -> std::result::Result<InlineDataShardFiles<'a>, &'static str> {
|
||||
let distribution = &fi.erasure.distribution;
|
||||
let mut data_files = vec![None; data_shards];
|
||||
if data_shards == 0 || data_shards != fi.erasure.data_blocks || data_shards > distribution.len() {
|
||||
return Err(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_GEOMETRY);
|
||||
}
|
||||
let mut data_files: smallvec::SmallVec<[Option<&FileInfo>; shard_source::INLINE_SHARD_SLOTS]> =
|
||||
smallvec::smallvec![None; data_shards];
|
||||
|
||||
for (disk_index, file_info) in observations {
|
||||
if !disk_is_online(disk_index) {
|
||||
@@ -6402,7 +6453,7 @@ fn collect_inline_data_shard_fileinfos_from_observations<'a>(
|
||||
|
||||
data_files
|
||||
.into_iter()
|
||||
.collect::<Option<Vec<_>>>()
|
||||
.collect::<Option<InlineDataShardFiles<'_>>>()
|
||||
.ok_or(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_MISSING_SHARD)
|
||||
}
|
||||
|
||||
@@ -7368,23 +7419,20 @@ fn join_errs(errs: &[Option<DiskError>]) -> String {
|
||||
errs.join(", ")
|
||||
}
|
||||
|
||||
async fn verify_inline_part_bitrot(meta: &FileInfo) -> disk::error::Result<()> {
|
||||
fn verify_inline_part_bitrot(meta: &FileInfo) -> disk::error::Result<()> {
|
||||
meta.validate_for_metadata_read()?;
|
||||
let [part] = meta.parts.as_slice() else {
|
||||
return Err(DiskError::FileCorrupt);
|
||||
};
|
||||
let data = meta.data.as_deref().ok_or(DiskError::FileCorrupt)?;
|
||||
let checksum = meta.erasure.get_checksum_info(part.number);
|
||||
let algo = match checksum.algorithm {
|
||||
HashAlgorithm::HighwayHash256S if meta.uses_legacy_checksum => HashAlgorithm::HighwayHash256SLegacy,
|
||||
algo @ (HashAlgorithm::HighwayHash256S | HashAlgorithm::HighwayHash256SLegacy) => algo,
|
||||
_ => return Err(DiskError::BitrotHashAlgoInvalid),
|
||||
};
|
||||
let algo = part_checksum_algorithm(meta, part.number);
|
||||
if !matches!(algo, HashAlgorithm::HighwayHash256S | HashAlgorithm::HighwayHash256SLegacy) {
|
||||
return Err(DiskError::BitrotHashAlgoInvalid);
|
||||
}
|
||||
let shard_size = inline_erasure_shard_size(meta.erasure.block_size, meta.erasure.data_blocks, meta.uses_legacy_checksum);
|
||||
let part_size =
|
||||
inline_erasure_shard_file_size(part.size, meta.erasure.block_size, meta.erasure.data_blocks, meta.uses_legacy_checksum);
|
||||
// Check framing arithmetic and the physical buffer length before the shared
|
||||
// verifier sizes its scratch buffer from the metadata.
|
||||
// Validate the complete framing before visiting borrowed payloads.
|
||||
let encoded_size = part_size
|
||||
.div_ceil(shard_size)
|
||||
.checked_mul(algo.size())
|
||||
@@ -7393,9 +7441,11 @@ async fn verify_inline_part_bitrot(meta: &FileInfo) -> disk::error::Result<()> {
|
||||
if encoded_size != data.len() {
|
||||
return Err(DiskError::FileCorrupt);
|
||||
}
|
||||
coding::bitrot_verify(Cursor::new(data), encoded_size, part_size, algo, shard_size)
|
||||
.await
|
||||
.map_err(|_| DiskError::FileCorrupt)
|
||||
let stride = shard_size.checked_add(algo.size()).ok_or(DiskError::FileCorrupt)?;
|
||||
for frame in data.chunks(stride) {
|
||||
coding::verified_bitrot_frame(&algo, false, frame).map_err(|_| DiskError::FileCorrupt)?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn validate_deep_scan_results(results: &[usize], expected_parts: usize) -> disk::error::Result<()> {
|
||||
@@ -7613,7 +7663,7 @@ async fn disks_with_all_parts(
|
||||
// before deciding whether reconstruction (and its bitrot readers) is needed.
|
||||
if (meta.data.is_some() || meta.size == 0) && !meta.parts.is_empty() {
|
||||
let part_status = if scan_mode == HealScanMode::Deep && meta.data.is_some() {
|
||||
match verify_inline_part_bitrot(meta).await {
|
||||
match verify_inline_part_bitrot(meta) {
|
||||
Ok(()) => CHECK_PART_SUCCESS,
|
||||
Err(DiskError::FileCorrupt) => CHECK_PART_FILE_CORRUPT,
|
||||
Err(err) => return Err(err),
|
||||
@@ -14991,21 +15041,19 @@ mod tests {
|
||||
let (_, files, _, _) = inline_bitrot_files_for_payload_with_mode(&payload, legacy).await;
|
||||
for mut meta in files {
|
||||
assert!(meta.erasure.checksums.is_empty(), "legacy metadata may omit per-part checksum entries");
|
||||
verify_inline_part_bitrot(&meta)
|
||||
.await
|
||||
.expect("healthy data and parity shards should verify");
|
||||
verify_inline_part_bitrot(&meta).expect("healthy data and parity shards should verify");
|
||||
let original = meta.data.clone().expect("fixture should retain inline bytes");
|
||||
for offset in [0, 32, original.len() - 1] {
|
||||
let mut damaged = original.to_vec();
|
||||
damaged[offset] ^= 1;
|
||||
meta.data = Some(Bytes::from(damaged));
|
||||
assert_eq!(verify_inline_part_bitrot(&meta).await, Err(DiskError::FileCorrupt));
|
||||
assert_eq!(verify_inline_part_bitrot(&meta), Err(DiskError::FileCorrupt));
|
||||
}
|
||||
let mut trailing = original.to_vec();
|
||||
trailing.push(0x7b);
|
||||
for damaged in [Vec::new(), original[..original.len() - 1].to_vec(), trailing] {
|
||||
meta.data = Some(Bytes::from(damaged));
|
||||
assert_eq!(verify_inline_part_bitrot(&meta).await, Err(DiskError::FileCorrupt));
|
||||
assert_eq!(verify_inline_part_bitrot(&meta), Err(DiskError::FileCorrupt));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15019,19 +15067,17 @@ mod tests {
|
||||
empty.parts[0].size = 0;
|
||||
empty.parts[0].actual_size = 0;
|
||||
empty.data = Some(Bytes::new());
|
||||
verify_inline_part_bitrot(&empty)
|
||||
.await
|
||||
.expect("empty inline objects have no bitrot frames");
|
||||
verify_inline_part_bitrot(&empty).expect("empty inline objects have no bitrot frames");
|
||||
empty.data = Some(Bytes::from_static(b"unexpected"));
|
||||
assert_eq!(verify_inline_part_bitrot(&empty).await, Err(DiskError::FileCorrupt));
|
||||
assert_eq!(verify_inline_part_bitrot(&empty), Err(DiskError::FileCorrupt));
|
||||
|
||||
let mut invalid = files[0].clone();
|
||||
invalid.erasure.block_size = 0;
|
||||
assert_eq!(verify_inline_part_bitrot(&invalid).await, Err(DiskError::FileCorrupt));
|
||||
assert_eq!(verify_inline_part_bitrot(&invalid), Err(DiskError::FileCorrupt));
|
||||
invalid = files[0].clone();
|
||||
invalid.parts.push(invalid.parts[0].clone());
|
||||
invalid.parts[1].number = 2;
|
||||
assert_eq!(verify_inline_part_bitrot(&invalid).await, Err(DiskError::FileCorrupt));
|
||||
assert_eq!(verify_inline_part_bitrot(&invalid), Err(DiskError::FileCorrupt));
|
||||
|
||||
let mut oversized = files[0].clone();
|
||||
oversized.erasure.block_size = 2;
|
||||
@@ -15040,7 +15086,7 @@ mod tests {
|
||||
oversized
|
||||
.validate_for_metadata_read()
|
||||
.expect("logical shard length should fit metadata bounds");
|
||||
assert_eq!(verify_inline_part_bitrot(&oversized).await, Err(DiskError::FileCorrupt));
|
||||
assert_eq!(verify_inline_part_bitrot(&oversized), Err(DiskError::FileCorrupt));
|
||||
|
||||
oversized.erasure.block_size = 1 << 40;
|
||||
oversized.size = 1 << 40;
|
||||
@@ -15048,7 +15094,7 @@ mod tests {
|
||||
oversized
|
||||
.validate_for_metadata_read()
|
||||
.expect("large metadata geometry should remain representable");
|
||||
assert_eq!(verify_inline_part_bitrot(&oversized).await, Err(DiskError::FileCorrupt));
|
||||
assert_eq!(verify_inline_part_bitrot(&oversized), Err(DiskError::FileCorrupt));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -15071,13 +15117,11 @@ mod tests {
|
||||
assert_eq!(meta.uses_legacy_checksum, legacy);
|
||||
assert!(meta.inline_data());
|
||||
assert!(meta.data.is_some(), "the production decoder should extract the historical inline value");
|
||||
verify_inline_part_bitrot(&meta)
|
||||
.await
|
||||
.expect("historical inline shard should pass deep verification");
|
||||
verify_inline_part_bitrot(&meta).expect("historical inline shard should pass deep verification");
|
||||
let mut damaged = meta.data.as_ref().expect("fixture should be inline").to_vec();
|
||||
*damaged.last_mut().expect("fixture shard should not be empty") ^= 1;
|
||||
meta.data = Some(Bytes::from(damaged));
|
||||
assert_eq!(verify_inline_part_bitrot(&meta).await, Err(DiskError::FileCorrupt));
|
||||
assert_eq!(verify_inline_part_bitrot(&meta), Err(DiskError::FileCorrupt));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15121,6 +15165,48 @@ mod tests {
|
||||
fi
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inline_put_admission_bounds_only_the_multi_block_extension() {
|
||||
let block = 1024 * 1024;
|
||||
let config = crate::config::storageclass::Config::default();
|
||||
let erasure = coding::Erasure::new(12, 4, block);
|
||||
let admits = |stored, actual, protected| should_inline_put(&config, &erasure, stored, actual, false, protected);
|
||||
assert!(admits(1280 * 1024, 1280 * 1024, false));
|
||||
assert!(!admits(1280 * 1024, 1280 * 1024, true));
|
||||
assert!(!admits(-1, 1280 * 1024, false));
|
||||
assert!(admits(-1, block as i64, false));
|
||||
assert!(!admits(-1, block as i64, true));
|
||||
assert!(!admits(2 * 1024 * 1024 + 1, 0, false));
|
||||
assert!(admits(0, 0, false));
|
||||
assert!(admits(1_572_856, 0, false));
|
||||
assert!(!admits(1_572_857, 0, false));
|
||||
assert!(should_inline_put(&config, &erasure, 196_608, 0, true, false));
|
||||
assert!(!should_inline_put(&config, &erasure, 196_609, 0, true, false));
|
||||
let small_blocks = coding::Erasure::new(12, 4, 4096);
|
||||
assert!(should_inline_put(&config, &small_blocks, 32 * 4096, 0, false, false));
|
||||
assert!(!should_inline_put(&config, &small_blocks, 32 * 4096 + 1, 0, false, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inline_body_buffering_limits_size_and_frame_count() {
|
||||
let mut info = FileInfo::new("bucket/object", 12, 4);
|
||||
info.size = 2 * 1024 * 1024;
|
||||
info.erasure.block_size = 1024 * 1024;
|
||||
assert!(inline_body_buffering_miss_reason(&info).is_none());
|
||||
info.size += 1;
|
||||
assert!(inline_body_buffering_miss_reason(&info).is_some());
|
||||
info.erasure.block_size = 4096;
|
||||
info.size = 32 * 4096;
|
||||
assert!(inline_body_buffering_miss_reason(&info).is_none());
|
||||
info.size += 1;
|
||||
assert!(inline_body_buffering_miss_reason(&info).is_some());
|
||||
info.size = -1;
|
||||
assert!(inline_body_buffering_miss_reason(&info).is_some());
|
||||
info.size = 1;
|
||||
info.erasure.block_size = 0;
|
||||
assert!(inline_body_buffering_miss_reason(&info).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn collect_inline_data_shards_by_index_uses_distribution_order() {
|
||||
let distribution = vec![3, 1, 5, 2, 4, 6];
|
||||
@@ -15162,6 +15248,100 @@ mod tests {
|
||||
];
|
||||
|
||||
assert!(collect_inline_data_shard_fileinfos_by_index(&files, &fi, 2, |_| true).is_none());
|
||||
assert_eq!(
|
||||
collect_inline_data_shard_fileinfos_by_index_or_reason(&files, &fi, usize::MAX, |_| true).expect_err("invalid count"),
|
||||
GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_GEOMETRY,
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn inline_frame_decoder_handles_legacy_padding_hashes_and_unhashed_parts() {
|
||||
for size in [1, 3, 8, 11, 16] {
|
||||
let payload = &b"abcdefghijklmnop"[..size];
|
||||
for (legacy, algorithm) in [
|
||||
(false, HashAlgorithm::HighwayHash256S),
|
||||
(true, HashAlgorithm::HighwayHash256SLegacy),
|
||||
(false, HashAlgorithm::None),
|
||||
] {
|
||||
let erasure = coding::Erasure::new_with_options(2, 2, 8, legacy);
|
||||
let mut writers: Vec<_> = (0..4)
|
||||
.map(|_| {
|
||||
coding::BitrotWriterWrapper::new(
|
||||
coding::CustomWriter::new_inline_buffer(),
|
||||
erasure.shard_size(),
|
||||
algorithm.clone(),
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
for block in payload.chunks(8) {
|
||||
let shards = erasure.encode_data(block).expect("encode golden frame");
|
||||
for (writer, shard) in writers.iter_mut().zip(shards) {
|
||||
writer.write(&shard).await.expect("write golden frame");
|
||||
}
|
||||
}
|
||||
let mut info = FileInfo::new("bucket/object", 2, 2);
|
||||
info.size = i64::try_from(payload.len()).expect("test payload size fits i64");
|
||||
info.erasure.block_size = 8;
|
||||
info.uses_legacy_checksum = legacy;
|
||||
info.add_object_part(1, "etag".to_owned(), payload.len(), None, info.size, None, None);
|
||||
info.erasure.checksums = vec![rustfs_filemeta::ChecksumInfo {
|
||||
part_number: 1,
|
||||
algorithm: algorithm.clone(),
|
||||
..Default::default()
|
||||
}];
|
||||
let mut files: Vec<_> = writers
|
||||
.into_iter()
|
||||
.enumerate()
|
||||
.map(|(index, writer)| {
|
||||
let mut file = info.clone();
|
||||
file.erasure.index = index + 1;
|
||||
file.data = writer.into_inline_data();
|
||||
file
|
||||
})
|
||||
.collect();
|
||||
let refs = [&files[0], &files[1]];
|
||||
let body = try_decode_inline_data_shards("golden", &info, &refs, false).expect("decode every golden frame");
|
||||
assert_eq!(body.as_ref(), payload);
|
||||
if algorithm.size() > 0 {
|
||||
for file in &files {
|
||||
verify_inline_part_bitrot(file).expect("deep verification covers both padded frames");
|
||||
}
|
||||
}
|
||||
for shard_index in 0..info.erasure.data_blocks {
|
||||
let original = files[shard_index].data.as_ref().expect("selected data shard").clone();
|
||||
let mut trailing = original.to_vec();
|
||||
trailing.push(0x7b);
|
||||
for malformed in [original[..original.len() - 1].to_vec(), trailing] {
|
||||
files[shard_index].data = Some(Bytes::from(malformed));
|
||||
for skip_verify_bitrot in [false, true] {
|
||||
assert!(
|
||||
try_decode_inline_data_shards("inexact", &info, &[&files[0], &files[1]], skip_verify_bitrot)
|
||||
.is_none(),
|
||||
"reject inexact shard {shard_index}: legacy={legacy}, algorithm={algorithm:?}, size={}",
|
||||
payload.len()
|
||||
);
|
||||
}
|
||||
}
|
||||
files[shard_index].data = Some(original);
|
||||
}
|
||||
let original = files[0].data.as_ref().expect("first data shard").clone();
|
||||
let mut truncated = original.to_vec();
|
||||
truncated.pop();
|
||||
files[0].data = Some(Bytes::from(truncated));
|
||||
assert!(try_decode_inline_data_shards("truncated", &info, &[&files[0], &files[1]], false).is_none());
|
||||
if algorithm.size() > 0 {
|
||||
assert_eq!(verify_inline_part_bitrot(&files[0]), Err(DiskError::FileCorrupt));
|
||||
let mut corrupt = original.to_vec();
|
||||
*corrupt.last_mut().expect("last frame payload") ^= 1;
|
||||
files[0].data = Some(Bytes::from(corrupt));
|
||||
assert!(try_decode_inline_data_shards("corrupt", &info, &[&files[0], &files[1]], false).is_none());
|
||||
assert_eq!(verify_inline_part_bitrot(&files[0]), Err(DiskError::FileCorrupt));
|
||||
assert!(try_decode_inline_data_shards("diagnostic", &info, &[&files[0], &files[1]], true).is_some());
|
||||
} else {
|
||||
assert_eq!(verify_inline_part_bitrot(&files[0]), Err(DiskError::BitrotHashAlgoInvalid));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -15169,7 +15349,7 @@ mod tests {
|
||||
let payload = b"small inline object payload that spans data shards";
|
||||
let (erasure, files, read_length, checksum_algo) = inline_bitrot_files_for_payload(payload).await;
|
||||
let mut readers = build_inline_bitrot_readers(
|
||||
&files,
|
||||
files.iter(),
|
||||
erasure.data_shards,
|
||||
"bucket",
|
||||
"object",
|
||||
@@ -15195,7 +15375,7 @@ mod tests {
|
||||
let (erasure, files, read_length, checksum_algo) = inline_bitrot_files_for_payload_with_mode(payload, true).await;
|
||||
assert_ne!(payload.len() % erasure.data_shards, 0, "test payload must exercise EC padding");
|
||||
let mut readers = build_inline_bitrot_readers(
|
||||
&files,
|
||||
files.iter(),
|
||||
erasure.data_shards,
|
||||
"bucket",
|
||||
"object",
|
||||
@@ -15226,7 +15406,7 @@ mod tests {
|
||||
*second = Bytes::from(corrupted);
|
||||
|
||||
let mut readers = build_inline_bitrot_readers(
|
||||
&files,
|
||||
files.iter(),
|
||||
erasure.total_shard_count(),
|
||||
"bucket",
|
||||
"object",
|
||||
@@ -15244,31 +15424,17 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inline_data_shards_direct_read_requires_single_block() {
|
||||
assert!(can_try_inline_data_shards_direct(1024, 1024));
|
||||
assert!(!can_try_inline_data_shards_direct(0, 1024));
|
||||
assert!(!can_try_inline_data_shards_direct(1025, 1024));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inline_erasure_offset_helpers_match_erasure_methods() {
|
||||
fn inline_erasure_size_helpers_match_erasure_methods() {
|
||||
for uses_legacy in [false, true] {
|
||||
let erasure = coding::Erasure::new_with_options(4, 2, 1024 * 1024, uses_legacy);
|
||||
for object_size in [1usize, 1024, 100 * 1024, 1024 * 1024] {
|
||||
for object_size in [1usize, 1024, 100 * 1024, 1024 * 1024, 1024 * 1024 + 1, 2 * 1024 * 1024 + 1] {
|
||||
assert_eq!(
|
||||
inline_erasure_shard_size(erasure.block_size, erasure.data_shards, uses_legacy),
|
||||
erasure.shard_size()
|
||||
);
|
||||
assert_eq!(
|
||||
inline_erasure_shard_file_offset(
|
||||
0,
|
||||
object_size,
|
||||
object_size,
|
||||
erasure.block_size,
|
||||
erasure.data_shards,
|
||||
uses_legacy,
|
||||
),
|
||||
erasure.shard_file_offset(0, object_size, object_size)
|
||||
inline_erasure_shard_file_size(object_size, erasure.block_size, erasure.data_shards, uses_legacy),
|
||||
usize::try_from(erasure.shard_file_size(object_size as i64)).expect("test shard size")
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -15789,25 +15955,14 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn inline_admission_falls_back_to_actual_size_for_transformed_streams() {
|
||||
let config = crate::config::storageclass::Config::default();
|
||||
let erasure = coding::Erasure::new(2, 2, 1024 * 1024);
|
||||
let unknown = HashReader::SIZE_PRESERVE_LAYER;
|
||||
|
||||
// A known stored size is authoritative, whatever the plaintext size says.
|
||||
assert_eq!(
|
||||
inline_admission_shard_size(&erasure, 16 * 1024, 4 * 1024 * 1024),
|
||||
erasure.shard_file_size(16 * 1024)
|
||||
);
|
||||
assert_eq!(inline_admission_shard_size(&erasure, 0, 4 * 1024), 0);
|
||||
|
||||
// A transformed stream is sized by its plaintext length (MinIO parity).
|
||||
assert_eq!(
|
||||
inline_admission_shard_size(&erasure, unknown, 16 * 1024),
|
||||
erasure.shard_file_size(16 * 1024)
|
||||
);
|
||||
|
||||
// Neither size known, or an empty transformed stream, cannot be admitted.
|
||||
assert!(inline_admission_shard_size(&erasure, unknown, 0) < 0);
|
||||
assert!(inline_admission_shard_size(&erasure, unknown, unknown) < 0);
|
||||
assert!(should_inline_put(&config, &erasure, 16 * 1024, 4 * 1024 * 1024, false, false));
|
||||
assert!(should_inline_put(&config, &erasure, 0, 4 * 1024, false, false));
|
||||
assert!(should_inline_put(&config, &erasure, unknown, 16 * 1024, false, false));
|
||||
assert!(!should_inline_put(&config, &erasure, unknown, 0, false, false));
|
||||
assert!(!should_inline_put(&config, &erasure, unknown, unknown, false, false));
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -43,28 +43,26 @@ use super::super::{
|
||||
ReplicationObjectBridge, Result, SET_DISK_COMMIT_TAIL_WARN_THRESHOLD_MS, SLASH_SEPARATOR, SUFFIX_ACTUAL_SIZE,
|
||||
SUFFIX_COMPRESSION, SUFFIX_COMPRESSION_SIZE, SUFFIX_RESTORE_COPYBACK, SUFFIX_RESTORE_OPERATION_ID,
|
||||
SUFFIX_RESTORE_WORKER_LOCK, SetDisks, SmallWritePath, StorageError, TRANSITION_COMPLETE, UpdateMetadataOpts, Uuid,
|
||||
WriteLayout, adaptive_duplex_buffer_size, build_get_object_info, build_inline_bitrot_readers,
|
||||
build_inline_bitrot_readers_from_refs, can_try_inline_data_shards_direct, check_object_lock_delete,
|
||||
WriteLayout, adaptive_duplex_buffer_size, build_get_object_info, build_inline_bitrot_readers, check_object_lock_delete,
|
||||
check_object_lock_for_deletion_with_state, check_object_lock_retention_update, classify_get_codec_streaming_object_class,
|
||||
classify_put_write_path, classify_storage_error, collect_inline_data_shard_fileinfos_by_index, contains_key_str,
|
||||
create_bitrot_writer_with_orig_volume, debug, delete_file_info_version_id, disk, ensure_delete_commit_locks_held, error,
|
||||
explicit_delete_removed_marker, finish_set_disk_read_lock, get_codec_streaming_reader_gate_with_plan,
|
||||
get_object_body_cache_hook, get_raw_etag, get_small_object_direct_memory_decision_with_threshold_and_plan,
|
||||
get_small_object_direct_memory_threshold, get_stage_timer_if_enabled, get_str,
|
||||
get_transitioned_object_reader_with_tier_manager, inline_admission_shard_size, inline_erasure_shard_file_offset,
|
||||
inline_erasure_shard_size, insert_str, is_deadlock_detection_enabled, is_err_object_not_found, is_err_version_not_found,
|
||||
is_explicit_null_version, is_get_codec_streaming_base_enabled, is_get_small_object_direct_memory_enabled,
|
||||
is_lock_optimization_enabled, issue3031_diag_enabled, join_all, known_put_object_storage_size, path_join_buf,
|
||||
put_restore_opts, record_compression_total_memory, record_get_codec_streaming_gate_decision,
|
||||
record_get_direct_memory_decision, record_get_object_pipeline_failure, record_get_object_pipeline_failure_for_path,
|
||||
record_get_object_reader_path_observation, record_get_stage_duration_if_enabled, record_lock_acquire,
|
||||
reduce_write_quorum_errs, release_materialized_read_lock, replication_write_may_pass_worm_gate,
|
||||
get_transitioned_object_reader_with_tier_manager, insert_str, is_deadlock_detection_enabled, is_err_object_not_found,
|
||||
is_err_version_not_found, is_explicit_null_version, is_get_codec_streaming_base_enabled,
|
||||
is_get_small_object_direct_memory_enabled, is_lock_optimization_enabled, issue3031_diag_enabled, join_all,
|
||||
known_put_object_storage_size, part_checksum_algorithm, path_join_buf, put_restore_opts, record_compression_total_memory,
|
||||
record_get_codec_streaming_gate_decision, record_get_direct_memory_decision, record_get_object_pipeline_failure,
|
||||
record_get_object_pipeline_failure_for_path, record_get_object_reader_path_observation, record_get_stage_duration_if_enabled,
|
||||
record_lock_acquire, reduce_write_quorum_errs, release_materialized_read_lock, replication_write_may_pass_worm_gate,
|
||||
republishes_data_movement_delete_marker, require_restore_operation_id, resolve_delete_version_state,
|
||||
resolve_tiered_decommission_write_quorum_result, resolve_write_layout, restore_commit_operation_id_from_metadata,
|
||||
restore_operation_id_from_metadata, send_event, set_disk_delete_creates_delete_marker,
|
||||
should_force_delete_marker_for_missing_version, should_persist_encryption_original_size,
|
||||
should_force_delete_marker_for_missing_version, should_inline_put, should_persist_encryption_original_size,
|
||||
should_preserve_delete_replication_state, should_use_inline_fast_path_with_plan, take_prepared_get_object_metadata,
|
||||
to_object_err, try_read_inline_data_shards_direct, warn,
|
||||
to_object_err, try_decode_inline_data_shards, warn,
|
||||
};
|
||||
use super::bitrot_self_verify::{BitrotSelfVerifyTarget, drop_failed_writer_disks, verify_written_bitrot_shards};
|
||||
use super::delete_recovery::DeleteRecoveryContext;
|
||||
@@ -3096,118 +3094,109 @@ impl crate::storage_api_contracts::object::ObjectIO for SetDisks {
|
||||
// requests do not pay for part and transform scans they cannot use.
|
||||
let read_path_plan = ReadPathPlan::new(&object_info, fi);
|
||||
|
||||
// Inline data fast path: skip duplex pipe for small inline objects.
|
||||
// Uses the shared predicate from ObjectInfo; additionally checks that
|
||||
// inline data is actually present and neither range nor partNumber is
|
||||
// in flight.
|
||||
let use_inline_fast_path = object_info.is_inline_fast_path_eligible()
|
||||
&& fi.data.is_some()
|
||||
&& range.is_none()
|
||||
&& opts.part_number.is_none()
|
||||
&& should_use_inline_fast_path_with_plan(&range, &object_info, fi, opts, read_path_plan);
|
||||
if use_inline_fast_path {
|
||||
let mut inline_prepare_stage_start = get_stage_timer_if_enabled(stage_metrics_enabled);
|
||||
// A verified snapshot and a full metadata fanout share one bounded
|
||||
// systematic decoder. Recovery keeps the normal erasure reader.
|
||||
if should_use_inline_fast_path_with_plan(&range, &object_info, fi, opts, read_path_plan) {
|
||||
let data_shards = fi.erasure.data_blocks;
|
||||
|
||||
let object_size = usize::try_from(fi.size)
|
||||
.map_err(|_| to_object_err(Error::other("inline fast path object size is invalid"), vec![bucket, object]))?;
|
||||
|
||||
if can_try_inline_data_shards_direct(object_size, fi.erasure.block_size)
|
||||
&& let Some(body) = verified_inline_body.filter(|body| body.len() == object_size)
|
||||
{
|
||||
if let Some(inline_prepare_stage_start) = inline_prepare_stage_start.take() {
|
||||
rustfs_io_metrics::record_get_object_stage_duration_by_size(
|
||||
GET_OBJECT_PATH_INLINE_DIRECT,
|
||||
GET_STAGE_INLINE_PREPARE,
|
||||
object_class.as_str(),
|
||||
size_bucket,
|
||||
inline_prepare_stage_start.elapsed().as_secs_f64(),
|
||||
);
|
||||
}
|
||||
if rustfs_io_metrics::get_stage_metrics_enabled() {
|
||||
rustfs_io_metrics::record_get_object_stage_duration_by_size(
|
||||
GET_OBJECT_PATH_INLINE_DIRECT,
|
||||
GET_STAGE_READER_SETUP,
|
||||
object_class.as_str(),
|
||||
size_bucket,
|
||||
0.0,
|
||||
);
|
||||
rustfs_io_metrics::record_get_object_stage_duration_by_size(
|
||||
GET_OBJECT_PATH_INLINE_DIRECT,
|
||||
GET_STAGE_DECODE,
|
||||
object_class.as_str(),
|
||||
size_bucket,
|
||||
0.0,
|
||||
);
|
||||
}
|
||||
record_get_object_reader_path_observation(GET_OBJECT_PATH_INLINE_DIRECT, object_class, size_bucket);
|
||||
let reader = GetObjectReader {
|
||||
stream: Box::new(Cursor::new(body.clone())),
|
||||
object_info,
|
||||
buffered_body: Some(body),
|
||||
body_source: GetObjectBodySource::Unprobed,
|
||||
};
|
||||
return Ok(reader);
|
||||
}
|
||||
|
||||
let checksum_info = fi.erasure.get_checksum_info(fi.parts[0].number);
|
||||
let checksum_algo =
|
||||
if fi.uses_legacy_checksum && checksum_info.algorithm == rustfs_utils::HashAlgorithm::HighwayHash256S {
|
||||
rustfs_utils::HashAlgorithm::HighwayHash256SLegacy
|
||||
} else {
|
||||
checksum_info.algorithm
|
||||
};
|
||||
|
||||
if can_try_inline_data_shards_direct(object_size, fi.erasure.block_size)
|
||||
&& let Some(data_files) = collect_inline_data_shard_fileinfos_by_index(files, fi, data_shards, |index| {
|
||||
let inline_prepare_stage_start = get_stage_timer_if_enabled(stage_metrics_enabled);
|
||||
let verified_body = verified_inline_body.filter(|body| body.len() == object_size);
|
||||
let reused_verified_body = verified_body.is_some();
|
||||
let data_files = if reused_verified_body {
|
||||
None
|
||||
} else {
|
||||
collect_inline_data_shard_fileinfos_by_index(files, fi, data_shards, |index| {
|
||||
disks.get(index).is_some_and(Option::is_some)
|
||||
})
|
||||
{
|
||||
let read_length = inline_erasure_shard_file_offset(
|
||||
0,
|
||||
object_size,
|
||||
object_size,
|
||||
fi.erasure.block_size,
|
||||
data_shards,
|
||||
fi.uses_legacy_checksum,
|
||||
};
|
||||
if let Some(start) = inline_prepare_stage_start {
|
||||
rustfs_io_metrics::record_get_object_stage_duration_by_size(
|
||||
GET_OBJECT_PATH_INLINE_DIRECT,
|
||||
GET_STAGE_INLINE_PREPARE,
|
||||
object_class.as_str(),
|
||||
size_bucket,
|
||||
start.elapsed().as_secs_f64(),
|
||||
);
|
||||
let shard_size = inline_erasure_shard_size(fi.erasure.block_size, data_shards, fi.uses_legacy_checksum);
|
||||
if let Some(inline_prepare_stage_start) = inline_prepare_stage_start.take() {
|
||||
rustfs_io_metrics::record_get_object_stage_duration_by_size(
|
||||
GET_OBJECT_PATH_INLINE_DIRECT,
|
||||
GET_STAGE_INLINE_PREPARE,
|
||||
object_class.as_str(),
|
||||
size_bucket,
|
||||
inline_prepare_stage_start.elapsed().as_secs_f64(),
|
||||
);
|
||||
}
|
||||
let reader_setup_stage_start = rustfs_io_metrics::get_stage_metrics_enabled().then(Instant::now);
|
||||
let mut readers = build_inline_bitrot_readers_from_refs(
|
||||
&data_files,
|
||||
bucket,
|
||||
object,
|
||||
read_length,
|
||||
shard_size,
|
||||
&checksum_algo,
|
||||
opts.skip_verify_bitrot,
|
||||
)
|
||||
.await?;
|
||||
if let Some(reader_setup_stage_start) = reader_setup_stage_start {
|
||||
rustfs_io_metrics::record_get_object_stage_duration_by_size(
|
||||
GET_OBJECT_PATH_INLINE_DIRECT,
|
||||
GET_STAGE_READER_SETUP,
|
||||
object_class.as_str(),
|
||||
size_bucket,
|
||||
reader_setup_stage_start.elapsed().as_secs_f64(),
|
||||
);
|
||||
}
|
||||
}
|
||||
let attempted_systematic_decode = data_files.is_some();
|
||||
let decode_stage_start = get_stage_timer_if_enabled(stage_metrics_enabled);
|
||||
let mut body = verified_body.or_else(|| {
|
||||
data_files.and_then(|files| try_decode_inline_data_shards(object, fi, &files, opts.skip_verify_bitrot))
|
||||
});
|
||||
if (reused_verified_body || attempted_systematic_decode)
|
||||
&& let Some(start) = decode_stage_start
|
||||
{
|
||||
rustfs_io_metrics::record_get_object_stage_duration_by_size(
|
||||
GET_OBJECT_PATH_INLINE_DIRECT,
|
||||
GET_STAGE_READER_SETUP,
|
||||
object_class.as_str(),
|
||||
size_bucket,
|
||||
0.0,
|
||||
);
|
||||
rustfs_io_metrics::record_get_object_stage_duration_by_size(
|
||||
GET_OBJECT_PATH_INLINE_DIRECT,
|
||||
GET_STAGE_DECODE,
|
||||
object_class.as_str(),
|
||||
size_bucket,
|
||||
if reused_verified_body {
|
||||
0.0
|
||||
} else {
|
||||
start.elapsed().as_secs_f64()
|
||||
},
|
||||
);
|
||||
}
|
||||
if body.is_none() {
|
||||
let checksum_algo = part_checksum_algorithm(fi, fi.parts[0].number);
|
||||
let erasure = self.erasure_cache.get_for_file_info(fi)?;
|
||||
let read_length = erasure.shard_file_offset(0, object_size, object_size);
|
||||
let total_shards = data_shards + fi.erasure.parity_blocks;
|
||||
let (_disks, files) = Self::shuffle_disks_and_parts_metadata_by_index(disks, files, fi);
|
||||
|
||||
// Decode directly
|
||||
let decode_stage_start = rustfs_io_metrics::get_stage_metrics_enabled().then(Instant::now);
|
||||
#[cfg(test)]
|
||||
crate::set_disk::disk_call_counters::record(object, crate::set_disk::disk_call_counters::KIND_BODY_DECODE, 0);
|
||||
if let Some(body) = try_read_inline_data_shards_direct(&mut readers, data_shards, read_length, object_size).await
|
||||
{
|
||||
// Check if we have enough inline data shards
|
||||
let inline_count = files
|
||||
.iter()
|
||||
.take(data_shards)
|
||||
.filter(|f| f.data.as_ref().is_some_and(|d| !d.is_empty()))
|
||||
.count();
|
||||
|
||||
if inline_count >= data_shards {
|
||||
let reader_setup_stage_start = rustfs_io_metrics::get_stage_metrics_enabled().then(Instant::now);
|
||||
let readers = build_inline_bitrot_readers(
|
||||
files.iter(),
|
||||
total_shards,
|
||||
bucket,
|
||||
object,
|
||||
read_length,
|
||||
erasure.shard_size(),
|
||||
&checksum_algo,
|
||||
opts.skip_verify_bitrot,
|
||||
)
|
||||
.await?;
|
||||
if let Some(reader_setup_stage_start) = reader_setup_stage_start {
|
||||
rustfs_io_metrics::record_get_object_stage_duration_by_size(
|
||||
GET_OBJECT_PATH_INLINE_DIRECT,
|
||||
GET_STAGE_READER_SETUP,
|
||||
object_class.as_str(),
|
||||
size_bucket,
|
||||
reader_setup_stage_start.elapsed().as_secs_f64(),
|
||||
);
|
||||
}
|
||||
|
||||
let decode_stage_start = rustfs_io_metrics::get_stage_metrics_enabled().then(Instant::now);
|
||||
let mut output = Cursor::new(Vec::with_capacity(object_size));
|
||||
#[cfg(test)]
|
||||
crate::set_disk::disk_call_counters::record(object, crate::set_disk::disk_call_counters::KIND_BODY_DECODE, 0);
|
||||
let (written, err) = erasure.decode(&mut output, readers, 0, object_size, object_size).await;
|
||||
if let Some(e) = err {
|
||||
return Err(to_object_err(e.into(), vec![bucket, object]));
|
||||
}
|
||||
if written != object_size {
|
||||
return Err(to_object_err(
|
||||
Error::other("inline fast path: erasure decode returned an unexpected body length"),
|
||||
vec![bucket, object],
|
||||
));
|
||||
}
|
||||
if let Some(decode_stage_start) = decode_stage_start {
|
||||
rustfs_io_metrics::record_get_object_stage_duration_by_size(
|
||||
GET_OBJECT_PATH_INLINE_DIRECT,
|
||||
@@ -3218,94 +3207,17 @@ impl crate::storage_api_contracts::object::ObjectIO for SetDisks {
|
||||
);
|
||||
}
|
||||
|
||||
record_get_object_reader_path_observation(GET_OBJECT_PATH_INLINE_DIRECT, object_class, size_bucket);
|
||||
let reader = GetObjectReader {
|
||||
stream: Box::new(Cursor::new(body.clone())),
|
||||
object_info,
|
||||
buffered_body: Some(body),
|
||||
body_source: GetObjectBodySource::Unprobed,
|
||||
};
|
||||
return Ok(reader);
|
||||
body = Some(Bytes::from(output.into_inner()));
|
||||
}
|
||||
}
|
||||
|
||||
let erasure = self.erasure_cache.get_for_file_info(fi)?;
|
||||
let read_length = erasure.shard_file_offset(0, object_size, object_size);
|
||||
let total_shards = data_shards + fi.erasure.parity_blocks;
|
||||
let (_disks, files) = Self::shuffle_disks_and_parts_metadata_by_index(disks, files, fi);
|
||||
|
||||
// Check if we have enough inline data shards
|
||||
let inline_count = files
|
||||
.iter()
|
||||
.take(data_shards)
|
||||
.filter(|f| f.data.as_ref().is_some_and(|d| !d.is_empty()))
|
||||
.count();
|
||||
|
||||
if inline_count >= data_shards {
|
||||
if let Some(inline_prepare_stage_start) = inline_prepare_stage_start.take() {
|
||||
rustfs_io_metrics::record_get_object_stage_duration_by_size(
|
||||
GET_OBJECT_PATH_INLINE_DIRECT,
|
||||
GET_STAGE_INLINE_PREPARE,
|
||||
object_class.as_str(),
|
||||
size_bucket,
|
||||
inline_prepare_stage_start.elapsed().as_secs_f64(),
|
||||
);
|
||||
}
|
||||
let reader_setup_stage_start = rustfs_io_metrics::get_stage_metrics_enabled().then(Instant::now);
|
||||
let readers = build_inline_bitrot_readers(
|
||||
&files,
|
||||
total_shards,
|
||||
bucket,
|
||||
object,
|
||||
read_length,
|
||||
erasure.shard_size(),
|
||||
&checksum_algo,
|
||||
opts.skip_verify_bitrot,
|
||||
)
|
||||
.await?;
|
||||
if let Some(reader_setup_stage_start) = reader_setup_stage_start {
|
||||
rustfs_io_metrics::record_get_object_stage_duration_by_size(
|
||||
GET_OBJECT_PATH_INLINE_DIRECT,
|
||||
GET_STAGE_READER_SETUP,
|
||||
object_class.as_str(),
|
||||
size_bucket,
|
||||
reader_setup_stage_start.elapsed().as_secs_f64(),
|
||||
);
|
||||
}
|
||||
|
||||
let decode_stage_start = rustfs_io_metrics::get_stage_metrics_enabled().then(Instant::now);
|
||||
let mut output = Cursor::new(Vec::with_capacity(object_size));
|
||||
#[cfg(test)]
|
||||
crate::set_disk::disk_call_counters::record(object, crate::set_disk::disk_call_counters::KIND_BODY_DECODE, 0);
|
||||
let (written, err) = erasure.decode(&mut output, readers, 0, object_size, object_size).await;
|
||||
if let Some(e) = err {
|
||||
return Err(to_object_err(e.into(), vec![bucket, object]));
|
||||
}
|
||||
if written == 0 && fi.size > 0 {
|
||||
return Err(to_object_err(
|
||||
Error::other("inline fast path: erasure decode returned 0 bytes"),
|
||||
vec![bucket, object],
|
||||
));
|
||||
}
|
||||
let body = Bytes::from(output.into_inner());
|
||||
if let Some(decode_stage_start) = decode_stage_start {
|
||||
rustfs_io_metrics::record_get_object_stage_duration_by_size(
|
||||
GET_OBJECT_PATH_INLINE_DIRECT,
|
||||
GET_STAGE_DECODE,
|
||||
object_class.as_str(),
|
||||
size_bucket,
|
||||
decode_stage_start.elapsed().as_secs_f64(),
|
||||
);
|
||||
}
|
||||
|
||||
if let Some(body) = body {
|
||||
record_get_object_reader_path_observation(GET_OBJECT_PATH_INLINE_DIRECT, object_class, size_bucket);
|
||||
let reader = GetObjectReader {
|
||||
return Ok(GetObjectReader {
|
||||
stream: Box::new(Cursor::new(body.clone())),
|
||||
object_info,
|
||||
buffered_body: Some(body),
|
||||
body_source: GetObjectBodySource::Unprobed,
|
||||
};
|
||||
return Ok(reader);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4784,25 +4696,19 @@ impl SetDisks {
|
||||
|
||||
let put_object_size = known_put_object_storage_size(data.size());
|
||||
let shard_file_size_raw = erasure.shard_file_size(put_object_size);
|
||||
// Transformed streams (unknown stored size) are admitted by their
|
||||
// plaintext size and then take the streaming encode with inline
|
||||
// buffer writers, since the single-block fast path needs a known length.
|
||||
// Every inline candidate keeps the single-block bound on its admission
|
||||
// size: the inline buffer writer grows without a cap, so an explicit
|
||||
// INLINE_BLOCK budget above `block_size` must not admit multi-block
|
||||
// payloads into memory and xl.meta. Protected inline writes also need
|
||||
// a known stored length for their proof metadata, so they never fall
|
||||
// back to the plaintext size.
|
||||
let inline_admission_size = if put_object_size >= 0 || protect_write {
|
||||
put_object_size
|
||||
} else {
|
||||
data.actual_size()
|
||||
};
|
||||
let is_inline_buffer = storage_class_config.should_inline(
|
||||
inline_admission_shard_size(&erasure, put_object_size, data.actual_size()),
|
||||
erasure.data_shards,
|
||||
// Known unprotected streams may span bounded inline frames. The
|
||||
// direct encoder remains single-block, and transformed/protected
|
||||
// writes keep their existing admission contract.
|
||||
let is_inline_buffer = should_inline_put(
|
||||
&storage_class_config,
|
||||
&erasure,
|
||||
put_object_size,
|
||||
data.actual_size(),
|
||||
opts.versioned,
|
||||
) && usize::try_from(inline_admission_size).is_ok_and(|size| size <= erasure.block_size);
|
||||
protect_write,
|
||||
);
|
||||
let multi_block_inline =
|
||||
is_inline_buffer && usize::try_from(put_object_size).is_ok_and(|size| size > erasure.block_size);
|
||||
|
||||
let collect_stage_timing = rustfs_io_metrics::put_stage_metrics_enabled() || issue3031_diag_enabled();
|
||||
let shard_file_size = shard_file_size_raw;
|
||||
@@ -4957,6 +4863,9 @@ impl SetDisks {
|
||||
}
|
||||
|
||||
let _ = mem::replace(&mut data.stream, reader);
|
||||
if multi_block_inline && usize::try_from(put_object_size).ok() != Some(w_size) {
|
||||
return Err(Error::other("inline stream length differs from its admitted storage size"));
|
||||
}
|
||||
// if let Err(err) = close_bitrot_writers(&mut writers).await {
|
||||
// error!("close_bitrot_writers err {:?}", err);
|
||||
// }
|
||||
@@ -15073,7 +14982,7 @@ mod inline_put_commit_path_tests {
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn unprotected_puts_keep_multi_block_inline_candidates_external() {
|
||||
async fn unprotected_puts_keep_oversized_inline_candidates_external() {
|
||||
for transformed in [true, false] {
|
||||
let (temp_dirs, disk_stores, set_disks) = hermetic_set_disks(4).await;
|
||||
let storage_class =
|
||||
@@ -15083,9 +14992,9 @@ mod inline_put_commit_path_tests {
|
||||
let bucket = "unprotected-inline-candidates";
|
||||
let object = "object.bin";
|
||||
make_bucket(&disk_stores, bucket).await;
|
||||
// Above the single erasure block: an explicit INLINE_BLOCK budget must
|
||||
// not pull a multi-block payload into the unbounded inline buffer.
|
||||
let plaintext = compressible_payload(1024 * 1024 + 17);
|
||||
// The bounded extension cannot admit this payload even when the
|
||||
// configured per-shard budget is much larger.
|
||||
let plaintext = compressible_payload(2 * 1024 * 1024 + 17);
|
||||
let (mut reader, opts) = if transformed {
|
||||
transformed_put(plaintext.clone())
|
||||
} else {
|
||||
@@ -15108,7 +15017,7 @@ mod inline_put_commit_path_tests {
|
||||
.unwrap_or_else(|err| panic!("disk {disk_index} should persist metadata: {err}"));
|
||||
assert!(
|
||||
!file_info.inline_data(),
|
||||
"disk {disk_index}: a payload above block_size must stay external (transformed={transformed})"
|
||||
"disk {disk_index}: a payload above the materialization cap must stay external (transformed={transformed})"
|
||||
);
|
||||
}
|
||||
assert!(
|
||||
@@ -15355,14 +15264,14 @@ mod inline_put_commit_path_tests {
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn ec_8_4_default_budget_keeps_large_inline_candidate_out_of_xl_meta() {
|
||||
async fn ec_8_4_default_budget_inlines_single_block_objects() {
|
||||
let (_temp_dirs, disk_stores, set_disks) = hermetic_set_disks(12).await;
|
||||
set_disks.set_test_storage_class_config(
|
||||
lookup_config_for_pools_without_env(&KVS::new(), &[12]).expect("EC8+4 storage class should resolve"),
|
||||
);
|
||||
let bucket = "ec-8-4-inline-budget";
|
||||
let object = "object.bin";
|
||||
let payload = vec![0x5c; 300 * 1024];
|
||||
let payload = vec![0x5c; 1024 * 1024];
|
||||
make_bucket(&disk_stores, bucket).await;
|
||||
|
||||
let mut reader = PutObjReader::from_vec(payload.clone());
|
||||
@@ -15374,7 +15283,7 @@ mod inline_put_commit_path_tests {
|
||||
set_disks.put_object(bucket, object, &mut reader, &ObjectOptions::default()),
|
||||
)
|
||||
.await
|
||||
.expect("EC8+4 PUT should commit through the non-inline path");
|
||||
.expect("EC8+4 PUT should commit through the inline path");
|
||||
|
||||
for (disk_index, disk) in disk_stores.iter().enumerate() {
|
||||
let file_info = disk
|
||||
@@ -15383,19 +15292,19 @@ mod inline_put_commit_path_tests {
|
||||
.unwrap_or_else(|err| panic!("disk {disk_index} should persist EC8+4 metadata: {err}"));
|
||||
assert_eq!(file_info.erasure.data_blocks, 8);
|
||||
assert_eq!(file_info.erasure.parity_blocks, 4);
|
||||
assert!(!file_info.inline_data(), "disk {disk_index} must keep the shard outside xl.meta");
|
||||
assert!(file_info.inline_data(), "disk {disk_index} must persist the shard in xl.meta");
|
||||
}
|
||||
|
||||
let mut object_reader = set_disks
|
||||
.get_object_reader(bucket, object, None, HeaderMap::new(), &ObjectOptions::default())
|
||||
.await
|
||||
.expect("non-inline EC8+4 object should remain readable");
|
||||
.expect("inline EC8+4 object should remain readable");
|
||||
let mut restored = Vec::new();
|
||||
object_reader
|
||||
.stream
|
||||
.read_to_end(&mut restored)
|
||||
.await
|
||||
.expect("non-inline EC8+4 object should stream");
|
||||
.expect("inline EC8+4 object should stream");
|
||||
assert_eq!(restored, payload);
|
||||
}
|
||||
|
||||
@@ -15408,7 +15317,7 @@ mod inline_put_commit_path_tests {
|
||||
);
|
||||
let bucket = "ec-8-4-versioned-inline-budget";
|
||||
let object = "object.bin";
|
||||
let payload = vec![0x73; 64 * 1024];
|
||||
let payload = vec![0x73; 128 * 1024];
|
||||
make_bucket(&disk_stores, bucket).await;
|
||||
|
||||
let options = ObjectOptions {
|
||||
@@ -15431,22 +15340,378 @@ mod inline_put_commit_path_tests {
|
||||
.read_version("", bucket, object, "", &ReadOptions::default())
|
||||
.await
|
||||
.unwrap_or_else(|err| panic!("disk {disk_index} should persist versioned EC8+4 metadata: {err}"));
|
||||
assert!(
|
||||
!file_info.inline_data(),
|
||||
"disk {disk_index} must keep the versioned shard outside xl.meta"
|
||||
);
|
||||
assert!(file_info.inline_data(), "disk {disk_index} must persist the versioned shard in xl.meta");
|
||||
}
|
||||
|
||||
let mut object_reader = set_disks
|
||||
.get_object_reader(bucket, object, None, HeaderMap::new(), &options)
|
||||
.await
|
||||
.expect("versioned non-inline EC8+4 object should remain readable");
|
||||
.expect("versioned inline EC8+4 object should remain readable");
|
||||
let mut restored = Vec::new();
|
||||
object_reader
|
||||
.stream
|
||||
.read_to_end(&mut restored)
|
||||
.await
|
||||
.expect("versioned non-inline EC8+4 object should stream");
|
||||
.expect("versioned inline EC8+4 object should stream");
|
||||
assert_eq!(restored, payload);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn inline_budget_changes_preserve_existing_inline_and_external_objects() {
|
||||
let (_temp_dirs, disk_stores, set_disks) = hermetic_set_disks(12).await;
|
||||
let default_config =
|
||||
lookup_config_for_pools_without_env(&KVS::new(), &[12]).expect("default EC8+4 storage class should resolve");
|
||||
let legacy_config = temp_env::with_var(INLINE_BLOCK_ENV, Some("32KiB"), || {
|
||||
lookup_config_for_pools(&KVS::new(), &[12]).expect("resolve the historical per-shard limit for this pool")
|
||||
});
|
||||
let bucket = "inline-budget-layout-compat";
|
||||
let payload = vec![0x6b; 300 * 1024];
|
||||
make_bucket(&disk_stores, bucket).await;
|
||||
|
||||
for (object, config, expected_inline) in [
|
||||
("legacy-external", legacy_config.clone(), false),
|
||||
("new-inline", default_config.clone(), true),
|
||||
] {
|
||||
set_disks.set_test_storage_class_config(config);
|
||||
let mut reader = PutObjReader::from_vec(payload.clone());
|
||||
set_disks
|
||||
.put_object(
|
||||
bucket,
|
||||
object,
|
||||
&mut reader,
|
||||
&ObjectOptions {
|
||||
no_lock: true,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("commit object using the selected placement policy");
|
||||
for disk in &disk_stores {
|
||||
let persisted = disk
|
||||
.read_version("", bucket, object, "", &ReadOptions::default())
|
||||
.await
|
||||
.expect("read actual persisted layout");
|
||||
assert_eq!(persisted.inline_data(), expected_inline, "placement for {object}");
|
||||
}
|
||||
}
|
||||
|
||||
for config in [default_config, legacy_config] {
|
||||
set_disks.set_test_storage_class_config(config);
|
||||
for object in ["legacy-external", "new-inline"] {
|
||||
let mut reader = set_disks
|
||||
.get_object_reader(bucket, object, None, HeaderMap::new(), &ObjectOptions::default())
|
||||
.await
|
||||
.expect("read historical layout after changing the budget");
|
||||
let mut restored = Vec::new();
|
||||
reader.stream.read_to_end(&mut restored).await.expect("read object body");
|
||||
assert_eq!(restored, payload, "body for {object}");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn multi_block_inline_preserves_default_geometry_and_exact_budget() {
|
||||
temp_env::async_with_vars([(rustfs_config::ENV_ERASURE_SHARD_BYTES, Some("0"))], async {
|
||||
let (directories, disks, set) = hermetic_set_disks(16).await;
|
||||
set.set_test_storage_class_config(
|
||||
lookup_config_for_pools_without_env(&KVS::new(), &[16]).expect("EC12+4 configuration"),
|
||||
);
|
||||
let bucket = "multi-block-inline-boundary";
|
||||
make_bucket(&disks, bucket).await;
|
||||
let block = 1024 * 1024;
|
||||
for length in [block + 1, 1280 * 1024, 1_572_855, 1_572_856, 1_572_857] {
|
||||
let object = format!("size-{length}");
|
||||
let payload: Vec<u8> = (0..length).map(|index| (index % 251) as u8).collect();
|
||||
let mut input = PutObjReader::from_vec(payload.clone());
|
||||
set.put_object(
|
||||
bucket,
|
||||
&object,
|
||||
&mut input,
|
||||
&ObjectOptions {
|
||||
no_lock: true,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("write boundary object");
|
||||
let inline = length <= 1_572_856;
|
||||
for disk in &disks {
|
||||
let info = disk
|
||||
.read_version(
|
||||
"",
|
||||
bucket,
|
||||
&object,
|
||||
"",
|
||||
&ReadOptions {
|
||||
read_data: true,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("read persisted geometry");
|
||||
assert_eq!(info.erasure.block_size, block);
|
||||
assert_eq!((info.erasure.data_blocks, info.erasure.parity_blocks), (12, 4));
|
||||
assert_eq!(info.inline_data(), inline, "placement at {length}");
|
||||
if inline {
|
||||
let shard_payload = block.div_ceil(12) + (length - block).div_ceil(12);
|
||||
assert!(shard_payload <= 128 * 1024);
|
||||
assert_eq!(info.data.as_ref().expect("framed inline data").len(), shard_payload + 64);
|
||||
}
|
||||
}
|
||||
assert_eq!(count_part_files(&directories), if inline { 0 } else { 16 });
|
||||
let calls = disk_call_counters::observe(&object);
|
||||
let mut reader = set
|
||||
.get_object_reader(bucket, &object, None, HeaderMap::new(), &ObjectOptions::default())
|
||||
.await
|
||||
.expect("read boundary object");
|
||||
if inline {
|
||||
assert_eq!(reader.buffered_body.as_ref().map(Bytes::len), Some(length));
|
||||
}
|
||||
let mut restored = Vec::new();
|
||||
reader.stream.read_to_end(&mut restored).await.expect("read all frames");
|
||||
assert_eq!(restored, payload);
|
||||
if inline {
|
||||
assert_eq!(calls.total(disk_call_counters::KIND_BODY_DECODE), 1);
|
||||
}
|
||||
let range = Some(HTTPRangeSpec {
|
||||
is_suffix_length: false,
|
||||
start: (block - 7) as i64,
|
||||
end: (block + 7).min(length - 1) as i64,
|
||||
});
|
||||
let mut reader = set
|
||||
.get_object_reader(bucket, &object, range, HeaderMap::new(), &ObjectOptions::default())
|
||||
.await
|
||||
.expect("read across the frame boundary");
|
||||
restored.clear();
|
||||
reader.stream.read_to_end(&mut restored).await.expect("read bounded range");
|
||||
assert_eq!(restored, payload[block - 7..(block + 8).min(length)]);
|
||||
}
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn multi_block_inline_without_metadata_early_stop_uses_only_data_shards() {
|
||||
temp_env::async_with_vars(
|
||||
[
|
||||
(rustfs_config::ENV_ERASURE_SHARD_BYTES, Some("0")),
|
||||
("RUSTFS_GET_METADATA_DATA_READ_EARLY_STOP_ENABLE", Some("false")),
|
||||
],
|
||||
async {
|
||||
let (_directories, disks, set) = hermetic_set_disks(16).await;
|
||||
set.set_test_storage_class_config(
|
||||
lookup_config_for_pools_without_env(&KVS::new(), &[16]).expect("EC12+4 configuration"),
|
||||
);
|
||||
let bucket = "inline-full-fanout-systematic";
|
||||
let object = "object.bin";
|
||||
make_bucket(&disks, bucket).await;
|
||||
let payload: Vec<u8> = (0..1280 * 1024).map(|index| (index % 251) as u8).collect();
|
||||
let mut input = PutObjReader::from_vec(payload.clone());
|
||||
set.put_object(
|
||||
bucket,
|
||||
object,
|
||||
&mut input,
|
||||
&ObjectOptions {
|
||||
no_lock: true,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("write multi-block inline object");
|
||||
let calls = disk_call_counters::observe(object);
|
||||
let mut reader = set
|
||||
.get_object_reader(bucket, object, None, HeaderMap::new(), &ObjectOptions::default())
|
||||
.await
|
||||
.expect("read without a preverified metadata body");
|
||||
assert_eq!(reader.buffered_body.as_ref().map(Bytes::len), Some(payload.len()));
|
||||
let mut restored = Vec::new();
|
||||
reader.stream.read_to_end(&mut restored).await.expect("read every frame");
|
||||
assert_eq!(restored, payload);
|
||||
assert_eq!(calls.total(disk_call_counters::KIND_BODY_DECODE), 1);
|
||||
assert_eq!(calls.total(disk_call_counters::KIND_INLINE_SHARD_OPEN), 12);
|
||||
},
|
||||
)
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn multi_block_inline_recovers_corrupt_or_truncated_second_frame() {
|
||||
temp_env::async_with_vars([(rustfs_config::ENV_ERASURE_SHARD_BYTES, Some("0"))], async {
|
||||
let (_directories, disks, set) = hermetic_set_disks(16).await;
|
||||
set.set_test_storage_class_config(
|
||||
lookup_config_for_pools_without_env(&KVS::new(), &[16]).expect("EC12+4 configuration"),
|
||||
);
|
||||
let bucket = "multi-block-inline-recovery";
|
||||
make_bucket(&disks, bucket).await;
|
||||
let payload: Vec<u8> = (0..1280 * 1024).map(|index| (index % 251) as u8).collect();
|
||||
for object in ["corrupt", "truncated", "trailing"] {
|
||||
let mut input = PutObjReader::from_vec(payload.clone());
|
||||
set.put_object(
|
||||
bucket,
|
||||
object,
|
||||
&mut input,
|
||||
&ObjectOptions {
|
||||
no_lock: true,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("write multi-frame fixture");
|
||||
let mut changed = false;
|
||||
for disk in &disks {
|
||||
let mut info = disk
|
||||
.read_version(
|
||||
"",
|
||||
bucket,
|
||||
object,
|
||||
"",
|
||||
&ReadOptions {
|
||||
read_data: true,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("read inline shard");
|
||||
if info.erasure.index != 1 {
|
||||
continue;
|
||||
}
|
||||
let mut raw = info.data.as_ref().expect("inline bytes").to_vec();
|
||||
let second_frame = info.erasure.block_size.div_ceil(12) + 32;
|
||||
match object {
|
||||
"truncated" => raw.truncate(second_frame + 33),
|
||||
"trailing" => raw.push(0x7b),
|
||||
_ => raw[second_frame + 32] ^= 1,
|
||||
}
|
||||
info.data = Some(Bytes::from(raw));
|
||||
disk.write_metadata("", bucket, object, info)
|
||||
.await
|
||||
.expect("persist test corruption");
|
||||
changed = true;
|
||||
break;
|
||||
}
|
||||
assert!(changed);
|
||||
set.invalidate_get_object_metadata_cache(bucket, object).await;
|
||||
assert_eq!(read_back(&set, bucket, object).await, payload);
|
||||
}
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn large_single_block_inline_get_reuses_verified_body() {
|
||||
temp_env::async_with_vars([(rustfs_config::ENV_ERASURE_SHARD_BYTES, Some("131072"))], async {
|
||||
let (_directories, disks, set) = hermetic_set_disks(16).await;
|
||||
set.set_test_storage_class_config(
|
||||
lookup_config_for_pools_without_env(&KVS::new(), &[16]).expect("EC12+4 configuration"),
|
||||
);
|
||||
let bucket = "large-inline-body-reuse";
|
||||
let object = "object.bin";
|
||||
let payload = vec![0x6d; 1280 * 1024];
|
||||
make_bucket(&disks, bucket).await;
|
||||
let mut input = PutObjReader::from_vec(payload.clone());
|
||||
set.put_object(
|
||||
bucket,
|
||||
object,
|
||||
&mut input,
|
||||
&ObjectOptions {
|
||||
no_lock: true,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("write one-block inline fixture");
|
||||
let stored = disks[0]
|
||||
.read_version("", bucket, object, "", &ReadOptions::default())
|
||||
.await
|
||||
.expect("read persisted geometry");
|
||||
assert_eq!(stored.erasure.block_size, 1536 * 1024);
|
||||
assert!(stored.inline_data());
|
||||
|
||||
let calls = disk_call_counters::observe(object);
|
||||
let mut reader = set
|
||||
.get_object_reader(bucket, object, None, HeaderMap::new(), &ObjectOptions::default())
|
||||
.await
|
||||
.expect("read large inline body");
|
||||
assert_eq!(reader.buffered_body.as_ref().map(Bytes::len), Some(payload.len()));
|
||||
let mut restored = Vec::new();
|
||||
reader.stream.read_to_end(&mut restored).await.expect("stream verified body");
|
||||
assert_eq!(restored, payload);
|
||||
assert_eq!(calls.total(disk_call_counters::KIND_BODY_DECODE), 1);
|
||||
})
|
||||
.await;
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn protected_inline_get_validates_proof_after_bitrot_is_recomputed() {
|
||||
let (_directories, disks, set) = hermetic_set_disks(4).await;
|
||||
let bucket = "inline-proof-binding";
|
||||
let object = "object.bin";
|
||||
let payload = vec![0x52; 16 * 1024];
|
||||
make_bucket(&disks, bucket).await;
|
||||
let mut input = PutObjReader::from_vec(payload.clone());
|
||||
set.put_object(
|
||||
bucket,
|
||||
object,
|
||||
&mut input,
|
||||
&ObjectOptions {
|
||||
no_lock: true,
|
||||
shard_integrity_write_mode: Some(crate::object_api::ShardIntegrityWriteMode::Protected),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("write protected inline object");
|
||||
let mut changed = false;
|
||||
for disk in &disks {
|
||||
let mut info = disk
|
||||
.read_version(
|
||||
"",
|
||||
bucket,
|
||||
object,
|
||||
"",
|
||||
&ReadOptions {
|
||||
read_data: true,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("read inline shard");
|
||||
assert!(info.parts[0].integrity.is_some());
|
||||
if info.erasure.index != 1 {
|
||||
continue;
|
||||
}
|
||||
let mut raw = info.data.as_ref().expect("inline shard payload").to_vec();
|
||||
let hash_size = HashAlgorithm::HighwayHash256S.size();
|
||||
raw[hash_size] ^= 1;
|
||||
{
|
||||
let (stored_hash, payload) = raw.split_at_mut(hash_size);
|
||||
let hash = HashAlgorithm::HighwayHash256S.hash_encode(payload);
|
||||
stored_hash.copy_from_slice(hash.as_ref());
|
||||
}
|
||||
info.data = Some(Bytes::from(raw));
|
||||
disk.write_metadata("", bucket, object, info)
|
||||
.await
|
||||
.expect("persist test corruption");
|
||||
changed = true;
|
||||
break;
|
||||
}
|
||||
assert!(changed, "a systematic data shard must be changed");
|
||||
set.invalidate_get_object_metadata_cache(bucket, object).await;
|
||||
let mut reader = set
|
||||
.get_object_reader(bucket, object, None, HeaderMap::new(), &ObjectOptions::default())
|
||||
.await
|
||||
.expect("recover from the proof-rejected shard");
|
||||
let mut restored = Vec::new();
|
||||
reader
|
||||
.stream
|
||||
.read_to_end(&mut restored)
|
||||
.await
|
||||
.expect("read reconstructed body");
|
||||
assert_eq!(restored, payload);
|
||||
}
|
||||
|
||||
@@ -22326,15 +22591,17 @@ mod put_object_tmp_cleanup_tests {
|
||||
|
||||
use super::hermetic_set_disks_support::hermetic_set_disks_isolated as hermetic_set_disks;
|
||||
use super::*;
|
||||
use crate::config::storageclass::lookup_config_for_pools_without_env;
|
||||
use crate::set_disk::core::io_primitives::{
|
||||
ENV_RUSTFS_PUT_RENAME_EARLY_ACK_ENABLE, rename_fanout_barrier, rename_fault_injection,
|
||||
};
|
||||
use rustfs_config::server_config::KVS;
|
||||
use std::{collections::HashSet, time::Duration};
|
||||
use tempfile::TempDir;
|
||||
use tokio::io::AsyncReadExt;
|
||||
|
||||
/// Large enough that the erasure shards are written as real tmp files
|
||||
/// (never inlined into xl.meta), so the cleanup tests exercise actual cleanup.
|
||||
/// Baseline external-shard payload for the four-drive cleanup fixtures.
|
||||
/// Wider layouts derive their payload from the effective inline budget.
|
||||
const TEST_OBJECT_SIZE: usize = 1 << 20;
|
||||
|
||||
/// Entries under `.rustfs.sys/tmp` on every disk, excluding the `.trash`
|
||||
@@ -22763,6 +23030,16 @@ mod put_object_tmp_cleanup_tests {
|
||||
disk_count, 0, parity,
|
||||
)
|
||||
.await;
|
||||
let storage_class =
|
||||
lookup_config_for_pools_without_env(&KVS::new(), &[disk_count]).expect("default fixture storage class");
|
||||
// Exercise physical old-generation cleanup at every erasure width.
|
||||
let external_size = storage_class
|
||||
.inline_block()
|
||||
.checked_mul(disk_count - parity)
|
||||
.and_then(|size| size.checked_add(1))
|
||||
.expect("external cleanup fixture size fits usize");
|
||||
let payload_size = TEST_OBJECT_SIZE.max(external_size);
|
||||
set.set_test_storage_class_config(storage_class);
|
||||
let bucket = "native-heal-commit-cleanup";
|
||||
let object = format!("generation-{disk_count}-{parity}-{read_repair}.bin");
|
||||
for disk in &disks {
|
||||
@@ -22773,13 +23050,14 @@ mod put_object_tmp_cleanup_tests {
|
||||
shard_integrity_write_mode: Some(crate::object_api::ShardIntegrityWriteMode::Protected),
|
||||
..Default::default()
|
||||
};
|
||||
set.put_object(bucket, &object, &mut PutObjReader::from_vec(vec![0x17; TEST_OBJECT_SIZE]), &options)
|
||||
set.put_object(bucket, &object, &mut PutObjReader::from_vec(vec![0x17; payload_size]), &options)
|
||||
.await
|
||||
.expect("acknowledge original generation on every disk");
|
||||
let old = disks[0]
|
||||
.read_version("", bucket, &object, "", &ReadOptions::default())
|
||||
.await
|
||||
.expect("read actual original generation");
|
||||
assert!(!old.inline_data(), "cleanup fixture must persist external shards");
|
||||
let old_dir = old.data_dir.expect("original external data directory");
|
||||
let old_part = dirs[0]
|
||||
.path()
|
||||
@@ -22798,7 +23076,7 @@ mod put_object_tmp_cleanup_tests {
|
||||
let writer_set = Arc::clone(&set);
|
||||
let writer_object = object.clone();
|
||||
let writer_options = options.clone();
|
||||
let payload = vec![0xa3; TEST_OBJECT_SIZE];
|
||||
let payload = vec![0xa3; payload_size];
|
||||
let writer_payload = payload.clone();
|
||||
let writer = tokio::spawn(async move {
|
||||
writer_set
|
||||
|
||||
@@ -17,11 +17,11 @@ use super::{
|
||||
GetObjectFileInfo, GetObjectMetadataCacheCapability, GetObjectMetadataCacheEntry, GetObjectMetadataCacheGeneration,
|
||||
GetObjectMetadataCacheKey, GetObjectMetadataCacheLookupKey, GetObjectReadPolicy, HashAlgorithm, LOG_COMPONENT_ECSTORE,
|
||||
LOG_SUBSYSTEM_SET_DISK, OBJECT_OP_IGNORED_ERRS, ObjectInfo, ObjectOptions, RUSTFS_META_BUCKET, ReadOptions, Result, SetDisks,
|
||||
StorageError, adaptive_duplex_buffer_size, build_get_codec_streaming_decode_engine, build_inline_bitrot_readers_from_refs,
|
||||
StorageError, adaptive_duplex_buffer_size, build_get_codec_streaming_decode_engine, build_inline_bitrot_readers,
|
||||
collect_inline_data_shard_fileinfos_by_index, debug, error, get_codec_streaming_metrics_path,
|
||||
get_codec_streaming_multipart_max_parts, get_object_read_policy, is_codec_streaming_multipart_enabled,
|
||||
is_multipart_reader_setup_prefetch_enabled, object_fits_single_block, reduce_read_quorum_errs, to_object_err,
|
||||
try_read_inline_data_shards_direct, warn,
|
||||
is_multipart_reader_setup_prefetch_enabled, object_fits_single_block, part_checksum_algorithm, reduce_read_quorum_errs,
|
||||
to_object_err, try_read_inline_data_shards_direct, warn,
|
||||
};
|
||||
use crate::diagnostics::get::{
|
||||
GET_DIRECT_MEMORY_SUBPATH_DISK_DATA_BLOCKS, GET_DIRECT_MEMORY_SUBPATH_INLINE_BUFFERED, GET_METADATA_CACHE_DECISION_HIT,
|
||||
@@ -1372,12 +1372,7 @@ impl SetDisks {
|
||||
|
||||
let erasure = erasure_cache.get_for_file_info(fi)?;
|
||||
|
||||
let checksum_info = fi.erasure.get_checksum_info(part.number);
|
||||
let checksum_algo = if fi.uses_legacy_checksum && checksum_info.algorithm == HashAlgorithm::HighwayHash256S {
|
||||
HashAlgorithm::HighwayHash256SLegacy
|
||||
} else {
|
||||
checksum_info.algorithm
|
||||
};
|
||||
let checksum_algo = part_checksum_algorithm(fi, part.number);
|
||||
let read_length = erasure.shard_file_offset(0, object_size, object_size);
|
||||
|
||||
if fi.data.is_some() {
|
||||
@@ -1392,8 +1387,9 @@ impl SetDisks {
|
||||
};
|
||||
|
||||
let reader_setup_stage_start = Instant::now();
|
||||
let mut readers = build_inline_bitrot_readers_from_refs(
|
||||
&data_files,
|
||||
let mut readers = build_inline_bitrot_readers(
|
||||
data_files.iter().copied(),
|
||||
data_files.len(),
|
||||
bucket,
|
||||
object,
|
||||
read_length,
|
||||
@@ -1665,7 +1661,7 @@ impl SetDisks {
|
||||
"Streaming multipart part"
|
||||
);
|
||||
|
||||
let checksum_algo = multipart_part_checksum_algo(&fi, part_number);
|
||||
let checksum_algo = part_checksum_algorithm(&fi, part_number);
|
||||
let read_length = till_offset.saturating_sub(read_offset);
|
||||
|
||||
let read_costs = coding::decode::should_collect_shard_read_costs().then(|| shard_read_costs_for_disks(&disks));
|
||||
@@ -1729,7 +1725,7 @@ impl SetDisks {
|
||||
part_number: next_number,
|
||||
read_offset: 0,
|
||||
read_length: erasure.shard_file_offset(0, next_length, next_size),
|
||||
checksum_algo: multipart_part_checksum_algo(&fi, next_number),
|
||||
checksum_algo: part_checksum_algorithm(&fi, next_number),
|
||||
};
|
||||
let files = Arc::clone(&files);
|
||||
let disks = Arc::clone(&disks);
|
||||
@@ -2326,12 +2322,7 @@ impl SetDisks {
|
||||
if part_length > part_size {
|
||||
return Err(Error::other("codec streaming reader part length exceeds part size"));
|
||||
}
|
||||
let checksum_info = fi.erasure.get_checksum_info(part_number);
|
||||
let checksum_algo = if fi.uses_legacy_checksum && checksum_info.algorithm == HashAlgorithm::HighwayHash256S {
|
||||
HashAlgorithm::HighwayHash256SLegacy
|
||||
} else {
|
||||
checksum_info.algorithm
|
||||
};
|
||||
let checksum_algo = part_checksum_algorithm(fi, part_number);
|
||||
let use_mmap_read = object_mmap_read_enabled();
|
||||
let till_offset = erasure.shard_file_offset(part_offset, part_length, part_size);
|
||||
let read_offset = (part_offset / erasure.block_size) * erasure.shard_size();
|
||||
@@ -2620,17 +2611,6 @@ struct PartReaderSetupSpec {
|
||||
checksum_algo: HashAlgorithm,
|
||||
}
|
||||
|
||||
/// Resolve the bitrot checksum algorithm for one part, honoring the legacy
|
||||
/// HighwayHash flag.
|
||||
fn multipart_part_checksum_algo(fi: &FileInfo, part_number: usize) -> HashAlgorithm {
|
||||
let checksum_info = fi.erasure.get_checksum_info(part_number);
|
||||
if fi.uses_legacy_checksum && checksum_info.algorithm == HashAlgorithm::HighwayHash256S {
|
||||
HashAlgorithm::HighwayHash256SLegacy
|
||||
} else {
|
||||
checksum_info.algorithm
|
||||
}
|
||||
}
|
||||
|
||||
fn multipart_reader_setup_prefetch_enabled(policy: GetObjectReadPolicy) -> bool {
|
||||
policy.allows_multipart_setup_prefetch() && is_multipart_reader_setup_prefetch_enabled()
|
||||
}
|
||||
|
||||
@@ -0,0 +1,47 @@
|
||||
// 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.
|
||||
|
||||
use rustfs_filemeta::{FileInfoOpts, get_file_info};
|
||||
use std::{env, fs, io};
|
||||
|
||||
fn main() -> Result<(), Box<dyn std::error::Error>> {
|
||||
let path = env::args()
|
||||
.nth(1)
|
||||
.ok_or_else(|| io::Error::new(io::ErrorKind::InvalidInput, "usage: inline_lab_inspect <xl.meta> [version]"))?;
|
||||
let version = env::args().nth(2).unwrap_or_default();
|
||||
let data = fs::read(path)?;
|
||||
let info = get_file_info(
|
||||
&data,
|
||||
"validation-bucket",
|
||||
"validation-object",
|
||||
&version,
|
||||
FileInfoOpts {
|
||||
data: false,
|
||||
include_free_versions: false,
|
||||
include_part_checksums: false,
|
||||
},
|
||||
)?;
|
||||
println!(
|
||||
"{}",
|
||||
serde_json::json!({
|
||||
"size": info.size,
|
||||
"block_size": info.erasure.block_size,
|
||||
"data_blocks": info.erasure.data_blocks,
|
||||
"parity_blocks": info.erasure.parity_blocks,
|
||||
"inline": info.inline_data(),
|
||||
"version_id": info.version_id,
|
||||
})
|
||||
);
|
||||
Ok(())
|
||||
}
|
||||
@@ -100,8 +100,8 @@ pub const REQUEST_COMPAT_SEND_SITES: &[RequestCompatSendSite] = &[
|
||||
json_field: "opts",
|
||||
bin_field: "opts_bin",
|
||||
},
|
||||
json_encoder: "let opts = match serde_json::to_string(&opts) {",
|
||||
policy: RequestJsonPolicy::AlwaysDualWriteUntilFallbackZero,
|
||||
json_encoder: "serde_json::to_string(opts)?",
|
||||
policy: RequestJsonPolicy::MsgpackOnlyEligible,
|
||||
},
|
||||
RequestCompatSendSite {
|
||||
field: CompatPayloadField {
|
||||
@@ -109,8 +109,8 @@ pub const REQUEST_COMPAT_SEND_SITES: &[RequestCompatSendSite] = &[
|
||||
json_field: "versions",
|
||||
bin_field: "versions_bin",
|
||||
},
|
||||
json_encoder: "versions_str.push(match serde_json::to_string(file_info_versions) {",
|
||||
policy: RequestJsonPolicy::AlwaysDualWriteUntilFallbackZero,
|
||||
json_encoder: "versions_json.push(serde_json::to_string(version)?);",
|
||||
policy: RequestJsonPolicy::MsgpackOnlyEligible,
|
||||
},
|
||||
RequestCompatSendSite {
|
||||
field: CompatPayloadField {
|
||||
|
||||
@@ -913,8 +913,9 @@ pub struct DeleteVersionsRequest {
|
||||
pub versions: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
|
||||
#[prost(string, tag = "4")]
|
||||
pub opts: ::prost::alloc::string::String,
|
||||
/// msgpack payloads mirroring the JSON fields above (grpc-optimization P2). Senders dual-write
|
||||
/// both; receivers prefer the \*\_bin form and fall back to the JSON string when it is empty.
|
||||
/// Senders dual-write for legacy peers. A nonempty versions_bin list determines
|
||||
/// the batch length and values. Malformed binary items reject the batch.
|
||||
/// An empty binary list selects the legacy versions list. Options decode independently.
|
||||
#[prost(bytes = "bytes", repeated, tag = "5")]
|
||||
pub versions_bin: ::prost::alloc::vec::Vec<::prost::bytes::Bytes>,
|
||||
#[prost(bytes = "bytes", tag = "6")]
|
||||
|
||||
@@ -4660,8 +4660,8 @@ mod tests {
|
||||
),
|
||||
("DeleteVersionRequest", "file_info", RequestJsonPolicy::AlwaysDualWriteUntilFallbackZero,),
|
||||
("DeleteVersionRequest", "opts", RequestJsonPolicy::AlwaysDualWriteUntilFallbackZero),
|
||||
("DeleteVersionsRequest", "opts", RequestJsonPolicy::AlwaysDualWriteUntilFallbackZero,),
|
||||
("DeleteVersionsRequest", "versions", RequestJsonPolicy::AlwaysDualWriteUntilFallbackZero,),
|
||||
("DeleteVersionsRequest", "opts", RequestJsonPolicy::MsgpackOnlyEligible),
|
||||
("DeleteVersionsRequest", "versions", RequestJsonPolicy::MsgpackOnlyEligible),
|
||||
("ReadMultipleRequest", "read_multiple_req", RequestJsonPolicy::MsgpackOnlyEligible),
|
||||
("ReadVersionRequest", "opts", RequestJsonPolicy::MsgpackOnlyEligible),
|
||||
("RenameDataRequest", "file_info", RequestJsonPolicy::MsgpackOnlyEligible),
|
||||
|
||||
@@ -583,8 +583,9 @@ message DeleteVersionsRequest {
|
||||
string volume = 2;
|
||||
repeated string versions = 3;
|
||||
string opts = 4;
|
||||
// msgpack payloads mirroring the JSON fields above (grpc-optimization P2). Senders dual-write
|
||||
// both; receivers prefer the *_bin form and fall back to the JSON string when it is empty.
|
||||
// Senders dual-write for legacy peers. A nonempty versions_bin list determines
|
||||
// the batch length and values. Malformed binary items reject the batch.
|
||||
// An empty binary list selects the legacy versions list. Options decode independently.
|
||||
repeated bytes versions_bin = 5;
|
||||
bytes opts_bin = 6;
|
||||
}
|
||||
|
||||
@@ -50,7 +50,7 @@ Two codec backends exist, selected per object from its metadata (never a runtime
|
||||
- **Modern backend** — Reed–Solomon over **GF(2⁸)** using `rustfs-erasure-codec` (a RustFS fork of `reed-solomon-erasure` v8, `Cargo.toml`), imported as `reed_solomon_erasure::galois_8::ReedSolomon` ([erasure.rs](../../crates/ecstore/src/erasure/coding/erasure.rs)). Vandermonde generator matrix; algorithm string `"rs-vandermonde"` ([object_api/mod.rs](../../crates/ecstore/src/object_api/mod.rs)). The GF(2⁸) field bounds total shards per set far above the geometry cap of 16 (§2). Used for **all new writes** — and, because MinIO uses the same `rs-vandermonde` GF(2⁸) scheme, for **all MinIO-migrated objects** too.
|
||||
- **Legacy backend** — Reed–Solomon over **GF(2¹⁶)** using `reed-solomon-simd` v3.1 (`Cargo.toml`), imported at [erasure.rs](../../crates/ecstore/src/erasure/coding/erasure.rs). Used **only** to read and heal objects written in **RustFS's own older ("main branch") format** — the `rmp_serde`-serialized layout detected by `uses_legacy_checksum` (see §11). This backend is **not** MinIO-compatible; MinIO-migrated data is decoded by the modern GF(2⁸) backend above (see [minio-file-format-compat.md](minio-file-format-compat.md)). The backend is chosen per object from its metadata (`uses_legacy_checksum`), never by a runtime toggle.
|
||||
|
||||
Industry alignment (all confirmed in code): byte-oriented RS over GF(2⁸) with a Vandermonde matrix, 1 MiB erasure block, and HighwayHash-256 bitrot checksums with a π-derived key — the same family and defaults MinIO uses. This is what makes byte-level `xl.meta` interoperability with MinIO possible (see [minio-file-format-compat.md](minio-file-format-compat.md)).
|
||||
Industry alignment (all confirmed in code): byte-oriented RS over GF(2⁸) with a Vandermonde matrix and HighwayHash-256 bitrot checksums with a π-derived key share the format family used by MinIO. RustFS defaults to a 1 MiB erasure block. Reads use each object’s persisted block geometry. The supported byte-level `xl.meta` interoperability is defined by [minio-file-format-compat.md](minio-file-format-compat.md).
|
||||
|
||||
Where the code lives: the erasure engine is owned by `crates/ecstore/src/erasure/` and is crate-private; the `xl.meta` model is owned by `crates/filemeta`. See [ecstore-layout-boundary.md](ecstore-layout-boundary.md).
|
||||
|
||||
@@ -140,7 +140,7 @@ distribution[i-1] = 1 + ((start + i) % N) for i in 1..=N // a cyclic rotatio
|
||||
|
||||
### 4.3 Streaming pipeline and fan-out
|
||||
|
||||
`Erasure::encode` / `encode_batched` ([encode.rs](../../crates/ecstore/src/erasure/coding/encode.rs)) read the source in `block_size` chunks on a producer task, encode each block, and stream the `N` shards of each block over a bounded channel to a consumer that fans them out through `MultiWriter` to the `N` shard writers. `block_size == 0` is rejected up front (`InvalidInput`). In-flight memory is bounded by the channel depth (default budget 32 MiB). A clean EOF stops the loop; the final partial block is padded per §4.2.
|
||||
`Erasure::encode` / `encode_batched` ([encode.rs](../../crates/ecstore/src/erasure/coding/encode.rs)) read the source in `block_size` chunks on a producer task, encode each block, and stream the `N` shards of each block over a bounded channel to a consumer that fans them out through `MultiWriter` to the `N` shard writers. `block_size == 0` is rejected up front (`InvalidInput`). Channel capacity is derived from the queue budget and the EC-expanded block size, with at least one slot. The default queue budget is 32 MiB. Producer, consumer, ingest, writer, and allocator buffers contribute additional memory, and a single expanded block can exceed that budget. Batched mode also owns pending batches. Queue accounting describes queued blocks. Per-PUT and process RSS also depend on those additional owners. A clean EOF stops the loop; the final partial block is padded per §4.2.
|
||||
|
||||
- **INVARIANT — write-quorum enforcement during encode.** `MultiWriter` writes shard `i` to writer `i`, drops any stalled/failed/short writer (sets it to `None`), and after each block requires `nil_count ≥ write_quorum`, else fails with a reduced-write-quorum error ([encode.rs](../../crates/ecstore/src/erasure/coding/encode.rs)). Shard index → writer index → on-disk position is fixed.
|
||||
|
||||
@@ -292,10 +292,12 @@ Fields: `version_id`, `mod_time`, `signature: [u8;4]`, `version_type`, `flags: u
|
||||
|
||||
### 6.6 Inline data
|
||||
|
||||
Small objects store their payload inline after the container CRC ([filemeta_inline.rs](../../crates/filemeta/src/filemeta_inline.rs)): 1 version byte (`INLINE_DATA_VER = 1`) then a msgpack map of `version-key → bin`. **INVARIANT — the map key** is the version-id string, `"null"` (`NULL_VERSION_ID`, [fileinfo.rs](../../crates/filemeta/src/fileinfo.rs)) for the null/None version, else the lowercase hyphenated UUID. Presence is determined **on read** solely by the `meta_sys[inline-data]` body marker (`FileInfo::inline_data`); the read path gates inline extraction on that marker alone. The header `InlineData` flag is **written** (mirrored from the body on marshal) but is **not** consulted on read, and a disagreement is tolerated — MinIO may leave the header flag unset while inline data is present, so a reader must **not** require the flag and the marker to agree. The inline threshold is `should_inline` ([storageclass.rs](../../crates/ecstore/src/config/storageclass.rs)): inline if `shard_size ≤ inline_block/8` for versioned buckets, else `≤ inline_block`; `DEFAULT_INLINE_BLOCK = 128 KiB`. A compressed or encrypted single PUT has no known stored size up front, so its shard size is derived from the plaintext `actual_size` (`inline_admission_shard_size`, MinIO `putObject` parity); such objects are inlined through the streaming encoder with in-memory bitrot writers rather than the single-block fast path. When shard-integrity protected writes are enabled, inline placement additionally requires a known stored length no greater than one erasure block; unknown transformed streams retain external shards and proof indexes.
|
||||
Small objects store their payload inline after the container CRC ([filemeta_inline.rs](../../crates/filemeta/src/filemeta_inline.rs)): 1 version byte (`INLINE_DATA_VER = 1`) then a msgpack map of `version-key → bin`. **INVARIANT — the map key** is the version-id string, `"null"` (`NULL_VERSION_ID`, [fileinfo.rs](../../crates/filemeta/src/fileinfo.rs)) for the null/None version, else the lowercase hyphenated UUID. Presence is determined **on read** solely by the `meta_sys[inline-data]` body marker (`FileInfo::inline_data`); the read path gates inline extraction on that marker alone. The header `InlineData` flag is **written** (mirrored from the body on marshal) but is **not** consulted on read, and a disagreement is tolerated — MinIO may leave the header flag unset while inline data is present, so a reader must **not** require the flag and the marker to agree. `should_inline` ([storageclass.rs](../../crates/ecstore/src/config/storageclass.rs)) admits a shard up to `inline_block/8` for versioned buckets and up to `inline_block` otherwise. The default is a fixed `DEFAULT_INLINE_BLOCK = 128 KiB` per shard for every EC geometry, matching MinIO. Explicit `RUSTFS_STORAGE_CLASS_INLINE_BLOCK` values use the same per-shard interpretation. Known-length unprotected PUTs may span multiple erasure blocks within a 2 MiB object limit and 32-frame limit, subject to the accumulated per-shard budget. The default block remains 1 MiB. The direct encoder remains single-block. Transformed streams and proof-protected writes retain their single-block admission bound. Known-length inline writers include every bitrot frame header in a checked capacity limit and reject overflow before appending data. The persisted marker governs existing-object reads independently of the current write budget. Config serialization retains the historical `inline_block_explicit` marker for readers that use it. A compressed or encrypted single PUT has no known stored size up front, so its shard size is derived from the plaintext `actual_size` (`should_inline_put`, MinIO `putObject` parity); such objects are inlined through the streaming encoder with in-memory bitrot writers rather than the single-block fast path. When shard-integrity protected writes are enabled, inline placement additionally requires a known stored length no greater than one erasure block; unknown transformed streams retain external shards and proof indexes.
|
||||
|
||||
---
|
||||
|
||||
Inline body materialization uses the shared `inline_body_buffering_miss_reason` contract ([set_disk/mod.rs](../../crates/ecstore/src/set_disk/mod.rs)) with a 2 MiB response limit and a bounded frame count. Metadata pre-verification and buffered GET consumption use this same contract, and an already verified body is reused within the selected snapshot. Parts carrying `PartIntegrity` use the readers that bind their proof verifier. Metadata early-stop and GET share `try_decode_inline_data_shards` for interleaved bitrot verification, per-block EC padding removal and body assembly. Data-shard metadata uses inline-capacity collections for normal EC sets. A healthy full metadata fanout decodes directly from cached bytes. Missing or damaged data shards enter the existing quorum-protected reconstruction path. Buffered GET, deep inline healing and ordinary bitrot readers share the borrowed `verified_bitrot_frame` primitive. Deep healing checks exact physical length before hashing the original frame slices, including every data and parity frame, and rejects trailing bytes, truncated prefixes and checksum mismatches.
|
||||
|
||||
## 7. Write path and write quorum
|
||||
|
||||
`put_object` and multipart resolve the write layout (§2.2), encode (§4), write shards with bitrot (§5), then commit atomically.
|
||||
@@ -379,7 +381,7 @@ Geometry & math
|
||||
|
||||
Algorithm
|
||||
- Modern RS over GF(2⁸) (`rs-vandermonde`) for new writes; legacy GF(2¹⁶) for old files, selected by `uses_legacy_checksum`.
|
||||
- `block_size = 1 MiB` (`BLOCK_SIZE_V2`), stored per version.
|
||||
- The default `block_size` is 1 MiB (`BLOCK_SIZE_V2`). `RUSTFS_ERASURE_SHARD_BYTES` derives new user-object geometry as `data_blocks × shard_bytes` through `erasure_block_size_for` ([fileinfo.rs](../../crates/filemeta/src/fileinfo.rs)). System metadata keeps the default. Each version stores its own geometry for subsequent reads.
|
||||
- Shard-size formulas: modern `div_ceil`; legacy `(div_ceil + 1) & !1`. Final block zero-padded before encode.
|
||||
- Bitrot `HighwayHash256S` (legacy key variant for old files); interleaved `[hash][data]` per block; `bitrot_shard_file_size = ceil(size/shard_size)*32 + size`; verify before use.
|
||||
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
# Cluster and erasure-coding lifecycle operations
|
||||
|
||||
**Use this when:** planning, starting, expanding, rebalancing, decommissioning, healing, replacing drives in, or restarting an erasure-coded RustFS deployment, or deciding whether an `EC:<parity>` setting (including `EC:0`) is safe for a workload.
|
||||
**Source of truth:** `crates/ecstore/src/layout/disks_layout.rs` (`DisksLayout::from_volumes`, `SET_SIZES`, `RUSTFS_ERASURE_SET_DRIVE_COUNT`), `crates/ecstore/src/config/storageclass.rs` (`default_parity_count`, `validate_parity_inner`, `Config::should_inline`, `Config::effective_inline_block`), `crates/ecstore/src/set_disk/mod.rs` (`resolve_write_layout`, `WriteLayout::from_parity`), `crates/ecstore/src/set_disk/metadata.rs` (`object_quorum_from_meta`, `common_parity`), `crates/ecstore/src/set_disk/ops/heal.rs` (no-parity `cannot_heal` classification), `crates/ecstore/src/store/init_format.rs` (`check_format_erasure_value_for_topology`), `rustfs/src/admin/handlers/pools.rs`, `rustfs/src/admin/handlers/rebalance.rs`, `rustfs/src/admin/handlers/heal.rs`, and `rustfs/src/admin/route_policy.rs` (admin surface).
|
||||
**Source of truth:** `crates/ecstore/src/layout/disks_layout.rs` (`DisksLayout::from_volumes`, `SET_SIZES`, `RUSTFS_ERASURE_SET_DRIVE_COUNT`), `crates/ecstore/src/config/storageclass.rs` (`default_parity_count`, `validate_parity_inner`, `Config::should_inline`, `Config::inline_block`), `crates/ecstore/src/set_disk/mod.rs` (`resolve_write_layout`, `WriteLayout::from_parity`), `crates/ecstore/src/set_disk/metadata.rs` (`object_quorum_from_meta`, `common_parity`), `crates/ecstore/src/set_disk/ops/heal.rs` (no-parity `cannot_heal` classification), `crates/ecstore/src/store/init_format.rs` (`check_format_erasure_value_for_topology`), `rustfs/src/admin/handlers/pools.rs`, `rustfs/src/admin/handlers/rebalance.rs`, `rustfs/src/admin/handlers/heal.rs`, and `rustfs/src/admin/route_policy.rs` (admin surface).
|
||||
|
||||
This runbook is the operator entry point. It restates only what an operator needs to act and links the normative contracts for everything else: [erasure-coding.md](../architecture/erasure-coding.md) (algorithm, quorum, on-disk format), [ecstore-layout-boundary.md](../architecture/ecstore-layout-boundary.md) (immutable layout), [decommission-compatibility.md](../architecture/decommission-compatibility.md) (decommission and rebalance contract), [heal-concurrency-model.md](../architecture/heal-concurrency-model.md) (heal versus write locking), [rolling-restart.md](rolling-restart.md) (restarts), [replacement-generation-recovery.md](replacement-generation-recovery.md) (drive replacement recovery), and [scanner-runtime-controls.md](scanner-runtime-controls.md) (heal and scanner knobs). Admin routes below require an authenticated request holding the matching `AdminAction`; the route to action mapping is owned by `rustfs/src/admin/route_policy.rs` (see [admin-route-action-snapshot.md](../architecture/admin-route-action-snapshot.md)).
|
||||
|
||||
@@ -60,7 +60,7 @@ A single local path (`rustfs D:\rustfs\data`) is a single-node single-drive depl
|
||||
| `RUSTFS_STORAGE_CLASS_STANDARD` | STANDARD parity as `EC:<n>` | Validated per pool; affects new writes only |
|
||||
| `RUSTFS_STORAGE_CLASS_RRS` | RRS parity as `EC:<n>` | Validated per pool; an explicit value fails on a single drive, the persisted default `EC:1` resolves to `0` there |
|
||||
| `RUSTFS_STORAGE_CLASS_OPTIMIZE` | Accepted for MinIO compatibility | Stored on `Config`, but `Config::capacity_optimized` has no caller: it changes nothing at runtime today |
|
||||
| `RUSTFS_STORAGE_CLASS_INLINE_BLOCK` | Fixed per-shard inline limit (bytesize syntax such as `128KiB`) | Replaces the scaled default in §4.3; values above 128 KiB log `storage_class_inline_block_large` |
|
||||
| `RUSTFS_STORAGE_CLASS_INLINE_BLOCK` | Fixed per-shard inline limit (bytesize syntax such as `128KiB`) | Overrides the fixed 128 KiB default in §4.3. Values above 128 KiB log `storage_class_inline_block_large` |
|
||||
|
||||
An empty `RUSTFS_STORAGE_CLASS_STANDARD` or `RUSTFS_STORAGE_CLASS_RRS` restores the automatic policy and overrides a persisted value (`standard_policy` / `rrs_policy`). `MINIO_`-prefixed spellings of these keys, of `ERASURE_SET_DRIVE_COUNT`, and of `VOLUMES` are mapped onto the `RUSTFS_` names when the `RUSTFS_` name is unset (`apply_external_env_compat` in `crates/utils/src/envs.rs`); when both are set the `RUSTFS_` value wins and the conflict is reported at startup.
|
||||
|
||||
@@ -103,7 +103,9 @@ Sixteen drives at `EC:4`: `K = 12`, about 75 percent usable, four failures toler
|
||||
|
||||
### 4.3 Inline objects
|
||||
|
||||
An object is stored inline in `xl.meta` when every shard is at most the per-shard budget (`Config::should_inline`). The default budget is `DEFAULT_INLINE_OBJECT_BUDGET / K` capped at `DEFAULT_INLINE_BLOCK` (256 KiB / K, at most 128 KiB per shard), so a wider set does not raise the maximum inline object size; on a versioned bucket the budget is divided by 8. `RUSTFS_STORAGE_CLASS_INLINE_BLOCK` replaces the scaled default with a fixed per-shard limit. Each drive keeps only its own shard inline, so inline data has the same loss semantics as external shards. Compressed or encrypted streams inline only when the stored size is known and within budget.
|
||||
An object is stored inline in `xl.meta` when every shard is at most the per-shard budget (`Config::should_inline`). The default is `DEFAULT_INLINE_BLOCK` (128 KiB per shard), matching MinIO's default. A versioned bucket uses one eighth of that budget. `RUSTFS_STORAGE_CLASS_INLINE_BLOCK` sets an explicit fixed per-shard limit. Each drive keeps its own bitrot-protected shard inline. PUT admission also requires the stored size, or the plaintext size for an unprotected transformed stream with unknown stored size, to fit one erasure block. Protected transformed streams require a known stored size. The complete format and transform rules are in [erasure-coding.md §6.6](../architecture/erasure-coding.md#66-inline-data).
|
||||
|
||||
Existing inline and external objects are read according to their persisted metadata after a budget change. The former scaled default admitted approximately 256 KiB per unversioned object across wider EC layouts. The fixed per-shard budget admits larger new objects as data-shard count grows, subject to the single-block bound. Operators can pin an explicit smaller per-shard limit for a selected geometry. Changing this setting affects future placement; rollback to a historical binary requires that binary's reader to accept the newly written layouts. Use [MinIO format compatibility](../architecture/minio-file-format-compat.md) for the supported migration direction and encrypted-object constraints.
|
||||
|
||||
### 4.4 Write and read paths
|
||||
|
||||
|
||||
@@ -66,20 +66,26 @@ Convergence-ready:
|
||||
| request | `ReadMultiple.read_multiple_req` | `ReadMultipleReq` |
|
||||
| request | `BatchReadVersion.batch_read_version_req` | `BatchReadVersionReq` |
|
||||
| request | `Read*.opts` | `ReadOptions` |
|
||||
| request | `DeleteVersions.versions` | binary-list-driven `FileInfoVersions` batch |
|
||||
| request | `DeleteVersions.opts` | named-map `DeleteOptions` |
|
||||
| response | `ReadVersion.file_info` | `FileInfo` (`cluster/rpc/remote_disk.rs`) |
|
||||
| response | `ReadXL.raw_file_info` | `RawFileInfo` |
|
||||
| response | `RenameData.rename_data_resp` | `RenameDataResp` |
|
||||
| response | `ReadMultiple` response list | per-item plus list fallback |
|
||||
| response | `BatchReadVersion` response list | per-item plus list fallback |
|
||||
|
||||
Delete messages, kept on dual-write until their own window reads zero with `_bin`-first decoders deployed fleet-wide (the client always dual-writes these regardless of the flags):
|
||||
Single-version delete fields retain dual-write until their own observation window establishes fleet-wide readiness.
|
||||
|
||||
| Direction | Message / field | Status |
|
||||
| --- | --- | --- |
|
||||
| request | `DeleteVersion.file_info` (`FileInfo`) | `_bin` present; dual-write; converge after its own window |
|
||||
| request | `DeleteVersion.opts` (`DeleteOptions`) | same |
|
||||
| request | `DeleteVersions.versions` (`FileInfoVersions`) | same |
|
||||
| request | `DeleteVersions.opts` (`DeleteOptions`) | same |
|
||||
|
||||
`DeleteVersions` receivers select the binary list whenever `versions_bin` contains entries. That list supplies the batch length and every decoded item, including requests whose JSON `versions` list is empty or has a different length. Empty or corrupt binary items reject the complete request before disk mutation. A request with an empty binary list uses the legacy JSON list and its length. Options retain their independent binary-first decoder. The sender captures the codec policy once per complete batch. Default mode emits both lists and both option encodings. Setting both `RUSTFS_INTERNODE_RPC_MSGPACK_ONLY=true` and `RUSTFS_INTERNODE_RPC_MSGPACK_ONLY_FLEET_CONFIRMED=true` emits the binary list and named-map options, with empty JSON fields. Before confirming the fleet, deploy the corrected binary-list-driven receiver to every destination and verify the observation counters and binary-only deletion results. Rolling upgrades and rollback to a receiver that traverses the JSON list require JSON compatibility mode before replacing nodes. These fields remain in the protobuf schema for older peers.
|
||||
|
||||
User-object recoverable deletion uses `RecoverDeleteTransaction` and guarded mutation messages with their existing binary payloads. Measure those operations with transaction preparation, commit, rollback and cleanup stages. The `DeleteVersions` codec comparison covers the legacy/internal batch RPC and its consumers.
|
||||
|
||||
`DeleteVersions` binary-only sending uses the explicit fleet-confirmation gate. In per-peer capability mode, batch deletion emits both JSON and binary fields. The generic peer capability proof covers the other eligible request families; binary-list-driven deletion additionally requires the corrected batch receiver on every destination.
|
||||
|
||||
Still JSON-only:
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ iostat -xz 5 > telemetry/iostat.txt &
|
||||
|
||||
| Knob | Default | Controls | Validating stage | Risk if widened |
|
||||
| --- | --- | --- | --- | --- |
|
||||
| `RUSTFS_ERASURE_SHARD_BYTES` | `0` | `erasure_block_size_for` in `crates/filemeta/src/fileinfo.rs` derives a new user-object block from data-shard count times this byte value. Zero selects the historical 1 MiB block. Validation limits live in `crates/config/src/constants/object.rs`. Cached at first use. | Stripe count, `erasure_encode_cpu`, GET path, range bytes, TTFB and RSS | Changes geometry across pools and storage classes, direct-write eligibility and bitrot frame size |
|
||||
| `RUSTFS_ERASURE_ENCODE_MAX_INFLIGHT_BYTES` | 32MiB (`crates/ecstore/src/erasure/coding/encode.rs`) | EC encode producer/consumer memory budget (blocks queued between encode and shard write) | `set_disk_encode` P95 + `rustfs_ec_encode_inflight_bytes_current` | RSS growth under high concurrency |
|
||||
| `RUSTFS_ERASURE_ENCODE_BYTESMUT_INGEST` | `true` | Streaming encode reads into an owned, EC-sized buffer, avoiding the input-to-encoder block copy. Set `false` to select the previous streaming Vec ingest path; batched encode always uses owned buffers. Cached at first use. | `erasure_encode_cpu`, PUT throughput and RSS | No disk-format change; queue budget does not bound total process memory |
|
||||
| `RUSTFS_OBJECT_IO_BUFFER_SIZE` | 128KiB (`crates/config/src/constants/object.rs`) | Streaming read-in / write-out block size | `ingress_prepare`, `set_disk_encode` | Larger buffers = fewer polls, more resident memory |
|
||||
@@ -108,6 +109,38 @@ Collect detailed diagnostics in dedicated rounds with `RUSTFS_OBS_PUT_STAGE_METR
|
||||
|
||||
These metrics cover the disk queue's Fsync lane. Direct fsync dispatches and cleanup work on the Isolated lane require their own stage observations. Peak gauges are process-lifetime high-water marks for workers whose diagnostics started while the detailed PUT gate was enabled, including startup and warmup. A retiring closure and its replacement can briefly overlap in this count while execution concurrency remains bounded. Restart each server per leg to establish a fresh lifetime. Guards finish accounting on normal exit and panic, including when the gate is disabled while a measured worker remains alive. Diagnostics use atomic accounting and cached metric handles outside the disk queue mutex; the recorder may acquire its own publication locks. Hold this observation overhead consistent within diagnostic comparisons.
|
||||
|
||||
#### Erasure block geometry experiment
|
||||
|
||||
The [isolated Docker inline lab](../../.docker/inline-lab/README.md) provides a frozen-source image and an owned external deployment adapter for the existing ABBA runner.
|
||||
|
||||
Freeze the inline per-shard budget, durability mode, codec mode, queue budget, and binary before changing `RUSTFS_ERASURE_SHARD_BYTES`. Use integer bytes for this setting. `configured_erasure_shard_bytes` validates its alignment and upper bound and caches the result. Restart the tested processes and create each leg's measurement dataset after the new geometry is active. Existing versions and active multipart uploads retain their recorded geometry, so pre-existing GET data cannot establish the new-write behavior.
|
||||
|
||||
The setting applies to every newly constructed user-object geometry. A fixed shard value produces different block sizes for different data-shard counts, including different storage classes in one pool. Record the persisted block size in each test cell. The per-shard placement budget and body materialization limits are separate contracts. Verified inline body reuse is bounded to 2 MiB and 32 frames. Trace metadata body verification and subsequent body decoding together, including reuse within the selected version snapshot.
|
||||
|
||||
Use one candidate shard value per ABBA run, starting with a small change appropriate to the target geometry. Include full GET, PUT, small Range GET, versioned objects, multipart, transformed objects, degraded reads and a reader rollback fixture. Large blocks reduce stripe transitions while expanding read/verification granularity and the maximum single-block direct-write input. The streaming queue has a minimum of one expanded block, and direct paths have their own buffering. Validate RSS, CPU scheduling, first-byte latency and error counts alongside throughput.
|
||||
|
||||
The pinned MinIO Community comparison uses a 1 MiB block for new objects. Its inline buffer writers can accumulate multiple blocks while the total erasure shard remains within the storage-class budget. RustFS supports bounded multi-block inline for known-length unprotected PUTs at its default 1 MiB block. The accumulated data-shard budget is 128 KiB, reduced to 16 KiB for versioned writes. EC12+4 therefore admits up to 1,572,856 logical bytes, with each bitrot frame header additionally charged to the bounded writer. Transformed and proof-protected writes retain their existing single-block admission contract. A geometry override is an independently measured configuration experiment with its own read-path and compatibility results. [MinIO object geometry](https://github.com/minio/minio/blob/7aac2a2c5b7c882e68c1ce017d8256be2feea27f/cmd/storage-datatypes.go#L388-L399) and [inline writer selection](https://github.com/minio/minio/blob/7aac2a2c5b7c882e68c1ce017d8256be2feea27f/cmd/erasure-object.go#L1398-L1440).
|
||||
|
||||
For transport comparisons, keep geometry fixed and independently evaluate JSON compatibility mode and the existing MessagePack-only flag pair. Inline RenameData carries its data through metadata RPCs, so JSON serialization and duplicate payloads can outweigh the saved part-file I/O. The Docker lab pins and checks both transport flags on every node. Use its version, geometry and multipart manifests for mixed-reader and full-reader rollback checks before a performance run. Restore JSON compatibility mode before introducing an older peer and record the oldest reader actually tested.
|
||||
|
||||
#### Borrowed inline verification kernel
|
||||
|
||||
The inline verifier operates on already loaded frame slices. Its manual ABBA comparison exercises the streaming verifier and the borrowed verifier over identical 4 KiB and 128 KiB shard payloads. Capture the reported debug/release profile, iteration counts, elapsed times and baseline drift. This measures frame verification CPU and copying costs. End-to-end acceptance uses the fixed-condition Docker ABBA matrix with request errors, throughput and tail latency recorded for every leg.
|
||||
|
||||
```bash
|
||||
cargo test -p rustfs-ecstore --lib --features test-util \
|
||||
inline_bitrot_borrowed_verification_benchmark -- --ignored --nocapture --test-threads=1
|
||||
```
|
||||
|
||||
For batch-delete codec acceptance, run `delete_versions_request_encoding_preserves_batches_and_fleet_guards` to verify the emitted fields, named-map options and encoded byte counts. Run `delete_versions_wire_roundtrip_preserves_json_and_binary_only_batches` in the `rustfs` library tests to exercise the actual remote sender, protobuf handler and disk mutation with both codec modes. Its retained-object oracle protects against deleting an unselected entry. Deploy JSON compatibility mode during mixed-version and old-reader tests, then confirm the homogeneous upgraded fleet before enabling binary-only batches as described in the [codec convergence runbook](internode-msgpack-json-convergence-runbook.md).
|
||||
|
||||
```bash
|
||||
cargo nextest run -p rustfs-ecstore --lib --features test-util --no-tests fail \
|
||||
-E 'test(delete_versions_request_encoding_preserves_batches_and_fleet_guards)'
|
||||
NO_PROXY='*' no_proxy='*' cargo nextest run -p rustfs --lib --features gateway-stack --no-tests fail \
|
||||
-E 'test(delete_versions_wire_roundtrip_preserves_json_and_binary_only_batches)'
|
||||
```
|
||||
|
||||
### 5.2 GET
|
||||
|
||||
| Knob | Default | Controls | Validating stage | Risk if enabled |
|
||||
|
||||
+111
-275
@@ -12,8 +12,6 @@
|
||||
// See the License for the specific language governing permissions and
|
||||
// limitations under the License.
|
||||
|
||||
mod owned;
|
||||
|
||||
use crate::runtime_sources::current_action_credentials;
|
||||
#[cfg(feature = "webdav")]
|
||||
use crate::runtime_sources::current_object_store_handle;
|
||||
@@ -496,13 +494,38 @@ impl rustfs_protocols::common::client::s3::StorageBackend for ProtocolStorageCli
|
||||
"Protocol storage client request"
|
||||
);
|
||||
|
||||
self.get_object_owned(
|
||||
bucket,
|
||||
key,
|
||||
credentials,
|
||||
start_pos.map(|first| rustfs_gateway_types::ByteRange::From { first }),
|
||||
)
|
||||
.await
|
||||
let mut builder = GetObjectInput::builder().bucket(bucket.to_string()).key(key.to_string());
|
||||
|
||||
// Add range header if start_pos is specified
|
||||
if let Some(start) = start_pos {
|
||||
let range = s3s::dto::Range::Int {
|
||||
first: start,
|
||||
last: None, // Read to end of file
|
||||
};
|
||||
builder = builder.range(Some(range));
|
||||
}
|
||||
|
||||
let input = builder.build().map_err(|e| {
|
||||
s3s::S3Error::with_message(s3s::S3ErrorCode::InvalidRequest, format!("Failed to build GetObjectInput: {}", e))
|
||||
})?;
|
||||
|
||||
let uri = build_object_uri(bucket, key, &[])?;
|
||||
let req = Self::create_request(
|
||||
input,
|
||||
Method::GET,
|
||||
uri,
|
||||
RequestParams {
|
||||
bucket: Some(bucket.to_string()),
|
||||
object: Some(key.to_string()),
|
||||
credentials,
|
||||
},
|
||||
)?;
|
||||
|
||||
match self.fs.get_object(req).await {
|
||||
Ok(response) => gateway_s3s_compat::generated::ops::get_object::output_from_s3s(response.output)
|
||||
.map_err(|e| conversion_error("GetObject output", e)),
|
||||
Err(e) => Err(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
async fn put_object(
|
||||
@@ -565,20 +588,31 @@ impl rustfs_protocols::common::client::s3::StorageBackend for ProtocolStorageCli
|
||||
) -> Result<gateway_dto::DeleteObjectOutput, Self::Error> {
|
||||
trace_protocol_request("delete_object", Some(bucket), Some(key));
|
||||
|
||||
let input = DeleteObjectInput::builder()
|
||||
.bucket(bucket.to_string())
|
||||
.key(key.to_string())
|
||||
.build()
|
||||
.map_err(|e| {
|
||||
s3s::S3Error::with_message(s3s::S3ErrorCode::InvalidRequest, format!("Failed to build DeleteObjectInput: {}", e))
|
||||
})?;
|
||||
|
||||
let uri = build_object_uri(bucket, key, &[])?;
|
||||
let envelope = Self::create_envelope(
|
||||
let req = Self::create_request(
|
||||
input,
|
||||
Method::DELETE,
|
||||
uri,
|
||||
RequestParams {
|
||||
bucket: Some(bucket.to_owned()),
|
||||
object: Some(key.to_owned()),
|
||||
bucket: Some(bucket.to_string()),
|
||||
object: Some(key.to_string()),
|
||||
credentials,
|
||||
},
|
||||
);
|
||||
rustfs_io_metrics::record_s3_op(rustfs_s3_ops::S3Operation::DeleteObject);
|
||||
self.owned_usecase()
|
||||
.execute_delete_object_fields(envelope, bucket.to_owned(), key.to_owned(), None)
|
||||
.await
|
||||
)?;
|
||||
|
||||
match self.fs.delete_object(req).await {
|
||||
Ok(response) => gateway_s3s_compat::generated::ops::delete_object::output_from_s3s(response.output)
|
||||
.map_err(|e| conversion_error("DeleteObject output", e)),
|
||||
Err(e) => Err(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
async fn head_object(
|
||||
@@ -589,32 +623,31 @@ impl rustfs_protocols::common::client::s3::StorageBackend for ProtocolStorageCli
|
||||
) -> Result<gateway_dto::HeadObjectOutput, Self::Error> {
|
||||
trace_protocol_request("head_object", Some(bucket), Some(key));
|
||||
|
||||
let input = HeadObjectInput::builder()
|
||||
.bucket(bucket.to_string())
|
||||
.key(key.to_string())
|
||||
.build()
|
||||
.map_err(|e| {
|
||||
s3s::S3Error::with_message(s3s::S3ErrorCode::InvalidRequest, format!("Failed to build HeadObjectInput: {}", e))
|
||||
})?;
|
||||
|
||||
let uri = build_object_uri(bucket, key, &[])?;
|
||||
let envelope = Self::create_envelope(
|
||||
let req = Self::create_request(
|
||||
input,
|
||||
Method::HEAD,
|
||||
uri,
|
||||
RequestParams {
|
||||
bucket: Some(bucket.to_owned()),
|
||||
object: Some(key.to_owned()),
|
||||
bucket: Some(bucket.to_string()),
|
||||
object: Some(key.to_string()),
|
||||
credentials,
|
||||
},
|
||||
);
|
||||
rustfs_io_metrics::record_s3_op(rustfs_s3_ops::S3Operation::HeadObject);
|
||||
self.owned_usecase()
|
||||
.execute_head_object_fields(
|
||||
envelope,
|
||||
crate::app::object_usecase::HeadObjectFields {
|
||||
bucket: bucket.to_owned(),
|
||||
key: key.to_owned(),
|
||||
version_id: None,
|
||||
part_number: None,
|
||||
range: None,
|
||||
sse_customer_key: None,
|
||||
sse_customer_key_md5: None,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.and_then(|answered| owned::head_output(answered.output))
|
||||
)?;
|
||||
|
||||
match self.fs.head_object(req).await {
|
||||
Ok(response) => gateway_s3s_compat::generated::ops::head_object::output_from_s3s(response.output)
|
||||
.map_err(|e| conversion_error("HeadObject output", e)),
|
||||
Err(e) => Err(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
async fn head_bucket(
|
||||
@@ -858,16 +891,37 @@ impl rustfs_protocols::common::client::s3::StorageBackend for ProtocolStorageCli
|
||||
"Protocol storage client request"
|
||||
);
|
||||
|
||||
self.get_object_owned(
|
||||
bucket,
|
||||
key,
|
||||
credentials,
|
||||
Some(rustfs_gateway_types::ByteRange::FromTo {
|
||||
first: start_pos,
|
||||
last: start_pos + length - 1,
|
||||
}),
|
||||
)
|
||||
.await
|
||||
let range = s3s::dto::Range::Int {
|
||||
first: start_pos,
|
||||
last: Some(start_pos + length - 1),
|
||||
};
|
||||
|
||||
let input = GetObjectInput::builder()
|
||||
.bucket(bucket.to_string())
|
||||
.key(key.to_string())
|
||||
.range(Some(range))
|
||||
.build()
|
||||
.map_err(|e| {
|
||||
s3s::S3Error::with_message(s3s::S3ErrorCode::InvalidRequest, format!("Failed to build GetObjectInput: {}", e))
|
||||
})?;
|
||||
|
||||
let uri = build_object_uri(bucket, key, &[])?;
|
||||
let req = Self::create_request(
|
||||
input,
|
||||
Method::GET,
|
||||
uri,
|
||||
RequestParams {
|
||||
bucket: Some(bucket.to_string()),
|
||||
object: Some(key.to_string()),
|
||||
credentials,
|
||||
},
|
||||
)?;
|
||||
|
||||
match self.fs.get_object(req).await {
|
||||
Ok(response) => gateway_s3s_compat::generated::ops::get_object::output_from_s3s(response.output)
|
||||
.map_err(|e| conversion_error("GetObject output", e)),
|
||||
Err(e) => Err(e.into()),
|
||||
}
|
||||
}
|
||||
|
||||
async fn copy_object(
|
||||
@@ -1349,30 +1403,16 @@ mod tests {
|
||||
},
|
||||
)
|
||||
.expect("request should build");
|
||||
let envelope = ProtocolStorageClient::create_envelope(
|
||||
Method::GET,
|
||||
http::Uri::from_static("/bucket?list-type=2"),
|
||||
RequestParams {
|
||||
bucket: Some("bucket".to_owned()),
|
||||
object: None,
|
||||
credentials: &credentials,
|
||||
},
|
||||
);
|
||||
assert_eq!(envelope.uri(), &request.uri);
|
||||
assert_eq!(envelope.headers(), &request.headers);
|
||||
for request_info in [
|
||||
request.extensions.get::<ReqInfo>().expect("request info should be present"),
|
||||
envelope.req_info().expect("owned request info"),
|
||||
] {
|
||||
let copied = request_info.cred.as_ref().expect("credentials should be present");
|
||||
assert_eq!(copied.access_key, credentials.access_key);
|
||||
assert_eq!(copied.secret_key, credentials.secret_key);
|
||||
assert_eq!(copied.session_token, credentials.session_token);
|
||||
assert_eq!(copied.parent_user, credentials.parent_user);
|
||||
assert_eq!(copied.groups, credentials.groups);
|
||||
assert_eq!(copied.claims, Some(claims.clone()));
|
||||
assert!(copied.is_service_account());
|
||||
}
|
||||
let request_info = request.extensions.get::<ReqInfo>().expect("request info should be present");
|
||||
let copied = request_info.cred.as_ref().expect("credentials should be present");
|
||||
|
||||
assert_eq!(copied.access_key, credentials.access_key);
|
||||
assert_eq!(copied.secret_key, credentials.secret_key);
|
||||
assert_eq!(copied.session_token, credentials.session_token);
|
||||
assert_eq!(copied.parent_user, credentials.parent_user);
|
||||
assert_eq!(copied.groups, credentials.groups);
|
||||
assert_eq!(copied.claims, Some(claims));
|
||||
assert!(copied.is_service_account());
|
||||
}
|
||||
|
||||
#[cfg(any(feature = "webdav", feature = "sftp"))]
|
||||
@@ -1483,208 +1523,4 @@ mod tests {
|
||||
|
||||
assert_eq!(uri.to_string(), "/bucket?list-type=2");
|
||||
}
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn protocol_mainflow_markers_versions_and_errors_match_legacy() {
|
||||
crate::app::gating_test_env::run_large_stack_test("protocol-mainflow-oracle", || async {
|
||||
use crate::runtime_sources::ServerContextSlot;
|
||||
use crate::storage_api::protocols::client::{
|
||||
BucketOperations, MakeBucketOptions, ObjectIO, StorageObjectOptions, StoragePutObjReader,
|
||||
};
|
||||
use http_body_util::BodyExt;
|
||||
use rustfs_protocols::common::client::s3::StorageBackend;
|
||||
let root = rustfs_credentials::Credentials {
|
||||
access_key: "protocol-oracle-root".into(),
|
||||
secret_key: "protocol-oracle-secret".into(),
|
||||
status: "on".into(),
|
||||
..Default::default()
|
||||
};
|
||||
let (_temp, context, _iam) = crate::protocols::policy_test::protocol_test_context(root.clone()).await;
|
||||
let store = context.object_store();
|
||||
let slot = ServerContextSlot::new();
|
||||
assert!(slot.install(context));
|
||||
let fs = FS::with_server_ctx(slot);
|
||||
let backend = ProtocolStorageClient::new(fs.clone());
|
||||
for (bucket, key, data, versioned) in [
|
||||
("protocol-version-oracle", "versioned-key", b"versioned data".as_slice(), true),
|
||||
("protocol-marker-oracle", "folder/", b"".as_slice(), false),
|
||||
] {
|
||||
store
|
||||
.make_bucket(
|
||||
bucket,
|
||||
&MakeBucketOptions {
|
||||
versioning_enabled: versioned,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("create bucket");
|
||||
let mut reader = StoragePutObjReader::from_vec(data.to_vec());
|
||||
store
|
||||
.put_object(
|
||||
bucket,
|
||||
key,
|
||||
&mut reader,
|
||||
&StorageObjectOptions {
|
||||
versioned,
|
||||
mod_time: Some(
|
||||
time::OffsetDateTime::from_unix_timestamp(1_700_000_000)
|
||||
.expect("valid test time")
|
||||
.replace_nanosecond(123_456_789)
|
||||
.expect("valid nanoseconds"),
|
||||
),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("seed object");
|
||||
let params = || RequestParams {
|
||||
bucket: Some(bucket.to_owned()),
|
||||
object: Some(key.to_owned()),
|
||||
credentials: &root,
|
||||
};
|
||||
let uri = build_object_uri(bucket, key, &[]).expect("object URI");
|
||||
let old = fs
|
||||
.get_object(
|
||||
ProtocolStorageClient::create_request(
|
||||
GetObjectInput::builder()
|
||||
.bucket(bucket.to_owned())
|
||||
.key(key.to_owned())
|
||||
.build()
|
||||
.expect("old GET input"),
|
||||
Method::GET,
|
||||
uri.clone(),
|
||||
params(),
|
||||
)
|
||||
.expect("old GET request"),
|
||||
)
|
||||
.await
|
||||
.expect("old GET");
|
||||
let old = gateway_s3s_compat::generated::ops::get_object::output_from_s3s(old.output).expect("old GET output");
|
||||
if versioned {
|
||||
assert_eq!(old.last_modified.expect("old LastModified").subsec_nanos(), 123_000_000);
|
||||
}
|
||||
let current = backend.get_object(bucket, key, &root, None).await.expect("protocol GET");
|
||||
assert_eq!(current.last_modified, old.last_modified);
|
||||
assert_eq!(current.version_id, old.version_id);
|
||||
assert_eq!(current.version_id.is_some(), versioned);
|
||||
assert_eq!(current.e_tag, old.e_tag);
|
||||
assert_eq!(current.content_length, old.content_length);
|
||||
let collect = |output: gateway_dto::GetObjectOutput| async move {
|
||||
output
|
||||
.body
|
||||
.expect("GET body")
|
||||
.into_body()
|
||||
.collect()
|
||||
.await
|
||||
.expect("read body")
|
||||
.to_bytes()
|
||||
};
|
||||
assert_eq!(collect(current).await, collect(old).await);
|
||||
let old = fs
|
||||
.head_object(
|
||||
ProtocolStorageClient::create_request(
|
||||
HeadObjectInput::builder()
|
||||
.bucket(bucket.to_owned())
|
||||
.key(key.to_owned())
|
||||
.build()
|
||||
.expect("old HEAD input"),
|
||||
Method::HEAD,
|
||||
uri,
|
||||
params(),
|
||||
)
|
||||
.expect("old HEAD request"),
|
||||
)
|
||||
.await
|
||||
.expect("old HEAD");
|
||||
let old = gateway_s3s_compat::generated::ops::head_object::output_from_s3s(old.output).expect("old HEAD output");
|
||||
if versioned {
|
||||
assert_eq!(old.last_modified.expect("old LastModified").subsec_nanos(), 123_000_000);
|
||||
}
|
||||
let current = backend.head_object(bucket, key, &root).await.expect("protocol HEAD");
|
||||
assert_eq!(current.last_modified, old.last_modified);
|
||||
assert_eq!(current.version_id, old.version_id);
|
||||
assert_eq!(current.e_tag, old.e_tag);
|
||||
assert_eq!(current.content_length, old.content_length);
|
||||
let deleted = backend.delete_object(bucket, key, &root).await.expect("protocol DELETE");
|
||||
if versioned {
|
||||
assert_eq!(deleted.delete_marker, Some(true));
|
||||
}
|
||||
assert_eq!(deleted.version_id.is_some(), versioned);
|
||||
let old_error: rustfs_s3_types::S3Error = fs
|
||||
.get_object(
|
||||
ProtocolStorageClient::create_request(
|
||||
GetObjectInput::builder()
|
||||
.bucket(bucket.to_owned())
|
||||
.key(key.to_owned())
|
||||
.build()
|
||||
.expect("old GET input"),
|
||||
Method::GET,
|
||||
build_object_uri(bucket, key, &[]).expect("object URI"),
|
||||
params(),
|
||||
)
|
||||
.expect("old GET request"),
|
||||
)
|
||||
.await
|
||||
.expect_err("old GET deleted object")
|
||||
.into();
|
||||
let current = backend
|
||||
.get_object(bucket, key, &root, None)
|
||||
.await
|
||||
.expect_err("protocol GET deleted object");
|
||||
assert_eq!(current.code(), old_error.code());
|
||||
assert_eq!(current.status_code(), old_error.status_code());
|
||||
assert_eq!(current.headers(), old_error.headers());
|
||||
if versioned {
|
||||
let headers = current.headers().expect("delete marker error headers");
|
||||
assert_eq!(
|
||||
headers
|
||||
.get("x-amz-version-id")
|
||||
.expect("marker version")
|
||||
.to_str()
|
||||
.expect("version text"),
|
||||
deleted.version_id.as_deref().expect("delete version")
|
||||
);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
#[test]
|
||||
fn protocol_mainflow_retention_timestamp_matches_legacy_precision() {
|
||||
use crate::app::object_usecase::{GetObjectOutputFacts, HeadObjectOutputFacts};
|
||||
let instant = rustfs_gateway_types::Timestamp::from_secs_nanos(1_700_000_000, 123_456_789).expect("test timestamp");
|
||||
let get = || GetObjectOutputFacts {
|
||||
dto: gateway_dto::GetObjectOutput {
|
||||
object_lock_retain_until_date: Some(instant),
|
||||
..Default::default()
|
||||
},
|
||||
..Default::default()
|
||||
};
|
||||
let head = || HeadObjectOutputFacts {
|
||||
dto: gateway_dto::HeadObjectOutput {
|
||||
object_lock_retain_until_date: Some(instant),
|
||||
..Default::default()
|
||||
},
|
||||
etag: None,
|
||||
};
|
||||
let old_get =
|
||||
gateway_s3s_compat::generated::ops::get_object::output_from_s3s(get().into_s3s().expect("old GET projection"))
|
||||
.expect("old GET output");
|
||||
let old_head =
|
||||
gateway_s3s_compat::generated::ops::head_object::output_from_s3s(head().into_s3s().expect("old HEAD projection"))
|
||||
.expect("old HEAD output");
|
||||
let old = (old_get.object_lock_retain_until_date, old_head.object_lock_retain_until_date);
|
||||
let expected =
|
||||
Some(rustfs_gateway_types::Timestamp::from_secs_nanos(1_700_000_000, 123_000_000).expect("millisecond timestamp"));
|
||||
assert_eq!(old, (expected, expected));
|
||||
let current = (
|
||||
owned::get_output(get())
|
||||
.expect("protocol GET output")
|
||||
.object_lock_retain_until_date,
|
||||
owned::head_output(head())
|
||||
.expect("protocol HEAD output")
|
||||
.object_lock_retain_until_date,
|
||||
);
|
||||
assert_eq!(current, old);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,130 +0,0 @@
|
||||
// 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.
|
||||
|
||||
//! Request and response projections for protocol reads and single-object deletion.
|
||||
//! Authorization stays on the protocol session edge; storage runs in the client's server context.
|
||||
|
||||
use super::{ProtocolStorageClient, RequestParams};
|
||||
use crate::app::object_usecase::{DefaultObjectUsecase, GetObjectBody, GetObjectOutputFacts, HeadObjectOutputFacts};
|
||||
use crate::app::{RequestCredentials, RequestEnvelope, RequestHead};
|
||||
use crate::runtime_sources::current_action_credentials;
|
||||
use crate::storage_api::protocols::client::{ReqInfo, RequestContext};
|
||||
use http::{HeaderMap, Method, Uri};
|
||||
use rustfs_gateway_types::{ETag, Timestamp, dto};
|
||||
use rustfs_s3_types::{S3Error, S3ErrorCode, S3Result};
|
||||
|
||||
impl ProtocolStorageClient {
|
||||
pub(super) async fn get_object_owned(
|
||||
&self,
|
||||
bucket: &str,
|
||||
key: &str,
|
||||
credentials: &rustfs_credentials::Credentials,
|
||||
range: Option<rustfs_gateway_types::ByteRange>,
|
||||
) -> S3Result<dto::GetObjectOutput> {
|
||||
let uri = super::build_object_uri(bucket, key, &[])?;
|
||||
let envelope = Self::create_envelope(
|
||||
Method::GET,
|
||||
uri,
|
||||
RequestParams {
|
||||
bucket: Some(bucket.to_owned()),
|
||||
object: Some(key.to_owned()),
|
||||
credentials,
|
||||
},
|
||||
);
|
||||
rustfs_io_metrics::record_s3_op(rustfs_s3_ops::S3Operation::GetObject);
|
||||
self.owned_usecase()
|
||||
.execute_get_object_fields(
|
||||
envelope,
|
||||
crate::app::object_usecase::GetObjectFields {
|
||||
bucket: bucket.to_owned(),
|
||||
key: key.to_owned(),
|
||||
version_id: None,
|
||||
part_number: None,
|
||||
range,
|
||||
sse_customer_key: None,
|
||||
sse_customer_key_md5: None,
|
||||
},
|
||||
)
|
||||
.await
|
||||
.and_then(|answered| get_output(answered.output))
|
||||
}
|
||||
|
||||
pub(super) fn owned_usecase(&self) -> DefaultObjectUsecase {
|
||||
DefaultObjectUsecase::with_context(self.fs.server_ctx().app_context())
|
||||
}
|
||||
|
||||
pub(super) fn create_envelope(method: Method, uri: Uri, params: RequestParams<'_>) -> RequestEnvelope {
|
||||
let is_owner = current_action_credentials().is_some_and(|root| params.credentials.access_key == root.access_key);
|
||||
let credentials =
|
||||
RequestCredentials::new(params.credentials.access_key.clone(), params.credentials.secret_key.clone(), None)
|
||||
.unwrap_or_else(|_| RequestCredentials::without_secret_key(params.credentials.access_key.clone(), None));
|
||||
let mut extensions = http::Extensions::new();
|
||||
extensions.insert(ReqInfo {
|
||||
cred: Some(params.credentials.clone()),
|
||||
is_owner,
|
||||
bucket: params.bucket,
|
||||
object: params.object,
|
||||
version_id: None,
|
||||
replication_request_authorized: false,
|
||||
region: None,
|
||||
request_context: Some(RequestContext::fallback()),
|
||||
suppress_denial_log: false,
|
||||
suppress_denial_audit: false,
|
||||
});
|
||||
RequestEnvelope::from_parts(
|
||||
RequestHead {
|
||||
method,
|
||||
uri,
|
||||
headers: HeaderMap::new(),
|
||||
credentials: Some(credentials),
|
||||
region: None,
|
||||
service: None,
|
||||
},
|
||||
extensions,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
fn etag(opaque: String, weak: bool) -> S3Result<ETag> {
|
||||
if weak { ETag::new_weak(opaque) } else { ETag::new(opaque) }
|
||||
.map_err(|_| S3Error::with_message(S3ErrorCode::InternalError, "Object response contains an invalid ETag"))
|
||||
}
|
||||
|
||||
// Protocol clients received millisecond timestamps through the legacy response codec.
|
||||
fn millisecond_timestamp(value: Timestamp) -> Timestamp {
|
||||
Timestamp::from_secs_nanos(value.secs(), value.subsec_millis() * 1_000_000)
|
||||
.expect("a millisecond remainder is below one second") // subsec_millis is at most 999.
|
||||
}
|
||||
|
||||
pub(super) fn get_output(mut output: GetObjectOutputFacts) -> S3Result<dto::GetObjectOutput> {
|
||||
output.dto.last_modified = output.dto.last_modified.map(millisecond_timestamp);
|
||||
output.dto.object_lock_retain_until_date = output.dto.object_lock_retain_until_date.map(millisecond_timestamp);
|
||||
output.dto.e_tag = output.etag.map(|tag| etag(tag.opaque, tag.weak)).transpose()?;
|
||||
output.dto.body = output
|
||||
.body
|
||||
.map(|body| match body {
|
||||
GetObjectBody::Bytes(bytes) => Ok(rustfs_gateway_stream::ByteStream::from_bytes(bytes)),
|
||||
GetObjectBody::Stream(stream) => rustfs_gateway_stream::ByteStream::new(stream)
|
||||
.map_err(|_| S3Error::with_message(S3ErrorCode::InternalError, "Invalid GetObject body capabilities")),
|
||||
})
|
||||
.transpose()?;
|
||||
Ok(output.dto)
|
||||
}
|
||||
|
||||
pub(super) fn head_output(mut output: HeadObjectOutputFacts) -> S3Result<dto::HeadObjectOutput> {
|
||||
output.dto.last_modified = output.dto.last_modified.map(millisecond_timestamp);
|
||||
output.dto.object_lock_retain_until_date = output.dto.object_lock_retain_until_date.map(millisecond_timestamp);
|
||||
output.dto.e_tag = output.etag.map(|tag| etag(tag.opaque, tag.weak)).transpose()?;
|
||||
Ok(output.dto)
|
||||
}
|
||||
@@ -1,198 +0,0 @@
|
||||
// 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.
|
||||
|
||||
//! Protocol mainflow behavior through the installed server's object use case.
|
||||
//! These probes exercise the protocol client, not the HTTP transport or authorization hook.
|
||||
|
||||
use super::ProtocolStorageClient;
|
||||
use super::policy_test::protocol_test_context;
|
||||
use crate::runtime_sources::ServerContextSlot;
|
||||
use crate::storage_api::protocols::client::{
|
||||
BucketOperations, MakeBucketOptions, ObjectIO, StorageObjectOptions, StoragePutObjReader,
|
||||
};
|
||||
use http_body_util::BodyExt;
|
||||
use rustfs_credentials::Credentials;
|
||||
use rustfs_protocols::common::client::s3::StorageBackend;
|
||||
use rustfs_s3_types::S3ErrorCode;
|
||||
|
||||
const KEY: &str = "directory/a ?#+%.txt";
|
||||
|
||||
async fn object_client(bucket: &str) -> (tempfile::TempDir, Credentials, ProtocolStorageClient, String) {
|
||||
let root = Credentials {
|
||||
access_key: "protocol-mainflow-root".into(),
|
||||
secret_key: "protocol-mainflow-secret".into(),
|
||||
status: "on".into(),
|
||||
..Default::default()
|
||||
};
|
||||
let (temp, context, _iam) = protocol_test_context(root.clone()).await;
|
||||
let store = context.object_store();
|
||||
store
|
||||
.make_bucket(bucket, &MakeBucketOptions::default())
|
||||
.await
|
||||
.expect("create bucket");
|
||||
let mut reader = StoragePutObjReader::from_vec(b"protocol-data".to_vec());
|
||||
let stored = store
|
||||
.put_object(bucket, KEY, &mut reader, &StorageObjectOptions::default())
|
||||
.await
|
||||
.expect("seed object");
|
||||
let slot = ServerContextSlot::new();
|
||||
assert!(slot.install(context));
|
||||
(
|
||||
temp,
|
||||
root,
|
||||
crate::init::protocol_storage_client_for_server(slot),
|
||||
stored.etag.expect("stored ETag"),
|
||||
)
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn protocol_mainflow_reads_ranges_and_data() {
|
||||
crate::app::gating_test_env::run_large_stack_test("protocol-mainflow-read", || async {
|
||||
let bucket = "protocol-mainflow-read";
|
||||
let (_temp, root, backend, stored_etag) = object_client(bucket).await;
|
||||
for (start, expected) in [(None, b"protocol-data".as_slice()), (Some(9), b"data".as_slice())] {
|
||||
let output = backend.get_object(bucket, KEY, &root, start).await.expect("protocol GET");
|
||||
assert_eq!(output.content_length, Some(expected.len() as i64));
|
||||
assert_eq!(output.e_tag.as_ref().expect("GET ETag").opaque_tag(), stored_etag);
|
||||
let body = output
|
||||
.body
|
||||
.expect("GET body")
|
||||
.into_body()
|
||||
.collect()
|
||||
.await
|
||||
.expect("consume GET")
|
||||
.to_bytes();
|
||||
assert_eq!(body.as_ref(), expected);
|
||||
assert_eq!(output.version_id, None);
|
||||
}
|
||||
let ranged = backend
|
||||
.get_object_range(bucket, KEY, &root, 2, 4)
|
||||
.await
|
||||
.expect("bounded range");
|
||||
assert_eq!(ranged.content_range.as_deref(), Some("bytes 2-5/13"));
|
||||
assert_eq!(
|
||||
ranged
|
||||
.body
|
||||
.expect("range body")
|
||||
.into_body()
|
||||
.collect()
|
||||
.await
|
||||
.expect("consume range")
|
||||
.to_bytes()
|
||||
.as_ref(),
|
||||
b"otoc"
|
||||
);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn protocol_mainflow_heads_object_metadata() {
|
||||
crate::app::gating_test_env::run_large_stack_test("protocol-mainflow-head", || async {
|
||||
let bucket = "protocol-mainflow-head";
|
||||
let (_temp, root, backend, stored_etag) = object_client(bucket).await;
|
||||
let head = backend.head_object(bucket, KEY, &root).await.expect("protocol HEAD");
|
||||
assert_eq!(head.content_length, Some(13));
|
||||
assert_eq!(head.e_tag.as_ref().expect("HEAD ETag").opaque_tag(), stored_etag);
|
||||
assert_eq!(head.version_id, None);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn protocol_mainflow_deletes_object() {
|
||||
crate::app::gating_test_env::run_large_stack_test("protocol-mainflow-delete", || async {
|
||||
let bucket = "protocol-mainflow-delete";
|
||||
let (_temp, root, backend, _stored_etag) = object_client(bucket).await;
|
||||
let deleted = backend.delete_object(bucket, KEY, &root).await.expect("protocol DELETE");
|
||||
assert_eq!(deleted.version_id, None);
|
||||
assert_eq!(deleted.delete_marker, Some(false));
|
||||
let missing = backend
|
||||
.get_object(bucket, KEY, &root, None)
|
||||
.await
|
||||
.expect_err("deleted object is absent");
|
||||
assert_eq!(missing.code(), &S3ErrorCode::NoSuchKey);
|
||||
});
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[serial_test::serial]
|
||||
fn protocol_mainflow_refuses_missing_objects_buckets_and_unsatisfied_ranges() {
|
||||
crate::app::gating_test_env::run_large_stack_test("protocol-mainflow-errors", || async {
|
||||
let bucket = "protocol-mainflow-errors";
|
||||
let (_temp, root, backend, _stored_etag) = object_client(bucket).await;
|
||||
for target in [bucket, "protocol-absent-bucket"] {
|
||||
let expected = if target == bucket {
|
||||
S3ErrorCode::NoSuchKey
|
||||
} else {
|
||||
S3ErrorCode::NoSuchBucket
|
||||
};
|
||||
assert_eq!(
|
||||
backend
|
||||
.get_object(target, "absent", &root, None)
|
||||
.await
|
||||
.expect_err("missing GET")
|
||||
.code(),
|
||||
&expected
|
||||
);
|
||||
assert_eq!(
|
||||
backend
|
||||
.get_object(target, "absent", &root, Some(1))
|
||||
.await
|
||||
.expect_err("missing open-range GET")
|
||||
.code(),
|
||||
&expected
|
||||
);
|
||||
assert_eq!(
|
||||
backend
|
||||
.get_object_range(target, "absent", &root, 1, 1)
|
||||
.await
|
||||
.expect_err("missing bounded-range GET")
|
||||
.code(),
|
||||
&expected
|
||||
);
|
||||
assert_eq!(
|
||||
backend
|
||||
.head_object(target, "absent", &root)
|
||||
.await
|
||||
.expect_err("missing HEAD")
|
||||
.code(),
|
||||
&expected
|
||||
);
|
||||
}
|
||||
for start in [13, 14, 1024] {
|
||||
for error in [
|
||||
backend
|
||||
.get_object(bucket, KEY, &root, Some(start))
|
||||
.await
|
||||
.expect_err("open range past end"),
|
||||
backend
|
||||
.get_object_range(bucket, KEY, &root, start, 1)
|
||||
.await
|
||||
.expect_err("bounded range past end"),
|
||||
] {
|
||||
assert_eq!(error.code(), &S3ErrorCode::InvalidRange);
|
||||
}
|
||||
}
|
||||
assert_eq!(
|
||||
backend
|
||||
.delete_object("protocol-absent-bucket", KEY, &root)
|
||||
.await
|
||||
.expect_err("missing DELETE bucket")
|
||||
.code(),
|
||||
&S3ErrorCode::NoSuchBucket
|
||||
);
|
||||
});
|
||||
}
|
||||
@@ -18,6 +18,3 @@ pub use client::ProtocolStorageClient;
|
||||
|
||||
#[cfg(test)]
|
||||
mod policy_test;
|
||||
|
||||
#[cfg(test)]
|
||||
mod mainflow_test;
|
||||
|
||||
@@ -54,7 +54,7 @@ fn decode_policy(value: serde_json::Value) -> Result<rustfs_policy::policy::Poli
|
||||
serde_json::from_str(&value.to_string())
|
||||
}
|
||||
|
||||
pub(super) async fn protocol_test_context(root: Credentials) -> (tempfile::TempDir, Arc<AppContext>, Arc<IamSys<ObjectStore>>) {
|
||||
async fn protocol_test_context(root: Credentials) -> (tempfile::TempDir, Arc<AppContext>, Arc<IamSys<ObjectStore>>) {
|
||||
let (temp, _paths, store) = crate::app::gating_test_env::isolated_multi_pool_ecstore().await;
|
||||
ObjectStore::new(store.clone())
|
||||
.save_iam_config(json!({"version": 1}), format!("{}/format.json", *IAM_CONFIG_PREFIX))
|
||||
|
||||
@@ -9483,20 +9483,34 @@ mod tests {
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
#[tokio::test]
|
||||
async fn target_delete_quorum_failure_restores_remote_marker_and_retries_fail() {
|
||||
struct DeleteRpcTarget {
|
||||
remote: super::DiskStore,
|
||||
local_disks: Vec<super::DiskStore>,
|
||||
shutdown: tokio::sync::oneshot::Sender<()>,
|
||||
server: tokio::task::JoinHandle<()>,
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
impl DeleteRpcTarget {
|
||||
async fn close(self) {
|
||||
self.remote.close().await.expect("close remote client");
|
||||
let _ = self.shutdown.send(());
|
||||
super::timeout(Duration::from_secs(10), self.server)
|
||||
.await
|
||||
.expect("server shuts down")
|
||||
.expect("server task");
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
async fn start_delete_rpc_target(fixture: &TargetRpcFixture) -> DeleteRpcTarget {
|
||||
use crate::storage::storage_api::{
|
||||
contract::object::ObjectOperations,
|
||||
ecstore_disk::{DeleteOptions, DiskOption, ReadOptions, new_disk},
|
||||
ecstore_error::StorageError,
|
||||
ecstore_disk::{DiskOption, new_disk},
|
||||
init_local_disks_with_instance_ctx,
|
||||
};
|
||||
|
||||
let fixture = target_rpc_fixture().await;
|
||||
let _ = rustfs_credentials::set_global_rpc_secret(Uuid::new_v4().to_string());
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.expect("bind DELETE target");
|
||||
let addr = listener.local_addr().expect("target address");
|
||||
let set = fixture.env.ecstore.all_set_disks().into_iter().next().expect("erasure set");
|
||||
let mut endpoints = fixture.env.endpoint_pools.as_ref()[0].endpoints.as_ref().clone();
|
||||
let mut remote_endpoint = Endpoint::try_from(format!("http://{addr}{}", fixture.env.disk_paths[0].display()).as_str())
|
||||
.expect("remote endpoint");
|
||||
@@ -9544,6 +9558,104 @@ mod tests {
|
||||
.await
|
||||
.expect("remote disk client");
|
||||
assert!(!remote.is_local());
|
||||
DeleteRpcTarget {
|
||||
remote,
|
||||
local_disks,
|
||||
shutdown,
|
||||
server,
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
#[tokio::test]
|
||||
async fn delete_versions_wire_roundtrip_preserves_json_and_binary_only_batches() {
|
||||
use crate::storage::DiskError;
|
||||
use crate::storage::storage_api::ecstore_disk::{DeleteOptions, FileInfoVersions, ReadOptions};
|
||||
let fixture = target_rpc_fixture().await;
|
||||
let target = start_delete_rpc_target(&fixture).await;
|
||||
let disk = &target.local_disks[0];
|
||||
let mut framed = rustfs_utils::HashAlgorithm::HighwayHash256S
|
||||
.hash_encode(b"abc")
|
||||
.as_ref()
|
||||
.to_vec();
|
||||
framed.extend_from_slice(b"abc");
|
||||
let framed = Bytes::from(framed);
|
||||
for (mode, enabled) in [("json", "false"), ("binary", "true")] {
|
||||
temp_env::async_with_vars(
|
||||
[
|
||||
(rustfs_config::ENV_INTERNODE_RPC_MSGPACK_ONLY, Some(enabled)),
|
||||
(rustfs_config::ENV_INTERNODE_RPC_MSGPACK_ONLY_FLEET_CONFIRMED, Some(enabled)),
|
||||
],
|
||||
async {
|
||||
rustfs_protos::reset_internode_rpc_msgpack_only_cache();
|
||||
let bucket = format!("batch-delete-{mode}");
|
||||
disk.make_volume(&bucket).await.expect("create isolated batch bucket");
|
||||
let mut groups = Vec::new();
|
||||
for object in ["first", "second", "retained"] {
|
||||
let mut info = rustfs_filemeta::FileInfo::new(object, 1, 0);
|
||||
info.erasure.index = 1;
|
||||
info.version_id = Some(Uuid::new_v4());
|
||||
info.mod_time = Some(OffsetDateTime::now_utc());
|
||||
info.size = 3;
|
||||
info.add_object_part(1, "etag".to_owned(), 3, info.mod_time, 3, None, None);
|
||||
info.data = Some(framed.clone());
|
||||
info.set_inline_data();
|
||||
disk.write_metadata(&bucket, &bucket, object, info.clone())
|
||||
.await
|
||||
.expect("seed version");
|
||||
if object != "retained" {
|
||||
groups.push(FileInfoVersions {
|
||||
volume: bucket.clone(),
|
||||
name: object.to_owned(),
|
||||
versions: vec![info],
|
||||
..Default::default()
|
||||
});
|
||||
}
|
||||
}
|
||||
let errors = target.remote.delete_versions(&bucket, groups, DeleteOptions::default()).await;
|
||||
assert_eq!(errors, vec![None, None], "{mode} batch must delete both entries");
|
||||
for object in ["first", "second"] {
|
||||
let result = disk.read_version(&bucket, &bucket, object, "", &ReadOptions::default()).await;
|
||||
assert!(
|
||||
matches!(result, Err(DiskError::FileNotFound | DiskError::FileVersionNotFound)),
|
||||
"{mode} {object}: {result:?}"
|
||||
);
|
||||
}
|
||||
let retained = disk
|
||||
.read_version(
|
||||
&bucket,
|
||||
&bucket,
|
||||
"retained",
|
||||
"",
|
||||
&ReadOptions {
|
||||
read_data: true,
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.await
|
||||
.expect("unselected version remains readable");
|
||||
assert_eq!(retained.data, Some(framed.clone()));
|
||||
rustfs_protos::reset_internode_rpc_msgpack_only_cache();
|
||||
},
|
||||
)
|
||||
.await;
|
||||
}
|
||||
target.close().await;
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
#[tokio::test]
|
||||
async fn target_delete_quorum_failure_restores_remote_marker_and_retries_fail() {
|
||||
use crate::storage::storage_api::{
|
||||
contract::object::ObjectOperations,
|
||||
ecstore_disk::{DeleteOptions, ReadOptions},
|
||||
ecstore_error::StorageError,
|
||||
};
|
||||
let fixture = target_rpc_fixture().await;
|
||||
let target = start_delete_rpc_target(&fixture).await;
|
||||
let remote = &target.remote;
|
||||
let local_disks = &target.local_disks;
|
||||
let set = fixture.env.ecstore.all_set_disks().into_iter().next().expect("erasure set");
|
||||
|
||||
let bucket = "delete-quorum-rpc";
|
||||
let object = "versioned-object";
|
||||
@@ -9562,7 +9674,7 @@ mod tests {
|
||||
original.data = Some(payload.clone());
|
||||
original.set_inline_data();
|
||||
let mut before = Vec::new();
|
||||
for disk in &local_disks {
|
||||
for disk in local_disks {
|
||||
disk.make_volume(bucket).await.expect("create target bucket");
|
||||
disk.write_metadata(bucket, bucket, object, original.clone())
|
||||
.await
|
||||
@@ -9677,13 +9789,8 @@ mod tests {
|
||||
assert_eq!(restored.data, Some(payload.clone()));
|
||||
}
|
||||
}
|
||||
*set.disks.write().await = local_disks.into_iter().map(Some).collect();
|
||||
remote.close().await.expect("close remote client");
|
||||
let _ = shutdown.send(());
|
||||
super::timeout(Duration::from_secs(10), server)
|
||||
.await
|
||||
.expect("server shuts down")
|
||||
.expect("server task");
|
||||
*set.disks.write().await = local_disks.iter().cloned().map(Some).collect();
|
||||
target.close().await;
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
|
||||
@@ -245,6 +245,34 @@ fn decode_msgpack_or_json_with_source<T: DeserializeOwned>(
|
||||
}
|
||||
}
|
||||
|
||||
fn decode_delete_versions_request_versions(
|
||||
request: &DeleteVersionsRequest,
|
||||
) -> std::result::Result<Vec<FileInfoVersions>, DiskError> {
|
||||
if request.versions_bin.is_empty() {
|
||||
let mut versions = Vec::with_capacity(request.versions.len());
|
||||
for version in &request.versions {
|
||||
versions.push(decode_msgpack_or_json(&[], version, "FileInfoVersions")?);
|
||||
}
|
||||
return Ok(versions);
|
||||
}
|
||||
|
||||
// The binary list owns both the batch length and its entries. A legacy
|
||||
// JSON list may be absent or stale, so it cannot repair a malformed item.
|
||||
let mut versions = Vec::with_capacity(request.versions_bin.len());
|
||||
for version in &request.versions_bin {
|
||||
if version.is_empty() {
|
||||
global_internode_metrics().record_msgpack_json_decode_error(
|
||||
INTERNODE_MSGPACK_DIRECTION_REQUEST,
|
||||
"FileInfoVersions",
|
||||
INTERNODE_MSGPACK_CODEC_MSGPACK,
|
||||
);
|
||||
return Err(DiskError::other("empty FileInfoVersions msgpack item"));
|
||||
}
|
||||
versions.push(decode_msgpack_or_json(version, "", "FileInfoVersions")?);
|
||||
}
|
||||
Ok(versions)
|
||||
}
|
||||
|
||||
fn encode_msgpack_with_capacity<T: serde::Serialize>(
|
||||
value: &T,
|
||||
value_name: &str,
|
||||
@@ -967,21 +995,17 @@ impl NodeService {
|
||||
)?;
|
||||
let request = request.into_inner();
|
||||
if let Some(disk) = self.find_disk(&request.disk).await? {
|
||||
let mut versions = Vec::with_capacity(request.versions.len());
|
||||
for (index, version) in request.versions.iter().enumerate() {
|
||||
let version_bin = request.versions_bin.get(index).map(|b| b.as_ref()).unwrap_or(&[]);
|
||||
match decode_msgpack_or_json::<FileInfoVersions>(version_bin, version, "FileInfoVersions") {
|
||||
Ok(version) => versions.push(version),
|
||||
Err(err) => {
|
||||
return Ok(Response::new(DeleteVersionsResponse {
|
||||
success: false,
|
||||
errors: Vec::new(),
|
||||
error: Some(DiskError::other(format!("decode FileInfoVersions failed: {err}")).into()),
|
||||
item_errors: Vec::new(),
|
||||
}));
|
||||
}
|
||||
};
|
||||
}
|
||||
let versions = match decode_delete_versions_request_versions(&request) {
|
||||
Ok(versions) => versions,
|
||||
Err(err) => {
|
||||
return Ok(Response::new(DeleteVersionsResponse {
|
||||
success: false,
|
||||
errors: Vec::new(),
|
||||
error: Some(err.into()),
|
||||
item_errors: Vec::new(),
|
||||
}));
|
||||
}
|
||||
};
|
||||
let opts = match decode_msgpack_or_json::<DeleteOptions>(&request.opts_bin, &request.opts, "DeleteOptions") {
|
||||
Ok(opts) => opts,
|
||||
Err(err) => {
|
||||
@@ -2914,19 +2938,20 @@ impl NodeService {
|
||||
mod tests {
|
||||
use super::{
|
||||
DeleteOptions, INTERNODE_OPERATION_GRPC_BATCH_READ_VERSION, INTERNODE_OPERATION_GRPC_READ_MULTIPLE,
|
||||
InternodeRpcDurationGuard, compat_response_json, decode_msgpack_or_json, decode_multipart_rename_request_file_info,
|
||||
decode_rename_data_request_file_info, encode_batch_read_version_response_payloads, encode_delete_versions_errors,
|
||||
encode_file_info_msgpack, encode_msgpack, encode_msgpack_named, encode_read_multiple_response_payloads,
|
||||
encode_rename_data_response_payloads, rejects_legacy_delete_transaction,
|
||||
InternodeRpcDurationGuard, compat_response_json, decode_delete_versions_request_versions, decode_msgpack_or_json,
|
||||
decode_multipart_rename_request_file_info, decode_rename_data_request_file_info,
|
||||
encode_batch_read_version_response_payloads, encode_delete_versions_errors, encode_file_info_msgpack, encode_msgpack,
|
||||
encode_msgpack_named, encode_read_multiple_response_payloads, encode_rename_data_response_payloads,
|
||||
rejects_legacy_delete_transaction,
|
||||
};
|
||||
use crate::storage::DiskError;
|
||||
use crate::storage::rpc::node_service::make_server;
|
||||
use crate::storage::storage_api::ReadMultipleResp;
|
||||
use crate::storage::storage_api::RenameDataResp;
|
||||
use crate::storage::storage_api::rpc_consumer::node_service::BatchReadVersionResp;
|
||||
use rustfs_filemeta::FileInfo;
|
||||
use rustfs_filemeta::{FileInfo, FileInfoVersions};
|
||||
use rustfs_io_metrics::internode_metrics::global_internode_metrics;
|
||||
use rustfs_protos::proto_gen::node_service::ReadVersionRequest;
|
||||
use rustfs_protos::proto_gen::node_service::{DeleteVersionsRequest, ReadVersionRequest};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serial_test::serial;
|
||||
use tonic::Request;
|
||||
@@ -2938,6 +2963,118 @@ mod tests {
|
||||
count: u32,
|
||||
}
|
||||
|
||||
fn delete_versions_group(name: &str) -> FileInfoVersions {
|
||||
FileInfoVersions {
|
||||
volume: "bucket".to_string(),
|
||||
name: name.to_string(),
|
||||
versions: vec![FileInfo {
|
||||
name: name.to_string(),
|
||||
version_id: Some(Uuid::from_u128(1)),
|
||||
..Default::default()
|
||||
}],
|
||||
..Default::default()
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete_versions_msgpack_only_decodes_every_binary_item() {
|
||||
let groups = [delete_versions_group("first"), delete_versions_group("second")];
|
||||
let request = DeleteVersionsRequest {
|
||||
versions_bin: groups
|
||||
.iter()
|
||||
.map(|group| {
|
||||
encode_msgpack_named(group, "FileInfoVersions")
|
||||
.expect("encode delete group")
|
||||
.into()
|
||||
})
|
||||
.collect(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let decoded = decode_delete_versions_request_versions(&request).expect("decode msgpack-only batch");
|
||||
assert_eq!(decoded.len(), groups.len());
|
||||
for (actual, expected) in decoded.iter().zip(&groups) {
|
||||
assert_eq!(actual.name, expected.name);
|
||||
assert_eq!(actual.versions, expected.versions);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete_versions_msgpack_list_controls_length_and_values_with_legacy_json_present() {
|
||||
for json_count in [0, 1, 2, 3] {
|
||||
let request = DeleteVersionsRequest {
|
||||
versions: vec!["invalid legacy JSON".to_string(); json_count],
|
||||
versions_bin: ["first", "second"]
|
||||
.iter()
|
||||
.map(|name| {
|
||||
encode_msgpack_named(&delete_versions_group(name), "FileInfoVersions")
|
||||
.expect("encode binary delete group")
|
||||
.into()
|
||||
})
|
||||
.collect(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let decoded = decode_delete_versions_request_versions(&request).expect("binary batch must take precedence");
|
||||
assert_eq!(decoded.iter().map(|group| group.name.as_str()).collect::<Vec<_>>(), ["first", "second"]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete_versions_json_only_preserves_legacy_batch() {
|
||||
let groups = [delete_versions_group("first"), delete_versions_group("second")];
|
||||
let request = DeleteVersionsRequest {
|
||||
versions: groups
|
||||
.iter()
|
||||
.map(|group| serde_json::to_string(group).expect("encode legacy delete group"))
|
||||
.collect(),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
let decoded = decode_delete_versions_request_versions(&request).expect("decode legacy JSON batch");
|
||||
assert_eq!(decoded.len(), groups.len());
|
||||
for (actual, expected) in decoded.iter().zip(&groups) {
|
||||
assert_eq!(actual.name, expected.name);
|
||||
assert_eq!(actual.versions, expected.versions);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete_versions_invalid_binary_item_never_uses_valid_json() {
|
||||
let json = serde_json::to_string(&delete_versions_group("legacy")).expect("encode legacy group");
|
||||
for invalid in [bytes::Bytes::new(), bytes::Bytes::from_static(b"invalid-msgpack")] {
|
||||
let request = DeleteVersionsRequest {
|
||||
versions: vec![json.clone(), json.clone()],
|
||||
versions_bin: vec![
|
||||
encode_msgpack_named(&delete_versions_group("first"), "FileInfoVersions")
|
||||
.expect("encode valid first group")
|
||||
.into(),
|
||||
invalid,
|
||||
],
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
assert!(
|
||||
decode_delete_versions_request_versions(&request).is_err(),
|
||||
"malformed binary batch must fail"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn delete_versions_invalid_json_only_batch_fails_and_empty_batch_stays_empty() {
|
||||
let invalid = DeleteVersionsRequest {
|
||||
versions: vec!["invalid JSON".to_string()],
|
||||
..Default::default()
|
||||
};
|
||||
assert!(decode_delete_versions_request_versions(&invalid).is_err());
|
||||
assert!(
|
||||
decode_delete_versions_request_versions(&DeleteVersionsRequest::default())
|
||||
.expect("empty legacy batch")
|
||||
.is_empty()
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_delete_transaction_policy_preserves_rollback_and_internal_maintenance() {
|
||||
let mut opts = DeleteOptions {
|
||||
|
||||
@@ -14714,6 +14714,7 @@ const MULTIPART_KEY_GUARD: &str = "validate_table_catalog_object_mutation(&bucke
|
||||
const MULTIPART_BORROWED_KEY_GUARD: &str = "validate_table_catalog_object_mutation(bucket, key).await?;";
|
||||
const OBJECT_METADATA_OBJECT_GUARD: &str = "validate_table_catalog_object_mutation(&bucket, &object).await?;";
|
||||
const OBJECT_METADATA_KEY_GUARD: &str = MULTIPART_KEY_GUARD;
|
||||
const OBJECT_METADATA_BORROWED_KEY_GUARD: &str = MULTIPART_BORROWED_KEY_GUARD;
|
||||
|
||||
fn assert_multipart_reserved_prefix_guard_calls(source: &crate::guard_sources::SourceSet) {
|
||||
let guard_calls = source.count(MULTIPART_KEY_GUARD) + source.count(MULTIPART_BORROWED_KEY_GUARD);
|
||||
@@ -14728,7 +14729,7 @@ fn assert_object_metadata_reserved_prefix_guard_calls(source: &crate::guard_sour
|
||||
source.describe()
|
||||
);
|
||||
assert_eq!(
|
||||
source.count(OBJECT_METADATA_KEY_GUARD),
|
||||
source.count(OBJECT_METADATA_KEY_GUARD) + source.count(OBJECT_METADATA_BORROWED_KEY_GUARD),
|
||||
2,
|
||||
"reserved-prefix guard calls across {}",
|
||||
source.describe()
|
||||
@@ -14745,8 +14746,7 @@ fn multipart_mutation_entrypoints_call_reserved_prefix_guard() {
|
||||
|
||||
#[test]
|
||||
fn object_metadata_mutation_entrypoints_call_reserved_prefix_guard() {
|
||||
// DeleteObjectTagging's call moved into the use case of batch B1; PutObjectTagging's is still on
|
||||
// the legacy edge.
|
||||
// Count mutation guards across the shared use cases and legacy entrypoints.
|
||||
let sources = crate::guard_sources::SourceSet::production("src/storage/ecfs.rs", "src/storage/legacy_edge")
|
||||
.and(crate::guard_sources::SourceSet::production("src/app/mod.rs", "src/app/object_meta"));
|
||||
assert_object_metadata_reserved_prefix_guard_calls(&sources);
|
||||
@@ -14821,6 +14821,91 @@ fn multipart_count_guard_accepts_borrowed_resource_names() {
|
||||
assert_multipart_reserved_prefix_guard_calls(&source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multipart_count_guard_accepts_owned_and_borrowed_resource_arguments() {
|
||||
let source = guard_fixture(
|
||||
&[
|
||||
("src/app/multipart_usecase.rs", guarded_methods(MULTIPART_KEY_GUARD, 2).as_str()),
|
||||
("src/app/multipart_usecase/complete.rs", guarded_methods(MULTIPART_KEY_GUARD, 1).as_str()),
|
||||
(
|
||||
"src/app/multipart_usecase/upload_part.rs",
|
||||
guarded_methods(MULTIPART_BORROWED_KEY_GUARD, 1).as_str(),
|
||||
),
|
||||
],
|
||||
"src/app/multipart_usecase.rs",
|
||||
"src/app/multipart_usecase",
|
||||
);
|
||||
|
||||
assert_multipart_reserved_prefix_guard_calls(&source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn multipart_count_guard_rejects_misbound_or_unpropagated_borrowed_guards() {
|
||||
for broken in [
|
||||
MULTIPART_BORROWED_KEY_GUARD.replace("(bucket,", "(other_bucket,"),
|
||||
MULTIPART_BORROWED_KEY_GUARD.replace(", key)", ", other_key)"),
|
||||
MULTIPART_BORROWED_KEY_GUARD.replace(".await?;", ".await;"),
|
||||
] {
|
||||
let parent = format!(
|
||||
"{}\n#[cfg(test)]\nmod tests {{\n fn mentions() {{\n {MULTIPART_BORROWED_KEY_GUARD}\n }}\n}}\n",
|
||||
guarded_methods(MULTIPART_KEY_GUARD, 3)
|
||||
);
|
||||
let source = guard_fixture(
|
||||
&[
|
||||
("src/app/multipart_usecase.rs", parent.as_str()),
|
||||
("src/app/multipart_usecase/upload_part.rs", guarded_methods(&broken, 1).as_str()),
|
||||
],
|
||||
"src/app/multipart_usecase.rs",
|
||||
"src/app/multipart_usecase",
|
||||
);
|
||||
|
||||
let message = crate::guard_sources::panic_message(move || assert_multipart_reserved_prefix_guard_calls(&source));
|
||||
assert!(message.contains("reserved-prefix guard calls"), "{broken}: {message}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn object_metadata_key_count_guard_accepts_borrowed_resource_names() {
|
||||
let source = guard_fixture(
|
||||
&[
|
||||
("src/app/mod.rs", guarded_methods(OBJECT_METADATA_OBJECT_GUARD, 2).as_str()),
|
||||
(
|
||||
"src/app/object_meta/retention.rs",
|
||||
guarded_methods(OBJECT_METADATA_BORROWED_KEY_GUARD, 2).as_str(),
|
||||
),
|
||||
],
|
||||
"src/app/mod.rs",
|
||||
"src/app/object_meta",
|
||||
);
|
||||
|
||||
assert_object_metadata_reserved_prefix_guard_calls(&source);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn object_metadata_key_count_guard_rejects_misbound_or_unpropagated_borrowed_guards() {
|
||||
for broken in [
|
||||
OBJECT_METADATA_BORROWED_KEY_GUARD.replace("(bucket,", "(other_bucket,"),
|
||||
OBJECT_METADATA_BORROWED_KEY_GUARD.replace(", key)", ", other_key)"),
|
||||
OBJECT_METADATA_BORROWED_KEY_GUARD.replace(".await?;", ".await;"),
|
||||
] {
|
||||
let parent = format!(
|
||||
"{}{}\n#[cfg(test)]\nmod tests {{\n fn mentions() {{\n {OBJECT_METADATA_BORROWED_KEY_GUARD}\n }}\n}}\n",
|
||||
guarded_methods(OBJECT_METADATA_OBJECT_GUARD, 2),
|
||||
guarded_methods(OBJECT_METADATA_KEY_GUARD, 1)
|
||||
);
|
||||
let source = guard_fixture(
|
||||
&[
|
||||
("src/app/mod.rs", parent.as_str()),
|
||||
("src/app/object_meta/retention.rs", guarded_methods(&broken, 1).as_str()),
|
||||
],
|
||||
"src/app/mod.rs",
|
||||
"src/app/object_meta",
|
||||
);
|
||||
let message = crate::guard_sources::panic_message(move || assert_object_metadata_reserved_prefix_guard_calls(&source));
|
||||
assert!(message.contains("reserved-prefix guard calls"), "{broken}: {message}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn object_metadata_key_count_guard_fails_when_a_moved_call_is_broken() {
|
||||
let moved_and_broken = guarded_methods(MULTIPART_KEY_GUARD, 1).replace("&key)", "key.as_str())");
|
||||
|
||||
@@ -22,8 +22,6 @@ classify_source_layer() {
|
||||
printf 'composition'
|
||||
elif [[ "$file" == rustfs/src/app/* ]]; then
|
||||
printf 'app'
|
||||
elif [[ "$file" == rustfs/src/protocols/client.rs ]] || [[ "$file" == rustfs/src/protocols/client/* ]]; then
|
||||
printf 'interface'
|
||||
elif [[ "$file" == rustfs/src/admin/* ]] || [[ "$file" == rustfs/src/storage/ecfs.rs ]] ||
|
||||
[[ "$file" == rustfs/src/storage/legacy_edge/* ]] || [[ "$file" == rustfs/src/storage/s3_api/* ]] ||
|
||||
[[ "$file" == rustfs/src/storage/s3_compat/* ]]; then
|
||||
@@ -49,12 +47,6 @@ classify_target_layer() {
|
||||
# their exported HTTP contracts belong to the interface boundary.
|
||||
printf 'interface'
|
||||
;;
|
||||
protocols)
|
||||
case "${path#protocols::}" in
|
||||
client | client::* | ProtocolStorageClient | ProtocolStorageClient::*) printf 'interface' ;;
|
||||
*) printf 'infra' ;;
|
||||
esac
|
||||
;;
|
||||
app)
|
||||
printf 'app'
|
||||
;;
|
||||
@@ -155,16 +147,6 @@ run_layer_model_self_tests() {
|
||||
assert_source_layer 'interface' rustfs/src/storage/legacy_edge/tests/object_meta.rs
|
||||
assert_source_layer 'infra' rustfs/src/storage/legacy_edge.rs
|
||||
assert_source_layer 'infra' rustfs/src/storage/legacy_edge_helper.rs
|
||||
assert_source_layer 'interface' rustfs/src/protocols/client.rs
|
||||
assert_source_layer 'interface' rustfs/src/protocols/client/owned.rs
|
||||
assert_source_layer 'infra' rustfs/src/protocols/client_helper.rs
|
||||
assert_target_layer 'interface' protocols::client
|
||||
assert_target_layer 'interface' protocols::client::ProtocolStorageClient
|
||||
assert_target_layer 'interface' protocols::ProtocolStorageClient
|
||||
assert_target_layer 'infra' protocols::client_helper
|
||||
assert_dependency_direction 'allowed' "$(classify_source_layer rustfs/src/protocols/client/owned.rs)" "$app_target"
|
||||
assert_dependency_direction 'reverse' "$app_source" "$(classify_target_layer protocols::client::ProtocolStorageClient)"
|
||||
assert_dependency_direction 'reverse' "$app_source" "$(classify_target_layer protocols::ProtocolStorageClient)"
|
||||
assert_source_layer 'app' rustfs/src/app/bucket_usecase/cors.rs
|
||||
assert_source_layer 'app' rustfs/src/app/multipart_usecase/complete.rs
|
||||
assert_target_layer 'interface' storage::legacy_edge
|
||||
|
||||
@@ -0,0 +1,535 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Own an isolated four-node Docker lab for inline geometry validation."""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import fcntl
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import re
|
||||
import secrets
|
||||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
import urllib.error
|
||||
import urllib.parse
|
||||
|
||||
ROOT = Path(__file__).resolve().parents[1]
|
||||
BASE_COMPOSE = ROOT / ".docker/compose/docker-compose.cluster.local-build.yml"
|
||||
OWNER_LABEL = "rustfs.validation.owner"
|
||||
NODES = tuple(f"node{i}" for i in range(1, 5))
|
||||
|
||||
CLIENT = r'''
|
||||
import boto3, hashlib, json, random, sys
|
||||
from botocore.config import Config
|
||||
cfg = json.load(sys.stdin)
|
||||
client = boto3.client("s3", endpoint_url="http://" + cfg.get("coordinator", "node1") + ":9000", region_name="us-east-1",
|
||||
aws_access_key_id=cfg["access_key"], aws_secret_access_key=cfg["secret_key"],
|
||||
config=Config(signature_version="s3v4", proxies={}, s3={"addressing_style":"path"}))
|
||||
if cfg["action"] == "create":
|
||||
client.create_bucket(Bucket=cfg["bucket"])
|
||||
print("{}")
|
||||
elif cfg["action"] == "probe":
|
||||
records = []
|
||||
for size in (4096, 1048576, 1048577, 1310720, 1572856, 1572857, 1572864):
|
||||
key = "geometry/probe-" + str(size)
|
||||
data = random.Random(size).randbytes(size)
|
||||
client.put_object(Bucket=cfg["bucket"], Key=key, Body=data)
|
||||
head = client.head_object(Bucket=cfg["bucket"], Key=key)
|
||||
assert head["ContentLength"] == size
|
||||
body = client.get_object(Bucket=cfg["bucket"], Key=key)["Body"].read()
|
||||
assert hashlib.sha256(body).digest() == hashlib.sha256(data).digest()
|
||||
for start in (0, 1048570, size - 4096):
|
||||
if start < 0 or start >= size:
|
||||
continue
|
||||
end = min(size - 1, start + 4095)
|
||||
result = client.get_object(Bucket=cfg["bucket"], Key=key, Range=f"bytes={start}-{end}")
|
||||
assert result["Body"].read() == data[start:end + 1]
|
||||
records.append({"key":key, "size":size, "sha256":hashlib.sha256(data).hexdigest()})
|
||||
print(json.dumps(records))
|
||||
elif cfg["action"] in ("compat-seed", "compat-check", "compat-finish-mpu", "compat-delete"):
|
||||
def payload(size, seed):
|
||||
return random.Random(seed).randbytes(size)
|
||||
|
||||
def record(key, size, seed, response):
|
||||
return {"key": key, "size": size, "seed": seed,
|
||||
"version_id": response.get("VersionId", "null"),
|
||||
"sdk_retry_attempts": response.get("ResponseMetadata", {}).get("RetryAttempts", 0),
|
||||
"sha256": hashlib.sha256(payload(size, seed)).hexdigest()}
|
||||
|
||||
manifest = cfg.get("manifest")
|
||||
if cfg["action"] == "compat-seed":
|
||||
from botocore.exceptions import ClientError
|
||||
try:
|
||||
client.head_bucket(Bucket=cfg["bucket"])
|
||||
except ClientError as error:
|
||||
if error.response["ResponseMetadata"]["HTTPStatusCode"] != 404:
|
||||
raise
|
||||
client.create_bucket(Bucket=cfg["bucket"])
|
||||
records = []
|
||||
for size in (0, 4096, 1048577, 1310720, 1572856, 1572857):
|
||||
key = "compat/plain-" + str(size)
|
||||
result = client.put_object(Bucket=cfg["bucket"], Key=key, Body=payload(size, size))
|
||||
records.append(record(key, size, size, result))
|
||||
client.put_bucket_versioning(Bucket=cfg["bucket"], VersioningConfiguration={"Status": "Enabled"})
|
||||
for seed, size in enumerate((0, 4096, 196608, 196609), 100):
|
||||
result = client.put_object(Bucket=cfg["bucket"], Key="compat/versions", Body=payload(size, seed))
|
||||
records.append(record("compat/versions", size, seed, result))
|
||||
key = "compat/resumed-multipart"
|
||||
upload = client.create_multipart_upload(Bucket=cfg["bucket"], Key=key)
|
||||
first = client.upload_part(Bucket=cfg["bucket"], Key=key, UploadId=upload["UploadId"],
|
||||
PartNumber=1, Body=payload(5 * 1024 * 1024, 200))
|
||||
manifest = {"bucket": cfg["bucket"], "records": records,
|
||||
"multipart": {"key": key, "upload_id": upload["UploadId"], "first_etag": first["ETag"]}}
|
||||
# Capture the complete seed inventory, including additional versions
|
||||
# whose contents match a known body oracle.
|
||||
expected = {(item["key"], item["version_id"]) for item in records}
|
||||
for page in client.get_paginator("list_object_versions").paginate(Bucket=cfg["bucket"], Prefix="compat/"):
|
||||
assert not page.get("DeleteMarkers"), "unexpected seed delete marker"
|
||||
for version in page.get("Versions", []):
|
||||
identity = (version["Key"], version["VersionId"])
|
||||
if identity in expected:
|
||||
continue
|
||||
data = client.get_object(Bucket=cfg["bucket"], Key=identity[0], VersionId=identity[1])["Body"].read()
|
||||
digest = hashlib.sha256(data).hexdigest()
|
||||
match = next((item for item in records if item["key"] == identity[0]
|
||||
and item["sha256"] == digest and item["size"] == len(data)), None)
|
||||
assert match is not None, "unexpected seed object or content"
|
||||
records.append(dict(match, version_id=identity[1]))
|
||||
expected.add(identity)
|
||||
else:
|
||||
assert manifest["bucket"] == cfg["bucket"]
|
||||
if cfg["action"] == "compat-finish-mpu" and not manifest["multipart"].get("complete"):
|
||||
upload = manifest["multipart"]
|
||||
second = client.upload_part(Bucket=cfg["bucket"], Key=upload["key"], UploadId=upload["upload_id"],
|
||||
PartNumber=2, Body=payload(1024 * 1024, 201))
|
||||
result = client.complete_multipart_upload(Bucket=cfg["bucket"], Key=upload["key"], UploadId=upload["upload_id"],
|
||||
MultipartUpload={"Parts": [{"PartNumber": 1, "ETag": upload["first_etag"]}, {"PartNumber": 2, "ETag": second["ETag"]}]})
|
||||
data = payload(5 * 1024 * 1024, 200) + payload(1024 * 1024, 201)
|
||||
manifest["records"].append({"key": upload["key"], "size": len(data), "seed": None,
|
||||
"version_id": result["VersionId"], "sha256": hashlib.sha256(data).hexdigest()})
|
||||
manifest["multipart"]["complete"] = True
|
||||
elif cfg["action"] == "compat-delete":
|
||||
selected = [item for item in manifest["records"] if item["key"] == "compat/versions"]
|
||||
if selected:
|
||||
result = client.delete_objects(Bucket=cfg["bucket"], Delete={"Objects": [
|
||||
{"Key": item["key"], "VersionId": item["version_id"]} for item in selected]})
|
||||
assert not result.get("Errors"), result.get("Errors")
|
||||
assert len(result.get("Deleted", [])) == len(selected)
|
||||
manifest["deleted_versions"] = selected
|
||||
manifest["records"] = [item for item in manifest["records"] if item["key"] != "compat/versions"]
|
||||
else:
|
||||
assert manifest.get("deleted_versions"), "manifest has no versions to delete"
|
||||
if cfg["action"] == "compat-check":
|
||||
actual_versions = set()
|
||||
for page in client.get_paginator("list_object_versions").paginate(Bucket=cfg["bucket"], Prefix="compat/"):
|
||||
assert not page.get("DeleteMarkers"), "unexpected delete marker"
|
||||
actual_versions.update((item["Key"], item["VersionId"]) for item in page.get("Versions", []))
|
||||
expected_versions = {(item["key"], item["version_id"]) for item in manifest["records"]}
|
||||
assert actual_versions == expected_versions, {"missing": sorted(expected_versions - actual_versions), "unexpected": sorted(actual_versions - expected_versions)}
|
||||
for item in manifest["records"]:
|
||||
args = {"Bucket": cfg["bucket"], "Key": item["key"], "VersionId": item["version_id"]}
|
||||
assert client.head_object(**args)["ContentLength"] == item["size"]
|
||||
data = client.get_object(**args)["Body"].read()
|
||||
assert len(data) == item["size"] and hashlib.sha256(data).hexdigest() == item["sha256"]
|
||||
if item["size"] > 1048576:
|
||||
result = client.get_object(**args, Range="bytes=1048570-1048582")
|
||||
assert result["Body"].read() == data[1048570:1048583]
|
||||
print(json.dumps(manifest))
|
||||
'''
|
||||
|
||||
|
||||
def write_private(path, value):
|
||||
temporary = path.with_suffix(path.suffix + ".tmp")
|
||||
with temporary.open("w") as output:
|
||||
os.chmod(temporary, 0o600)
|
||||
json.dump(value, output, indent=2)
|
||||
output.write("\n")
|
||||
temporary.replace(path)
|
||||
|
||||
|
||||
def sha256_file(path):
|
||||
digest = hashlib.sha256()
|
||||
with Path(path).open("rb") as source:
|
||||
for chunk in iter(lambda: source.read(1024 * 1024), b""):
|
||||
digest.update(chunk)
|
||||
return digest.hexdigest()
|
||||
|
||||
|
||||
class DockerLab:
|
||||
def __init__(self, state, config):
|
||||
self.state = Path(state)
|
||||
self.config = config
|
||||
|
||||
def docker(self, *args, input_text=None):
|
||||
result = subprocess.run(
|
||||
["docker", "--context", self.config["context"], *args],
|
||||
input=input_text, text=True, capture_output=True,
|
||||
)
|
||||
if result.returncode:
|
||||
detail = result.stderr.strip()[-4000:]
|
||||
for field in ("access_key", "secret_key"):
|
||||
if self.config.get(field):
|
||||
detail = detail.replace(self.config[field], "<redacted>")
|
||||
raise RuntimeError(f"Docker {args[0]} failed ({result.returncode}): {detail}")
|
||||
return result.stdout
|
||||
|
||||
def docker_json(self, *args):
|
||||
return json.loads(self.docker(*args))
|
||||
|
||||
def resource_ids(self, kind):
|
||||
listing = {"container": ("ps", "-aq"), "volume": ("volume", "ls", "-q"),
|
||||
"network": ("network", "ls", "-q")}[kind]
|
||||
return self.docker(*listing, "--filter", "label=com.docker.compose.project=" + self.config["project"]).split()
|
||||
|
||||
def assert_owned(self):
|
||||
for kind in ("container", "volume", "network"):
|
||||
for identifier in self.resource_ids(kind):
|
||||
command = ("inspect", identifier) if kind == "container" else (kind, "inspect", identifier)
|
||||
item = self.docker_json(*command)[0]
|
||||
labels = item["Config"].get("Labels", {}) if kind == "container" else item.get("Labels", {})
|
||||
if (labels or {}).get(OWNER_LABEL) != self.config["owner"]:
|
||||
raise ValueError(f"refusing to alter unowned {kind} {identifier}")
|
||||
|
||||
def assert_spec_owned(self, spec):
|
||||
for kind, group in (("volume", "volumes"), ("network", "networks")):
|
||||
existing = set(self.docker(kind, "ls", "--format", "{{.Name}}").splitlines())
|
||||
for resource in spec.get(group, {}).values():
|
||||
name = resource["name"]
|
||||
if name in existing:
|
||||
labels = self.docker_json(kind, "inspect", name)[0].get("Labels", {}) or {}
|
||||
if labels.get(OWNER_LABEL) != self.config["owner"]:
|
||||
raise ValueError(f"refusing to use unowned {kind} {name}")
|
||||
|
||||
def compose(self, *args):
|
||||
return self.docker("compose", "--project-name", self.config["project"],
|
||||
"--file", str(self.state / "compose.json"), *args)
|
||||
|
||||
def make_spec(self, shard_bytes, rpc_mode="json-compat"):
|
||||
environment = {key: value for key, value in os.environ.items()
|
||||
if not key.startswith(("RUSTFS_", "OTEL_"))}
|
||||
environment["RUSTFS_IMAGE"] = self.config["image_id"]
|
||||
raw = subprocess.run(
|
||||
["docker", "--context", self.config["context"], "compose", "--env-file", "/dev/null",
|
||||
"--project-name", self.config["project"], "--file", str(BASE_COMPOSE), "config", "--format", "json"],
|
||||
env=environment, check=True, capture_output=True, text=True,
|
||||
)
|
||||
return self.customize_spec(json.loads(raw.stdout), shard_bytes, rpc_mode)
|
||||
|
||||
def customize_spec(self, spec, shard_bytes, rpc_mode="json-compat"):
|
||||
if rpc_mode not in ("json-compat", "msgpack-only"):
|
||||
raise ValueError("unsupported inline lab RPC mode")
|
||||
msgpack_only = str(rpc_mode == "msgpack-only").lower()
|
||||
if set(spec["services"]) != set(NODES):
|
||||
raise ValueError("inline lab requires the repository's four-node compose topology")
|
||||
if any(item.get("external") for group in ("volumes", "networks") for item in spec.get(group, {}).values()):
|
||||
raise ValueError("inline lab requires owned volumes and networks")
|
||||
labels = {OWNER_LABEL: self.config["owner"]}
|
||||
for index, name in enumerate(NODES):
|
||||
service = spec["services"][name]
|
||||
service.pop("build", None)
|
||||
service.pop("container_name", None)
|
||||
service.pop("ports", None)
|
||||
service["image"] = self.config["image_id"]
|
||||
service["command"] = ["server", "http://node{1...4}:9000/data/rustfs{0...3}"]
|
||||
service["labels"] = dict(service.get("labels", {}), **labels)
|
||||
service["mem_limit"] = self.config["memory"]
|
||||
service["cpus"] = 1
|
||||
if self.config["cpu_sets"]:
|
||||
service["cpuset"] = self.config["cpu_sets"][index]
|
||||
service["environment"].update({
|
||||
"RUSTFS_ADDRESS": ":9000",
|
||||
"RUSTFS_ACCESS_KEY": self.config["access_key"],
|
||||
"RUSTFS_SECRET_KEY": self.config["secret_key"],
|
||||
"RUSTFS_CONSOLE_ENABLE": "false",
|
||||
"RUSTFS_OBS_ENDPOINT": "",
|
||||
"NO_PROXY": "*",
|
||||
"no_proxy": "*",
|
||||
"RUSTFS_COMPRESSION_ENABLED": "false",
|
||||
"RUSTFS_UNSAFE_BYPASS_DISK_CHECK": "true",
|
||||
"RUSTFS_STORAGE_CLASS_STANDARD": "EC:4",
|
||||
"RUSTFS_ERASURE_SET_DRIVE_COUNT": "16",
|
||||
"RUSTFS_STORAGE_CLASS_INLINE_BLOCK": "128KiB",
|
||||
"RUSTFS_ERASURE_SHARD_BYTES": str(shard_bytes),
|
||||
"RUSTFS_DURABILITY_MODE": "strict",
|
||||
"RUSTFS_INTERNODE_RPC_MSGPACK_ONLY": msgpack_only,
|
||||
"RUSTFS_INTERNODE_RPC_MSGPACK_ONLY_FLEET_CONFIRMED": msgpack_only,
|
||||
})
|
||||
spec["services"]["node1"]["ports"] = [{"target": 9000, "published": str(self.config["port"]),
|
||||
"host_ip": "127.0.0.1", "protocol": "tcp"}]
|
||||
for group in ("volumes", "networks"):
|
||||
for item in spec.get(group, {}).values():
|
||||
item["labels"] = dict(item.get("labels", {}), **labels)
|
||||
return spec
|
||||
|
||||
def container(self, node):
|
||||
result = self.compose("ps", "--quiet", node).strip()
|
||||
if not result or "\n" in result:
|
||||
raise ValueError(f"expected one running {node} container")
|
||||
return result
|
||||
|
||||
def client(self, bucket, action, manifest=None, coordinator="node1"):
|
||||
if coordinator not in NODES:
|
||||
raise ValueError("compatibility coordinator must be an owned lab node")
|
||||
spec = json.loads((self.state / "compose.json").read_text())
|
||||
network_key = next(iter(spec["services"]["node1"]["networks"]))
|
||||
network = spec["networks"][network_key]["name"]
|
||||
payload = {key: self.config[key] for key in ("access_key", "secret_key")}
|
||||
payload.update(bucket=bucket, action=action, manifest=manifest, coordinator=coordinator)
|
||||
result = self.docker("run", "--rm", "--pull", "never", "--label", OWNER_LABEL + "=" + self.config["owner"],
|
||||
"--network", network, "--entrypoint", "python3", "-i", self.config["client_image_id"],
|
||||
"-c", CLIENT, input_text=json.dumps(payload))
|
||||
return json.loads(result)
|
||||
|
||||
def mc_proxy(self, image, arguments):
|
||||
arguments = list(arguments)
|
||||
if arguments[:1] == ["--"]:
|
||||
arguments.pop(0)
|
||||
if arguments[:2] == ["alias", "set"]:
|
||||
if len(arguments) < 6:
|
||||
raise ValueError("mc alias set needs the lab endpoint and credentials")
|
||||
endpoint = urllib.parse.urlsplit(arguments[3])
|
||||
if endpoint.scheme != "http" or endpoint.hostname not in ("127.0.0.1", "localhost") or endpoint.port != self.config["port"]:
|
||||
raise ValueError("mc proxy alias must target this lab's loopback endpoint")
|
||||
arguments[3] = "http://node1:9000"
|
||||
spec = json.loads((self.state / "compose.json").read_text())
|
||||
network_key = next(iter(spec["services"]["node1"]["networks"]))
|
||||
network = spec["networks"][network_key]["name"]
|
||||
config_dir = Path(os.environ.get("MC_CONFIG_DIR", str(self.state / "mc-config"))).resolve()
|
||||
config_dir.mkdir(parents=True, exist_ok=True, mode=0o700)
|
||||
image_id = self.docker_json("image", "inspect", image)[0]["Id"]
|
||||
command = ["docker", "--context", self.config["context"], "run", "--rm", "--pull", "never",
|
||||
"--label", OWNER_LABEL + "=" + self.config["owner"], "--network", network,
|
||||
"--mount", f"type=bind,src={config_dir},dst=/mc-config", "--env", "MC_CONFIG_DIR=/mc-config",
|
||||
"--env", "NO_PROXY=*", image_id, *arguments]
|
||||
result = subprocess.run(command)
|
||||
if result.returncode:
|
||||
raise RuntimeError(f"Linux mc probe exited with code {result.returncode}")
|
||||
|
||||
def wait_ready(self):
|
||||
deadline = time.monotonic() + 240
|
||||
pending = list(NODES)
|
||||
while time.monotonic() < deadline:
|
||||
pending = []
|
||||
for node in NODES:
|
||||
try:
|
||||
status = self.docker("exec", self.container(node), "curl", "--silent", "--show-error",
|
||||
"--connect-timeout", "2", "--max-time", "3", "--output", "/dev/null",
|
||||
"--write-out", "%{http_code}", "http://127.0.0.1:9000/health/ready").strip()
|
||||
if status != "200":
|
||||
pending.append(node)
|
||||
except RuntimeError:
|
||||
pending.append(node)
|
||||
if not pending:
|
||||
return
|
||||
time.sleep(1)
|
||||
raise TimeoutError("inline Docker nodes did not become ready: " + ", ".join(pending))
|
||||
|
||||
def archive_compat_manifests(self):
|
||||
manifests = sorted(self.state.glob("compat-*.json"))
|
||||
if not manifests:
|
||||
return
|
||||
history = self.state / "compat-history" / secrets.token_hex(8)
|
||||
history.mkdir(parents=True, mode=0o700)
|
||||
for manifest in manifests:
|
||||
manifest.rename(history / manifest.name)
|
||||
|
||||
def deploy(self, bucket, keep_data, shard_bytes, rpc_mode="json-compat"):
|
||||
validate_shard_bytes(shard_bytes)
|
||||
if not re.fullmatch(r"[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]", bucket):
|
||||
raise ValueError("a valid isolated S3 bucket is required")
|
||||
if os.environ.get("HOTPATH_ABBA_DRIVE_SYNC", "true") != "true":
|
||||
raise ValueError("this lab validates strict durability cells")
|
||||
if sha256_file(self.config["binary"]) != self.config["binary_sha256"]:
|
||||
raise ValueError("benchmark binary changed after configuration")
|
||||
self.assert_owned()
|
||||
spec = self.make_spec(shard_bytes, rpc_mode)
|
||||
self.assert_spec_owned(spec)
|
||||
candidate = self.state / "compose.next.json"
|
||||
write_private(candidate, spec)
|
||||
self.docker("compose", "--project-name", self.config["project"], "--file", str(candidate), "config", "--quiet")
|
||||
if (self.state / "compose.json").exists():
|
||||
self.compose("down", *([] if keep_data else ["--volumes"]))
|
||||
if not keep_data:
|
||||
self.archive_compat_manifests()
|
||||
candidate.replace(self.state / "compose.json")
|
||||
self.compose("up", "--detach", "--no-build", "--pull", "never")
|
||||
self.wait_ready()
|
||||
actual_hashes = []
|
||||
for node in NODES:
|
||||
identifier = self.container(node)
|
||||
info = self.docker_json("inspect", identifier)[0]
|
||||
if info["Image"] != self.config["image_id"]:
|
||||
raise ValueError(f"unexpected running image for {node}")
|
||||
actual_env = dict(item.split("=", 1) for item in info["Config"]["Env"])
|
||||
for key in ("RUSTFS_ERASURE_SHARD_BYTES", "RUSTFS_STORAGE_CLASS_INLINE_BLOCK", "RUSTFS_DURABILITY_MODE",
|
||||
"RUSTFS_INTERNODE_RPC_MSGPACK_ONLY", "RUSTFS_INTERNODE_RPC_MSGPACK_ONLY_FLEET_CONFIRMED"):
|
||||
if actual_env.get(key) != spec["services"][node]["environment"][key]:
|
||||
raise ValueError(f"unexpected running {key} for {node}")
|
||||
actual_hashes.append(self.docker("exec", identifier, "sha256sum", "/usr/local/bin/rustfs").split()[0])
|
||||
expected = self.config["binary_sha256"]
|
||||
if any(value != expected for value in actual_hashes):
|
||||
raise ValueError("running server binary differs from the benchmark artifact")
|
||||
if not keep_data:
|
||||
self.client(bucket, "create")
|
||||
evidence = Path(os.environ.get("HOTPATH_ABBA_DEPLOY_EVIDENCE_FILE", str(self.state / "deploy.env")))
|
||||
values = {
|
||||
"leg": os.environ.get("HOTPATH_ABBA_LEG", "manual"),
|
||||
"phase": os.environ.get("HOTPATH_ABBA_PHASE", "manual"),
|
||||
"bucket": bucket, "binary_sha256": expected,
|
||||
"dataset_reset": str(not keep_data).lower(), "shard_bytes": shard_bytes,
|
||||
"inline_block": 131072, "rpc_mode": rpc_mode, "durability": "strict", "topology": "4x4-EC12+4",
|
||||
"image_id": self.config["image_id"], "source_revision": self.config["revision"],
|
||||
}
|
||||
evidence.parent.mkdir(parents=True, exist_ok=True)
|
||||
evidence.write_text("".join(f"{key}={value}\n" for key, value in values.items()))
|
||||
print(f"ready project={self.config['project']} shard_bytes={shard_bytes}")
|
||||
|
||||
def probe(self, bucket):
|
||||
records = self.client(bucket, "probe")
|
||||
node = self.container("node1")
|
||||
spec = json.loads((self.state / "compose.json").read_text())
|
||||
shard_bytes = int(spec["services"]["node1"]["environment"]["RUSTFS_ERASURE_SHARD_BYTES"])
|
||||
expected_block = shard_bytes * 12 if shard_bytes else 1024 * 1024
|
||||
for record in records:
|
||||
path = f"/data/rustfs0/{bucket}/{record['key']}/xl.meta"
|
||||
geometry = self.docker_json("exec", node, "/usr/local/bin/inline_lab_inspect", path)
|
||||
if (geometry["data_blocks"], geometry["parity_blocks"], geometry["block_size"]) != (12, 4, expected_block):
|
||||
raise ValueError("unexpected persisted EC layout or block size")
|
||||
record["geometry"] = geometry
|
||||
write_private(self.state / "probe.json", records)
|
||||
print(json.dumps(records, indent=2))
|
||||
|
||||
|
||||
def validate_shard_bytes(value):
|
||||
if value < 0 or value > 64 * 1024 * 1024 or (value and value % 4096):
|
||||
raise ValueError("shard bytes must be zero or a 4 KiB multiple up to 64 MiB")
|
||||
|
||||
|
||||
def configure(args):
|
||||
state = Path(args.state_dir).resolve()
|
||||
state.mkdir(parents=True, exist_ok=True)
|
||||
os.chmod(state, 0o700)
|
||||
previous = json.loads((state / "config.json").read_text()) if (state / "config.json").exists() else None
|
||||
if previous and (previous["context"], previous["project"]) != (args.context, args.project):
|
||||
raise ValueError("state belongs to a different Docker context or project")
|
||||
config = previous or {"owner": secrets.token_hex(16), "access_key": "inline-lab-access", "secret_key": secrets.token_hex(24)}
|
||||
config.update(context=args.context, project=args.project, port=args.port, binary=str(Path(args.binary).resolve()),
|
||||
memory=args.memory, cpu_sets=args.cpu_sets.split(";") if args.cpu_sets else [])
|
||||
if not re.fullmatch(r"[a-z0-9][a-z0-9_-]{0,50}", args.project):
|
||||
raise ValueError("invalid Docker compose project")
|
||||
if not 1 <= args.port <= 65535 or (config["cpu_sets"] and (len(config["cpu_sets"]) != 4 or any(not re.fullmatch(r"[0-9,-]+", value) for value in config["cpu_sets"]))):
|
||||
raise ValueError("invalid port or four-node CPU set list")
|
||||
if not re.fullmatch(r"[0-9a-f]{40}", args.revision):
|
||||
raise ValueError("source revision must be a complete Git commit")
|
||||
config["binary_sha256"] = sha256_file(config["binary"])
|
||||
lab = DockerLab(state, config)
|
||||
lab.assert_owned()
|
||||
image = lab.docker_json("image", "inspect", args.image)[0]
|
||||
if image["Config"].get("Labels", {}).get("org.opencontainers.image.revision") != args.revision:
|
||||
raise ValueError("image revision does not match the selected source")
|
||||
config.update(image_id=image["Id"], image_ref=args.image, revision=args.revision,
|
||||
client_image_id=lab.docker_json("image", "inspect", args.client_image)[0]["Id"])
|
||||
write_private(state / "config.json", config)
|
||||
print(f"configured project={args.project} endpoint=127.0.0.1:{args.port}")
|
||||
|
||||
|
||||
def execute(args):
|
||||
if args.command == "configure":
|
||||
configure(args)
|
||||
return
|
||||
state = Path(args.state_dir).resolve()
|
||||
config = json.loads((state / "config.json").read_text())
|
||||
lab = DockerLab(state, config)
|
||||
lab.assert_owned()
|
||||
if args.command == "deploy":
|
||||
lab.deploy(args.bucket, args.keep_data, args.shard_bytes, args.rpc_mode)
|
||||
elif args.command == "probe":
|
||||
lab.probe(args.bucket)
|
||||
elif args.command.startswith("compat-"):
|
||||
if not re.fullmatch(r"[a-z0-9][a-z0-9.-]{1,61}[a-z0-9]", args.bucket):
|
||||
raise ValueError("a valid isolated compatibility bucket is required")
|
||||
manifest_path = state / f"compat-{args.bucket}.json"
|
||||
if args.command == "compat-seed":
|
||||
if manifest_path.exists():
|
||||
raise ValueError("compatibility manifest already exists")
|
||||
manifest = None
|
||||
else:
|
||||
manifest = json.loads(manifest_path.read_text())
|
||||
result = lab.client(args.bucket, args.command, manifest, args.coordinator)
|
||||
if args.command == "compat-seed":
|
||||
coordinator = lab.docker_json("inspect", lab.container(args.coordinator))[0]
|
||||
result["writer_revision"] = coordinator["Config"]["Labels"]["org.opencontainers.image.revision"]
|
||||
result["writer_coordinator"] = args.coordinator
|
||||
if args.command != "compat-check":
|
||||
# Retain the successful mutation before fallible read/geometry checks
|
||||
# so a retry can use the returned version IDs and completed MPU state.
|
||||
write_private(manifest_path, result)
|
||||
result = lab.client(args.bucket, "compat-check", result, args.coordinator)
|
||||
node = lab.container("node1")
|
||||
for record in result["records"]:
|
||||
path = f"/data/rustfs0/{args.bucket}/{record['key']}/xl.meta"
|
||||
version = "00000000-0000-0000-0000-000000000000" if record["version_id"] == "null" else record["version_id"]
|
||||
geometry = lab.docker_json("exec", node, "/usr/local/bin/inline_lab_inspect", path, version)
|
||||
if "geometry" in record and geometry != record["geometry"]:
|
||||
raise ValueError(f"persisted geometry changed for {record['key']} version {record['version_id']}")
|
||||
record["geometry"] = geometry
|
||||
write_private(manifest_path, result)
|
||||
print(f"{args.command} verified {len(result['records'])} objects/versions")
|
||||
elif args.command == "mc":
|
||||
lab.mc_proxy(args.image, args.arguments)
|
||||
elif (state / "compose.json").exists():
|
||||
lab.compose("down", *(["--volumes"] if args.purge else []))
|
||||
if args.purge:
|
||||
lab.archive_compat_manifests()
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--state-dir", required=True)
|
||||
commands = parser.add_subparsers(dest="command", required=True)
|
||||
setup = commands.add_parser("configure")
|
||||
setup.add_argument("--context", required=True)
|
||||
setup.add_argument("--project", required=True)
|
||||
setup.add_argument("--image", required=True)
|
||||
setup.add_argument("--client-image", default="rustfs-inline-build-tools:1.100")
|
||||
setup.add_argument("--revision", required=True)
|
||||
setup.add_argument("--binary", required=True)
|
||||
setup.add_argument("--port", type=int, default=19080)
|
||||
setup.add_argument("--memory", default="4g")
|
||||
setup.add_argument("--cpu-sets", default="")
|
||||
deploy = commands.add_parser("deploy")
|
||||
deploy.add_argument("--bucket", default=os.environ.get("HOTPATH_ABBA_BUCKET", ""))
|
||||
deploy.add_argument("--shard-bytes", type=int, default=int(os.environ.get("RUSTFS_ERASURE_SHARD_BYTES", "0")))
|
||||
deploy.add_argument("--keep-data", action="store_true")
|
||||
deploy.add_argument("--rpc-mode", choices=("json-compat", "msgpack-only"),
|
||||
default=os.environ.get("RUSTFS_INLINE_LAB_RPC_MODE", "json-compat"))
|
||||
probe = commands.add_parser("probe")
|
||||
probe.add_argument("--bucket", required=True)
|
||||
for action in ("compat-seed", "compat-check", "compat-finish-mpu", "compat-delete"):
|
||||
command = commands.add_parser(action)
|
||||
command.add_argument("--bucket", required=True)
|
||||
command.add_argument("--coordinator", choices=NODES, default="node1")
|
||||
mc = commands.add_parser("mc")
|
||||
mc.add_argument("--image", required=True)
|
||||
mc.add_argument("arguments", nargs=argparse.REMAINDER)
|
||||
stop = commands.add_parser("down")
|
||||
stop.add_argument("--purge", action="store_true")
|
||||
args = parser.parse_args()
|
||||
state = Path(args.state_dir).resolve()
|
||||
state.mkdir(parents=True, exist_ok=True, mode=0o700)
|
||||
with (state / ".lock").open("a") as lock:
|
||||
try:
|
||||
fcntl.flock(lock, fcntl.LOCK_EX | fcntl.LOCK_NB)
|
||||
except BlockingIOError as error:
|
||||
raise ValueError("inline Docker lab is already in use") from error
|
||||
execute(args)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
try:
|
||||
main()
|
||||
except (ValueError, OSError, RuntimeError, subprocess.CalledProcessError) as error:
|
||||
print(f"inline Docker lab failed: {error}", file=sys.stderr)
|
||||
sys.exit(1)
|
||||
Executable
+6
@@ -0,0 +1,6 @@
|
||||
#!/usr/bin/env bash
|
||||
set -euo pipefail
|
||||
SCRIPT_DIR="$(python3 -c 'import os,sys; print(os.path.dirname(os.path.realpath(sys.argv[1])))' "${BASH_SOURCE[0]}")"
|
||||
exec "$SCRIPT_DIR/python_bin.sh" "$SCRIPT_DIR/inline_docker_lab.py" \
|
||||
--state-dir "${RUSTFS_INLINE_LAB_STATE:?set the owned inline lab state directory}" \
|
||||
mc --image "${RUSTFS_INLINE_MC_IMAGE:?set the pinned Linux mc image}" -- "$@"
|
||||
@@ -0,0 +1,356 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Regression checks for ownership and geometry lab configuration."""
|
||||
|
||||
import argparse
|
||||
import contextlib
|
||||
import hashlib
|
||||
import io
|
||||
import importlib.util
|
||||
import json
|
||||
from pathlib import Path
|
||||
import tempfile
|
||||
import sys
|
||||
import types
|
||||
import unittest
|
||||
from unittest import mock
|
||||
|
||||
SPEC = importlib.util.spec_from_file_location("inline_docker_lab", Path(__file__).with_name("inline_docker_lab.py"))
|
||||
LAB = importlib.util.module_from_spec(SPEC)
|
||||
SPEC.loader.exec_module(LAB)
|
||||
|
||||
|
||||
def configuration():
|
||||
return {
|
||||
"context": "test", "project": "inline-test", "owner": "test-owner",
|
||||
"image_id": "sha256:test-image", "port": 19080, "memory": "4g",
|
||||
"cpu_sets": ["0", "1", "2", "3"], "access_key": "test-access",
|
||||
"secret_key": "test-secret",
|
||||
}
|
||||
|
||||
|
||||
def compose_fixture():
|
||||
return {
|
||||
"services": {node: {"environment": {}, "ports": ["9000:9000"],
|
||||
"build": {"context": "."}, "networks": {"lab": None}}
|
||||
for node in LAB.NODES},
|
||||
"networks": {"lab": {"name": "inline-test_lab"}},
|
||||
"volumes": {"disk": {"name": "inline-test_disk"}},
|
||||
}
|
||||
|
||||
|
||||
class InlineDockerLabTests(unittest.TestCase):
|
||||
def test_compose_pins_image_and_publishes_only_loopback(self):
|
||||
lab = LAB.DockerLab("/unused", configuration())
|
||||
result = lab.customize_spec(compose_fixture(), 131072)
|
||||
for index, node in enumerate(LAB.NODES):
|
||||
service = result["services"][node]
|
||||
self.assertEqual(service["image"], "sha256:test-image")
|
||||
self.assertNotIn("build", service)
|
||||
self.assertEqual(service["cpuset"], str(index))
|
||||
self.assertEqual(service["environment"]["RUSTFS_ERASURE_SHARD_BYTES"], "131072")
|
||||
self.assertEqual(service["environment"]["RUSTFS_DURABILITY_MODE"], "strict")
|
||||
self.assertEqual(service["environment"]["RUSTFS_STORAGE_CLASS_INLINE_BLOCK"], "128KiB")
|
||||
self.assertEqual(service["labels"][LAB.OWNER_LABEL], "test-owner")
|
||||
self.assertEqual(result["services"]["node1"]["ports"][0]["host_ip"], "127.0.0.1")
|
||||
for node in LAB.NODES[1:]:
|
||||
self.assertNotIn("ports", result["services"][node])
|
||||
for kind in ("volumes", "networks"):
|
||||
self.assertEqual(next(iter(result[kind].values()))["labels"][LAB.OWNER_LABEL], "test-owner")
|
||||
|
||||
def test_rpc_modes_override_inherited_flags_on_every_node(self):
|
||||
lab = LAB.DockerLab("/unused", configuration())
|
||||
for mode, enabled in (("json-compat", "false"), ("msgpack-only", "true")):
|
||||
spec = compose_fixture()
|
||||
for service in spec["services"].values():
|
||||
service["environment"]["RUSTFS_INTERNODE_RPC_MSGPACK_ONLY"] = "true"
|
||||
service["environment"]["RUSTFS_INTERNODE_RPC_MSGPACK_ONLY_FLEET_CONFIRMED"] = "true"
|
||||
result = lab.customize_spec(spec, 0, mode)
|
||||
for node in LAB.NODES:
|
||||
environment = result["services"][node]["environment"]
|
||||
self.assertEqual(environment["RUSTFS_INTERNODE_RPC_MSGPACK_ONLY"], enabled)
|
||||
self.assertEqual(environment["RUSTFS_INTERNODE_RPC_MSGPACK_ONLY_FLEET_CONFIRMED"], enabled)
|
||||
self.assertEqual(environment["RUSTFS_ERASURE_SHARD_BYTES"], "0")
|
||||
with self.assertRaisesRegex(ValueError, "RPC mode"):
|
||||
lab.customize_spec(compose_fixture(), 0, "unknown")
|
||||
|
||||
def test_external_resources_and_changed_topology_fail(self):
|
||||
lab = LAB.DockerLab("/unused", configuration())
|
||||
for kind in ("networks", "volumes"):
|
||||
spec = compose_fixture()
|
||||
next(iter(spec[kind].values()))["external"] = True
|
||||
with self.subTest(kind=kind), self.assertRaises(ValueError):
|
||||
lab.customize_spec(spec, 0)
|
||||
spec = compose_fixture()
|
||||
spec["services"].pop("node4")
|
||||
with self.assertRaises(ValueError):
|
||||
lab.customize_spec(spec, 0)
|
||||
|
||||
def test_ownership_guard_accepts_owned_and_rejects_foreign_resources(self):
|
||||
lab = LAB.DockerLab("/unused", configuration())
|
||||
for kind in ("container", "volume", "network"):
|
||||
lab.resource_ids = lambda current, target=kind: ["resource"] if current == target else []
|
||||
for owner in ("test-owner", "foreign-owner", None):
|
||||
labels = {LAB.OWNER_LABEL: owner} if owner else {}
|
||||
item = {"Config": {"Labels": labels}, "Labels": labels}
|
||||
lab.docker_json = mock.Mock(return_value=[item])
|
||||
with self.subTest(kind=kind, owner=owner):
|
||||
if owner == "test-owner":
|
||||
lab.assert_owned()
|
||||
else:
|
||||
with self.assertRaisesRegex(ValueError, "unowned"):
|
||||
lab.assert_owned()
|
||||
|
||||
def test_selected_resources_without_project_labels_are_protected(self):
|
||||
lab = LAB.DockerLab("/unused", configuration())
|
||||
lab.docker = mock.Mock(return_value="inline-test_disk\ninline-test_lab\n")
|
||||
lab.docker_json = mock.Mock(return_value=[{"Labels": {}}])
|
||||
with self.assertRaisesRegex(ValueError, "unowned"):
|
||||
lab.assert_spec_owned(compose_fixture())
|
||||
lab.docker_json = mock.Mock(return_value=[{"Labels": {LAB.OWNER_LABEL: "test-owner"}}])
|
||||
lab.assert_spec_owned(compose_fixture())
|
||||
|
||||
def test_invalid_shard_geometry_fails(self):
|
||||
for value in (0, 4096, 131072, 64 * 1024 * 1024):
|
||||
LAB.validate_shard_bytes(value)
|
||||
for value in (-1, 1, 131073, 64 * 1024 * 1024 + 4096):
|
||||
with self.subTest(value=value), self.assertRaises(ValueError):
|
||||
LAB.validate_shard_bytes(value)
|
||||
|
||||
def test_configuration_checks_source_and_writes_private_state(self):
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
state = Path(temporary)
|
||||
binary = state / "binary"
|
||||
binary.write_bytes(b"test-binary")
|
||||
args = argparse.Namespace(state_dir=temporary, context="test", project="inline-test", port=19080,
|
||||
binary=str(binary), memory="4g", cpu_sets="", revision="a" * 40,
|
||||
image="image", client_image="client")
|
||||
image = {"Id": "sha256:server", "Config": {"Labels": {"org.opencontainers.image.revision": "b" * 40}}}
|
||||
with mock.patch.object(LAB.DockerLab, "assert_owned"), mock.patch.object(LAB.DockerLab, "docker_json", return_value=[image]):
|
||||
with self.assertRaisesRegex(ValueError, "revision"):
|
||||
LAB.configure(args)
|
||||
self.assertFalse((state / "config.json").exists())
|
||||
image["Config"]["Labels"]["org.opencontainers.image.revision"] = "a" * 40
|
||||
with mock.patch.object(LAB.DockerLab, "assert_owned"), mock.patch.object(LAB.DockerLab, "docker_json", return_value=[image]):
|
||||
LAB.configure(args)
|
||||
saved = json.loads((state / "config.json").read_text())
|
||||
self.assertEqual(saved["binary_sha256"], LAB.sha256_file(binary))
|
||||
self.assertEqual((state / "config.json").stat().st_mode & 0o777, 0o600)
|
||||
|
||||
def test_changed_binary_stops_before_container_mutation(self):
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
binary = Path(temporary) / "binary"
|
||||
binary.write_bytes(b"current")
|
||||
config = configuration() | {"binary": str(binary), "binary_sha256": "stale"}
|
||||
lab = LAB.DockerLab(temporary, config)
|
||||
lab.compose = mock.Mock()
|
||||
lab.assert_owned = mock.Mock()
|
||||
with self.assertRaisesRegex(ValueError, "binary changed"):
|
||||
lab.deploy("inline-test-bucket", False, 0)
|
||||
lab.compose.assert_not_called()
|
||||
lab.assert_owned.assert_not_called()
|
||||
|
||||
def test_docker_errors_redact_test_credentials(self):
|
||||
lab = LAB.DockerLab("/unused", configuration())
|
||||
response = mock.Mock(returncode=1, stderr="test-access test-secret", stdout="")
|
||||
with mock.patch.object(LAB.subprocess, "run", return_value=response):
|
||||
with self.assertRaises(RuntimeError) as caught:
|
||||
lab.docker("inspect", "missing")
|
||||
self.assertNotIn("test-access", str(caught.exception))
|
||||
self.assertNotIn("test-secret", str(caught.exception))
|
||||
self.assertIn("<redacted>", str(caught.exception))
|
||||
|
||||
def test_state_lock_blocks_concurrent_mutation(self):
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
lock_path = Path(temporary) / ".lock"
|
||||
with lock_path.open("a") as held:
|
||||
LAB.fcntl.flock(held, LAB.fcntl.LOCK_EX | LAB.fcntl.LOCK_NB)
|
||||
with mock.patch.object(LAB.sys, "argv", ["lab", "--state-dir", temporary, "down"]), \
|
||||
mock.patch.object(LAB, "execute") as execute:
|
||||
with self.assertRaisesRegex(ValueError, "already in use"):
|
||||
LAB.main()
|
||||
execute.assert_not_called()
|
||||
|
||||
def test_linux_mc_proxy_keeps_raw_stdout_and_uses_private_alias(self):
|
||||
with tempfile.TemporaryDirectory() as temporary:
|
||||
state = Path(temporary)
|
||||
(state / "compose.json").write_text(json.dumps(compose_fixture()))
|
||||
lab = LAB.DockerLab(state, configuration())
|
||||
lab.docker_json = mock.Mock(return_value=[{"Id": "sha256:client"}])
|
||||
with mock.patch.dict(LAB.os.environ, {"MC_CONFIG_DIR": str(state / "probe-config")}), \
|
||||
mock.patch.object(LAB.subprocess, "run", return_value=mock.Mock(returncode=0)) as run:
|
||||
lab.mc_proxy("client", ["--", "alias", "set", "probe", "http://127.0.0.1:19080", "test-access", "test-secret"])
|
||||
command = run.call_args.args[0]
|
||||
self.assertIn("http://node1:9000", command)
|
||||
self.assertIn("sha256:client", command)
|
||||
self.assertEqual(run.call_args.kwargs, {})
|
||||
for endpoint in ("https://other.example:9000", "https://127.0.0.1:19080"):
|
||||
with self.subTest(endpoint=endpoint), self.assertRaisesRegex(ValueError, "loopback"):
|
||||
lab.mc_proxy("client", ["alias", "set", "probe", endpoint, "test-access", "test-secret"])
|
||||
|
||||
def test_readiness_checks_every_node_dependency_endpoint(self):
|
||||
lab = LAB.DockerLab("/unused", configuration())
|
||||
lab.container = mock.Mock(side_effect=lambda node: node)
|
||||
lab.docker = mock.Mock(return_value="200")
|
||||
with mock.patch.object(LAB.time, "monotonic", side_effect=[0, 0]):
|
||||
lab.wait_ready()
|
||||
self.assertEqual(lab.docker.call_count, 4)
|
||||
self.assertEqual([call.args[1] for call in lab.docker.call_args_list], list(LAB.NODES))
|
||||
self.assertTrue(all(call.args[-1].endswith("/health/ready") for call in lab.docker.call_args_list))
|
||||
|
||||
def test_readiness_rejects_a_live_cluster_with_one_unready_node(self):
|
||||
lab = LAB.DockerLab("/unused", configuration())
|
||||
lab.container = mock.Mock(side_effect=lambda node: node)
|
||||
lab.docker = mock.Mock(side_effect=lambda *args: "503" if args[1] == "node4" else "200")
|
||||
with mock.patch.object(LAB.time, "monotonic", side_effect=[0, 0, 241]), mock.patch.object(LAB.time, "sleep"):
|
||||
with self.assertRaisesRegex(TimeoutError, "node4"):
|
||||
lab.wait_ready()
|
||||
self.assertEqual(lab.docker.call_count, 4)
|
||||
|
||||
def test_readiness_waits_for_transient_dependency_recovery(self):
|
||||
lab = LAB.DockerLab("/unused", configuration())
|
||||
lab.container = mock.Mock(side_effect=lambda node: node)
|
||||
lab.docker = mock.Mock(side_effect=["200", "200", "200", "503", "200", "200", "200", "200"])
|
||||
with mock.patch.object(LAB.time, "monotonic", side_effect=[0, 0, 1, 241]), mock.patch.object(LAB.time, "sleep") as sleep:
|
||||
lab.wait_ready()
|
||||
self.assertEqual(lab.docker.call_count, 8)
|
||||
sleep.assert_called_once_with(1)
|
||||
|
||||
def test_cleanup_archives_manifests_only_when_volumes_are_purged(self):
|
||||
for purge in (False, True):
|
||||
with self.subTest(purge=purge), tempfile.TemporaryDirectory() as directory:
|
||||
state = Path(directory)
|
||||
(state / "config.json").write_text(json.dumps(configuration()))
|
||||
(state / "compose.json").write_text("{}")
|
||||
manifest = state / "compat-inline-test.json"
|
||||
manifest.write_text("known oracle")
|
||||
args = argparse.Namespace(command="down", state_dir=directory, purge=purge)
|
||||
with mock.patch.object(LAB.DockerLab, "assert_owned"), mock.patch.object(LAB.DockerLab, "compose") as compose:
|
||||
LAB.execute(args)
|
||||
compose.assert_called_once_with("down", *(["--volumes"] if purge else []))
|
||||
self.assertEqual(manifest.exists(), not purge)
|
||||
if purge:
|
||||
archived = list((state / "compat-history").glob("*/compat-inline-test.json"))
|
||||
self.assertEqual(len(archived), 1)
|
||||
self.assertEqual(archived[0].read_text(), "known oracle")
|
||||
|
||||
def test_dataset_reset_archives_only_compatibility_manifests(self):
|
||||
with tempfile.TemporaryDirectory() as directory:
|
||||
state = Path(directory)
|
||||
manifest = state / "compat-inline-test.json"
|
||||
manifest.write_text("known oracle")
|
||||
config = state / "config.json"
|
||||
config.write_text("configuration")
|
||||
lab = LAB.DockerLab(state, configuration())
|
||||
lab.archive_compat_manifests()
|
||||
self.assertFalse(manifest.exists())
|
||||
archived = list((state / "compat-history").glob("*/compat-inline-test.json"))
|
||||
self.assertEqual(len(archived), 1)
|
||||
self.assertEqual(archived[0].read_text(), "known oracle")
|
||||
self.assertEqual(config.read_text(), "configuration")
|
||||
lab.archive_compat_manifests()
|
||||
self.assertEqual(len(list((state / "compat-history").iterdir())), 1)
|
||||
|
||||
def test_compatibility_client_rejects_external_coordinators_before_docker(self):
|
||||
lab = LAB.DockerLab("/unused", configuration())
|
||||
lab.docker = mock.Mock()
|
||||
with self.assertRaisesRegex(ValueError, "owned lab node"):
|
||||
lab.client("inline-test", "compat-check", coordinator="other.example")
|
||||
lab.docker.assert_not_called()
|
||||
|
||||
def test_compatibility_mutation_receipt_survives_verification_failure(self):
|
||||
record = {"key": "compat/resumed-multipart", "version_id": "completed-version"}
|
||||
for action, receipt in (
|
||||
("compat-finish-mpu", {"records": [record], "multipart": {"complete": True}}),
|
||||
("compat-delete", {"records": [], "deleted_versions": [record]}),
|
||||
):
|
||||
for failure in ("read", "geometry"):
|
||||
with self.subTest(action=action, failure=failure), tempfile.TemporaryDirectory() as directory:
|
||||
state = Path(directory)
|
||||
(state / "config.json").write_text(json.dumps(configuration()))
|
||||
path = state / "compat-inline-test.json"
|
||||
path.write_text(json.dumps({"bucket": "inline-test", "records": []}))
|
||||
result = dict(receipt, bucket="inline-test")
|
||||
# Keep one surviving object so the geometry failure is exercised.
|
||||
if failure == "geometry":
|
||||
result = dict(result, records=[record])
|
||||
args = argparse.Namespace(command=action, state_dir=directory, bucket="inline-test", coordinator="node2")
|
||||
responses = [result, ValueError("read verification failed") if failure == "read" else result]
|
||||
with mock.patch.object(LAB.DockerLab, "assert_owned"), \
|
||||
mock.patch.object(LAB.DockerLab, "client", side_effect=responses) as client, \
|
||||
mock.patch.object(LAB.DockerLab, "container", return_value="owned-node"), \
|
||||
mock.patch.object(LAB.DockerLab, "docker_json", side_effect=ValueError("geometry verification failed")):
|
||||
with self.assertRaisesRegex(ValueError, "verification failed"):
|
||||
LAB.execute(args)
|
||||
self.assertEqual(json.loads(path.read_text()), result)
|
||||
self.assertEqual(path.stat().st_mode & 0o777, 0o600)
|
||||
self.assertEqual(client.call_args_list[-1], mock.call("inline-test", "compat-check", result, "node2"))
|
||||
|
||||
def test_compatibility_client_returns_mutation_receipts_and_retries_without_writes(self):
|
||||
client = mock.Mock()
|
||||
client.upload_part.return_value = {"ETag": "second-etag"}
|
||||
client.complete_multipart_upload.return_value = {"VersionId": "completed-version"}
|
||||
client.delete_objects.return_value = {"Deleted": [{"Key": "compat/versions", "VersionId": "deleted-version"}]}
|
||||
client.get_paginator.side_effect = AssertionError("verification must follow receipt persistence")
|
||||
config_module = types.ModuleType("botocore.config")
|
||||
config_module.Config = mock.Mock()
|
||||
boto_module = types.ModuleType("boto3")
|
||||
boto_module.client = mock.Mock(return_value=client)
|
||||
modules = {"boto3": boto_module, "botocore": types.ModuleType("botocore"), "botocore.config": config_module}
|
||||
for action, initial in (
|
||||
("compat-finish-mpu", {"records": [], "multipart": {"key": "compat/mpu", "upload_id": "pending", "first_etag": "first"}}),
|
||||
("compat-delete", {"records": [{"key": "compat/versions", "version_id": "deleted-version"}]}),
|
||||
):
|
||||
with self.subTest(action=action):
|
||||
manifest = dict(initial, bucket="inline-test")
|
||||
request = {"bucket": "inline-test", "action": action, "access_key": "test-access",
|
||||
"secret_key": "test-secret", "manifest": manifest}
|
||||
output = io.StringIO()
|
||||
with mock.patch.dict(sys.modules, modules), mock.patch("sys.stdin", io.StringIO(json.dumps(request))), contextlib.redirect_stdout(output):
|
||||
exec(LAB.CLIENT, {})
|
||||
receipt = json.loads(output.getvalue())
|
||||
if action == "compat-finish-mpu":
|
||||
self.assertTrue(receipt["multipart"]["complete"])
|
||||
self.assertEqual(receipt["records"][0]["version_id"], "completed-version")
|
||||
else:
|
||||
self.assertEqual(receipt["deleted_versions"], initial["records"])
|
||||
self.assertEqual(receipt["records"], [])
|
||||
client.reset_mock()
|
||||
request["manifest"] = receipt
|
||||
output = io.StringIO()
|
||||
with mock.patch.dict(sys.modules, modules), mock.patch("sys.stdin", io.StringIO(json.dumps(request))), contextlib.redirect_stdout(output):
|
||||
exec(LAB.CLIENT, {})
|
||||
self.assertEqual(json.loads(output.getvalue()), receipt)
|
||||
self.assertEqual(client.mock_calls, [])
|
||||
|
||||
def test_compatibility_client_rejects_wrong_bytes_and_version_inventory(self):
|
||||
manifest = {"bucket": "inline-test", "records": [{"key": "compat/plain", "version_id": "null",
|
||||
"size": 3, "sha256": hashlib.sha256(b"abc").hexdigest()}]}
|
||||
client = mock.Mock()
|
||||
client.head_object.return_value = {"ContentLength": 3}
|
||||
config_module = types.ModuleType("botocore.config")
|
||||
config_module.Config = mock.Mock()
|
||||
boto_module = types.ModuleType("boto3")
|
||||
boto_module.client = mock.Mock(return_value=client)
|
||||
modules = {"boto3": boto_module, "botocore": types.ModuleType("botocore"), "botocore.config": config_module}
|
||||
for inventory, body, valid in (([], b"abc", False),
|
||||
([{"Key": "compat/plain", "VersionId": "null"}], b"bad", False),
|
||||
([{"Key": "compat/plain", "VersionId": "null"}], b"abc", True)):
|
||||
client.get_paginator.return_value.paginate.return_value = [{"Versions": inventory}]
|
||||
client.get_object.return_value = {"Body": io.BytesIO(body)}
|
||||
request = {"bucket": "inline-test", "action": "compat-check", "access_key": "test-access",
|
||||
"secret_key": "test-secret", "manifest": manifest}
|
||||
output = io.StringIO()
|
||||
with mock.patch.dict(sys.modules, modules), mock.patch("sys.stdin", io.StringIO(json.dumps(request))), contextlib.redirect_stdout(output):
|
||||
if valid:
|
||||
exec(LAB.CLIENT, {})
|
||||
self.assertEqual(json.loads(output.getvalue()), manifest)
|
||||
else:
|
||||
with self.assertRaises(AssertionError):
|
||||
exec(LAB.CLIENT, {})
|
||||
|
||||
def test_embedded_client_is_valid_python(self):
|
||||
compile(LAB.CLIENT, "inline lab S3 client", "exec")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -286,18 +286,6 @@ for silent in ${REAL_SPLIT_FILES[@]+"${REAL_SPLIT_FILES[@]}"}; do
|
||||
done
|
||||
|
||||
# --- layer dependencies ------------------------------------------------------
|
||||
# Protocol edges may call the app; app code cannot call either public client path.
|
||||
mkdir -p "$FX/rustfs/src/protocols/client"
|
||||
cat >"$FX/rustfs/src/protocols/client/layer_probe.rs" <<'PROTOCOL_EDGE'
|
||||
use crate::app::RequestEnvelope;
|
||||
PROTOCOL_EDGE
|
||||
cat >"$FX/rustfs/src/protocols/client_helper.rs" <<'PROTOCOL_NEIGHBOR'
|
||||
use crate::app::RequestEnvelope;
|
||||
PROTOCOL_NEIGHBOR
|
||||
cat >"$FX/rustfs/src/app/protocol_client_layer_probe.rs" <<'PROTOCOL_REVERSE'
|
||||
use crate::protocols::client::ProtocolStorageClient;
|
||||
use crate::protocols::ProtocolStorageClient;
|
||||
PROTOCOL_REVERSE
|
||||
LAYER_OUT="$FX/.layer.out"
|
||||
if (cd "$FX" && ./scripts/check_layer_dependencies.sh) >"$LAYER_OUT" 2>&1; then
|
||||
fail "layer guard passed over a planted reverse dependency"
|
||||
@@ -306,10 +294,6 @@ expect_reported "$LAYER_OUT" "dep|$E|interface->composition|" "crate::startup_se
|
||||
expect_silent "$LAYER_OUT" "dep|$EDGE_IMPORTS|" "moved ecfs imports stay legal"
|
||||
expect_silent "$LAYER_OUT" "dep|rustfs/src/app/lifecycle_transition_api_test/" "moved lifecycle transition tests stay excluded"
|
||||
expect_silent "$LAYER_OUT" "dep|$LISTING|" "moved bucket usecase code keeps the app layer"
|
||||
expect_silent "$LAYER_OUT" "dep|rustfs/src/protocols/client/layer_probe.rs|" "protocol client edge may use app contracts"
|
||||
expect_reported "$LAYER_OUT" "dep|rustfs/src/protocols/client_helper.rs|infra->app|" "crate::app::RequestEnvelope" "neighboring protocol helper remains infrastructure"
|
||||
expect_reported "$LAYER_OUT" "dep|rustfs/src/app/protocol_client_layer_probe.rs|app->interface|" "crate::protocols::client::ProtocolStorageClient" "app cannot import the protocol client module"
|
||||
expect_reported "$LAYER_OUT" "dep|rustfs/src/app/protocol_client_layer_probe.rs|app->interface|" "crate::protocols::ProtocolStorageClient" "app cannot import the protocol client re-export"
|
||||
|
||||
# --- logging hot span --------------------------------------------------------
|
||||
LOG_OUT="$FX/.logging.out"
|
||||
|
||||
Reference in New Issue
Block a user