mirror of
https://github.com/rustfs/rustfs.git
synced 2026-11-16 21:14:45 +00:00
Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8ba7ac862d | |||
| f80522ef35 |
@@ -39,10 +39,10 @@ script-tests: ## Run shell script tests
|
||||
./scripts/test_entrypoint_directories.sh
|
||||
./scripts/test_internode_grpc_ab_bench.sh
|
||||
$(RUSTFS_PYTHON_BIN) ./scripts/test_internode_grpc_window.py
|
||||
$(RUSTFS_PYTHON_BIN) ./scripts/test_internode_rpc_timeout_boundary.py
|
||||
$(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 3
|
||||
rustfs-ecstore 7858 2
|
||||
rustfs-extension-schema 23 0
|
||||
rustfs-filemeta 361 0
|
||||
rustfs-gateway-adapter 74 0
|
||||
|
||||
@@ -1,58 +0,0 @@
|
||||
# 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"]
|
||||
@@ -1,5 +0,0 @@
|
||||
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"]
|
||||
@@ -1,133 +0,0 @@
|
||||
# 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,44 +2559,9 @@ fn encode_file_info_versions_msgpack(value: &FileInfoVersions) -> Result<Vec<u8>
|
||||
encode_msgpack_with_capacity(value, capacity)
|
||||
}
|
||||
|
||||
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.
|
||||
/// 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 compat_json<T: Serialize>(value: &T, policy: &MsgpackSendPolicy) -> Result<String> {
|
||||
if policy.omit_eligible_json() {
|
||||
return Ok(String::new());
|
||||
@@ -3582,10 +3547,52 @@ impl DiskAPI for RemoteDisk {
|
||||
return vec![Some(DiskError::FaultyDisk); versions.len()];
|
||||
}
|
||||
|
||||
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()],
|
||||
// `_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 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) => {
|
||||
@@ -3597,7 +3604,14 @@ impl DiskAPI for RemoteDisk {
|
||||
}
|
||||
};
|
||||
|
||||
let mut request = Request::new(request);
|
||||
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 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());
|
||||
@@ -6323,94 +6337,6 @@ 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");
|
||||
@@ -7361,10 +7287,7 @@ mod tests {
|
||||
);
|
||||
}
|
||||
|
||||
fn with_internode_msgpack_env<R, const N: usize>(
|
||||
vars: [(&'static str, Option<&'static str>); N],
|
||||
f: impl FnOnce() -> R,
|
||||
) -> R {
|
||||
fn with_internode_msgpack_env<R>(vars: [(&'static str, Option<&'static str>); 2], f: impl FnOnce() -> R) -> R {
|
||||
temp_env::with_vars(vars, || {
|
||||
rustfs_protos::reset_internode_rpc_msgpack_only_cache();
|
||||
let result = f();
|
||||
|
||||
@@ -101,6 +101,7 @@ 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![
|
||||
@@ -151,7 +152,6 @@ 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,10 +245,8 @@ impl Config {
|
||||
return false;
|
||||
}
|
||||
|
||||
let Ok(shard_size) = usize::try_from(shard_size) else {
|
||||
return false;
|
||||
};
|
||||
let inline_block = self.inline_block();
|
||||
let shard_size = shard_size as usize;
|
||||
let inline_block = self.effective_inline_block(data_shards);
|
||||
|
||||
if versioned {
|
||||
shard_size <= inline_block / 8
|
||||
@@ -257,7 +255,27 @@ impl Config {
|
||||
}
|
||||
}
|
||||
|
||||
/// Per-shard inline data budget, defaulting to 128 KiB across EC layouts.
|
||||
/// 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)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn inline_block(&self) -> usize {
|
||||
if !self.initialized {
|
||||
DEFAULT_INLINE_BLOCK
|
||||
@@ -549,7 +567,7 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn should_inline_uses_fixed_default_threshold_for_every_ec_layout() {
|
||||
fn should_inline_scales_default_threshold_by_data_shards() {
|
||||
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");
|
||||
|
||||
@@ -558,14 +576,10 @@ 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", 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),
|
||||
("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),
|
||||
("negative", -1, 2, false, false),
|
||||
("zero data shards", 0, 0, false, false),
|
||||
] {
|
||||
@@ -612,35 +626,37 @@ mod tests {
|
||||
let shard_size = erasure.shard_file_size(object_size);
|
||||
let inline = config.should_inline(shard_size, data_shards, false);
|
||||
|
||||
// The per-shard budget stays monotonic across object sizes.
|
||||
// PUT separately bounds inline body materialization.
|
||||
// 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.
|
||||
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 fits the per-shard budget for EC{data_shards}+{parity_shards}"
|
||||
!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}"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inline_block_preserves_fixed_default_and_explicit_limits() {
|
||||
fn effective_inline_block_scales_default_budget_and_preserves_explicit_limit() {
|
||||
let config = Config::default();
|
||||
assert_eq!(config.inline_block(), 128 * 1024);
|
||||
assert!(!config.should_inline(0, 0, false));
|
||||
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);
|
||||
|
||||
let explicit = lookup_config_for_pools_with_env(
|
||||
&KVS::new(),
|
||||
&[12],
|
||||
StorageClassEnvOverrides {
|
||||
inline_block: Some("32KiB".to_string()),
|
||||
inline_block: Some("128KiB".to_string()),
|
||||
..Default::default()
|
||||
},
|
||||
)
|
||||
.expect("explicit inline block should resolve");
|
||||
assert_eq!(explicit.inline_block(), 32 * 1024);
|
||||
assert_eq!(explicit.effective_inline_block(12), 128 * 1024);
|
||||
}
|
||||
|
||||
#[test]
|
||||
@@ -889,21 +905,6 @@ 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
|
||||
|
||||
@@ -9992,13 +9992,6 @@ impl LocalDisk {
|
||||
check_path_length(file_path.to_string_lossy().as_ref())?;
|
||||
|
||||
let xl_path = path_join(&[file_path.as_path(), Path::new(STORAGE_FORMAT_FILE)]);
|
||||
#[cfg(target_os = "linux")]
|
||||
let object_path = {
|
||||
let (root_bucket, object_path) = build_local_disk_object_path(&self.root, volume, path);
|
||||
check_local_disk_object_path_components(&self.root, &root_bucket, &object_path)?;
|
||||
object_path
|
||||
};
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
let object_path = self.get_object_path(volume, path)?;
|
||||
let mut namespace_owner: Option<Arc<dyn Send + Sync>> =
|
||||
Some(os::acquire_metadata_mutation_lease(&object_path, namespace_owner).await);
|
||||
@@ -17655,9 +17648,12 @@ impl DiskAPI for LocalDisk {
|
||||
fi.data = None;
|
||||
}
|
||||
|
||||
// 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.
|
||||
// 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.
|
||||
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(&[
|
||||
@@ -17930,9 +17926,6 @@ 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)
|
||||
@@ -18655,16 +18648,9 @@ mod test {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn legacy_inline_read_ahead_stays_single_block_for_ec_layouts() {
|
||||
fn legacy_inline_read_ahead_matches_writer_policy_for_ec_layouts() {
|
||||
let config = crate::config::storageclass::Config::default();
|
||||
let object_sizes = [
|
||||
128 * 1024_i64,
|
||||
256 * 1024,
|
||||
512 * 1024,
|
||||
1024 * 1024,
|
||||
1024 * 1024 + 1,
|
||||
4 * 1024 * 1024,
|
||||
];
|
||||
let object_sizes = [128 * 1024_i64, 256 * 1024, 512 * 1024, 1024 * 1024, 4 * 1024 * 1024];
|
||||
|
||||
for (data_shards, parity_shards) in [(8, 4), (12, 4)] {
|
||||
for object_size in object_sizes {
|
||||
@@ -18677,8 +18663,7 @@ mod test {
|
||||
..Default::default()
|
||||
}];
|
||||
|
||||
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;
|
||||
let writer_decision = config.should_inline(fi.shard_file_size(object_size), data_shards, false);
|
||||
assert_eq!(
|
||||
should_read_legacy_inline_part(&fi, &config),
|
||||
writer_decision,
|
||||
@@ -18691,13 +18676,13 @@ mod test {
|
||||
ec12.data_dir = Some(Uuid::from_u128(1));
|
||||
ec12.parts = vec![ObjectPartInfo {
|
||||
number: 1,
|
||||
size: 1024 * 1024 + 1,
|
||||
actual_size: 1024 * 1024 + 1,
|
||||
size: 1024 * 1024,
|
||||
actual_size: 1024 * 1024,
|
||||
..Default::default()
|
||||
}];
|
||||
assert!(
|
||||
ec12.shard_file_size(1024 * 1024 + 1) < 128 * 1024,
|
||||
"a multi-block external object can still fit the per-shard budget"
|
||||
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"
|
||||
);
|
||||
assert!(!should_read_legacy_inline_part(&ec12, &config));
|
||||
}
|
||||
|
||||
@@ -209,7 +209,7 @@ impl DiscoverySession {
|
||||
None => regular_bytes(&proof_root.join(DELETE_QUORUM_COMMITTED_FILE))
|
||||
.map_err(std::io::Error::from)?
|
||||
.filter(|bytes| !bytes.is_empty())
|
||||
.and_then(|bytes| parse_commit_receipt(&bytes).ok())
|
||||
.and_then(|bytes| serde_json::from_slice::<CommitReceipt>(&bytes).ok())
|
||||
.map(|receipt| receipt.journal),
|
||||
};
|
||||
let logical = record
|
||||
@@ -273,21 +273,6 @@ struct CommitReceipt {
|
||||
finished: bool,
|
||||
}
|
||||
|
||||
/// Parse a commit receipt from `delete-quorum-committed`.
|
||||
/// A bare `DeleteRecoveryJournal` (from hardlinking `delete-prepared`) always
|
||||
/// represents `finished = false`; `finished = true` is only persisted via the
|
||||
/// `CommitReceipt` wrapper when replacing the receipt entry.
|
||||
fn parse_commit_receipt(bytes: &[u8]) -> Result<CommitReceipt> {
|
||||
if let Ok(receipt) = serde_json::from_slice::<CommitReceipt>(bytes) {
|
||||
return Ok(receipt);
|
||||
}
|
||||
let journal = serde_json::from_slice::<DeleteRecoveryJournal>(bytes).map_err(|_| DiskError::FileCorrupt)?;
|
||||
Ok(CommitReceipt {
|
||||
journal,
|
||||
finished: false,
|
||||
})
|
||||
}
|
||||
|
||||
pub(super) struct DeletePreparationContext {
|
||||
pub transaction: Uuid,
|
||||
pub bucket_incarnation: Option<Uuid>,
|
||||
@@ -881,8 +866,9 @@ pub(super) fn inspection_with_markers_bounded(
|
||||
let receipt: Option<CommitReceipt> = receipt_bytes
|
||||
.as_deref()
|
||||
.filter(|bytes| !bytes.is_empty())
|
||||
.map(parse_commit_receipt)
|
||||
.transpose()?;
|
||||
.map(serde_json::from_slice)
|
||||
.transpose()
|
||||
.map_err(|_| DiskError::FileCorrupt)?;
|
||||
let committed = receipt.is_some();
|
||||
let finished = regular_marker(&rollback.join(FINISHED))? || receipt.as_ref().is_some_and(|receipt| receipt.finished);
|
||||
let journal: Option<DeleteRecoveryJournal> = prepared
|
||||
@@ -1199,7 +1185,6 @@ struct PreparedDeleteReceiptEntry {
|
||||
journal: DeleteRecoveryJournal,
|
||||
sole_transaction: bool,
|
||||
had_old_data_dir: bool,
|
||||
prepared_synced: bool,
|
||||
rollback_dir_fd: Option<Arc<std::fs::File>>,
|
||||
file_path_dir: Option<Arc<std::fs::File>>,
|
||||
}
|
||||
@@ -1553,7 +1538,11 @@ impl LocalDisk {
|
||||
.push(serde_json::from_slice::<DeleteRecoveryJournal>(&bytes).map_err(|_| DiskError::FileCorrupt)?);
|
||||
}
|
||||
if let Some(bytes) = receipt.filter(|bytes| !bytes.is_empty()) {
|
||||
records.push(parse_commit_receipt(&bytes)?.journal);
|
||||
records.push(
|
||||
serde_json::from_slice::<CommitReceipt>(&bytes)
|
||||
.map_err(|_| DiskError::FileCorrupt)?
|
||||
.journal,
|
||||
);
|
||||
}
|
||||
for record in records {
|
||||
if record.protocol_version != DELETE_RECOVERY_PROTOCOL_VERSION
|
||||
@@ -2929,7 +2918,11 @@ impl LocalDisk {
|
||||
);
|
||||
}
|
||||
if let Some(bytes) = receipt.filter(|bytes| !bytes.is_empty()) {
|
||||
records.push(parse_commit_receipt(&bytes)?.journal);
|
||||
records.push(
|
||||
serde_json::from_slice::<CommitReceipt>(&bytes)
|
||||
.map_err(|_| DiskError::FileCorrupt)?
|
||||
.journal,
|
||||
);
|
||||
}
|
||||
for record in records {
|
||||
if record.protocol_version != DELETE_RECOVERY_PROTOCOL_VERSION
|
||||
@@ -3157,7 +3150,6 @@ impl LocalDisk {
|
||||
journal,
|
||||
sole_transaction,
|
||||
had_old_data_dir,
|
||||
prepared_synced: sync,
|
||||
rollback_dir_fd,
|
||||
file_path_dir,
|
||||
},
|
||||
@@ -3221,7 +3213,6 @@ impl LocalDisk {
|
||||
entry.journal,
|
||||
entry.sole_transaction,
|
||||
entry.had_old_data_dir,
|
||||
entry.prepared_synced,
|
||||
entry.rollback_dir_fd,
|
||||
entry.file_path_dir,
|
||||
)),
|
||||
@@ -3256,61 +3247,33 @@ impl LocalDisk {
|
||||
lease,
|
||||
sync,
|
||||
move || -> std::io::Result<Result<Option<PublishDeleteFastReturn>>> {
|
||||
if let Some((
|
||||
journal_raw,
|
||||
journal,
|
||||
sole_transaction,
|
||||
had_old_data_dir,
|
||||
prepared_synced,
|
||||
rollback_dir_fd,
|
||||
file_path_dir,
|
||||
)) = cached_receipt
|
||||
if let Some((journal_raw, journal, sole_transaction, had_old_data_dir, rollback_dir_fd, file_path_dir)) =
|
||||
cached_receipt
|
||||
&& child_regular_file_exists(rollback_dir_fd.as_deref(), PREPARED, &rollback.join(PREPARED))
|
||||
{
|
||||
// Share the immutable Stage 1 PREPARED inode; any later receipt update must replace the entry by rename.
|
||||
let linked = if !sync || prepared_synced {
|
||||
let tmp_receipt = staging_root.join(format!("receipt-{transaction}.tmp"));
|
||||
let receipt_bytes = format_commit_receipt_bytes(&journal_raw, false);
|
||||
let write_res = (|| -> std::io::Result<()> {
|
||||
let mut file = std::fs::File::create(&tmp_receipt)?;
|
||||
std::io::Write::write_all(&mut file, &receipt_bytes)?;
|
||||
if sync && !receipt_bytes.is_empty() {
|
||||
file.sync_data()?;
|
||||
}
|
||||
os::record_native_publication(&receipt_path);
|
||||
link_child_files(
|
||||
rollback_dir_fd.as_deref(),
|
||||
PREPARED,
|
||||
&rollback.join(PREPARED),
|
||||
rename_into_dir_fd(
|
||||
&tmp_receipt,
|
||||
rollback_dir_fd.as_deref(),
|
||||
DELETE_QUORUM_COMMITTED_FILE,
|
||||
&receipt_path,
|
||||
)
|
||||
.is_ok()
|
||||
} else {
|
||||
false
|
||||
};
|
||||
if linked {
|
||||
)?;
|
||||
if sync {
|
||||
os::fsync_directory_handle_std(&rollback, rollback_dir_fd.as_deref())?;
|
||||
}
|
||||
} else {
|
||||
let tmp_receipt = staging_root.join(format!("receipt-{transaction}.tmp"));
|
||||
let receipt_bytes = format_commit_receipt_bytes(&journal_raw, false);
|
||||
let write_res = (|| -> std::io::Result<()> {
|
||||
let mut file = std::fs::File::create(&tmp_receipt)?;
|
||||
std::io::Write::write_all(&mut file, &receipt_bytes)?;
|
||||
if sync && !receipt_bytes.is_empty() {
|
||||
file.sync_data()?;
|
||||
}
|
||||
os::record_native_publication(&receipt_path);
|
||||
rename_into_dir_fd(
|
||||
&tmp_receipt,
|
||||
rollback_dir_fd.as_deref(),
|
||||
DELETE_QUORUM_COMMITTED_FILE,
|
||||
&receipt_path,
|
||||
)?;
|
||||
if sync {
|
||||
os::fsync_directory_handle_std(&rollback, rollback_dir_fd.as_deref())?;
|
||||
}
|
||||
Ok(())
|
||||
})();
|
||||
if let Err(err) = write_res {
|
||||
let _ = std::fs::remove_file(&tmp_receipt);
|
||||
return Err(err);
|
||||
}
|
||||
Ok(())
|
||||
})();
|
||||
if let Err(err) = write_res {
|
||||
let _ = std::fs::remove_file(&tmp_receipt);
|
||||
return Err(err);
|
||||
}
|
||||
let published_entry = bucket_path.map(|bucket_path| {
|
||||
(
|
||||
@@ -8487,9 +8450,6 @@ mod tests {
|
||||
journal: journal.clone(),
|
||||
finished: true,
|
||||
};
|
||||
fs::remove_file(rollback.join(DELETE_QUORUM_COMMITTED_FILE))
|
||||
.await
|
||||
.expect("remove receipt before replacement");
|
||||
fs::write(
|
||||
rollback.join(DELETE_QUORUM_COMMITTED_FILE),
|
||||
serde_json::to_vec(&finished_receipt).expect("serialize finished receipt"),
|
||||
@@ -8658,265 +8618,6 @@ mod tests {
|
||||
);
|
||||
assert!(!rollback.exists());
|
||||
}
|
||||
|
||||
#[cfg(unix)]
|
||||
#[tokio::test]
|
||||
async fn delete_recovery_stage2_hardlinks_prepared_journal_and_falls_back_on_conflict() {
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
|
||||
let _strict = durability_mode_override::set(DurabilityMode::Strict);
|
||||
let (_temp, disk, info, _) = fixture().await;
|
||||
let root = disk.io_get_object_path("recovery", "object").expect("object path");
|
||||
let opts = DeleteOptions {
|
||||
recoverable_delete: true,
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
#[cfg(target_os = "linux")]
|
||||
{
|
||||
let proc_vol = format!("{}/recovery", disk.io_root().display());
|
||||
assert!(matches!(
|
||||
disk.delete_version(&proc_vol, "object", info.clone(), false, opts.clone())
|
||||
.await,
|
||||
Err(DiskError::InvalidPath)
|
||||
));
|
||||
}
|
||||
|
||||
let tx1 = Uuid::new_v4();
|
||||
assert_eq!(
|
||||
disk.try_fused_recoverable_delete_version("recovery", "object", &info, &opts, tx1, None)
|
||||
.await
|
||||
.expect("fused prepare tx1"),
|
||||
Some(())
|
||||
);
|
||||
let (journal1, sole1, satisfied1) = disk
|
||||
.try_publish_prepared_delete_local("recovery", "object", tx1, None)
|
||||
.await
|
||||
.expect("publish tx1")
|
||||
.expect("tx1 satisfied");
|
||||
assert!(sole1 && satisfied1);
|
||||
|
||||
let rollback1 = root.join(tx1.to_string());
|
||||
assert!(
|
||||
os::fsync_dir_recorder::was_fsynced(&rollback1),
|
||||
"strict Stage 2 hardlink must fsync rollback directory"
|
||||
);
|
||||
let prep_meta1 = std::fs::metadata(rollback1.join(PREPARED)).expect("prepared metadata");
|
||||
let rec_meta1 = std::fs::metadata(rollback1.join(DELETE_QUORUM_COMMITTED_FILE)).expect("receipt metadata");
|
||||
assert_eq!(
|
||||
(prep_meta1.dev(), prep_meta1.ino()),
|
||||
(rec_meta1.dev(), rec_meta1.ino()),
|
||||
"Stage 2 fast path must hardlink PREPARED to DELETE_QUORUM_COMMITTED_FILE"
|
||||
);
|
||||
let raw_receipt1 = std::fs::read(rollback1.join(DELETE_QUORUM_COMMITTED_FILE)).expect("read bare receipt");
|
||||
let parsed_bare = parse_commit_receipt(&raw_receipt1).expect("parse bare journal receipt");
|
||||
assert!(!parsed_bare.finished && parsed_bare.journal == journal1);
|
||||
let wrapped_true = format_commit_receipt_bytes(&raw_receipt1, true);
|
||||
let parsed_wrapped = parse_commit_receipt(&wrapped_true).expect("parse wrapped finished receipt");
|
||||
assert!(parsed_wrapped.finished && parsed_wrapped.journal == journal1);
|
||||
assert!(matches!(parse_commit_receipt(b"{\"invalid\":1}"), Err(DiskError::FileCorrupt)));
|
||||
assert_eq!(
|
||||
disk.inspect_delete_transaction("recovery", "object", tx1)
|
||||
.await
|
||||
.expect("inspect QuorumCommitted")
|
||||
.state,
|
||||
DeleteRecoveryState::QuorumCommitted
|
||||
);
|
||||
|
||||
// Verify DiscoverySession::advance_bounded (:212) extracts the bound logical key ("directory/")
|
||||
// from a bare-journal receipt when PREPARED is absent (physical dir name is "directory").
|
||||
let dir_root = disk.io_get_object_path("recovery", "directory/").expect("dir key path");
|
||||
let mut dir_info = info.clone();
|
||||
dir_info.name = "directory/".to_owned();
|
||||
let mut dir_meta = FileMeta::new();
|
||||
dir_meta.add_version(dir_info.clone()).expect("add dir version");
|
||||
fs::create_dir_all(&dir_root).await.expect("create dir_root");
|
||||
fs::write(dir_root.join(STORAGE_FORMAT_FILE), dir_meta.marshal_msg().expect("marshal dir meta"))
|
||||
.await
|
||||
.expect("write dir xl.meta");
|
||||
let tx_dir = Uuid::new_v4();
|
||||
assert_eq!(
|
||||
disk.try_fused_recoverable_delete_version("recovery", "directory/", &dir_info, &opts, tx_dir, None)
|
||||
.await
|
||||
.expect("fused prepare tx_dir"),
|
||||
Some(())
|
||||
);
|
||||
let (journal_dir, _, _) = disk
|
||||
.try_publish_prepared_delete_local("recovery", "directory/", tx_dir, None)
|
||||
.await
|
||||
.expect("publish tx_dir")
|
||||
.expect("tx_dir satisfied");
|
||||
let rollback_dir = dir_root.join(tx_dir.to_string());
|
||||
fs::remove_file(rollback_dir.join(PREPARED))
|
||||
.await
|
||||
.expect("unlink dir PREPARED");
|
||||
fs::remove_file(rollback_dir.join(STORAGE_FORMAT_FILE_BACKUP))
|
||||
.await
|
||||
.expect("unlink dir backup");
|
||||
let discovered_dir = disk
|
||||
.discover_delete_transactions("recovery", None, None, 16)
|
||||
.await
|
||||
.expect("bucket-wide discovery of directory/ bare-journal receipt");
|
||||
assert!(
|
||||
discovered_dir
|
||||
.transactions
|
||||
.iter()
|
||||
.any(|id| id.object == "directory/" && id.transaction == tx_dir),
|
||||
"DiscoverySession must parse logical key 'directory/' from bare-journal receipt"
|
||||
);
|
||||
assert!(
|
||||
disk.try_finish_and_finalize_prepared_delete_local("recovery", "directory/", tx_dir, &journal_dir, None)
|
||||
.await
|
||||
.expect("finalize tx_dir")
|
||||
);
|
||||
|
||||
// Removing PREPARED and backup while retaining the bare-journal receipt infers CommitFinished
|
||||
// and exercises all bare-journal parse_commit_receipt sites (bucket-wide discovery + predecessor scans).
|
||||
fs::remove_file(rollback1.join(PREPARED)).await.expect("unlink PREPARED");
|
||||
fs::remove_file(rollback1.join(STORAGE_FORMAT_FILE_BACKUP))
|
||||
.await
|
||||
.expect("unlink backup");
|
||||
assert_eq!(
|
||||
disk.inspect_delete_transaction("recovery", "object", tx1)
|
||||
.await
|
||||
.expect("inspect CommitFinished from bare-journal receipt")
|
||||
.state,
|
||||
DeleteRecoveryState::CommitFinished
|
||||
);
|
||||
let discovered_bucket = disk
|
||||
.discover_delete_transactions("recovery", None, None, 16)
|
||||
.await
|
||||
.expect("bucket-wide discovery of bare-journal receipt");
|
||||
assert!(discovered_bucket.transactions.iter().any(|id| id.transaction == tx1));
|
||||
let preds = disk
|
||||
.delete_recovery_predecessors("recovery", "object", Uuid::new_v4(), None, None)
|
||||
.await
|
||||
.expect("predecessor scan of bare-journal receipt");
|
||||
assert_eq!(preds, vec![tx1]);
|
||||
|
||||
// Re-create xl.meta while tx1's bare-journal receipt is still present so Stage 1's predecessor scan
|
||||
// parses tx1's bare-journal receipt, and pre-populate tx2's receipt before Stage 2 to force EEXIST fallback.
|
||||
let mut meta = FileMeta::new();
|
||||
meta.add_version(info.clone()).expect("add version");
|
||||
fs::create_dir_all(&root).await.expect("recreate object dir");
|
||||
fs::write(root.join(STORAGE_FORMAT_FILE), meta.marshal_msg().expect("marshal meta"))
|
||||
.await
|
||||
.expect("write xl.meta");
|
||||
|
||||
let tx2 = Uuid::new_v4();
|
||||
assert_eq!(
|
||||
disk.try_fused_recoverable_delete_version("recovery", "object", &info, &opts, tx2, None)
|
||||
.await
|
||||
.expect("fused prepare tx2"),
|
||||
Some(())
|
||||
);
|
||||
let rollback2 = root.join(tx2.to_string());
|
||||
fs::write(rollback2.join(DELETE_QUORUM_COMMITTED_FILE), b"stale")
|
||||
.await
|
||||
.expect("pre-create conflicting receipt");
|
||||
let (journal2, sole2, satisfied2) = disk
|
||||
.try_publish_prepared_delete_local("recovery", "object", tx2, None)
|
||||
.await
|
||||
.expect("publish tx2 fallback")
|
||||
.expect("tx2 satisfied");
|
||||
assert!(!sole2 && satisfied2);
|
||||
assert_eq!(journal2.predecessors, vec![tx1]);
|
||||
let prep_meta2 = std::fs::metadata(rollback2.join(PREPARED)).expect("prepared2 metadata");
|
||||
let rec_meta2 = std::fs::metadata(rollback2.join(DELETE_QUORUM_COMMITTED_FILE)).expect("receipt2 metadata");
|
||||
assert_ne!(
|
||||
(prep_meta2.dev(), prep_meta2.ino()),
|
||||
(rec_meta2.dev(), rec_meta2.ino()),
|
||||
"EEXIST fallback must replace receipt with a distinct wrapper inode"
|
||||
);
|
||||
assert!(
|
||||
disk.try_finish_and_finalize_prepared_delete_local("recovery", "object", tx1, &journal1, None)
|
||||
.await
|
||||
.expect("finalize tx1")
|
||||
);
|
||||
assert!(
|
||||
disk.try_finish_and_finalize_prepared_delete_local("recovery", "object", tx2, &journal2, None)
|
||||
.await
|
||||
.expect("finalize tx2")
|
||||
);
|
||||
|
||||
// Prepare tx3 under Relaxed (`prepared_synced == false`), then escalate to Strict before Stage 2:
|
||||
// Stage 2 must not hardlink the unsynced PREPARED inode and must instead write a fresh synced receipt.
|
||||
fs::create_dir_all(&root).await.expect("recreate object dir for tx3");
|
||||
fs::write(root.join(STORAGE_FORMAT_FILE), meta.marshal_msg().expect("marshal meta"))
|
||||
.await
|
||||
.expect("write xl.meta for tx3");
|
||||
drop(_strict);
|
||||
let tx3 = Uuid::new_v4();
|
||||
{
|
||||
let _relaxed = durability_mode_override::set(DurabilityMode::Relaxed);
|
||||
assert_eq!(
|
||||
disk.try_fused_recoverable_delete_version("recovery", "object", &info, &opts, tx3, None)
|
||||
.await
|
||||
.expect("fused prepare tx3 relaxed"),
|
||||
Some(())
|
||||
);
|
||||
}
|
||||
let _strict_again = durability_mode_override::set(DurabilityMode::Strict);
|
||||
let (journal3, sole3, satisfied3) = disk
|
||||
.try_publish_prepared_delete_local("recovery", "object", tx3, None)
|
||||
.await
|
||||
.expect("publish tx3 escalated to strict")
|
||||
.expect("tx3 satisfied");
|
||||
assert!(sole3 && satisfied3);
|
||||
let rollback3 = root.join(tx3.to_string());
|
||||
let prep_meta3 = std::fs::metadata(rollback3.join(PREPARED)).expect("prepared3 metadata");
|
||||
let rec_meta3 = std::fs::metadata(rollback3.join(DELETE_QUORUM_COMMITTED_FILE)).expect("receipt3 metadata");
|
||||
assert_ne!(
|
||||
(prep_meta3.dev(), prep_meta3.ino()),
|
||||
(rec_meta3.dev(), rec_meta3.ino()),
|
||||
"unsynced Stage 1 preparation must not be hardlinked when Stage 2 requires sync"
|
||||
);
|
||||
assert!(
|
||||
disk.try_finish_and_finalize_prepared_delete_local("recovery", "object", tx3, &journal3, None)
|
||||
.await
|
||||
.expect("finalize tx3")
|
||||
);
|
||||
drop(_strict_again);
|
||||
|
||||
// Prepare and publish tx4 under Relaxed (`!sync`): Stage 2 must hardlink PREPARED without directory fsync.
|
||||
fs::create_dir_all(&root).await.expect("recreate object dir for tx4");
|
||||
fs::write(root.join(STORAGE_FORMAT_FILE), meta.marshal_msg().expect("marshal meta"))
|
||||
.await
|
||||
.expect("write xl.meta for tx4");
|
||||
let tx4 = Uuid::new_v4();
|
||||
{
|
||||
let _relaxed = durability_mode_override::set(DurabilityMode::Relaxed);
|
||||
assert_eq!(
|
||||
disk.try_fused_recoverable_delete_version("recovery", "object", &info, &opts, tx4, None)
|
||||
.await
|
||||
.expect("fused prepare tx4 relaxed"),
|
||||
Some(())
|
||||
);
|
||||
let (journal4, sole4, satisfied4) = disk
|
||||
.try_publish_prepared_delete_local("recovery", "object", tx4, None)
|
||||
.await
|
||||
.expect("publish tx4 relaxed")
|
||||
.expect("tx4 satisfied");
|
||||
assert!(sole4 && satisfied4);
|
||||
let rollback4 = root.join(tx4.to_string());
|
||||
assert!(
|
||||
!os::fsync_dir_recorder::was_fsynced(&rollback4),
|
||||
"relaxed Stage 2 hardlink must not fsync rollback directory"
|
||||
);
|
||||
let prep_meta4 = std::fs::metadata(rollback4.join(PREPARED)).expect("prepared4 metadata");
|
||||
let rec_meta4 = std::fs::metadata(rollback4.join(DELETE_QUORUM_COMMITTED_FILE)).expect("receipt4 metadata");
|
||||
assert_eq!(
|
||||
(prep_meta4.dev(), prep_meta4.ino()),
|
||||
(rec_meta4.dev(), rec_meta4.ino()),
|
||||
"relaxed Stage 2 must hardlink PREPARED to DELETE_QUORUM_COMMITTED_FILE"
|
||||
);
|
||||
assert!(
|
||||
disk.try_finish_and_finalize_prepared_delete_local("recovery", "object", tx4, &journal4, None)
|
||||
.await
|
||||
.expect("finalize tx4")
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
||||
@@ -2371,8 +2371,6 @@ type NativeRootIdentity = (u64, u64);
|
||||
struct NativePublicationHistory {
|
||||
roots: HashMap<NativeRootIdentity, NativeRootHistory>,
|
||||
aliases: HashMap<PathBuf, HashSet<NativeRootIdentity>>,
|
||||
#[cfg(target_os = "linux")]
|
||||
live_proc_roots: HashMap<PathBuf, (NativeRootIdentity, Weak<std::fs::File>)>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Default)]
|
||||
@@ -2452,59 +2450,12 @@ pub(crate) fn register_native_publication_root(root: &Path, io_root: &Path) -> O
|
||||
/// Record before queueing filesystem work. Cancellation never removes Started.
|
||||
pub(crate) fn record_native_publication(path: &Path) {
|
||||
let aliases: Vec<_> = {
|
||||
#[cfg(target_os = "linux")]
|
||||
let mut history = NATIVE_PUBLICATION_HISTORY.lock();
|
||||
#[cfg(not(target_os = "linux"))]
|
||||
let history = NATIVE_PUBLICATION_HISTORY.lock();
|
||||
let mut unpinned = Vec::new();
|
||||
for alias in path.ancestors() {
|
||||
if !history.aliases.contains_key(alias) {
|
||||
continue;
|
||||
}
|
||||
#[cfg(target_os = "linux")]
|
||||
if let Some((live_identity, weak)) = history.live_proc_roots.get(alias) {
|
||||
if weak.strong_count() > 0 {
|
||||
let live_identity = *live_identity;
|
||||
if history
|
||||
.aliases
|
||||
.get(alias)
|
||||
.is_some_and(|ids| ids.len() == 1 && ids.contains(&live_identity))
|
||||
{
|
||||
let Ok(relative) = path.strip_prefix(alias) else {
|
||||
continue;
|
||||
};
|
||||
let mut components = relative.components().filter(|part| !matches!(part, Component::CurDir));
|
||||
let Some(first) = components.next() else {
|
||||
continue;
|
||||
};
|
||||
let bucket = match first {
|
||||
Component::Normal(bucket) if components.all(|part| matches!(part, Component::Normal(_))) => {
|
||||
bucket.to_str()
|
||||
}
|
||||
_ => None,
|
||||
};
|
||||
let root = history.roots.entry(live_identity).or_default();
|
||||
match bucket {
|
||||
Some(bucket) => {
|
||||
if !root.started.contains(bucket) {
|
||||
root.started.insert(bucket.to_owned());
|
||||
}
|
||||
}
|
||||
None => root.unknown = true,
|
||||
}
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
history.live_proc_roots.remove(alias);
|
||||
}
|
||||
}
|
||||
unpinned.push(alias.to_path_buf());
|
||||
}
|
||||
unpinned
|
||||
path.ancestors()
|
||||
.filter(|alias| history.aliases.contains_key(*alias))
|
||||
.map(Path::to_path_buf)
|
||||
.collect()
|
||||
};
|
||||
if aliases.is_empty() {
|
||||
return;
|
||||
}
|
||||
// Physical lookups must never hold the process-wide publication mutex.
|
||||
let observations: Vec<_> = aliases
|
||||
.into_iter()
|
||||
@@ -6165,18 +6116,7 @@ impl PublicationRoot {
|
||||
#[cfg(target_os = "linux")]
|
||||
let io_path = {
|
||||
use std::os::fd::AsRawFd;
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
let proc_alias = PathBuf::from(format!("/proc/self/fd/{}", directory.as_raw_fd()));
|
||||
if let Ok(metadata) = directory.metadata()
|
||||
&& metadata.is_dir()
|
||||
{
|
||||
let identity = (metadata.dev(), metadata.ino());
|
||||
NATIVE_PUBLICATION_HISTORY
|
||||
.lock()
|
||||
.live_proc_roots
|
||||
.insert(proc_alias.clone(), (identity, Arc::downgrade(&directory)));
|
||||
}
|
||||
Arc::new(proc_alias.join("."))
|
||||
Arc::new(PathBuf::from(format!("/proc/self/fd/{}/.", directory.as_raw_fd())))
|
||||
};
|
||||
|
||||
Ok(Self {
|
||||
@@ -14927,95 +14867,6 @@ mod fd_relative_tests {
|
||||
use super::*;
|
||||
use std::io::{Read, Write};
|
||||
|
||||
#[test]
|
||||
fn live_proc_root_fast_path_preserves_three_way_semantics_and_retires_on_drop() {
|
||||
use std::sync::atomic::{AtomicUsize, Ordering};
|
||||
|
||||
let temp = tempfile::tempdir().expect("temporary disk");
|
||||
let root = PublicationRoot::new(temp.path()).expect("pinned root");
|
||||
let io_path = root.io_path().to_path_buf();
|
||||
let proc_alias: PathBuf = io_path.components().collect();
|
||||
let reg = register_native_publication_root(temp.path(), &io_path).expect("register root");
|
||||
let backend: Arc<dyn super::super::local::LocalIoBackend> =
|
||||
Arc::new(super::super::local::StdBackend::new(temp.path().to_path_buf()));
|
||||
let disk_id = uuid::Uuid::new_v4();
|
||||
|
||||
let bucket_a = format!("proc-fast-a-{}", uuid::Uuid::new_v4());
|
||||
let bucket_b = format!("proc-fast-b-{}", uuid::Uuid::new_v4());
|
||||
let witness_a = reg
|
||||
.witness(&bucket_a, disk_id, Arc::clone(&backend))
|
||||
.expect("witness a before publication");
|
||||
let witness_b = reg
|
||||
.witness(&bucket_b, disk_id, Arc::clone(&backend))
|
||||
.expect("witness b before publication");
|
||||
|
||||
let stat_hits = Arc::new(AtomicUsize::new(0));
|
||||
let stat_hits_hook = Arc::clone(&stat_hits);
|
||||
let stat_guard = prepared_publication_test_hooks::install_at(
|
||||
prepared_publication_test_hooks::Stage::NativeRootIdentity,
|
||||
&proc_alias,
|
||||
move || {
|
||||
stat_hits_hook.fetch_add(1, Ordering::SeqCst);
|
||||
},
|
||||
);
|
||||
|
||||
// Root-level path (`path == alias` or `alias/.`) must be a no-op and must not set `unknown` or stat.
|
||||
record_native_publication(&io_path);
|
||||
record_native_publication(&proc_alias);
|
||||
assert_eq!(stat_hits.load(Ordering::SeqCst), 0, "live proc fast path must skip stat");
|
||||
drop(stat_guard);
|
||||
assert!(validate_native_creation_witnesses(std::slice::from_ref(&witness_a)));
|
||||
assert!(validate_native_creation_witnesses(std::slice::from_ref(&witness_b)));
|
||||
|
||||
// Publishing into `bucket_a` marks only `bucket_a` as started without statting or poisoning `bucket_b`.
|
||||
let stat_hits_hook = Arc::clone(&stat_hits);
|
||||
let stat_guard = prepared_publication_test_hooks::install_at(
|
||||
prepared_publication_test_hooks::Stage::NativeRootIdentity,
|
||||
&proc_alias,
|
||||
move || {
|
||||
stat_hits_hook.fetch_add(1, Ordering::SeqCst);
|
||||
},
|
||||
);
|
||||
record_native_publication(&io_path.join(&bucket_a).join("object/xl.meta"));
|
||||
assert_eq!(stat_hits.load(Ordering::SeqCst), 0, "live proc fast path must skip stat");
|
||||
drop(stat_guard);
|
||||
assert!(!validate_native_creation_witnesses(std::slice::from_ref(&witness_a)));
|
||||
assert!(validate_native_creation_witnesses(std::slice::from_ref(&witness_b)));
|
||||
|
||||
// Non-Normal component (`..`) sets `unknown = true`, invalidating remaining witnesses on that root.
|
||||
let stat_hits_hook = Arc::clone(&stat_hits);
|
||||
let stat_guard = prepared_publication_test_hooks::install_at(
|
||||
prepared_publication_test_hooks::Stage::NativeRootIdentity,
|
||||
&proc_alias,
|
||||
move || {
|
||||
stat_hits_hook.fetch_add(1, Ordering::SeqCst);
|
||||
},
|
||||
);
|
||||
record_native_publication(&io_path.join(&bucket_b).join("../escape"));
|
||||
assert_eq!(stat_hits.load(Ordering::SeqCst), 0, "live proc fast path must skip stat");
|
||||
drop(stat_guard);
|
||||
assert!(!validate_native_creation_witnesses(std::slice::from_ref(&witness_b)));
|
||||
|
||||
// Dropping the last strong owner of the root directory fd retires the live proc entry and falls back to stat.
|
||||
assert!(NATIVE_PUBLICATION_HISTORY.lock().live_proc_roots.contains_key(&proc_alias));
|
||||
drop(root);
|
||||
let stat_hits_hook = Arc::clone(&stat_hits);
|
||||
let _stat_guard = prepared_publication_test_hooks::install_at(
|
||||
prepared_publication_test_hooks::Stage::NativeRootIdentity,
|
||||
&proc_alias,
|
||||
move || {
|
||||
stat_hits_hook.fetch_add(1, Ordering::SeqCst);
|
||||
},
|
||||
);
|
||||
record_native_publication(&io_path.join("after-drop"));
|
||||
assert!(!NATIVE_PUBLICATION_HISTORY.lock().live_proc_roots.contains_key(&proc_alias));
|
||||
assert_eq!(
|
||||
stat_hits.load(Ordering::SeqCst),
|
||||
1,
|
||||
"retired proc root must fall back to native_root_identity"
|
||||
);
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn guarded_first_publication_recovers_from_a_concurrent_parent_prune() {
|
||||
let temp = tempfile::tempdir().expect("temporary disk");
|
||||
|
||||
@@ -303,24 +303,6 @@ 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
|
||||
@@ -328,13 +310,17 @@ pub(crate) fn verified_bitrot_frame<'a>(
|
||||
/// 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 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());
|
||||
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));
|
||||
}
|
||||
Ok((data, verify))
|
||||
}
|
||||
|
||||
@@ -979,11 +965,10 @@ pub struct InlineBuffer {
|
||||
foreground: Vec<u8>,
|
||||
background: Option<crate::disk::background_memory::BackgroundBuffer>,
|
||||
filled: usize,
|
||||
max_len: Option<usize>,
|
||||
}
|
||||
|
||||
impl InlineBuffer {
|
||||
fn new(max_len: Option<usize>) -> Self {
|
||||
fn new() -> Self {
|
||||
let background = crate::disk::current_resource_unit()
|
||||
.and_then(|unit| unit.memory_budget())
|
||||
.map(|budget| crate::disk::background_memory::BackgroundBuffer::new(Some(budget)));
|
||||
@@ -991,7 +976,6 @@ impl InlineBuffer {
|
||||
foreground: Vec::new(),
|
||||
background,
|
||||
filled: 0,
|
||||
max_len,
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1006,22 +990,10 @@ 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 = self
|
||||
.max_len
|
||||
.unwrap_or_else(|| buffer.as_slice().len().checked_mul(2).unwrap_or(length).max(length));
|
||||
let capacity = 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)?;
|
||||
}
|
||||
@@ -1032,13 +1004,6 @@ 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);
|
||||
}
|
||||
@@ -1057,11 +1022,7 @@ impl InlineBuffer {
|
||||
impl CustomWriter {
|
||||
/// Create a new inline buffer writer
|
||||
pub fn new_inline_buffer() -> Self {
|
||||
Self::InlineBuffer(InlineBuffer::new(None))
|
||||
}
|
||||
|
||||
pub(crate) fn new_bounded_inline_buffer(max_len: usize) -> Self {
|
||||
Self::InlineBuffer(InlineBuffer::new(Some(max_len)))
|
||||
Self::InlineBuffer(InlineBuffer::new())
|
||||
}
|
||||
|
||||
/// Create a new disk writer from any AsyncWrite implementation
|
||||
@@ -1514,80 +1475,6 @@ 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;
|
||||
@@ -3056,25 +2943,6 @@ 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;
|
||||
@@ -3089,25 +2957,6 @@ 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,20 +812,12 @@ 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) -> disk::error::Result<i64> {
|
||||
fn bitrot_create_file_size(length: i64, shard_size: usize, checksum_algo: &HashAlgorithm) -> i64 {
|
||||
if length <= 0 {
|
||||
return Ok(length);
|
||||
return length;
|
||||
}
|
||||
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"))
|
||||
let length = length as usize;
|
||||
(length.div_ceil(shard_size) * checksum_algo.size() + length) as i64
|
||||
}
|
||||
|
||||
pub async fn create_bitrot_writer(
|
||||
@@ -851,16 +843,12 @@ 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 {
|
||||
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)
|
||||
}
|
||||
CustomWriter::new_inline_buffer()
|
||||
} else if let Some(disk) = disk {
|
||||
let file = disk.create_file(origvolume, volume, path, framed_length).await?;
|
||||
let length = bitrot_create_file_size(length, shard_size, &checksum_algo);
|
||||
|
||||
let file = disk.create_file(origvolume, volume, path, length).await?;
|
||||
#[cfg(feature = "hotpath")]
|
||||
let file = instrument_raw_shard_writer(file, disk.is_local());
|
||||
CustomWriter::from_file_writer(file)
|
||||
@@ -879,41 +867,23 @@ mod tests {
|
||||
|
||||
#[test]
|
||||
fn bitrot_create_file_size_grows_known_length_by_checksums() {
|
||||
// 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);
|
||||
// 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);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn bitrot_create_file_size_keeps_empty_and_unknown_distinct() {
|
||||
assert_eq!(
|
||||
bitrot_create_file_size(0, 4, &HashAlgorithm::HighwayHash256).expect("empty frame size"),
|
||||
0
|
||||
);
|
||||
assert_eq!(bitrot_create_file_size(0, 4, &HashAlgorithm::HighwayHash256), 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)
|
||||
.expect("unknown length sentinel"),
|
||||
bitrot_create_file_size(rustfs_rio::HashReader::SIZE_PRESERVE_LAYER, 4, &HashAlgorithm::HighwayHash256),
|
||||
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>,
|
||||
}
|
||||
@@ -1792,28 +1762,6 @@ 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;
|
||||
|
||||
@@ -9904,19 +9904,6 @@ 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);
|
||||
@@ -9939,13 +9926,9 @@ 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")
|
||||
@@ -10239,15 +10222,6 @@ 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, 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,
|
||||
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,
|
||||
};
|
||||
use futures::future::join_all;
|
||||
use metrics::counter;
|
||||
@@ -656,8 +656,68 @@ fn verify_inline_body_from_observations<'a>(
|
||||
disks.get(index).is_some_and(Option::is_some)
|
||||
})?;
|
||||
|
||||
try_decode_inline_data_shards(_object, candidate, &data_files, false)
|
||||
.ok_or(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_BODY_VERIFY)
|
||||
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)
|
||||
}
|
||||
|
||||
fn data_read_early_stop_inline_candidate_miss_reason(candidate: &FileInfo) -> Option<&'static str> {
|
||||
@@ -695,7 +755,10 @@ 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);
|
||||
}
|
||||
inline_body_buffering_miss_reason(candidate)
|
||||
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
|
||||
}
|
||||
|
||||
pub(in crate::set_disk) fn non_inline_data_read_candidate_is_safe(candidate: &FileInfo) -> bool {
|
||||
|
||||
+163
-318
@@ -51,13 +51,12 @@ 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_BODY_VERIFY,
|
||||
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_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_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_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_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,
|
||||
@@ -793,8 +792,7 @@ 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: usize = 2 * 1024 * 1024;
|
||||
const INLINE_FAST_PATH_MAX_BLOCKS: usize = 32;
|
||||
const INLINE_FAST_PATH_MAX_OBJECT_SIZE: i64 = 1024 * 1024;
|
||||
|
||||
// --- Metadata Early-Stop Configuration ---
|
||||
|
||||
@@ -6072,51 +6070,6 @@ 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,
|
||||
@@ -6128,12 +6081,18 @@ fn should_use_inline_fast_path_with_plan(
|
||||
return false;
|
||||
}
|
||||
|
||||
if plan.shape().is_none() {
|
||||
let Some(shape) = plan.shape() else {
|
||||
return false;
|
||||
}
|
||||
// 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
|
||||
};
|
||||
// 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
|
||||
}
|
||||
|
||||
enum SmallWritePath {
|
||||
@@ -6222,9 +6181,27 @@ 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<'a>(
|
||||
files: impl Iterator<Item = &'a FileInfo> + Send,
|
||||
async fn build_inline_bitrot_readers(
|
||||
files: &[FileInfo],
|
||||
total_shards: usize,
|
||||
bucket: &str,
|
||||
object: &str,
|
||||
@@ -6234,7 +6211,7 @@ async fn build_inline_bitrot_readers<'a>(
|
||||
skip_verify_bitrot: bool,
|
||||
) -> disk::error::Result<Vec<Option<InlineBitrotReader>>> {
|
||||
let mut readers = Vec::with_capacity(total_shards);
|
||||
for file in files.take(total_shards) {
|
||||
for file in files.iter().take(total_shards) {
|
||||
let reader = if let Some(data) = &file.data {
|
||||
create_bitrot_reader_from_bytes(
|
||||
Some(data.clone()),
|
||||
@@ -6257,83 +6234,38 @@ async fn build_inline_bitrot_readers<'a>(
|
||||
Ok(readers)
|
||||
}
|
||||
|
||||
/// 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
|
||||
}
|
||||
}
|
||||
|
||||
/// 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],
|
||||
#[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,
|
||||
) -> Option<Bytes> {
|
||||
if inline_body_buffering_miss_reason(fi).is_some() {
|
||||
return None;
|
||||
) -> 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);
|
||||
}
|
||||
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))
|
||||
Ok(readers)
|
||||
}
|
||||
|
||||
async fn try_read_inline_data_shards_direct(
|
||||
@@ -6374,6 +6306,10 @@ 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;
|
||||
@@ -6402,14 +6338,31 @@ fn inline_erasure_shard_file_size(total_length: usize, block_size: usize, data_s
|
||||
num_shards * shard_size + last_shard_size
|
||||
}
|
||||
|
||||
type InlineDataShardFiles<'a> = smallvec::SmallVec<[&'a FileInfo; shard_source::INLINE_SHARD_SLOTS]>;
|
||||
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)
|
||||
}
|
||||
|
||||
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<InlineDataShardFiles<'a>> {
|
||||
) -> Option<Vec<&'a FileInfo>> {
|
||||
collect_inline_data_shard_fileinfos_by_index_or_reason(parts_metadata, fi, data_shards, disk_is_online).ok()
|
||||
}
|
||||
|
||||
@@ -6418,7 +6371,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<InlineDataShardFiles<'a>, &'static str> {
|
||||
) -> std::result::Result<Vec<&'a FileInfo>, &'static str> {
|
||||
collect_inline_data_shard_fileinfos_from_observations(
|
||||
parts_metadata
|
||||
.iter()
|
||||
@@ -6435,13 +6388,9 @@ 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<InlineDataShardFiles<'a>, &'static str> {
|
||||
) -> std::result::Result<Vec<&'a FileInfo>, &'static str> {
|
||||
let distribution = &fi.erasure.distribution;
|
||||
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];
|
||||
let mut data_files = vec![None; data_shards];
|
||||
|
||||
for (disk_index, file_info) in observations {
|
||||
if !disk_is_online(disk_index) {
|
||||
@@ -6474,7 +6423,7 @@ fn collect_inline_data_shard_fileinfos_from_observations<'a>(
|
||||
|
||||
data_files
|
||||
.into_iter()
|
||||
.collect::<Option<InlineDataShardFiles<'_>>>()
|
||||
.collect::<Option<Vec<_>>>()
|
||||
.ok_or(GET_METADATA_EARLY_STOP_REASON_DATA_READ_INLINE_MISSING_SHARD)
|
||||
}
|
||||
|
||||
@@ -7440,20 +7389,23 @@ fn join_errs(errs: &[Option<DiskError>]) -> String {
|
||||
errs.join(", ")
|
||||
}
|
||||
|
||||
fn verify_inline_part_bitrot(meta: &FileInfo) -> disk::error::Result<()> {
|
||||
async 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 algo = part_checksum_algorithm(meta, part.number);
|
||||
if !matches!(algo, HashAlgorithm::HighwayHash256S | HashAlgorithm::HighwayHash256SLegacy) {
|
||||
return Err(DiskError::BitrotHashAlgoInvalid);
|
||||
}
|
||||
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 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);
|
||||
// Validate the complete framing before visiting borrowed payloads.
|
||||
// Check framing arithmetic and the physical buffer length before the shared
|
||||
// verifier sizes its scratch buffer from the metadata.
|
||||
let encoded_size = part_size
|
||||
.div_ceil(shard_size)
|
||||
.checked_mul(algo.size())
|
||||
@@ -7462,11 +7414,9 @@ fn verify_inline_part_bitrot(meta: &FileInfo) -> disk::error::Result<()> {
|
||||
if encoded_size != data.len() {
|
||||
return 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(())
|
||||
coding::bitrot_verify(Cursor::new(data), encoded_size, part_size, algo, shard_size)
|
||||
.await
|
||||
.map_err(|_| DiskError::FileCorrupt)
|
||||
}
|
||||
|
||||
fn validate_deep_scan_results(results: &[usize], expected_parts: usize) -> disk::error::Result<()> {
|
||||
@@ -7684,7 +7634,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) {
|
||||
match verify_inline_part_bitrot(meta).await {
|
||||
Ok(()) => CHECK_PART_SUCCESS,
|
||||
Err(DiskError::FileCorrupt) => CHECK_PART_FILE_CORRUPT,
|
||||
Err(err) => return Err(err),
|
||||
@@ -15062,19 +15012,21 @@ 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).expect("healthy data and parity shards should verify");
|
||||
verify_inline_part_bitrot(&meta)
|
||||
.await
|
||||
.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), Err(DiskError::FileCorrupt));
|
||||
assert_eq!(verify_inline_part_bitrot(&meta).await, 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), Err(DiskError::FileCorrupt));
|
||||
assert_eq!(verify_inline_part_bitrot(&meta).await, Err(DiskError::FileCorrupt));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -15088,17 +15040,19 @@ mod tests {
|
||||
empty.parts[0].size = 0;
|
||||
empty.parts[0].actual_size = 0;
|
||||
empty.data = Some(Bytes::new());
|
||||
verify_inline_part_bitrot(&empty).expect("empty inline objects have no bitrot frames");
|
||||
verify_inline_part_bitrot(&empty)
|
||||
.await
|
||||
.expect("empty inline objects have no bitrot frames");
|
||||
empty.data = Some(Bytes::from_static(b"unexpected"));
|
||||
assert_eq!(verify_inline_part_bitrot(&empty), Err(DiskError::FileCorrupt));
|
||||
assert_eq!(verify_inline_part_bitrot(&empty).await, Err(DiskError::FileCorrupt));
|
||||
|
||||
let mut invalid = files[0].clone();
|
||||
invalid.erasure.block_size = 0;
|
||||
assert_eq!(verify_inline_part_bitrot(&invalid), Err(DiskError::FileCorrupt));
|
||||
assert_eq!(verify_inline_part_bitrot(&invalid).await, 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), Err(DiskError::FileCorrupt));
|
||||
assert_eq!(verify_inline_part_bitrot(&invalid).await, Err(DiskError::FileCorrupt));
|
||||
|
||||
let mut oversized = files[0].clone();
|
||||
oversized.erasure.block_size = 2;
|
||||
@@ -15107,7 +15061,7 @@ mod tests {
|
||||
oversized
|
||||
.validate_for_metadata_read()
|
||||
.expect("logical shard length should fit metadata bounds");
|
||||
assert_eq!(verify_inline_part_bitrot(&oversized), Err(DiskError::FileCorrupt));
|
||||
assert_eq!(verify_inline_part_bitrot(&oversized).await, Err(DiskError::FileCorrupt));
|
||||
|
||||
oversized.erasure.block_size = 1 << 40;
|
||||
oversized.size = 1 << 40;
|
||||
@@ -15115,7 +15069,7 @@ mod tests {
|
||||
oversized
|
||||
.validate_for_metadata_read()
|
||||
.expect("large metadata geometry should remain representable");
|
||||
assert_eq!(verify_inline_part_bitrot(&oversized), Err(DiskError::FileCorrupt));
|
||||
assert_eq!(verify_inline_part_bitrot(&oversized).await, Err(DiskError::FileCorrupt));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
@@ -15138,11 +15092,13 @@ 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).expect("historical inline shard should pass deep verification");
|
||||
verify_inline_part_bitrot(&meta)
|
||||
.await
|
||||
.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), Err(DiskError::FileCorrupt));
|
||||
assert_eq!(verify_inline_part_bitrot(&meta).await, Err(DiskError::FileCorrupt));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -15186,48 +15142,6 @@ 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];
|
||||
@@ -15269,100 +15183,6 @@ 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]
|
||||
@@ -15370,7 +15190,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.iter(),
|
||||
&files,
|
||||
erasure.data_shards,
|
||||
"bucket",
|
||||
"object",
|
||||
@@ -15396,7 +15216,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.iter(),
|
||||
&files,
|
||||
erasure.data_shards,
|
||||
"bucket",
|
||||
"object",
|
||||
@@ -15427,7 +15247,7 @@ mod tests {
|
||||
*second = Bytes::from(corrupted);
|
||||
|
||||
let mut readers = build_inline_bitrot_readers(
|
||||
files.iter(),
|
||||
&files,
|
||||
erasure.total_shard_count(),
|
||||
"bucket",
|
||||
"object",
|
||||
@@ -15445,17 +15265,31 @@ mod tests {
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn inline_erasure_size_helpers_match_erasure_methods() {
|
||||
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() {
|
||||
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, 1024 * 1024 + 1, 2 * 1024 * 1024 + 1] {
|
||||
for object_size in [1usize, 1024, 100 * 1024, 1024 * 1024] {
|
||||
assert_eq!(
|
||||
inline_erasure_shard_size(erasure.block_size, erasure.data_shards, uses_legacy),
|
||||
erasure.shard_size()
|
||||
);
|
||||
assert_eq!(
|
||||
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")
|
||||
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)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -15976,14 +15810,25 @@ 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;
|
||||
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));
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -43,26 +43,28 @@ 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, check_object_lock_delete,
|
||||
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,
|
||||
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, 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,
|
||||
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,
|
||||
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_inline_put, should_persist_encryption_original_size,
|
||||
should_force_delete_marker_for_missing_version, 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_decode_inline_data_shards, warn,
|
||||
to_object_err, try_read_inline_data_shards_direct, warn,
|
||||
};
|
||||
use super::bitrot_self_verify::{BitrotSelfVerifyTarget, drop_failed_writer_disks, verify_written_bitrot_shards};
|
||||
use super::delete_recovery::DeleteRecoveryContext;
|
||||
@@ -3094,109 +3096,118 @@ 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);
|
||||
|
||||
// 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) {
|
||||
// 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);
|
||||
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]))?;
|
||||
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| {
|
||||
|
||||
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| {
|
||||
disks.get(index).is_some_and(Option::is_some)
|
||||
})
|
||||
};
|
||||
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 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,
|
||||
let read_length = inline_erasure_shard_file_offset(
|
||||
0,
|
||||
object_size,
|
||||
object_size,
|
||||
fi.erasure.block_size,
|
||||
data_shards,
|
||||
fi.uses_legacy_checksum,
|
||||
);
|
||||
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);
|
||||
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(),
|
||||
);
|
||||
}
|
||||
|
||||
// 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],
|
||||
));
|
||||
}
|
||||
// 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
|
||||
{
|
||||
if let Some(decode_stage_start) = decode_stage_start {
|
||||
rustfs_io_metrics::record_get_object_stage_duration_by_size(
|
||||
GET_OBJECT_PATH_INLINE_DIRECT,
|
||||
@@ -3207,17 +3218,94 @@ impl crate::storage_api_contracts::object::ObjectIO for SetDisks {
|
||||
);
|
||||
}
|
||||
|
||||
body = Some(Bytes::from(output.into_inner()));
|
||||
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);
|
||||
}
|
||||
}
|
||||
if let Some(body) = body {
|
||||
|
||||
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(),
|
||||
);
|
||||
}
|
||||
|
||||
record_get_object_reader_path_observation(GET_OBJECT_PATH_INLINE_DIRECT, object_class, size_bucket);
|
||||
return Ok(GetObjectReader {
|
||||
let reader = GetObjectReader {
|
||||
stream: Box::new(Cursor::new(body.clone())),
|
||||
object_info,
|
||||
buffered_body: Some(body),
|
||||
body_source: GetObjectBodySource::Unprobed,
|
||||
});
|
||||
};
|
||||
return Ok(reader);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4696,19 +4784,25 @@ 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);
|
||||
// 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(),
|
||||
// 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,
|
||||
opts.versioned,
|
||||
protect_write,
|
||||
);
|
||||
let multi_block_inline =
|
||||
is_inline_buffer && usize::try_from(put_object_size).is_ok_and(|size| size > erasure.block_size);
|
||||
) && usize::try_from(inline_admission_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;
|
||||
@@ -4863,9 +4957,6 @@ 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);
|
||||
// }
|
||||
@@ -14982,7 +15073,7 @@ mod inline_put_commit_path_tests {
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn unprotected_puts_keep_oversized_inline_candidates_external() {
|
||||
async fn unprotected_puts_keep_multi_block_inline_candidates_external() {
|
||||
for transformed in [true, false] {
|
||||
let (temp_dirs, disk_stores, set_disks) = hermetic_set_disks(4).await;
|
||||
let storage_class =
|
||||
@@ -14992,9 +15083,9 @@ mod inline_put_commit_path_tests {
|
||||
let bucket = "unprotected-inline-candidates";
|
||||
let object = "object.bin";
|
||||
make_bucket(&disk_stores, bucket).await;
|
||||
// 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);
|
||||
// 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);
|
||||
let (mut reader, opts) = if transformed {
|
||||
transformed_put(plaintext.clone())
|
||||
} else {
|
||||
@@ -15017,7 +15108,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 the materialization cap must stay external (transformed={transformed})"
|
||||
"disk {disk_index}: a payload above block_size must stay external (transformed={transformed})"
|
||||
);
|
||||
}
|
||||
assert!(
|
||||
@@ -15264,14 +15355,14 @@ mod inline_put_commit_path_tests {
|
||||
|
||||
#[tokio::test]
|
||||
#[serial]
|
||||
async fn ec_8_4_default_budget_inlines_single_block_objects() {
|
||||
async fn ec_8_4_default_budget_keeps_large_inline_candidate_out_of_xl_meta() {
|
||||
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; 1024 * 1024];
|
||||
let payload = vec![0x5c; 300 * 1024];
|
||||
make_bucket(&disk_stores, bucket).await;
|
||||
|
||||
let mut reader = PutObjReader::from_vec(payload.clone());
|
||||
@@ -15283,7 +15374,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 inline path");
|
||||
.expect("EC8+4 PUT should commit through the non-inline path");
|
||||
|
||||
for (disk_index, disk) in disk_stores.iter().enumerate() {
|
||||
let file_info = disk
|
||||
@@ -15292,19 +15383,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 persist the shard in xl.meta");
|
||||
assert!(!file_info.inline_data(), "disk {disk_index} must keep the shard outside xl.meta");
|
||||
}
|
||||
|
||||
let mut object_reader = set_disks
|
||||
.get_object_reader(bucket, object, None, HeaderMap::new(), &ObjectOptions::default())
|
||||
.await
|
||||
.expect("inline EC8+4 object should remain readable");
|
||||
.expect("non-inline EC8+4 object should remain readable");
|
||||
let mut restored = Vec::new();
|
||||
object_reader
|
||||
.stream
|
||||
.read_to_end(&mut restored)
|
||||
.await
|
||||
.expect("inline EC8+4 object should stream");
|
||||
.expect("non-inline EC8+4 object should stream");
|
||||
assert_eq!(restored, payload);
|
||||
}
|
||||
|
||||
@@ -15317,7 +15408,7 @@ mod inline_put_commit_path_tests {
|
||||
);
|
||||
let bucket = "ec-8-4-versioned-inline-budget";
|
||||
let object = "object.bin";
|
||||
let payload = vec![0x73; 128 * 1024];
|
||||
let payload = vec![0x73; 64 * 1024];
|
||||
make_bucket(&disk_stores, bucket).await;
|
||||
|
||||
let options = ObjectOptions {
|
||||
@@ -15340,378 +15431,22 @@ 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 persist the versioned shard in xl.meta");
|
||||
assert!(
|
||||
!file_info.inline_data(),
|
||||
"disk {disk_index} must keep the versioned shard outside xl.meta"
|
||||
);
|
||||
}
|
||||
|
||||
let mut object_reader = set_disks
|
||||
.get_object_reader(bucket, object, None, HeaderMap::new(), &options)
|
||||
.await
|
||||
.expect("versioned inline EC8+4 object should remain readable");
|
||||
.expect("versioned non-inline EC8+4 object should remain readable");
|
||||
let mut restored = Vec::new();
|
||||
object_reader
|
||||
.stream
|
||||
.read_to_end(&mut restored)
|
||||
.await
|
||||
.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");
|
||||
.expect("versioned non-inline EC8+4 object should stream");
|
||||
assert_eq!(restored, payload);
|
||||
}
|
||||
|
||||
@@ -22592,17 +22327,15 @@ 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;
|
||||
|
||||
/// Baseline external-shard payload for the four-drive cleanup fixtures.
|
||||
/// Wider layouts derive their payload from the effective inline budget.
|
||||
/// Large enough that the erasure shards are written as real tmp files
|
||||
/// (never inlined into xl.meta), so the cleanup tests exercise actual cleanup.
|
||||
const TEST_OBJECT_SIZE: usize = 1 << 20;
|
||||
|
||||
/// Entries under `.rustfs.sys/tmp` on every disk, excluding the `.trash`
|
||||
@@ -23031,16 +22764,6 @@ 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 {
|
||||
@@ -23051,14 +22774,13 @@ 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; payload_size]), &options)
|
||||
set.put_object(bucket, &object, &mut PutObjReader::from_vec(vec![0x17; TEST_OBJECT_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()
|
||||
@@ -23077,7 +22799,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; payload_size];
|
||||
let payload = vec![0xa3; TEST_OBJECT_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,
|
||||
StorageError, adaptive_duplex_buffer_size, build_get_codec_streaming_decode_engine, build_inline_bitrot_readers_from_refs,
|
||||
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, part_checksum_algorithm, reduce_read_quorum_errs,
|
||||
to_object_err, try_read_inline_data_shards_direct, warn,
|
||||
is_multipart_reader_setup_prefetch_enabled, object_fits_single_block, 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,
|
||||
@@ -1476,7 +1476,12 @@ impl SetDisks {
|
||||
|
||||
let erasure = erasure_cache.get_for_file_info(fi)?;
|
||||
|
||||
let checksum_algo = part_checksum_algorithm(fi, part.number);
|
||||
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 read_length = erasure.shard_file_offset(0, object_size, object_size);
|
||||
|
||||
if fi.data.is_some() {
|
||||
@@ -1491,9 +1496,8 @@ impl SetDisks {
|
||||
};
|
||||
|
||||
let reader_setup_stage_start = Instant::now();
|
||||
let mut readers = build_inline_bitrot_readers(
|
||||
data_files.iter().copied(),
|
||||
data_files.len(),
|
||||
let mut readers = build_inline_bitrot_readers_from_refs(
|
||||
&data_files,
|
||||
bucket,
|
||||
object,
|
||||
read_length,
|
||||
@@ -1765,7 +1769,7 @@ impl SetDisks {
|
||||
"Streaming multipart part"
|
||||
);
|
||||
|
||||
let checksum_algo = part_checksum_algorithm(&fi, part_number);
|
||||
let checksum_algo = multipart_part_checksum_algo(&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));
|
||||
@@ -1829,7 +1833,7 @@ impl SetDisks {
|
||||
part_number: next_number,
|
||||
read_offset: 0,
|
||||
read_length: erasure.shard_file_offset(0, next_length, next_size),
|
||||
checksum_algo: part_checksum_algorithm(&fi, next_number),
|
||||
checksum_algo: multipart_part_checksum_algo(&fi, next_number),
|
||||
};
|
||||
let files = Arc::clone(&files);
|
||||
let disks = Arc::clone(&disks);
|
||||
@@ -2426,7 +2430,12 @@ impl SetDisks {
|
||||
if part_length > part_size {
|
||||
return Err(Error::other("codec streaming reader part length exceeds part size"));
|
||||
}
|
||||
let checksum_algo = part_checksum_algorithm(fi, part_number);
|
||||
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 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();
|
||||
@@ -2715,6 +2724,17 @@ 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()
|
||||
}
|
||||
|
||||
@@ -1,47 +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.
|
||||
|
||||
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: "serde_json::to_string(opts)?",
|
||||
policy: RequestJsonPolicy::MsgpackOnlyEligible,
|
||||
json_encoder: "let opts = match serde_json::to_string(&opts) {",
|
||||
policy: RequestJsonPolicy::AlwaysDualWriteUntilFallbackZero,
|
||||
},
|
||||
RequestCompatSendSite {
|
||||
field: CompatPayloadField {
|
||||
@@ -109,8 +109,8 @@ pub const REQUEST_COMPAT_SEND_SITES: &[RequestCompatSendSite] = &[
|
||||
json_field: "versions",
|
||||
bin_field: "versions_bin",
|
||||
},
|
||||
json_encoder: "versions_json.push(serde_json::to_string(version)?);",
|
||||
policy: RequestJsonPolicy::MsgpackOnlyEligible,
|
||||
json_encoder: "versions_str.push(match serde_json::to_string(file_info_versions) {",
|
||||
policy: RequestJsonPolicy::AlwaysDualWriteUntilFallbackZero,
|
||||
},
|
||||
RequestCompatSendSite {
|
||||
field: CompatPayloadField {
|
||||
|
||||
@@ -913,9 +913,8 @@ pub struct DeleteVersionsRequest {
|
||||
pub versions: ::prost::alloc::vec::Vec<::prost::alloc::string::String>,
|
||||
#[prost(string, tag = "4")]
|
||||
pub opts: ::prost::alloc::string::String,
|
||||
/// 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.
|
||||
/// 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.
|
||||
#[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::MsgpackOnlyEligible),
|
||||
("DeleteVersionsRequest", "versions", RequestJsonPolicy::MsgpackOnlyEligible),
|
||||
("DeleteVersionsRequest", "opts", RequestJsonPolicy::AlwaysDualWriteUntilFallbackZero,),
|
||||
("DeleteVersionsRequest", "versions", RequestJsonPolicy::AlwaysDualWriteUntilFallbackZero,),
|
||||
("ReadMultipleRequest", "read_multiple_req", RequestJsonPolicy::MsgpackOnlyEligible),
|
||||
("ReadVersionRequest", "opts", RequestJsonPolicy::MsgpackOnlyEligible),
|
||||
("RenameDataRequest", "file_info", RequestJsonPolicy::MsgpackOnlyEligible),
|
||||
|
||||
@@ -583,9 +583,8 @@ message DeleteVersionsRequest {
|
||||
string volume = 2;
|
||||
repeated string versions = 3;
|
||||
string opts = 4;
|
||||
// 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.
|
||||
// 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.
|
||||
repeated bytes versions_bin = 5;
|
||||
bytes opts_bin = 6;
|
||||
}
|
||||
|
||||
@@ -411,10 +411,13 @@ impl ListObjectsOptions {
|
||||
|
||||
fn decode_s3_name(name: &str, encoding_type: &str) -> Result<String, std::io::Error> {
|
||||
match encoding_type {
|
||||
"url" => urlencoding::decode(name)
|
||||
.map(|decoded| decoded.into_owned())
|
||||
.map_err(|err| std::io::Error::new(ErrorKind::InvalidData, err)),
|
||||
_ => Ok(name.to_string()),
|
||||
"url" => {
|
||||
//return url::QueryUnescape(name);
|
||||
return Ok(name.to_string());
|
||||
}
|
||||
_ => {
|
||||
return Ok(name.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -446,170 +449,6 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn url_encoded_s3_names_are_decoded() {
|
||||
for (encoded, expected) in [
|
||||
("test_file%283%29.png", "test_file(3).png"),
|
||||
("dir%20a/file.txt", "dir a/file.txt"),
|
||||
("%E4%B8%AD%E6%96%87.txt", "中文.txt"),
|
||||
("%F0%9F%98%80.txt", "😀.txt"),
|
||||
("file%2bname+%25.txt", "file+name+%.txt"),
|
||||
("literal%252F.txt", "literal%2F.txt"),
|
||||
("dir%2Ffile%00%01.txt", "dir/file\0\u{1}.txt"),
|
||||
("", ""),
|
||||
] {
|
||||
assert_eq!(decode_s3_name(encoded, "url").expect("valid URL-encoded S3 key"), expected);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn s3_names_without_url_encoding_are_preserved() {
|
||||
for encoding in ["", "unknown"] {
|
||||
let name = "中文+%20%FF.txt";
|
||||
assert_eq!(decode_s3_name(name, encoding).expect("unencoded key should pass through"), name);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn url_encoded_s3_names_reject_invalid_utf8() {
|
||||
for name in ["%FF", "%C3%28", "%E4%B8", "%ED%A0%80", "%C0%AF"] {
|
||||
let err = decode_s3_name(name, "url").expect_err("invalid UTF-8 must not become a different object key");
|
||||
assert_eq!(err.kind(), ErrorKind::InvalidData);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn url_encoded_s3_names_preserve_malformed_percent_escapes() {
|
||||
// Match urlencoding's permissive handling without treating '+' as a space.
|
||||
for name in ["file%", "file%2", "file%GG+name"] {
|
||||
assert_eq!(decode_s3_name(name, "url").expect("literal malformed escape"), name);
|
||||
}
|
||||
}
|
||||
|
||||
async fn list_response_fixture(responses: Vec<&'static str>) -> (TransitionClient, tokio::task::JoinHandle<Vec<url::Url>>) {
|
||||
let listener = TcpListener::bind("127.0.0.1:0").await.expect("list fixture should bind");
|
||||
let endpoint = listener.local_addr().expect("list fixture address").to_string();
|
||||
let fixture = tokio::spawn(async move {
|
||||
tokio::time::timeout(Duration::from_secs(5), async move {
|
||||
let mut requests = Vec::new();
|
||||
for body in responses {
|
||||
let (mut stream, _) = listener.accept().await.expect("list fixture should accept request");
|
||||
let mut request = Vec::new();
|
||||
let mut buffer = [0; 1024];
|
||||
while !request.windows(4).any(|window| window == b"\r\n\r\n") {
|
||||
let read = stream.read(&mut buffer).await.expect("list fixture should read request");
|
||||
assert_ne!(read, 0, "request headers must be complete");
|
||||
request.extend_from_slice(&buffer[..read]);
|
||||
assert!(request.len() <= 16 * 1024, "fixture request headers should be bounded");
|
||||
}
|
||||
let request = std::str::from_utf8(&request).expect("request headers should be UTF-8");
|
||||
let target = request.split_whitespace().nth(1).expect("request should have a target");
|
||||
requests.push(url::Url::parse(&format!("http://localhost{target}")).expect("request URL should parse"));
|
||||
let response = format!(
|
||||
"HTTP/1.1 200 OK\r\nContent-Type: application/xml\r\nContent-Length: {}\r\nConnection: close\r\n\r\n{body}",
|
||||
body.len()
|
||||
);
|
||||
stream.write_all(response.as_bytes()).await.expect("list fixture should send response");
|
||||
}
|
||||
requests
|
||||
})
|
||||
.await
|
||||
.expect("list fixture should finish within its deadline")
|
||||
});
|
||||
let client = TransitionClient::new_with_timeouts(
|
||||
&endpoint,
|
||||
timeout_test_options(),
|
||||
"",
|
||||
TransitionClientTimeouts::new(Duration::from_secs(1), Duration::from_secs(1), Duration::from_secs(1)),
|
||||
)
|
||||
.await
|
||||
.expect("list fixture client should build");
|
||||
client
|
||||
.bucket_loc_cache
|
||||
.lock()
|
||||
.expect("location cache should lock")
|
||||
.set("bucket", "us-east-1");
|
||||
(client, fixture)
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_objects_v2_decodes_prefixes_and_preserves_continuation_tokens() {
|
||||
let (client, fixture) = list_response_fixture(vec![
|
||||
r#"<ListBucketResult><EncodingType>url</EncodingType><IsTruncated>true</IsTruncated>
|
||||
<CommonPrefixes><Prefix>dir%20a/</Prefix></CommonPrefixes>
|
||||
<NextContinuationToken>opaque%2F+token</NextContinuationToken></ListBucketResult>"#,
|
||||
"<ListBucketResult><EncodingType>url</EncodingType><IsTruncated>false</IsTruncated></ListBucketResult>",
|
||||
])
|
||||
.await;
|
||||
let first = client
|
||||
.list_objects_v2_query("bucket", "", "", false, false, "/", "", 1, HeaderMap::new())
|
||||
.await
|
||||
.expect("first object page should decode");
|
||||
assert_eq!(first.common_prefixes[0].prefix, "dir a/");
|
||||
assert_eq!(first.next_continuation_token, "opaque%2F+token");
|
||||
let second = client
|
||||
.list_objects_v2_query("bucket", "", &first.next_continuation_token, false, false, "/", "", 1, HeaderMap::new())
|
||||
.await
|
||||
.expect("second object page should succeed");
|
||||
assert!(!second.is_truncated);
|
||||
let requests = fixture.await.expect("object list fixture should join");
|
||||
let query: HashMap<_, _> = requests[1].query_pairs().into_owned().collect();
|
||||
assert_eq!(query.get("continuation-token").map(String::as_str), Some("opaque%2F+token"));
|
||||
assert_eq!(query.get("encoding-type").map(String::as_str), Some("url"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_versions_decodes_names_and_round_trips_pagination_markers() {
|
||||
let (client, fixture) = list_response_fixture(vec![
|
||||
r#"<ListVersionsResult><EncodingType>url</EncodingType><IsTruncated>true</IsTruncated>
|
||||
<Version><Key>dir%20a/%E4%B8%AD%E6%96%87%2B%252F.txt</Key><VersionId>version%2F+id</VersionId></Version>
|
||||
<DeleteMarker><Key>deleted%20file%2B.txt</Key><VersionId>delete%2F+id</VersionId></DeleteMarker>
|
||||
<CommonPrefixes><Prefix>dir%20a/</Prefix></CommonPrefixes>
|
||||
<NextKeyMarker>dir%20a/%E4%B8%AD%E6%96%87%2B%252F.txt</NextKeyMarker>
|
||||
<NextVersionIdMarker>version%2F+id</NextVersionIdMarker></ListVersionsResult>"#,
|
||||
"<ListVersionsResult><EncodingType>url</EncodingType><IsTruncated>false</IsTruncated></ListVersionsResult>",
|
||||
])
|
||||
.await;
|
||||
let mut opts = ListObjectsOptions::default();
|
||||
opts.set("prefix", "dir a/");
|
||||
let first = client
|
||||
.list_object_versions_query("bucket", &opts, "", "", "/")
|
||||
.await
|
||||
.expect("first version page");
|
||||
assert_eq!(first.versions[0].key, "dir a/中文+%2F.txt");
|
||||
assert_eq!(first.versions[0].version_id, "version%2F+id");
|
||||
assert_eq!(first.delete_markers[0].key, "deleted file+.txt");
|
||||
assert_eq!(first.delete_markers[0].version_id, "delete%2F+id");
|
||||
assert_eq!(first.common_prefixes[0].prefix, "dir a/");
|
||||
assert_eq!(first.next_key_marker, "dir a/中文+%2F.txt");
|
||||
assert_eq!(first.next_version_id_marker, "version%2F+id");
|
||||
let second = client
|
||||
.list_object_versions_query("bucket", &opts, &first.next_key_marker, &first.next_version_id_marker, "/")
|
||||
.await
|
||||
.expect("second version page");
|
||||
assert!(!second.is_truncated);
|
||||
let requests = fixture.await.expect("version list fixture should join");
|
||||
let query: HashMap<_, _> = requests[1].query_pairs().into_owned().collect();
|
||||
assert_eq!(query.get("key-marker").map(String::as_str), Some("dir a/中文+%2F.txt"));
|
||||
assert_eq!(query.get("version-id-marker").map(String::as_str), Some("version%2F+id"));
|
||||
assert_eq!(query.get("prefix").map(String::as_str), Some("dir a/"));
|
||||
assert_eq!(query.get("encoding-type").map(String::as_str), Some("url"));
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn list_versions_rejects_invalid_utf8_keys() {
|
||||
let (client, fixture) = list_response_fixture(vec![
|
||||
"<ListVersionsResult><EncodingType>url</EncodingType><Version><Key>%FF</Key></Version></ListVersionsResult>",
|
||||
])
|
||||
.await;
|
||||
let err = client
|
||||
.list_object_versions_query("bucket", &ListObjectsOptions::default(), "", "", "")
|
||||
.await
|
||||
.expect_err("invalid UTF-8 in a remote key should fail the listing");
|
||||
assert_eq!(err.kind(), ErrorKind::InvalidData);
|
||||
assert_eq!(fixture.await.expect("invalid key fixture should join").len(), 1);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn list_versions_xml_preserves_versions_and_delete_markers() {
|
||||
let xml = br#"
|
||||
|
||||
@@ -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 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).
|
||||
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)).
|
||||
|
||||
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`). 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.
|
||||
`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.
|
||||
|
||||
- **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,12 +292,10 @@ 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. `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.
|
||||
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.
|
||||
|
||||
---
|
||||
|
||||
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.
|
||||
@@ -381,7 +379,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`.
|
||||
- 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.
|
||||
- `block_size = 1 MiB` (`BLOCK_SIZE_V2`), stored per version.
|
||||
- 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::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::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).
|
||||
|
||||
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`) | Overrides the fixed 128 KiB 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`) | Replaces the scaled 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,9 +103,7 @@ 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 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.
|
||||
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.
|
||||
|
||||
### 4.4 Write and read paths
|
||||
|
||||
|
||||
@@ -228,6 +228,27 @@ Every offered Ping is recorded, including schedule drops, deadlines and errors.
|
||||
|
||||
Use identical probe source and settings on the two frozen library revisions, in separate Cargo targets, and record the harness overlay and binary identity independently from the already-built clean server binaries. Qualify repeated A cells and then A1/B1/B2/A2 before expanding to coalescing, isolation, pool or window experiments. A successful local mock regression verifies the probe's calling and accounting boundaries; acceptance against the actual authenticated four-node services is still required.
|
||||
|
||||
### Timeout-boundary evidence
|
||||
|
||||
Use `scripts/check_internode_rpc_timeout_boundary.py` after a task-owned fault injector has recorded three independent probe reports: a stall whose measured duration remains below the declared RPC timeout, a stall whose requested and measured durations both exceed it, and a no-fault recovery run. The gate does not inject faults, deploy services or infer a timeout from wall-clock labels; the manifest references separate measured fault receipts and the raw reports.
|
||||
|
||||
```json
|
||||
{
|
||||
"schema": 1,
|
||||
"scope": "internode-rpc-timeout-boundary",
|
||||
"rpc_timeout_ms": 10000,
|
||||
"under_budget": {"fault_receipt": "under-fault.json", "report": "under.json"},
|
||||
"over_budget": {"fault_receipt": "over-fault.json", "report": "over.json"},
|
||||
"recovery": {"report": "recovery.json"}
|
||||
}
|
||||
```
|
||||
|
||||
```bash
|
||||
python3 scripts/check_internode_rpc_timeout_boundary.py --manifest /path/to/manifest.json --out /path/to/verification.json
|
||||
```
|
||||
|
||||
Each fault receipt is a bounded JSON object containing a non-empty `target`, `requested_stall_ms` and `actual_stall_ms`. Exit 0 requires complete bulk coverage, exact offered-control coverage, no errors below the timeout, at least one `deadline` above it, and a zero-error recovery report. `schedule_drop` and `rpc_error` never substitute for the expected deadline. Exit 1 means structurally complete evidence did not satisfy the boundary; exit 2 means the evidence is invalid. The verifier binds all reports and fault receipts by SHA-256, rejects path escape/reuse and refuses to overwrite or alias raw evidence. Deployment ownership, actual fault delivery, phase-scoped telemetry and performance attribution remain separate gates.
|
||||
|
||||
## Acceptance gates
|
||||
|
||||
Record the verdict (pass/fail plus measured delta) in the paired directory's summary.
|
||||
|
||||
@@ -66,26 +66,20 @@ 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 |
|
||||
|
||||
Single-version delete fields retain dual-write until their own observation window establishes fleet-wide readiness.
|
||||
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):
|
||||
|
||||
| Direction | Message / field | Status |
|
||||
| --- | --- | --- |
|
||||
| request | `DeleteVersion.file_info` (`FileInfo`) | `_bin` present; dual-write; converge after its own window |
|
||||
| request | `DeleteVersion.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.
|
||||
| request | `DeleteVersions.versions` (`FileInfoVersions`) | same |
|
||||
| request | `DeleteVersions.opts` (`DeleteOptions`) | same |
|
||||
|
||||
Still JSON-only:
|
||||
|
||||
|
||||
@@ -68,7 +68,6 @@ 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 |
|
||||
@@ -109,38 +108,6 @@ 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 |
|
||||
|
||||
@@ -33,7 +33,6 @@ use crate::app::object::shared::reject_veeam_sosapi_mutation;
|
||||
use crate::app::runtime_sources::{AppContext, current_object_store_handle_for_context};
|
||||
use crate::app::storage_api::object_meta_usecase::contract::ObjectOperations as _;
|
||||
use crate::app::storage_api::object_meta_usecase::validate_bucket_object_lock_enabled;
|
||||
use crate::app::storage_api::object_usecase::error::is_err_version_not_found;
|
||||
use crate::app::storage_api::object_usecase::options::get_opts;
|
||||
use crate::app::storage_api::object_usecase::{ECStore, StorageObjectInfo as ObjectInfo};
|
||||
use crate::error::ApiError;
|
||||
@@ -64,7 +63,8 @@ impl ObjectMetaUsecase {
|
||||
}
|
||||
}
|
||||
|
||||
/// Looks up an object's metadata in a bucket with Object Lock enabled.
|
||||
/// The version of `key` that `version_id` names, on a bucket with Object Lock enabled. A failed
|
||||
/// read is `InternalError`, whatever the store's reason.
|
||||
async fn locked_object_info(
|
||||
store: &ECStore,
|
||||
envelope: &RequestEnvelope,
|
||||
@@ -73,14 +73,10 @@ async fn locked_object_info(
|
||||
version_id: Option<String>,
|
||||
) -> S3Result<ObjectInfo> {
|
||||
validate_bucket_object_lock_enabled(bucket).await?;
|
||||
let explicit_version = version_id.is_some();
|
||||
let opts = get_opts(bucket, key, version_id, None, envelope.headers())
|
||||
.await
|
||||
.map_err(ApiError::from)?;
|
||||
store.get_object_info(bucket, key, &opts).await.map_err(|error| {
|
||||
if explicit_version && is_err_version_not_found(&error) {
|
||||
return ApiError::from(error).into();
|
||||
}
|
||||
error!(
|
||||
component = "storage",
|
||||
subsystem = "object",
|
||||
|
||||
@@ -9483,34 +9483,20 @@ mod tests {
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
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 {
|
||||
#[tokio::test]
|
||||
async fn target_delete_quorum_failure_restores_remote_marker_and_retries_fail() {
|
||||
use crate::storage::storage_api::{
|
||||
ecstore_disk::{DiskOption, new_disk},
|
||||
contract::object::ObjectOperations,
|
||||
ecstore_disk::{DeleteOptions, DiskOption, ReadOptions, new_disk},
|
||||
ecstore_error::StorageError,
|
||||
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");
|
||||
@@ -9558,104 +9544,6 @@ 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";
|
||||
@@ -9674,7 +9562,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
|
||||
@@ -9789,8 +9677,13 @@ mod tests {
|
||||
assert_eq!(restored.data, Some(payload.clone()));
|
||||
}
|
||||
}
|
||||
*set.disks.write().await = local_disks.iter().cloned().map(Some).collect();
|
||||
target.close().await;
|
||||
*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");
|
||||
}
|
||||
|
||||
#[cfg(not(windows))]
|
||||
|
||||
@@ -245,34 +245,6 @@ 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,
|
||||
@@ -995,17 +967,21 @@ impl NodeService {
|
||||
)?;
|
||||
let request = request.into_inner();
|
||||
if let Some(disk) = self.find_disk(&request.disk).await? {
|
||||
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 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 opts = match decode_msgpack_or_json::<DeleteOptions>(&request.opts_bin, &request.opts, "DeleteOptions") {
|
||||
Ok(opts) => opts,
|
||||
Err(err) => {
|
||||
@@ -2938,20 +2914,19 @@ impl NodeService {
|
||||
mod tests {
|
||||
use super::{
|
||||
DeleteOptions, INTERNODE_OPERATION_GRPC_BATCH_READ_VERSION, INTERNODE_OPERATION_GRPC_READ_MULTIPLE,
|
||||
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,
|
||||
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,
|
||||
};
|
||||
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, FileInfoVersions};
|
||||
use rustfs_filemeta::FileInfo;
|
||||
use rustfs_io_metrics::internode_metrics::global_internode_metrics;
|
||||
use rustfs_protos::proto_gen::node_service::{DeleteVersionsRequest, ReadVersionRequest};
|
||||
use rustfs_protos::proto_gen::node_service::ReadVersionRequest;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use serial_test::serial;
|
||||
use tonic::Request;
|
||||
@@ -2963,118 +2938,6 @@ 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 {
|
||||
|
||||
@@ -14857,91 +14857,6 @@ fn object_metadata_borrowed_guard_rejects_test_only_replacements() {
|
||||
assert!(message.contains("reserved-prefix guard calls"), "{message}");
|
||||
}
|
||||
|
||||
#[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())");
|
||||
|
||||
@@ -318,27 +318,6 @@ async fn object_metadata_answers_as_stored(server: rustfs::embedded::RustFSServe
|
||||
let until = retention.retain_until_date().expect("a retain-until date");
|
||||
assert_eq!(until.secs(), 2_051_305_200, "the stored instant, 2035-01-01T23:00:00Z");
|
||||
|
||||
let missing_version = "00000000-0000-4000-8000-000000000000";
|
||||
let missing_retention = client
|
||||
.get_object_retention()
|
||||
.bucket(&locked)
|
||||
.key("stored")
|
||||
.version_id(missing_version)
|
||||
.send()
|
||||
.await
|
||||
.expect_err("retention for a missing version");
|
||||
assert_eq!(refusal(&missing_retention), (Some("NoSuchVersion".to_owned()), Some(404)));
|
||||
|
||||
let missing_hold = client
|
||||
.get_object_legal_hold()
|
||||
.bucket(&locked)
|
||||
.key("stored")
|
||||
.version_id(missing_version)
|
||||
.send()
|
||||
.await
|
||||
.expect_err("legal hold for a missing version");
|
||||
assert_eq!(refusal(&missing_hold), (Some("NoSuchVersion".to_owned()), Some(404)));
|
||||
|
||||
let missing = client
|
||||
.get_object_tagging()
|
||||
.bucket(BUCKET)
|
||||
|
||||
@@ -130,6 +130,7 @@ their issue closes.
|
||||
| `hotpath_warp_ab_gate.sh` | dev-tool | Relative-budget gate evaluated over the warp A/B results | used by `run_hotpath_warp_ab.sh`; hotpath runbook |
|
||||
| `run_internode_grpc_ab_bench.sh` | dev-tool | One-click A/B driver for the internode gRPC optimization stages | `docs/operations/internode-grpc-benchmark-runbook.md` |
|
||||
| `run_internode_transport_baseline.sh` | dev-tool | Internode transport baseline runner | internode runbook; `crates/io-metrics/README.md` |
|
||||
| `check_internode_rpc_timeout_boundary.py` | dev-tool | Verifies under-budget success, over-budget deadlines and post-stall recovery from recorded internode RPC probe reports | internode gRPC benchmark runbook; `test_internode_rpc_timeout_boundary.py` |
|
||||
| `run_four_node_cluster_failover_bench.sh` | dev-tool | Four-node cluster failover benchmark with configurable host ports and optional server-only image build | `docker/compose/README.md`; internode runbook |
|
||||
| `run_object_batch_bench.sh` | dev-tool | Batch object benchmark runner with PUT-specific Warp summary extraction | internode + scanner runbooks |
|
||||
| `test_object_batch_bench.sh` | dev-tool | Regression test for Warp PUT summary extraction | `scripts/test_object_batch_bench.sh` |
|
||||
|
||||
+163
@@ -0,0 +1,163 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Verify recorded internode RPC timeout-boundary and recovery evidence."""
|
||||
|
||||
import argparse
|
||||
import hashlib
|
||||
import json
|
||||
from pathlib import Path
|
||||
import sys
|
||||
|
||||
|
||||
MAX_MANIFEST_BYTES = 1024 * 1024
|
||||
MAX_REPORT_BYTES = 512 * 1024 * 1024
|
||||
|
||||
|
||||
def require(condition, message):
|
||||
if not condition:
|
||||
raise ValueError(message)
|
||||
|
||||
|
||||
def unique_object(pairs):
|
||||
result = {}
|
||||
for key, value in pairs:
|
||||
require(key not in result, f"duplicate JSON key: {key}")
|
||||
result[key] = value
|
||||
return result
|
||||
|
||||
|
||||
def uint(value, name):
|
||||
require(type(value) is int and value >= 0, f"invalid {name}")
|
||||
return value
|
||||
|
||||
|
||||
def load(path, limit):
|
||||
require(path.is_file() and path.stat().st_size <= limit, f"missing or oversized evidence: {path.name}")
|
||||
raw = path.read_bytes()
|
||||
return json.loads(raw, object_pairs_hook=unique_object), hashlib.sha256(raw).hexdigest()
|
||||
|
||||
|
||||
def evidence_path(root, value, seen):
|
||||
require(isinstance(value, str) and value, "missing evidence path")
|
||||
path = (root / value).resolve()
|
||||
require(path == root or root in path.parents, "evidence path escapes manifest directory")
|
||||
require(path not in seen, "evidence file reused across phases")
|
||||
seen.add(path)
|
||||
return path
|
||||
|
||||
|
||||
def samples(report, operation):
|
||||
rows = report.get("samples")
|
||||
require(isinstance(rows, list) and rows, "missing probe samples")
|
||||
return [row for row in rows if row.get("operation") == operation]
|
||||
|
||||
|
||||
def report_status(report):
|
||||
require(report.get("complete") is True, "probe report is incomplete")
|
||||
require(report.get("bulk_coverage_verified") is True, "probe report lacks validated bulk coverage")
|
||||
duration = uint(report.get("offered_duration_secs"), "offered duration")
|
||||
rate = uint(report.get("control_rps"), "control rate")
|
||||
expected = uint(report.get("control_expected"), "expected control count")
|
||||
require(duration > 0 and rate > 0 and expected == duration * rate, "invalid control offering contract")
|
||||
ping = samples(report, "Ping")
|
||||
read_all = samples(report, "ReadAll")
|
||||
require(len(ping) == expected and read_all, "probe sample coverage does not match its contract")
|
||||
allowed = {"ok", "deadline", "schedule_drop", "rpc_error"}
|
||||
require(all(row.get("outcome") in allowed for row in ping + read_all), "unknown probe outcome")
|
||||
observed_errors = sum(row.get("outcome") != "ok" for row in ping + read_all)
|
||||
require(uint(report.get("errors"), "probe error count") == observed_errors, "probe error count does not match samples")
|
||||
fixture = report.get("fixture_sha256")
|
||||
require(isinstance(fixture, str) and len(fixture) == 64 and all(char in "0123456789abcdef" for char in fixture),
|
||||
"invalid fixture identity")
|
||||
targets = uint(report.get("targets"), "target count")
|
||||
peers = uint(report.get("peers"), "peer count")
|
||||
workers = uint(report.get("bulk_workers"), "bulk worker count")
|
||||
scope = report.get("scope")
|
||||
require(targets > 0 and peers > 0 and workers > 0 and isinstance(scope, str) and scope,
|
||||
"invalid probe workload identity")
|
||||
identity = {"fixture_sha256": fixture, "targets": targets, "peers": peers, "bulk_workers": workers,
|
||||
"control_rps": rate, "scope": scope}
|
||||
return ping, read_all, identity
|
||||
|
||||
|
||||
def phase(report, expected):
|
||||
ping, read_all, identity = report_status(report)
|
||||
outcomes = [row["outcome"] for row in ping + read_all]
|
||||
if expected == "success":
|
||||
return not outcomes.count("deadline") and not outcomes.count("schedule_drop") and not outcomes.count("rpc_error"), identity
|
||||
require(expected == "deadline", "unknown timeout-boundary expectation")
|
||||
return outcomes.count("deadline") > 0 and not outcomes.count("schedule_drop") and not outcomes.count("rpc_error"), identity
|
||||
|
||||
|
||||
def check(manifest, root):
|
||||
root = root.resolve()
|
||||
require(isinstance(manifest, dict) and manifest.get("schema") == 1, "unsupported timeout-boundary schema")
|
||||
require(manifest.get("scope") == "internode-rpc-timeout-boundary", "wrong timeout-boundary scope")
|
||||
timeout = uint(manifest.get("rpc_timeout_ms"), "RPC timeout")
|
||||
require(timeout > 0, "RPC timeout must be positive")
|
||||
seen = set()
|
||||
receipts = []
|
||||
verdicts = {}
|
||||
workload_identity = None
|
||||
phases = (("under_budget", "success"), ("over_budget", "deadline"), ("recovery", "success"))
|
||||
for name, expectation in phases:
|
||||
descriptor = manifest.get(name)
|
||||
require(isinstance(descriptor, dict), f"missing {name} descriptor")
|
||||
if name != "recovery":
|
||||
fault_path = evidence_path(root, descriptor.get("fault_receipt"), seen)
|
||||
fault, fault_digest = load(fault_path, MAX_MANIFEST_BYTES)
|
||||
require(isinstance(fault, dict) and isinstance(fault.get("target"), str) and fault["target"],
|
||||
f"invalid {name} fault target")
|
||||
requested = uint(fault.get("requested_stall_ms"), f"{name} requested stall")
|
||||
actual = uint(fault.get("actual_stall_ms"), f"{name} actual stall")
|
||||
require(0 < requested <= actual, f"invalid {name} stall receipt")
|
||||
if name == "under_budget":
|
||||
require(actual < timeout, "under-budget stall crossed the RPC timeout")
|
||||
else:
|
||||
require(requested > timeout and actual > timeout, "over-budget stall did not cross the RPC timeout")
|
||||
receipts.append({"phase": name, "kind": "fault", "path": descriptor["fault_receipt"],
|
||||
"sha256": fault_digest})
|
||||
path = evidence_path(root, descriptor.get("report"), seen)
|
||||
report, digest = load(path, MAX_REPORT_BYTES)
|
||||
verdicts[name], identity = phase(report, expectation)
|
||||
if workload_identity is None:
|
||||
workload_identity = identity
|
||||
else:
|
||||
require(identity == workload_identity, "probe workload identity changed across timeout phases")
|
||||
receipts.append({"phase": name, "kind": "report", "path": descriptor["report"], "sha256": digest})
|
||||
return {
|
||||
"observed_pass": all(verdicts.values()),
|
||||
"scope": manifest["scope"],
|
||||
"rpc_timeout_ms": timeout,
|
||||
"phases": verdicts,
|
||||
"workload": workload_identity,
|
||||
"reports": receipts,
|
||||
"limits": "Recorded request outcomes only; deployment ownership, fault delivery, Prometheus windows and performance attribution remain separate evidence.",
|
||||
}, seen
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__)
|
||||
parser.add_argument("--manifest", type=Path, required=True)
|
||||
parser.add_argument("--out", type=Path, required=True)
|
||||
args = parser.parse_args()
|
||||
try:
|
||||
require(args.manifest.is_file() and args.manifest.stat().st_size <= MAX_MANIFEST_BYTES,
|
||||
"missing or oversized timeout-boundary manifest")
|
||||
raw = args.manifest.read_bytes()
|
||||
manifest = json.loads(raw, object_pairs_hook=unique_object)
|
||||
result, inputs = check(manifest, args.manifest.resolve().parent)
|
||||
output = args.out.resolve()
|
||||
require(output not in inputs | {args.manifest.resolve()}, "output would overwrite raw evidence")
|
||||
if args.out.exists():
|
||||
require(not any(args.out.samefile(path) for path in inputs | {args.manifest.resolve()}),
|
||||
"output aliases raw evidence")
|
||||
result["manifest_sha256"] = hashlib.sha256(raw).hexdigest()
|
||||
args.out.write_text(json.dumps(result, indent=2, allow_nan=False) + "\n")
|
||||
return 0 if result["observed_pass"] else 1
|
||||
except (ValueError, OSError, TypeError, KeyError, AttributeError, json.JSONDecodeError) as error:
|
||||
print(f"Invalid internode RPC timeout-boundary evidence: {error}", file=sys.stderr)
|
||||
return 2
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
@@ -1,535 +0,0 @@
|
||||
#!/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)
|
||||
@@ -1,6 +0,0 @@
|
||||
#!/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}" -- "$@"
|
||||
@@ -1,356 +0,0 @@
|
||||
#!/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()
|
||||
+173
@@ -0,0 +1,173 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Regression cases for the internode RPC timeout-boundary evidence gate."""
|
||||
|
||||
import copy
|
||||
import json
|
||||
import os
|
||||
from pathlib import Path
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
|
||||
import check_internode_rpc_timeout_boundary as gate
|
||||
|
||||
|
||||
class TimeoutBoundaryTests(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.directory = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(self.directory.cleanup)
|
||||
self.root = Path(self.directory.name)
|
||||
self.reports = {
|
||||
"under": self.report(30, 10, []),
|
||||
"over": self.report(35, 10, [("Ping", "deadline"), ("ReadAll", "deadline")]),
|
||||
"recovery": self.report(15, 10, []),
|
||||
}
|
||||
for name, report in self.reports.items():
|
||||
(self.root / f"{name}.json").write_text(json.dumps(report))
|
||||
self.faults = {
|
||||
"under": {"target": "node4", "requested_stall_ms": 8_000, "actual_stall_ms": 9_100},
|
||||
"over": {"target": "node4", "requested_stall_ms": 12_000, "actual_stall_ms": 12_600},
|
||||
}
|
||||
self.manifest = {
|
||||
"schema": 1,
|
||||
"scope": "internode-rpc-timeout-boundary",
|
||||
"rpc_timeout_ms": 10_000,
|
||||
"under_budget": {"fault_receipt": "under-fault.json", "report": "under.json"},
|
||||
"over_budget": {"fault_receipt": "over-fault.json", "report": "over.json"},
|
||||
"recovery": {"report": "recovery.json"},
|
||||
}
|
||||
|
||||
@staticmethod
|
||||
def report(duration, rate, failures):
|
||||
samples = []
|
||||
for sequence in range(duration * rate):
|
||||
samples.append({"operation": "Ping", "outcome": "ok", "peer": sequence % 4})
|
||||
for sequence in range(8):
|
||||
samples.append({"operation": "ReadAll", "outcome": "ok", "peer": sequence % 4})
|
||||
for operation, outcome in failures:
|
||||
row = next(sample for sample in samples if sample["operation"] == operation and sample["outcome"] == "ok")
|
||||
row["outcome"] = outcome
|
||||
return {
|
||||
"complete": True,
|
||||
"errors": len(failures),
|
||||
"bulk_coverage_verified": True,
|
||||
"offered_duration_secs": duration,
|
||||
"control_rps": rate,
|
||||
"control_expected": duration * rate,
|
||||
"fixture_sha256": "0" * 64,
|
||||
"targets": 4,
|
||||
"peers": 4,
|
||||
"bulk_workers": 2,
|
||||
"scope": "Authenticated production RPC clients",
|
||||
"samples": samples,
|
||||
}
|
||||
|
||||
def write_reports(self):
|
||||
for name, report in self.reports.items():
|
||||
(self.root / f"{name}.json").write_text(json.dumps(report))
|
||||
for name, fault in self.faults.items():
|
||||
(self.root / f"{name}-fault.json").write_text(json.dumps(fault))
|
||||
|
||||
def check(self):
|
||||
self.write_reports()
|
||||
return gate.check(self.manifest, self.root)[0]
|
||||
|
||||
def test_valid_boundary_and_recovery_pass(self):
|
||||
result = self.check()
|
||||
self.assertTrue(result["observed_pass"])
|
||||
self.assertEqual(result["phases"], {"under_budget": True, "over_budget": True, "recovery": True})
|
||||
|
||||
def test_schedule_drop_cannot_substitute_for_deadline(self):
|
||||
for report in ("under", "over", "recovery"):
|
||||
with self.subTest(report=report):
|
||||
original = copy.deepcopy(self.reports[report])
|
||||
row = next(sample for sample in self.reports[report]["samples"] if sample["operation"] == "Ping")
|
||||
was_ok = row["outcome"] == "ok"
|
||||
row["outcome"] = "schedule_drop"
|
||||
self.reports[report]["errors"] += was_ok
|
||||
self.assertFalse(self.check()["observed_pass"])
|
||||
self.reports[report] = original
|
||||
|
||||
def test_under_budget_errors_over_budget_success_and_recovery_errors_fail(self):
|
||||
cases = (("under", "deadline", 1), ("over", "ok", -2), ("recovery", "rpc_error", 1))
|
||||
for report, outcome, error_delta in cases:
|
||||
with self.subTest(report=report):
|
||||
original = copy.deepcopy(self.reports[report])
|
||||
if report == "over":
|
||||
for sample in self.reports[report]["samples"]:
|
||||
sample["outcome"] = "ok"
|
||||
else:
|
||||
next(sample for sample in self.reports[report]["samples"] if sample["operation"] == "Ping")["outcome"] = outcome
|
||||
self.reports[report]["errors"] += error_delta
|
||||
self.assertFalse(self.check()["observed_pass"])
|
||||
self.reports[report] = original
|
||||
|
||||
def test_invalid_stall_receipts_and_control_contract_fail_closed(self):
|
||||
edits = (
|
||||
lambda: self.faults["under"].update(actual_stall_ms=10_000),
|
||||
lambda: self.faults["over"].update(requested_stall_ms=9_000),
|
||||
lambda: self.faults["under"].update(requested_stall_ms=9_200),
|
||||
lambda: self.reports["under"].update(control_expected=1),
|
||||
)
|
||||
for edit in edits:
|
||||
with self.subTest(edit=edit):
|
||||
manifest = copy.deepcopy(self.manifest)
|
||||
reports = copy.deepcopy(self.reports)
|
||||
faults = copy.deepcopy(self.faults)
|
||||
edit()
|
||||
with self.assertRaises(ValueError):
|
||||
self.check()
|
||||
self.manifest, self.reports, self.faults = manifest, reports, faults
|
||||
|
||||
def test_paths_cannot_escape_or_reuse_evidence(self):
|
||||
self.manifest["under_budget"]["report"] = "../outside.json"
|
||||
with self.assertRaisesRegex(ValueError, "escapes"):
|
||||
self.check()
|
||||
self.manifest["under_budget"]["report"] = "under.json"
|
||||
self.manifest["recovery"]["report"] = "under.json"
|
||||
with self.assertRaisesRegex(ValueError, "reused"):
|
||||
self.check()
|
||||
|
||||
def test_probe_workload_identity_cannot_change_between_phases(self):
|
||||
for field, value in (("fixture_sha256", "1" * 64), ("targets", 3), ("peers", 3),
|
||||
("bulk_workers", 1), ("control_rps", 9), ("scope", "different")):
|
||||
with self.subTest(field=field):
|
||||
self.reports["recovery"][field] = value
|
||||
if field == "control_rps":
|
||||
self.reports["recovery"]["control_expected"] = self.reports["recovery"]["offered_duration_secs"] * value
|
||||
self.reports["recovery"]["samples"] = self.report(15, value, [])["samples"]
|
||||
with self.assertRaisesRegex(ValueError, "identity changed"):
|
||||
self.check()
|
||||
self.reports["recovery"] = self.report(15, 10, [])
|
||||
|
||||
def run_cli(self, output):
|
||||
self.write_reports()
|
||||
manifest = self.root / "manifest.json"
|
||||
manifest.write_text(json.dumps(self.manifest))
|
||||
return subprocess.run([sys.executable, str(Path(gate.__file__)), "--manifest", str(manifest),
|
||||
"--out", str(output)], capture_output=True, text=True)
|
||||
|
||||
def test_entry_point_distinguishes_pass_fail_and_invalid(self):
|
||||
output = self.root / "result.json"
|
||||
self.assertEqual(self.run_cli(output).returncode, 0)
|
||||
self.reports["recovery"]["samples"][0]["outcome"] = "deadline"
|
||||
self.reports["recovery"]["errors"] = 1
|
||||
self.assertEqual(self.run_cli(output).returncode, 1)
|
||||
self.manifest["scope"] = "command"
|
||||
self.assertEqual(self.run_cli(output).returncode, 2)
|
||||
|
||||
def test_entry_point_preserves_raw_and_hard_linked_evidence(self):
|
||||
raw = self.root / "under.json"
|
||||
self.write_reports()
|
||||
before = raw.read_bytes()
|
||||
self.assertEqual(self.run_cli(raw).returncode, 2)
|
||||
self.assertEqual(raw.read_bytes(), before)
|
||||
alias = self.root / "alias.json"
|
||||
os.link(raw, alias)
|
||||
self.assertEqual(self.run_cli(alias).returncode, 2)
|
||||
self.assertEqual(raw.read_bytes(), before)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Reference in New Issue
Block a user