Compare commits

..

42 Commits

Author SHA1 Message Date
houseme af4595f0a6 fix(heal): cleanup consumed MRF replay journals
Do not retain Accepted or Merged replay intents as startup anchors after they have been handed to the heal manager. Only refused or still-pending replay records keep the journal on disk until a successor snapshot can persist them.

This keeps successor snapshots limited to the pending queue, which lets successful replay remove both authoritative and legacy journal paths and restores the crash-boundary tests around successor flush.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
(cherry picked from commit d5b8f49c9d)
2026-09-08 02:11:30 +08:00
houseme 10e4e323a2 fix(error): merge equivalent api message branches
Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
2026-09-08 01:54:38 +08:00
houseme 5ef88c77a5 fix(heal): rearm MRF replay leases before admission (#7435)
Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-08 01:45:09 +08:00
houseme 88f8a7fb21 feat(common): add durable MRF proof matching (#7429)
Add a fail-closed MRF repair proof adapter that only consumes anchors when the durable anchor and verified proof share the same full identity, ingress lease, and bucket incarnation.

Legacy replay intents without leases cannot become dischargeable anchors, so the current retained journal behavior remains unchanged until a durable writer and producer proof source are connected.

Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-08 00:55:39 +08:00
houseme 1f65bd828d feat(heal): publish verified MRF repair events
Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>
2026-09-08 00:00:53 +08:00
Zhengchao An 7c85c72fd1 docs: scope agent guidance and consolidate review workflows (#7419) 2026-09-07 23:58:05 +08:00
Zhengchao An 27d167f7b6 ci(upgrade): run rc.5 multipart layout checks (#7421)
Wire the existing rc.5 multipart upgrade and diagnostic baseline tests into the upgrade matrix.
2026-09-07 23:58:02 +08:00
houseme 1a5e2b6256 test(scanner): bind segment proof generations (#7416)
Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 23:43:42 +08:00
houseme 474fcf78fb fix: align object version limit handling (#7415)
Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 23:43:19 +08:00
houseme 752d4a81ab test(scanner): prove restart quantum stages (#7414)
Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 23:22:02 +08:00
houseme 0686277ee4 fix(heal): retain MRF replay anchors until successor proof (#7413)
Keep replayed MRF records crash-replayable after manager admission until a later durable successor proof can tombstone them. Queue-full and transient replay submission failures now also preserve the old journal anchor instead of allowing cleanup to erase the only recovery source.

Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 23:21:47 +08:00
cxymds 7373a5902e fix(ci): use test-domain facade in delete-marker regression (#7412) 2026-09-07 23:21:30 +08:00
cxymds e95a0ed6d9 fix(s3): allow delete-marker metadata during delete preflight (#7411) 2026-09-07 22:31:44 +08:00
houseme f0e0f5307d feat(ecstore): expose pool meta write gate status (#7399)
* feat(ecstore): expose pool meta write gate status

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>

* fix(server): keep cluster snapshot on storage facade

Map the pool metadata write gate status inside the cluster snapshot collector without naming rustfs_ecstore from the outer runtime module. This keeps the snapshot behavior unchanged while satisfying the architecture migration boundary.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>

* test(scanner): align scoped maintenance expectation

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>

* chore: update error other format baseline

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>

---------

Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 22:31:25 +08:00
cxymds 6855640192 fix(rebalance): preserve explicit stop intent and real failures (#7410) 2026-09-07 22:30:51 +08:00
cxymds f11697d6e2 fix(pool): publish durable decommission capacity revisions (#7409) 2026-09-07 22:26:29 +08:00
Zhengchao An 736b6a366c fix(storage): bound multipart admission wait below SDK write timeouts (#7408)
A multipart UploadPart queued for a foreground write permit is not read while it waits, so the client's socket write stalls for the whole wait and the client's own write timeout decides the outcome; botocore reports that as ConnectionClosedError. Lower the default queue wait from 30 s to 10 s so the part receives SlowDown before mainstream SDK timeouts, and stop forcing a 4 MiB SO_RCVBUF on the API listener (new RUSTFS_HTTP_SOCKET_RECV_BUFFER_BYTES restores a fixed size) so a queued connection no longer lets up to 8 MiB of unread body accumulate in kernel memory.

Fixes #7385.

Co-authored-by: houseme <housemecn@gmail.com>
2026-09-07 22:25:06 +08:00
cxymds 7b40b9503b feat(observability): diagnose node-local S3 write failures (#7407) 2026-09-07 22:24:50 +08:00
houseme e22b879996 test(scanner): cover cohort overflow tail fairness (#7403)
Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 22:20:12 +08:00
houseme b0dac1ac24 feat(scanner): admit verified segment invalidations (#7402)
Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 22:19:47 +08:00
houseme 90e3ed701e test(e2e): prebuild scanner heal evidence binaries (#7400)
* test(e2e): prebuild scanner heal evidence binaries

* test(e2e): widen scanner heal crash evidence window

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>

---------

Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 22:19:32 +08:00
cxymds fd92853ac4 fix(ecstore): recover interrupted pool metadata writes (#7387)
* fix(ecstore): recover interrupted pool metadata writes

* chore(ci): update error format ratchet baseline

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>

---------

Co-authored-by: houseme <housemecn@gmail.com>
Co-authored-by: zhi22915 <qiuzgang@gmail.com>
Co-authored-by: Zhengchao An <anzhengchao@gmail.com>
2026-09-07 22:17:51 +08:00
houseme bc0f608431 test(scanner): align scoped maintenance oracle (#7404)
Keep the production scoped scanner test from mutating an unselected bucket during the dirty-only cycle. That cycle intentionally reuses the clean baseline, while the later Deep and full maintenance cycles still mutate cold storage and prove a full walk refreshes it.

Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 22:14:29 +08:00
Zhengchao An f20a575994 ci(star-history): bump repo-visuals-action to v1.4.0 (#7406)
Pin the star history workflow to the freshly released v1.4.0 of
overtrue/repo-visuals-action, which adds the chart-layout input and a
refreshed editorial chart/contributor-wall style. The workflow keeps its
existing inputs, so chart-layout stays at the editorial default.
2026-09-07 21:43:13 +08:00
houseme cc91483fac test(heal): preserve MRF replay identity matrix (#7398)
Add an MRF pipeline regression that replays a single authoritative journal containing same-object records that differ by kind and erasure-set scope while a stale legacy mirror is present. The test proves restart replay admits each authoritative responsibility independently and never merges the stale mirror epoch.

Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 20:20:21 +08:00
houseme c8fc50ada2 feat(heal): accept verified object repair receipts (#7397)
Introduce an object heal receipt wrapper so storage owners can report a positive repaired or verified result without changing legacy heal consumers.

Task-level object heal now records only receipts that match the requested object identity, version, pool, set, and carry a bucket incarnation. Legacy and mismatched receipts still fall back to unknown outcome accounting.

Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 19:55:29 +08:00
houseme 9badf3939c fix(admin): report pool metadata write blocks (#7396)
Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 19:55:20 +08:00
houseme c71c686e2a fix(scanner): bind scoped set reuse to bucket incarnations (#7395)
Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 19:55:10 +08:00
houseme 45f57ca57a test(e2e): allow scanner heal evidence port ranges (#7394)
* test(scanner): wire crash evidence runner

Add the background target crash release-evidence case and require its oracle to carry process-crash-restart evidence with the unclean shutdown marker.

Add a single-case runner that records begin/list/run/finish receipts, validates the concrete case, and confirms the release gate remains blocked by pending mixed-version and release lanes.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>

* test(scanner): align crash evidence feature identity

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>

* test(scanner): harden crash evidence runner

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>

* test(e2e): allow scanner heal evidence port ranges

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>

---------

Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 19:54:57 +08:00
houseme 265f429358 test(scanner): require heal pressure evidence metrics (#7392)
Require scanner/heal ABBA adapters to emit foreground pressure, heal lock wait p99, and heal attempt counters before a measured W10/W11 run can be accepted.

Report per-leg pressure ratios, lock p99 samples, and attempt cost per healed object so synthetic harness runs remain evidence-contract validation rather than performance proof.

Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 19:54:48 +08:00
houseme 47f640f23e test(scanner): prove segment activation gates (#7388)
Extend the segment observation fixture with durable activation prerequisites and add scanner oracles for cold segment zero-walk and distributed invalidation fallback.

Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 19:30:43 +08:00
houseme 237c96dd3b test(heal): cover transport receipt replay after peer restart (#7390)
Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 19:30:34 +08:00
houseme 647fe1a292 test(heal): cover MRF crash replay gaps (#7389)
Add a Unix process-kill fixture for the authoritative successor fsync boundary where the scoped journal is durable while the legacy mirror still contains the startup epoch. Also extend heal-control transport replay coverage so a duplicate producer after a lost response receives the canonical merged receipt without creating another task.

Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 19:30:25 +08:00
houseme 0c6314babc fix(scanner): consume raw page owner resume oracle (#7391)
Treat persisted raw page owner entries as a validated set, not a read_dir-order prefix, so restart scans can consume committed owner pages without recounting them against the raw enumeration budget. Commit checkpointed partial pages, validate owner parent/generation/digests before the skip oracle, and fail closed on duplicate/corrupt page state.

Extend the real scanner restart driver to enforce fixed raw-entry and object budgets across fresh OS processes, and report owner-index coverage in each worker round.

Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 19:30:15 +08:00
houseme fc76099280 test(scanner): cover scoped ack loss confirmation (#7393)
Add a scoped dirty-usage ACK confirmation fixture for transport failures after the send attempt. The test confirms that same-instance clean activity can reconcile a lost response, while peer restart and concurrent dirty usage stay pending.

Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 19:30:06 +08:00
唐小鸭 899f81f3ad fix(replication): resolve drifted replicas via a target version ledger (#7368)
* fix(replication): resolve drifted replicas via a target version ledger

A replication target that mints its own version ids (Wasabi, AWS S3)
never answers to the source uuid, so every version-addressed mutation
after the initial PUT failed forever: permanent version deletes answered
NoSuchVersion every heal cycle, and tag / retention / legal-hold updates
re-PUT the object, minting one more target version per update
(rustfs/backlog#2340).

Record the id the target assigned as a per-target ledger on the source
version (replication-target-version-<arn>, written through the existing
status writeback) and resolve every later mutation through it: version
deletes DELETE the ledger id, metadata updates go through the
metadata-only Object Lock and tagging APIs. Replicas written before the
ledger existed are located by exact key and ETag, minus the candidates
other generations of the key already claim through their own ledgers; an
ambiguous remainder is refused with a backoff instead of guessed, since a
wrong pick would destroy a live generation. A fresh write never consults
content identity. NoSuchVersion on a version-addressed DELETE counts as
purged.

The fake target gains the Wasabi shape (404 NoSuchVersion on an unknown
id, per-version Object Lock APIs) and the matrix covers the three
mutation classes plus the same-bytes generation case.

* fix(scanner): drop the unused Digest import

Same one-line change as rustfs/rustfs#7366 (main is red with it under -D warnings); carried here so the stacked PRs' merge commits compile until that fix lands.

* fix(admin): probe replication-check mutations by the assigned version id (#7373)

On a target that mints its own version ids the DeleteMarker and
VersionDelete phases of ?replication-check were skipped: they addressed
the source id, which such a target never had. The replication worker now
addresses the id the target assigned (the target-version ledger), and
the probe already holds that id from its own PUT, so run both phases
against it. VersionFidelity keeps failing with the mismatch code and the
target stays FAILED; the phases report whether ledger-addressed purges
work against this endpoint (rustfs/backlog#2340).

* fix(replication): abandon purges to targets the bucket no longer names (#7377)

* fix(admin): probe replication-check mutations by the assigned version id

On a target that mints its own version ids the DeleteMarker and
VersionDelete phases of ?replication-check were skipped: they addressed
the source id, which such a target never had. The replication worker now
addresses the id the target assigned (the target-version ledger), and
the probe already holds that id from its own PUT, so run both phases
against it. VersionFidelity keeps failing with the mismatch code and the
target stays FAILED; the phases report whether ledger-addressed purges
work against this endpoint (rustfs/backlog#2340).

* fix(replication): abandon purges to targets the bucket no longer names

A permanent version delete whose replication keeps failing stays in
xl.meta as a PENDING purge, hidden from listings, until every target
confirms it. Once the operator removes the replication configuration or
the rule naming that target nothing ever confirms it: the heal path
derived its delete decision from the configuration (the decision string
is not persisted) and skipped the version forever, so DeleteBucket
answered BucketNotEmpty for a residue the client could neither list nor
remove (rustfs/backlog#2340).

Owe a version purge to the targets its purge state names, let the heal
path through without a configuration, and have the delete worker settle
a target the configuration no longer names as abandoned: the purge is
reported complete locally through the normal writeback, the replica on
the former target is left alone, and the event
replication_purge_abandoned plus a counter are the record.

* fix(admin): send replication-check marker creation without a version id

Running the DeleteMarker / VersionDelete phases on a target that mints
its own version ids exposed two probe-shape bugs on real Wasabi:

- the DeleteMarker phase put the assigned version id on its DELETE. A
  RustFS peer reads the source-deletemarker header and creates a marker,
  but a generic S3 target executes it as a permanent delete of the probe
  version, so VersionDelete then answered NoSuchVersion. Use the same wire
  shape as live delete replication: no versionId on a marker creation.
- cleanup treated NoSuchVersion on the version the VersionDelete phase had
  already removed as a failure (RustFS/MinIO answer 204 there).

Also gate the no-configuration heal pass-through for pending purges on a
purge state that actually names targets, so a purge without a recorded
target keeps the ordinary skip (scanner unit test), and merge origin/main
(#7365 settles the pool-metadata probe test that failed in CI).

---------

Co-authored-by: houseme <housemecn@gmail.com>
2026-09-07 11:23:32 +00:00
cxymds 37bda24e1c fix: reject unsupported pool expansion with actionable errors (#7360)
* fix: reject unsupported pool expansion with actionable errors

Report singleton-pool and persisted-topology constraints before misleading startup retries. Preserve single-node multi-drive admission and existing parity policies, and cover format preservation plus operator recovery guidance for issue #6186.

* fix: keep pool layout errors typed

Preserve actionable pool layout diagnostics without adding generic formatted errors. Tighten the shrink-only baseline and assert that both typed payloads survive the I/O boundary.

---------

Co-authored-by: houseme <housemecn@gmail.com>
2026-09-07 11:07:42 +00:00
houseme 4c2a0cdf9a chore(scanner): stage Scanner/Heal follow-up slices (#7374)
* fix(scanner): remove unused digest import

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>

* feat(scanner): add raw page owner index (#7375)

* feat(scanner): add raw page owner index

Add a serializable raw enumeration page owner index for scanner resume work.

The index exposes unsupported, building, and ready states, validates committed page identity by recomputing digests, and uses generation checks for CAS-style page commits.

Focused tests cover small-budget restart progress, page digest/source drift rejection, corrupt deserialized state, CAS failure, precommit crash, empty sources, and invalid entry boundaries.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>

* feat(scanner): persist raw page owner resume state (#7379)

Wire the scanner raw enumeration partial-cache writer to the raw page owner index so interrupted bucket walks can retain validated page-builder state across scanner restarts.

Keep complete owner sources terminal-only, add partial-source ingestion for in-progress raw directory reads, and validate the persisted page index through bucket checkpoint preparation.

Co-authored-by: zhi22915 <qiuzgang@gmail.com>

---------

Co-authored-by: zhi22915 <qiuzgang@gmail.com>

* test(scanner): fence segment producer observations (#7381)

Require the segment observation fixture to carry source, incarnation, key-format, baseline, process epoch, generation-window, gap, overflow, and producer-coverage proof before accepting a narrowed proposal. Keep the diagnostic path fixture-only and remove its ordinary stderr output.

Co-authored-by: zhi22915 <qiuzgang@gmail.com>

* fix(ecstore): isolate pool metadata read probes (#7367)

Co-authored-by: zhi22915 <qiuzgang@gmail.com>

* test(heal): cover MRF crash successor matrix (#7369)

* test(heal): cover MRF crash successor matrix

Add process-boundary MRF replay coverage for the successor snapshot window after a retained startup journal is flushed but before cleanup deletes it. Extend the mixed authoritative/legacy reader fixture with a scoped v2 journal epoch to pin the no-merge contract.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>

* test(heal): cover service-kill MRF replay (#7380)

Add a Unix process fixture that waits after publishing the pending MRF successor snapshot, then is terminated by the parent before restart replay.

Co-authored-by: zhi22915 <qiuzgang@gmail.com>

---------

Co-authored-by: zhi22915 <qiuzgang@gmail.com>

* test(heal): cover transport-lost start receipts (#7371)

Add gRPC transport fault fixtures for heal-control start admission. The tests distinguish pre-admission transport loss from post-admission response loss, then verify exact envelope retries reuse the canonical receipt while fresh forceStart requests create distinct tasks.

Co-authored-by: zhi22915 <qiuzgang@gmail.com>

* test(scanner): add crash-restart heal evidence case (#7370)

* test(scanner): add crash-restart heal evidence case

Add a distinct W21 background target crash case to the scanner/heal evidence registry and oracle path.

Keep the existing restart lane on graceful process restart, keep the crash lane on hard kill, and make the wiring checker reject evidence/oracle mismatches.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>

* test(scanner): support older Python wiring checks

Let the scanner/heal evidence wiring checker run under Python 3.9/3.10 by falling back to tomli and chunked SHA-256 hashing when the Python 3.11 standard APIs are unavailable.

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>

---------

Co-authored-by: zhi22915 <qiuzgang@gmail.com>

* fix(scanner): reject stale raw page source seeds (#7382)

Do not prefill a resumed raw page owner with previously indexed entries when starting a new raw directory observation pass. The next pass must observe the same prefix again before the page index can advance; otherwise the index is discarded fail-closed.

Co-authored-by: zhi22915 <qiuzgang@gmail.com>

* fix(scanner): defer raw page revalidation until observed (#7384)

A resumed raw page owner index must not prefill entries from older cache state, but it also must not discard a valid multi-entry index before the current raw directory pass has observed enough entries to prove identity. Track the persisted index floor and only run the strict owner identity check once the current pass reaches that floor.

Co-authored-by: zhi22915 <qiuzgang@gmail.com>

---------

Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 18:13:39 +08:00
houseme b370e746a0 fix(io-metrics): simplify early eviction check (#7383)
Replace a needless bool return with the equivalent predicate so clippy can pass with warnings denied.

Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 18:12:00 +08:00
Zhengchao An 95e6c89c1c fix(replication): carry the compression layout through SSE-C passthrough (#7366)
* fix(scanner): drop the unused Digest import

* fix(replication): carry the compression layout through SSE-C passthrough (#7372)

* fix(replication): queue an in-flight version only once (#7376)
2026-09-07 18:07:33 +08:00
houseme aafa7e2b7f test(ecstore): align heal capacity admission regression (#7386)
Align the suspended-owner heal regression with read-only pool metadata admission semantics. The quorum-boundary case now asserts that heal fails the current capacity admission without latching the global pool metadata writer.

Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 17:52:23 +08:00
houseme 5211b56277 fix(ecstore): isolate pool metadata read probes (#7365)
* fix(ecstore): isolate pool metadata read probes

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>

* fix(readiness): surface blocked pool metadata writes

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>

* fix(scanner): remove unused digest import

Co-Authored-By: heihutu <heihutu@gmail.com>

Co-Authored-By: zhi22915 <qiuzgang@gmail.com>

---------

Co-authored-by: zhi22915 <qiuzgang@gmail.com>
2026-09-07 16:42:39 +08:00
154 changed files with 11747 additions and 1441 deletions
@@ -0,0 +1,33 @@
# Adversarial Review Shape
Use when root `AGENTS.md` triggers adversarial validation or for a substantial PR
review. Paths below are repository-relative. The root finding standard and
completion rule apply; selecting a lens does not require finding a defect.
Risk and review shape:
- **Exempt:** documentation, comments, formatting, or typos with no runtime,
build, test, or agent-execution effect.
- **Mechanical:** renames, moves, test/tooling-only changes, and agent-rule
changes. Run correctness and simplicity lenses.
- **Standard:** localized behavior changes. Run one integrated final-diff pass
covering correctness, simplicity, and test coverage; add only domain lenses
matched by the diff.
- **High risk / substantial PR review:** high risk includes locking,
erasure/quorum/heal, replication, multipart, RPC, lifecycle/tiering,
persistence/fsync, IAM/KMS/auth, cryptography, on-disk/on-wire formats, and
S3-visible semantics. Cover all applicable lenses using exactly two
independent reviewers when delegation is explicitly authorized. Split the
lenses between them. Otherwise perform two fresh sequential passes.
- **Outbound client defaults:** what `TargetClient`, `PutObjectOptions`, or
the remote SDK configuration sends to every replication or migration target
is high risk for every target class even when the change fixes one. Follow
the SOP in `docs/postmortems/2026-09-03-replication-checksum-default-regression.md`:
run the outbound target matrix, document each new env knob in the same PR,
and list verified and unverified target classes in the PR Impact section.
Available domain lenses are security, concurrency/durability, compatibility,
and performance. Select `.agents/skills/adversarial-validation/SKILL.md` for an
explicit adversarial request, a high-risk change, or a substantial PR review;
then read only its matching role references. A routine standard pass does not
load the playbook unless the reviewer needs a RustFS-specific probe.
+65
View File
@@ -0,0 +1,65 @@
# Implementation Rules
Applies when changing code or running artifact-heavy work. Paths below
are repository-relative. Read only the relevant sections during read-only review.
## Worktree and Disk Hygiene
- Start implementation from the latest `origin/main` and confirm the requested
change is not already present.
- An existing clean, isolated task worktree is sufficient. Create another
worktree only when the current checkout is shared, dirty with unrelated work,
or belongs to another task.
- Never commit from a shared checkout.
- Use a task-specific branch named `<type>/<topic>`, such as `fix/...`,
`feat/...`, `test/...`, or `docs/...`, unless the user specifies a name.
- Do not include agent, tool, contributor, account, or organization names in
branch names.
- Push to the user-requested remote or the repository's configured push remote.
Do not hard-code or infer a remote from an account name.
- Check free space before artifact-heavy builds, tests, coverage, or downloads.
Re-check before a broad gate when space is tight.
- Remove only task-owned temporary/build artifacts. Never delete another task's
worktree or uncommitted data.
- At handoff, mention disk or cleanup details only when they affected execution
or artifacts/worktrees remain intentionally.
## Change Style
- Preserve existing control flow unless changing it is required for correctness.
- Prefer a direct local edit over new files, wrappers, managers, or speculative
abstractions.
- Add a helper only when it removes current duplication, names a real domain
boundary, or isolates a non-trivial invariant.
- Remove an in-scope path superseded by the change. If compatibility requires it,
adapt at the boundary to one canonical core and use the repository's
`RUSTFS_COMPAT_TODO` policy.
- Comments explain non-obvious invariants or reasons. Do not narrate code or
record change history.
- Mention unrelated problems when useful; do not fix them in a narrow task.
## Reuse and Boundary Rules
- Before adding helpers, constants, fixtures, or wrappers, search the touched
crate, the domain-owning crate, `crates/utils`, `crates/common`, and relevant
direct dependencies.
- Reuse requires matching semantics: normalization, error types, deadlines,
durability, and compatibility must fit the call site. A narrowly named local
helper is better than forced reuse with different semantics.
- Validate untrusted input at its trust boundary, then trust the validated type.
Values crossing disk, RPC, persistence, or version boundaries remain
untrusted at every consumer.
- Re-check boundary values immediately before destructive actions such as
delete, overwrite, or quorum decisions.
- Every new branch needs a concrete triggering input/state. For decoded or peer
data, corruption and mixed-version input are valid triggers.
- Required values must return a typed error when absent or corrupt; do not use a
default that converts corruption into a plausible result.
- Attach error context once where it is actionable. Do not erase typed errors
below aggregation or quorum layers.
## Naming
Use Rust API naming: `SCREAMING_SNAKE_CASE` constants/statics, `snake_case`
functions/variables, and `PascalCase` types. Do not rename unrelated existing
violations.
+51
View File
@@ -0,0 +1,51 @@
# Git and Pull Request Rules
Applies to commits, pushes, PRs, and issue/discussion actions. Paths below are
repository-relative. User authorization and root `AGENTS.md` still govern scope.
## Final PR Preflight
Before creating or updating a PR, reuse completed review and verification:
- Verify the actual base (normally `origin/main`) and the complete task diff,
including file names and whitespace. Exclude secrets, logs, generated
artifacts, and unrelated edits. Retain an existing PR's base unless requested.
- Confirm the final diff passed the root verification tier; fix task-owned
failures and run missing scoped checks. Report unresolved required checks or
authority without expanding the task. Do not start another general review.
- Keep the English Conventional Commit title at most 72 characters. Use the
template headings, actual checks, material risks, and rollback notes.
- Immediately before writing to GitHub, confirm the head and task diff are
unchanged. Rerun only checks invalidated by edits or relevant state changes.
## Pull Request Lifecycle
- Creating or updating a PR includes one immediate snapshot of checks,
mergeability, reviews, and unresolved threads.
- Unless the user explicitly requests monitoring, a release workflow requires
it, or an automation already owns it, hand off after the PR is open with the
current state and next event to watch. Do not delay ordinary handoff with
fixed quiet-period sleeps.
- For requested monitoring, use event-driven or bounded waits. Report only state
changes, actionable failures, or a meaningful prolonged delay.
- Investigate failures/comments before changing code. Fix task-attributable
issues, rerun affected verification, push, reply or resolve the thread, then
resume the requested monitor.
- Never merge without required reviewer approval or explicit authority.
- After an observed merge, verify the commit reached the base, then clean the
task worktree/branch when safe. Preserve unmerged work for closed PRs unless
deletion was explicitly authorized.
## Git and PR Baseline
- Follow Conventional Commits; keep the subject at most 72 characters.
- Source comments, commits, PR titles, and PR bodies are in English.
- Keep every heading from `.github/pull_request_template.md`; use `N/A` where
needed and include commands actually run.
- Use `--body-file` for multiline `gh pr create`/`gh pr edit` content.
- PR/issue/discussion content must not contain the literal sequence `\n` or
hard-wrapped prose paragraphs.
- Do not include local absolute paths or tool-specific labels/prefixes in GitHub
content.
- Resolve review threads after the underlying issue is fixed. If declining a
suggestion, reply with a short evidence-based reason.
+11 -8
View File
@@ -1,11 +1,11 @@
---
name: adversarial-validation
description: Review a final RustFS diff adversarially when the user requests adversarial review, the root AGENTS.md classifies the change as high risk, or a substantial PR is being reviewed. Do not use for ordinary questions, diagnosis, planning, status, documentation-only work, or routine low-risk implementation.
description: Review RustFS diffs or designs for explicit adversarial requests, high-risk changes under the repository review policy, or substantial PR reviews. Skip ordinary questions, diagnosis, planning, status, routine low-risk implementation, and prose with no execution effect.
---
# RustFS Adversarial Validation
Use the risk tier and review shape defined in the root `AGENTS.md`. This skill
Use the [repository risk tiers and review shape](../../references/adversarial-validation.md). This skill
routes a review to RustFS-specific probes without loading unrelated domains.
## Select Lenses
@@ -31,15 +31,18 @@ adversarial review.
## Review Protocol
1. Freeze the exact final diff/head and list the selected lenses.
2. Run the review shape required by root `AGENTS.md`.
1. Freeze the exact final diff/head (or the design under review) and list the
selected lenses.
2. Run the review shape required by the repository risk tier.
3. For each selected lens, either report a concrete finding or a null verdict
naming the attacks performed.
4. A finding needs `file:line`, a triggering input/state/interleaving, the wrong
outcome, and a focused fix or missing regression check.
5. Fix or rebut every finding with code-path, test, or invariant evidence.
4. Apply root `AGENTS.md`'s finding standard. Test each candidate against callers,
existing coverage, and invariants before accepting it; an adversarial role
does not have to produce a defect.
5. Fix or rebut supported findings with code-path, test, or invariant evidence.
6. After a non-trivial edit, rerun only lenses affected by that edit against the
new exact diff.
Do not turn a null verdict into a long checklist. Record concise evidence that
the relevant failure classes were attacked.
the relevant failure classes were attacked, then stop under the root completion
rule. Keep the required per-lens verdicts for high-risk PRs.
@@ -3,9 +3,10 @@
- For every behavior claim, name the focused test/check that fails if the
changed hunk is reverted. If none is practical, require the reason and
residual risk.
- Confirm tests exercise the real production path and assert returned values,
exact bytes, stored state, or the specific error variant—not only success,
`is_err()`, or no panic.
- Confirm tests exercise the real production path and distinguish the intended
behavior from the named regression. A success, `is_err()`, or no-panic check
can be sufficient when that is the actual contract; require exact values,
bytes, state, or error variants when those distinctions matter to the change.
- For new flags/modes, verify each branch and ask which test fails if the branch
is inverted.
- For new error propagation, inject the failure and assert the caller observes
+6 -4
View File
@@ -1,12 +1,13 @@
---
name: arch-checks
description: Resolve failures from the repository's architecture guard scripts — check_layer_dependencies.sh, check_architecture_migration_rules.sh, check_unsafe_code_allowances.sh, check_logging_guardrails.sh, check_doc_paths.sh. Use when make pre-commit / pre-pr or CI fails on one of these checks.
description: Diagnose failures from check_layer_dependencies.sh, check_architecture_migration_rules.sh, check_unsafe_code_allowances.sh, check_logging_guardrails.sh, check_doc_paths.sh, or check_no_planning_docs.sh. Use when one of these guards fails, not for every architecture question or documentation edit.
---
# Architecture Guard Checks
All five run in `make pre-commit` / `make pre-pr` and in CI. Fix the cause;
never weaken a check to get green.
Read only the section for the failing guard. Use `.config/make/` and the current
workflow to verify its wiring; not every guard is part of every gate. Fix the
cause and rerun the failed guard; never weaken a check to get green.
## `check_layer_dependencies.sh` — layer DAG in `rustfs/src`
@@ -54,7 +55,8 @@ Instruction docs (`AGENTS.md`, `CLAUDE.md`, `ARCHITECTURE.md`) and every
Markdown file under `docs/` (architecture, operations, testing, index) must not
reference repo file paths that no longer exist. If your refactor moved code,
update the docs that point at it — the error message lists `doc -> stale-path`
pairs. Cite paths plus symbol names, never line numbers (see `docs/README.md`).
pairs. In durable docs, cite paths plus symbol names rather than line numbers
(see `docs/architecture/README.md`). Review findings still need `file:line`.
## `check_no_planning_docs.sh`
@@ -8,19 +8,11 @@ description: Review a commit, PR, or merged patch when the user requests ordinar
Use this skill for an ordinary requested review. If the root policy or user calls
for adversarial validation, use `adversarial-validation` instead of running both.
## Quick Start
1. Read the scope: commit, PR, patch, or file list.
2. Map each changed area by risk and user impact.
3. Inspect each risky change in context.
4. Report findings first, ordered by severity.
5. Close with residual risks and verification recommendations.
## Core Workflow
### 1) Scope and assumptions
- Confirm change source (diff, commit, PR, files), target branch, language/runtime, and version.
- If context is missing, state assumptions before deeper analysis.
- Derive the change source, target branch, and relevant runtime/version from the
supplied diff and metadata. Ask only when missing context could change the verdict.
- Focus only on requested scope; avoid reviewing unrelated files.
### 2) Risk map
@@ -40,43 +32,20 @@ for adversarial validation, use `adversarial-validation` instead of running both
- unchecked assumptions and null/empty/error-path handling
- stale tests, fixtures, and configs
- hidden coupling to shared helpers/constants/features
- If a point is uncertain, mark it as an open question instead of guessing.
- Apply root `AGENTS.md`'s finding standard: try to disprove a candidate before
reporting it. Mention an unresolved question only when it could materially
change the verdict; do not fill the report with speculative possibilities.
#### Rust-specific checks (apply to all Rust changes)
#### Rust-specific checks
Run the full checklist in [rust-code-quality](../rust-code-quality/SKILL.md) — the canonical Rust review checklist for the unwrap/casting/cloning/locking/recursion/error-type/serde/test rules and the reuse-and-necessity checks (duplicated helpers, defensive branches without a nameable trigger, redundant error wrapping). Do not restate those rules here; carry its P0P3 ratings over unchanged and use this skill's output format.
For changed Rust behavior, use the matching sections of [rust-code-quality](../rust-code-quality/SKILL.md). Reuse checks already performed by the selected review workflow. Comment-only or formatting-only Rust diffs do not require the full Rust checklist. Carry its P0P3 ratings over unchanged and use this skill's output format.
### 4) Findings-first output
- Order findings by severity:
- P0: critical failure, security breach, or data loss risk
- P1: high-impact regression
- P2: medium risk correctness gap
- P3: low risk/quality debt
- For each finding include:
- Severity
- `path:line` reference
- concise issue statement
- impact and likely failure mode
- specific fix or mitigation
- validation step to confirm
- If no issues exist, explicitly state `No findings` and why.
- Order supported findings by P0P3 severity; preserve the Rust ratings above.
Include `path:line`, the failure and impact, a focused fix, and its validation.
- If no supported issues remain, state `No findings` with the reviewed scope and
any material verification limitation. Do not append optional improvements to
make a clean review look productive.
### 5) Close
- Report assumptions and unknowns.
- Suggest targeted checks (tests, canary checks, logs/metrics, migration validation).
## Output Template
1. Findings
2. No findings (if applicable)
3. Assumptions / Unknowns
4. Recommended verification steps
## Finding Template
- `[P1] Missing timeout for downstream call`
- Location: `path/to/file.rs:123`
- Issue: ...
- Impact: ...
- Fix suggestion: ...
- Validation: ...
Close after the required review. Recommend additional verification only for an
identified unresolved risk or required gate; reuse evidence for unchanged code.
+28 -32
View File
@@ -1,6 +1,6 @@
---
name: issue-triage
description: Triage a GitHub issue — determine if it is already fixed, needs implementation, or should be closed. Searches related commits and PRs, verifies implementation status, and posts a triage comment or closes the issue. Use when the user provides an issue URL and asks whether it can be closed or needs work.
description: Assess whether a GitHub issue is fixed, needs implementation, or can be closed by checking related work and current code. Use for issue completion/triage requests. Status questions are read-only; comment, close, or change labels only when the conversation authorizes that action.
---
# Issue Triage
@@ -20,6 +20,8 @@ Read the issue body to understand what was requested. Extract:
- Any linked PRs or commits mentioned in the body or comments.
- Any checklist items or sub-issues.
Resolve the issue repository and implementation repository separately (for example, `rustfs/backlog` tracks work in `rustfs/rustfs`). Pass the implementation repository explicitly to PR queries; the current checkout may belong to another repository.
### 2. Search for related work
Search git history for commits referencing the issue:
@@ -29,26 +31,29 @@ git log --oneline --all --grep="<N>" | head -30
Search for related PRs:
```bash
gh pr list --search "fixes #<N> OR closes #<N> OR #<N>" --state all --json number,title,state,mergedAt
gh pr list --repo <implementation-repo> --search "<issue-url>" --state all --json number,title,state,mergedAt
```
Also search qualified issue references and subject keywords; for same-repository
issues, include `#<N>`. Follow explicit links even without a text match. A search
page with no match does not prove the work is absent.
If the issue mentions specific PRs, check their status:
```bash
gh pr view <PR_N> --json state,mergedAt,title
gh pr view <PR_N> --repo <implementation-repo> --json state,mergedAt,title,mergeCommit,baseRefName
```
### 3. Verify implementation
For each linked or related PR that is merged, verify the fix is actually present on the current main branch:
Fetch the implementation repository's current base branch. For each merged candidate, verify its merge commit is present and inspect the current code for the claimed behavior; a commit message match alone is not proof:
```bash
git log --oneline main | grep -i "<keyword>"
# or
git log --oneline main --grep="<PR_N>"
git fetch <implementation-remote> <base-branch>
git merge-base --is-ancestor <merge-commit> <implementation-remote>/<base-branch>
```
If the issue describes a specific defect, check the relevant code to confirm the fix is in place:
If the issue describes a specific defect, inspect the fetched base's code rather than assuming the current checkout contains it:
```bash
grep -n "<pattern>" crates/<relevant>/src/<file>.rs
git show <implementation-remote>/<base-branch>:crates/<relevant>/src/<file>.rs
```
For issues with checklists, verify each item individually. If sub-items are tracked as separate issues, check those too:
@@ -58,13 +63,15 @@ gh issue view <SUB_N> --repo <owner/repo> --json state
### 4. Determine verdict
- **All items fixed and merged**: Close with a summary comment listing what was fixed and which PRs.
- **Some items fixed, some remaining**: Comment with status of each item. Do not close.
- **Not yet implemented**: Comment with a summary of what remains. Do not close.
- **Superseded or no longer relevant**: Close with explanation.
- **All items fixed and merged**: Recommend closing; name the verified PRs and behavior.
- **Some items fixed, some remaining**: Keep open; report each remaining item.
- **Not yet implemented**: Keep open; report what remains.
- **Superseded or no longer relevant**: Recommend closing with evidence.
### 5. Take action
For a status-only request, return the assessment without GitHub writes. If commenting, closing, or label edits are authorized, perform only those actions; do not ask again for authority already given. Prepare the final assessment before asking for any missing authority. Write `rustfs/backlog` issue content in Chinese.
Close with comment:
```bash
gh issue close <N> --repo <owner/repo> --comment "<body>"
@@ -75,9 +82,9 @@ Comment without closing:
gh issue comment <N> --repo <owner/repo> --body-file /tmp/triage.md
```
Update issue labels if needed:
Update labels only when label changes are authorized, using existing repository labels; never add tool-specific labels:
```bash
gh issue edit <N> --repo <owner/repo> --add-label "completed" --remove-label "needs-triage"
gh issue edit <N> --repo <owner/repo> --add-label "<existing-label>"
```
Always use `--body-file` for multiline content, never inline `--body`.
@@ -85,27 +92,16 @@ Always use `--body-file` for multiline content, never inline `--body`.
### 6. Handle multi-issue batches
When the user asks to check multiple issues (e.g., "check all issues by user X" or "scan backlog for closable issues"):
1. List the issues: `gh issue list --repo <repo> --author <user> --state open --json number,title,updatedAt`
1. List the full requested scope with pagination (for example `gh api --paginate 'repos/<repo>/issues?state=open&per_page=100'`, excluding entries with `pull_request`). Add an author filter only when the user requested one; the default page/limit is not evidence that all issues were checked.
2. For each issue, run steps 1-5 above.
3. Report a summary table of all triaged issues with verdicts.
## Output format
## Report
### Issue Triage: #<N> — <title>
**State**: OPEN / CLOSED
**Linked PRs**: <list with merge status>
#### Assessment
<what was requested vs what is implemented>
#### Verdict
- Close — all items resolved by <PR list>
- Keep open — <remaining items>
- Not started — <what needs to be done>
#### Action taken
- Closed with comment / Commented / No action
Identify the issue and current state, verified implementation/PR evidence,
remaining items, verdict, and action actually taken. Use a table for batches;
a single issue does not require a heading for each field. Follow step 4's
verdicts without repeating the assessment in another template.
## Notes
@@ -1,6 +1,6 @@
---
name: plugin-contract-guard
description: Invariants and change procedure for the target-plugin / extension system — plugin manifests, admin plugin/extension catalog and instance APIs, secret redaction, external-plugin install policy. Use when editing crates/targets (manifest, plugin, control_plane, catalog, runtime), crates/extension-schema, or rustfs/src/admin plugin_contract.rs / plugins_*.rs / extensions.rs / target_descriptor.rs.
description: Guard changes to target-plugin manifests, extension schemas, admin catalog/instance contracts, secret redaction, and external-plugin install policy. Use when a diff changes those contracts in crates/targets, crates/extension-schema, or admin plugin/extension handlers; path membership alone, comments, and unrelated runtime internals do not trigger it.
---
# Plugin & Extension Contract Guard
@@ -1,46 +0,0 @@
---
name: pr-creation-checker
description: Perform the final RustFS PR preflight and draft compliant English title/body metadata immediately before creating or updating a PR. Do not use during implementation or as a second general code review.
---
# PR Creation Checker
Use this skill only at the PR boundary. Reuse completed diff review and
verification evidence; do not reread the repository or rerun equivalent checks.
## Preflight
1. Confirm the branch is based on current `origin/main` and contains only the
intended task diff.
2. Inspect `git diff --stat`, `git diff --check`, and changed file names for
secrets, logs, generated artifacts, or unrelated edits.
3. Confirm the checks selected by root `AGENTS.md` passed on the final diff.
Do not replace focused behavioral tests with a generic gate or rerun checks
already covered by an unchanged umbrella run.
4. Read `.github/pull_request_template.md`. Consult `Makefile`, `.config/make/`,
or CI only when the required command/current gate is uncertain.
5. Return `BLOCKED` for an unclean scope, missing required evidence, failed
required checks, or non-compliant metadata.
## Metadata
- Title: English Conventional Commit, at most 72 characters, with no tool
prefix.
- Body: English, exact template headings, `N/A` where needed, concise rationale,
actual verification commands, and material risks/rollback notes.
- Use repository-relative paths; never include local absolute paths.
- Keep prose paragraphs on one logical line and never include the literal
sequence `\n`.
- Use a temporary body file with `gh pr create --body-file` or
`gh pr edit --body-file`; never pass multiline Markdown inline.
## Output
- Status: `READY` or `BLOCKED`.
- Title.
- Complete PR body.
- Verification commands and results.
- Risks or `N/A`.
Immediately before the GitHub write, repeat only the five preflight checks above
against the final head.
@@ -1,4 +0,0 @@
interface:
display_name: "PR Creation Checker"
short_description: "Draft RustFS-ready PRs with checks, template, and blockers."
default_prompt: "Use $pr-creation-checker for final PR preflight and compliant English title/body metadata."
+30 -84
View File
@@ -1,147 +1,93 @@
---
name: pr-review
description: Review a GitHub PR end-to-end from a URL or number — fetch metadata, inspect the diff, run multi-role adversarial review, check CI status, and post the review comment. Use when the user provides a PR link and asks to review it.
description: Review a GitHub PR from a URL or number using its actual base/head and risk-appropriate code review. Use when the user asks for a PR review, not a status lookup or PR wording edit. Publish a review only when authorized; delegation and monitoring follow the requested scope and root AGENTS.md.
---
# PR Review
Use this skill when the user provides a GitHub PR URL or number and asks to review it. This covers the full review lifecycle: data gathering, code review, CI verification, and posting the result.
Use this skill for PR context and review delivery. An ordinary review request is read-only unless the conversation also authorizes posting or fixes. Reuse that authorization without asking again; prepare the review before requesting any missing publication approval.
## Prerequisites
- Read `AGENTS.md` for the repository's adversarial validation policy and change-style rules.
- The `adversarial-validation` skill handles the review role playbooks; this skill orchestrates the workflow around it.
- Follow root `AGENTS.md`; classify risk with the [review policy](../../references/adversarial-validation.md) and consult relevant [change-style and boundary rules](../../references/implementation.md).
- Select `code-change-verification` for ordinary review or `adversarial-validation` for explicitly adversarial, substantial, or high-risk review; do not run both on the same diff.
## Workflow
### 1. Gather PR context
```bash
gh pr view <N> --json title,author,state,body,additions,deletions,changedFiles,commits,baseRefName,headRefName
gh pr diff <N> --name-only
gh pr view <N> --repo <owner/repo> --json title,author,state,body,additions,deletions,changedFiles,commits,baseRefName,headRefName,baseRefOid,headRefOid
gh pr diff <N> --repo <owner/repo> --name-only
```
Read the PR body and linked issues to understand the change's purpose. If the PR references an issue, fetch that too:
```bash
gh issue view <ISSUE> --json title,body,state
gh issue view <ISSUE> --repo <issue-owner/repo> --json title,body,state
```
### 2. Fetch the diff and classify the change
```bash
git fetch origin pull/<N>/head:pr-<N>
git diff main...pr-<N> --stat
git fetch <repo-remote> <baseRefName> refs/pull/<N>/head
git diff <baseRefOid>...<headRefOid> --stat
```
Classify the change by risk tier (per AGENTS.md):
- **Exempt**: docs/comments/instruction-only, formatting, typos.
- **Mechanical**: renames, file moves, test-only or tooling changes.
- **Standard** (default): any behavior change.
- **High risk**: locking, erasure coding, quorum/heal, replication, multipart, RPC, lifecycle/tiering, metadata formats, persistence/fsync, IAM/KMS/auth, on-disk/on-wire formats, S3 API-visible behavior.
Resolve `<repo-remote>` to the PR repository; do not assume the current checkout's `origin` or `main` matches. Record the exact base/head used. If either moved during fetching, refresh the snapshot before reviewing. Classify using the repository review policy; instruction changes that affect agent execution are mechanical, not exempt.
### 3. Cluster changed files and delegate review
### 3. Review the changed behavior
Group the changed files into logical clusters (by crate or functional area). For each cluster, spawn a subagent with a focused review prompt that includes:
- The cluster's changed files and their diffs.
- The applicable adversarial role probes (from the `adversarial-validation` skill).
- The repository's AGENTS.md rules relevant to that domain.
Group files by functional area to trace callers and invariants. Use the root risk tier's review shape and only matching lenses. File count does not authorize delegation. When delegation is explicitly authorized, high-risk/substantial reviews use exactly two independent reviewers with the applicable lenses split between them; otherwise use two fresh sequential passes. Reviewers do not spawn further agents.
For standard-tier changes: correctness adversary + simplicity adversary + test-coverage skeptic, plus every role whose domain the diff touches.
For high-risk changes: run all seven roles.
Each subagent must produce findings (concrete failure scenario with file:line) or a null report ("attacked X, Y, Z — no break found").
Findings need a concrete failure scenario with `file:line`; a null verdict briefly names the relevant probes. Reuse existing evidence and choose local checks from the final diff under the root verification policy.
### 4. Check CI status
```bash
gh pr checks <N>
gh pr checks <N> --repo <owner/repo>
```
If any checks fail, investigate:
Investigate a failed check when it bears on a finding or the user requested CI diagnosis/merge readiness:
```bash
gh run view --log-failed --job=<JOB_ID>
gh run view --repo <owner/repo> --log-failed --job=<JOB_ID>
```
Determine whether failures are pre-existing (on main), flaky, or caused by the PR.
Use current evidence to distinguish pre-existing, flaky, and PR-caused failures. Do not classify them by guesswork or turn a code-only review into unrelated CI repair.
### 5. Synthesize findings
Combine all subagent findings into a structured review:
- **Summary**: one-paragraph overview of the change and overall assessment.
- **Findings**: each finding with severity (critical/major/minor/nit), file:line, concrete failure scenario, and suggested fix.
- **CI status**: pass/fail with notes on any failures.
- **Verdict**: APPROVE, REQUEST_CHANGES, or COMMENT.
Report the PR, reviewed base/head, and risk tier, then summarize the assessment.
Use the selected review's P0P3 ratings and root finding standard: supported
findings with `file:line`, failure scenario, and fix, or `No findings`.
State the observed check status, including pending or unavailable checks, and
the verdict (`APPROVE`, `REQUEST_CHANGES`, or `COMMENT`). Do not infer a pass
from missing checks or add style nits to populate a clean review.
### 6. Post the review
Write the review body to a temp file and post via CLI:
Only when posting is authorized, write the review body to a temp file and post via CLI. Refresh the PR head first; if it changed, review the delta and update the verdict before posting:
```bash
# Request changes
gh pr review <N> --request-changes --body-file /tmp/pr_review.md
gh pr review <N> --repo <owner/repo> --request-changes --body-file /tmp/pr_review.md
# Approve
gh pr review <N> --approve --body-file /tmp/pr_review.md
gh pr review <N> --repo <owner/repo> --approve --body-file /tmp/pr_review.md
# Comment only (no verdict)
gh pr review <N> --comment --body-file /tmp/pr_review.md
gh pr review <N> --repo <owner/repo> --comment --body-file /tmp/pr_review.md
```
For inline comments on specific lines, use the GitHub API:
```bash
cat > /tmp/pr_review.json <<'EOF'
{
"body": "review body",
"event": "REQUEST_CHANGES",
"comments": [
{
"path": "crates/foo/src/bar.rs",
"line": 42,
"body": "finding description"
}
]
}
EOF
gh api --method POST /repos/{owner}/{repo}/pulls/<N>/reviews --input /tmp/pr_review.json
```
For authorized inline comments, use [the submission example](references/posting.md).
Always use `--body-file` or `--input`, never inline multiline `--body`.
### 7. Handle follow-up
If the review requests changes:
- Monitor for new commits: `gh pr view <N> --json commits`
- Re-review changed files only: `git diff pr-<N>..origin/pull/<N>/head`
- Update the review when findings are addressed.
If CI was failing due to pre-existing main breakage:
- Comment on the PR noting the failure is pre-existing.
- Suggest updating the branch: `gh pr update-branch <N>`
## Output format
### PR Review: #<N> — <title>
**Author**: <author>
**Risk tier**: exempt | mechanical | standard | high-risk
**Changed files**: <count> across <cluster count> clusters
#### Summary
<one-paragraph overview>
#### Findings
| Severity | Location | Finding |
|----------|----------|---------|
| critical | file:line | concrete failure scenario |
#### CI Status
- All checks pass / Failing: <details>
#### Verdict
APPROVE / REQUEST_CHANGES / COMMENT
Follow the [PR lifecycle](../../references/pull-requests.md) and any explicit monitoring request. For follow-up, fetch the new head and compare the recorded reviewed SHA with the new SHA; revisit affected callers and findings. Never use an unfetched `origin/pull/<N>/head` ref as evidence. Update the posted review or resolve addressed threads only within existing authorization.
## Notes
- The user may ask for review in Chinese; respond in the same language but keep the review body in English per AGENTS.md rules.
- When the user asks for "多角色对抗 review", run the full adversarial validation protocol — this skill's step 3 covers that.
- If the PR is from a fork, check `maintainerCanModify` before attempting to push fixes.
- For very large PRs (>50 files), cluster aggressively and delegate in parallel to keep review time reasonable.
- For very large PRs, batch the review by functional area while keeping the same bounded review shape.
@@ -0,0 +1,22 @@
# Inline PR Review Submission
Read only when an inline review is authorized. Recheck the PR head before posting and bind the review to the reviewed commit.
For inline comments on specific lines, use the GitHub API:
```bash
cat > /tmp/pr_review.json <<'EOF'
{
"commit_id": "<reviewed-head-sha>",
"body": "review body",
"event": "REQUEST_CHANGES",
"comments": [
{
"path": "crates/foo/src/bar.rs",
"line": 42,
"body": "finding description"
}
]
}
EOF
gh api --method POST /repos/{owner}/{repo}/pulls/<N>/reviews --input /tmp/pr_review.json
```
+16 -23
View File
@@ -1,6 +1,6 @@
---
name: rust-code-quality
description: Run a focused Rust quality review when the user requests one, when reviewing a Rust PR/commit, or when another selected review workflow delegates Rust-specific checks. Do not auto-load for every implementation edit.
description: Run a focused Rust quality review when the user requests one or a selected review workflow needs Rust-specific checks for changed behavior. Do not auto-load for every implementation edit, comment-only or formatting-only Rust diff, or repeat an already completed review.
---
# Rust Code Quality Gate
@@ -8,12 +8,18 @@ description: Run a focused Rust quality review when the user requests one, when
Use this skill for a dedicated Rust review to cover rules that `cargo clippy`
does not catch.
Search matches and checklist items are candidates, not findings. Apply the root
finding standard; distinguish a demonstrated bug, an explicit rule violation,
and an optional preference. P2/P3 suggestions do not need to be invented or
included in an otherwise clean correctness review.
## Quick Start
1. Identify changed `.rs` files.
2. Run automated checks on changed files.
3. Run manual review checklist on the diff.
4. Resolve or rebut every finding with evidence; P0/P1 findings cannot be deferred.
2. Run the matching candidate searches on changed files.
3. Apply the manual checklist sections whose behavior the diff touches.
4. Report or rebut every finding with evidence; P0/P1 findings block approval.
Fix them when implementation is authorized; a read-only review reports them.
## Automated Checks
@@ -35,7 +41,7 @@ rg -n 'Result<.*String>' <changed-files>
rg -n 'Box<dyn.*Error' <changed-files>
# 5. println/eprintln in production
rg -n 'println!\|eprintln!' <changed-files>
rg -n 'println!|eprintln!' <changed-files>
# 6. Ordering::Relaxed usage (verify each is intentional)
rg -n 'Ordering::Relaxed' <changed-files>
@@ -80,7 +86,7 @@ For the Rust diff under review, verify:
- [ ] Test volume and line count are never treated as production-code growth
### Serde
- [ ] Structs from untrusted input have `#[serde(deny_unknown_fields)]`
- [ ] Structs from untrusted input reject unknown fields where the compatibility contract permits; otherwise validate security-critical fields explicitly and test the supported input shape
- [ ] `#[serde(default)]` not used on security-critical fields without validation
### Code Hygiene
@@ -104,20 +110,7 @@ For the Rust diff under review, verify:
## Output Template
```
## Rust Code Quality Report
### Automated Scan
- unwrap/expect candidates inspected: N
- numeric-cast candidates inspected: N
- error-type candidates inspected: N
- output-macro candidates inspected: N
### Findings
- [P1] `path:line` — description
- Fix: ...
- Validation: ...
### Verdict
PASS / BLOCKED (list blocking findings)
```
Use the calling review's output format. For a standalone review, report supported
findings with severity, location, impact, fix, and validation, or `No findings`.
Include only material unverified checks. Candidate counts are not a quality
metric and do not need a separate scan report.
+13 -104
View File
@@ -4,9 +4,14 @@ description: "Run the end-to-end RustFS console gate, version bump, preview vali
---
# RustFS Release Publish (preview-validated pipeline)
This skill orchestrates a full release. It wraps `rustfs-release-version-bump` (which only edits version files and opens the PR) with a mandatory preview-tag validation loop before the final tag is published.
This skill orchestrates a full release. It wraps `rustfs-release-version-bump` (invoked here with the authorized commit/push/PR scope) with a mandatory preview-tag validation loop before the final tag is published.
Core design: **version files never carry a `-preview.N` suffix**. The preview suffix exists only in tag names. A preview tag creates a visible GitHub Release marked Prerelease and uploads versioned assets, but it never becomes GitHub Latest and never updates `*-latest`, `latest.json`, R2, Docker, or Helm channels. That Release is temporary: `build.yml` deletes it automatically once the final tag's Release is published, so the Releases page ends up carrying deliverables only while the `-preview.N` tags stay behind as the traceability record. This works because the binary self-reports the git tag it was built from (`build::TAG` via shadow_rs, see `rustfs/src/config/cli.rs` `SHORT_VERSION`), and `build.yml` derives artifact names and preview classification from the tag name — Cargo.toml's version is only a no-tag fallback. Therefore the preview tag and the final tag can (and MUST) point at the exact same commit: what you validated is byte-for-byte the source that ships.
The binary reports its build tag (`build::TAG` via shadow_rs; `SHORT_VERSION` in
`rustfs/src/config/cli.rs`), and `build.yml` derives asset names and preview
classification from that tag. Cargo.toml supplies only the no-tag fallback.
Preview and final tags must therefore share the validated source commit;
their tag-dependent version and asset names differ. The channel and cleanup
constraints are defined once under Preview tag naming and Hard rules below.
Pipeline shape:
@@ -29,9 +34,9 @@ On validation failure: fix lands on main via normal PR (version files are alread
- Final target version, for example `1.0.0-beta.10`.
- Preview iteration `N` (default: next unused preview tag for that target; check with `git tag -l '<target>-preview.*'` after `git fetch --tags`).
If the target version is missing or ambiguous, stop and ask before doing anything (see the semver gate below).
If the target version is missing or ambiguous, collect the current release/tag baseline and ask before version edits or publication. Continue independent read-only preflight while the answer is pending (see the semver gate below).
## Semver gate — confirm the target version before touching anything
## Semver gate — resolve the target before version edits or publication
Versions follow [SemVer 2.0.0](https://semver.org/). Precedence reminder:
@@ -43,7 +48,7 @@ Numeric prerelease identifiers compare numerically (`beta.9 < beta.10`), not lex
Rules:
- A request like "发个版" / "release the next version" without an exact version string is ALWAYS ambiguous. Derive the current latest tag (`git tag --sort=-v:refname | head`), then ask the user to choose via AskUserQuestion with concrete candidates, e.g. from `1.0.0-beta.10`: next prerelease `1.0.0-beta.11`, promote to `1.0.0-rc.1`, promote to stable `1.0.0`. Never guess between these — they have very different meanings (channel promotion vs. iteration) and different CI classification consequences.
- A request like "发个版" / "release the next version" without an exact version string is ALWAYS ambiguous. Derive the current latest tag (`git tag --sort=-v:refname | head`), then ask the user to choose with concrete candidates, e.g. from `1.0.0-beta.10`: next prerelease `1.0.0-beta.11`, promote to `1.0.0-rc.1`, promote to stable `1.0.0`. Never guess between these — they have very different meanings (channel promotion vs. iteration) and different CI classification consequences.
- After a stable `X.Y.Z` exists, the next version must state which component bumps: patch `X.Y.(Z+1)` for fixes only, minor `X.(Y+1).0` for backward-compatible features, major `(X+1).0.0` for breaking changes. If the user names a bump type but not a number, compute it from the latest stable tag and echo the exact resulting version back for confirmation.
- Echo the final confirmed version string verbatim in your first status report; every later phase must use exactly that string. If at any point the user's wording and the confirmed version diverge, stop and re-confirm.
@@ -77,58 +82,7 @@ Rules:
### Console release gate
Complete this gate before changing any RustFS version file or creating any RustFS tag. RustFS `build.yml` downloads the asset returned by `repos/rustfs/console/releases/latest`, so a successful Console build alone is insufficient.
1. Read the latest published Console tag and compare it with Console `main`:
```bash
CONSOLE_REPO="rustfs/console"
CONSOLE_LATEST=$(gh api "repos/${CONSOLE_REPO}/releases/latest" --jq .tag_name)
gh api "repos/${CONSOLE_REPO}/compare/${CONSOLE_LATEST}...main" \
--jq '{status, ahead_by, behind_by, commits: [.commits[] | {sha, message: .commit.message}]}'
```
- `ahead_by == 0`: no merged Console change is waiting for release. Still verify the current latest asset using step 4, then continue to Phase 1.
- `ahead_by > 0` and `behind_by == 0`: publish Console before continuing. Report the merged commits and select the next unused `vX.Y.Z` tag. Default to the next patch version when the changes are fixes or backward-compatible UI work; stop for confirmation if a minor/major bump is plausible.
- Any diverged history or `behind_by > 0`: stop and resolve the Console release baseline explicitly. Do not guess a range or publish RustFS.
2. Clone/fetch `rustfs/console` into a scratch directory and record its exact `main` commit. Before creating a tag, check for a `v*` tag or Release workflow already associated with that hash. If one is in progress, wait for it instead of creating another version:
```bash
CONSOLE_SCRATCH=$(mktemp -d)
gh repo clone "$CONSOLE_REPO" "$CONSOLE_SCRATCH/console"
git -C "$CONSOLE_SCRATCH/console" fetch origin main --tags
CONSOLE_HASH=$(git -C "$CONSOLE_SCRATCH/console" rev-parse origin/main)
git -C "$CONSOLE_SCRATCH/console" tag --points-at "$CONSOLE_HASH" 'v*'
gh run list -R "$CONSOLE_REPO" --workflow release.yml --commit "$CONSOLE_HASH" --limit 5
```
If no release exists or is running for `CONSOLE_HASH`, create the selected annotated tag at that exact hash and push it:
```bash
git -C "$CONSOLE_SCRATCH/console" tag -a "<console-tag>" -m "Release <console-tag>" "$CONSOLE_HASH"
git -C "$CONSOLE_SCRATCH/console" push origin "<console-tag>"
```
Console tags include the `v` prefix. Pushing the tag triggers `.github/workflows/release.yml` (`🚀 Release`). Remove `CONSOLE_SCRATCH` after the gate completes.
3. Find the exact tag run and wait for completion:
```bash
gh run list -R "$CONSOLE_REPO" --workflow release.yml --branch "<console-tag>" --limit 1
gh run watch -R "$CONSOLE_REPO" "<console-run-id>" --exit-status
```
4. Block until the published Release is non-draft, the latest endpoint returns the expected tag, and `rustfs-console-<console-tag>.zip` is uploaded, non-empty, and carries a `sha256:` digest:
```bash
gh release view -R "$CONSOLE_REPO" "<console-tag>" --json isDraft,isPrerelease,assets,url
test "$(gh api "repos/${CONSOLE_REPO}/releases/latest" --jq .tag_name)" = "<console-tag>"
test "$(gh api "repos/${CONSOLE_REPO}/releases/tags/<console-tag>" \
--jq '[.assets[] | select(.name == "rustfs-console-<console-tag>.zip" and .state == "uploaded" and .size > 0 and (.digest | startswith("sha256:")))] | length')" -eq 1
```
Treat a missing/mismatched asset, digest, latest tag, or failed/cancelled workflow as BLOCKED. Do not start Phase 1 until the Console gate passes. Record `CONSOLE_TAG`, `CONSOLE_HASH`, Console run URL, and Release URL for the final report.
Read and complete [the Console gate](references/console-gate.md) before Phase 1. Verify the latest published Console asset and exact commit; if Console main is ahead, complete its release and asset verification first. A successful build alone does not satisfy this gate.
## Phase 1 — Version bump to the final target (once)
@@ -164,54 +118,9 @@ On a restart (N+1), refresh `PREVIEW_HASH=$(git rev-parse origin/main)` first
- Record `PREVIOUS_DELIVERABLE`, selected from published Releases by `publishedAt` after excluding the current tag and every `-preview.N` tag. Verify `gh release view "<preview-tag>" --json body --jq .body` contains `## What's Changed` and, when `PREVIOUS_DELIVERABLE` exists, `**Full Changelog**: https://github.com/rustfs/rustfs/compare/<PREVIOUS_DELIVERABLE>...<preview-tag>`. For a repository with no previous deliverable, verify a Full Changelog link exists and record the GitHub baseline fallback.
- Confirm preview-triggered Docker and Helm jobs are skipped. Preview validation covers the built RustFS binaries, embedded console, and rc compatibility; Docker image construction and Helm publication are deferred to the final tag because the Dockerfiles consume GitHub Release assets.
## Phase 4 — Run the artifact locally, verify the console
## Phases 45Local artifact, Console, and rc acceptance
Work inside the session scratchpad directory; never leave stray data dirs.
```bash
gh release download "<preview-tag>" -p "rustfs-macos-aarch64-v<preview-tag>.zip" -D "$SCRATCH"
cd "$SCRATCH" && unzip -o rustfs-*.zip
./rustfs --version # must report the PREVIEW TAG (build::TAG), not the Cargo.toml version, plus expected short SHA
mkdir -p data
RUSTFS_ACCESS_KEY=rustfsadmin RUSTFS_SECRET_KEY=rustfsadmin ./rustfs ./data
```
Defaults: S3 endpoint `:9000`, embedded console `:9001`.
Checks (all must pass):
- `./rustfs --version` reports the preview tag name and the short SHA of `PREVIEW_HASH`. Reporting `<target>` without the `-preview.N` suffix means the build did not embed the tag — treat as FAIL and investigate before proceeding.
- `curl -fsS http://localhost:9000/health/ready` returns ready.
- Startup log shows the embedded console being served (this was the regression that `fix(release): require embedded console assets` guards).
- Open `http://localhost:9001` in the browser: login with `rustfsadmin`/`rustfsadmin`; dashboard renders without JS console errors; create a bucket, upload a file, download it back (byte-identical), delete the object and bucket. Keep the server running for Phase 5.
## Phase 5 — Validate with the latest rc client
`rc` is the RustFS CLI client from <https://github.com/rustfs/cli>.
- Ensure the latest release is installed: compare `rc --version` against `gh api repos/rustfs/cli/releases/latest --jq .tag_name`; update via `brew upgrade rustfs/tap/rc` (or download the release binary).
- Point it at the preview server and run the command matrix, recording PASS/FAIL per command:
```bash
rc alias set preview http://localhost:9000 rustfsadmin rustfsadmin
rc ls preview/
rc mb preview/rel-check
rc cp <local-file> preview/rel-check/
rc stat preview/rel-check/<file>
rc cat preview/rel-check/<file> # matches source
rc cp preview/rel-check/<file> ./out && cmp <local-file> ./out
rc cp -r <local-dir>/ preview/rel-check/dir/
rc find preview/rel-check --name "*"
rc share download preview/rel-check/<file> --expire 1h # presigned URL fetchable via curl
rc rm preview/rel-check/<file> && rc rm -r --force preview/rel-check/dir
rc rb preview/rel-check
rc admin user list preview/
rc admin user add preview/ relcheckuser relchecksecret12
rc admin user remove preview/ relcheckuser
rc alias remove preview
```
- Any FAIL blocks the release. Afterwards stop the server and delete the scratch data directory.
Read and complete [preview acceptance](references/preview-acceptance.md): verify the downloaded binary's tag/SHA and readiness, exercise Console CRUD with byte-identical download, and pass the full latest-rc command matrix. Any failure blocks final publication. Retain the results for the confirmation gate below.
### Manual confirmation gate
@@ -0,0 +1,58 @@
# Console Release Gate
Read during Phase 0, before changing RustFS version files or tags. Follow the parent skill's release scope and authorization rules.
### Console release gate
Complete this gate before changing any RustFS version file or creating any RustFS tag. RustFS `build.yml` downloads the asset returned by `repos/rustfs/console/releases/latest`, so a successful Console build alone is insufficient.
1. Read the latest published Console tag and compare it with Console `main`:
```bash
CONSOLE_REPO="rustfs/console"
CONSOLE_LATEST=$(gh api "repos/${CONSOLE_REPO}/releases/latest" --jq .tag_name)
gh api "repos/${CONSOLE_REPO}/compare/${CONSOLE_LATEST}...main" \
--jq '{status, ahead_by, behind_by, commits: [.commits[] | {sha, message: .commit.message}]}'
```
- `ahead_by == 0`: no merged Console change is waiting for release. Still verify the current latest asset using step 4, then continue to Phase 1.
- `ahead_by > 0` and `behind_by == 0`: publish Console before continuing. Report the merged commits and select the next unused `vX.Y.Z` tag. Default to the next patch version when the changes are fixes or backward-compatible UI work; stop for confirmation if a minor/major bump is plausible.
- Any diverged history or `behind_by > 0`: stop and resolve the Console release baseline explicitly. Do not guess a range or publish RustFS.
2. Clone/fetch `rustfs/console` into a scratch directory and record its exact `main` commit. Before creating a tag, check for a `v*` tag or Release workflow already associated with that hash. If one is in progress, wait for it instead of creating another version:
```bash
CONSOLE_SCRATCH=$(mktemp -d)
gh repo clone "$CONSOLE_REPO" "$CONSOLE_SCRATCH/console"
git -C "$CONSOLE_SCRATCH/console" fetch origin main --tags
CONSOLE_HASH=$(git -C "$CONSOLE_SCRATCH/console" rev-parse origin/main)
git -C "$CONSOLE_SCRATCH/console" tag --points-at "$CONSOLE_HASH" 'v*'
gh run list -R "$CONSOLE_REPO" --workflow release.yml --commit "$CONSOLE_HASH" --limit 5
```
If no release exists or is running for `CONSOLE_HASH`, create the selected annotated tag at that exact hash and push it:
```bash
git -C "$CONSOLE_SCRATCH/console" tag -a "<console-tag>" -m "Release <console-tag>" "$CONSOLE_HASH"
git -C "$CONSOLE_SCRATCH/console" push origin "<console-tag>"
```
Console tags include the `v` prefix. Pushing the tag triggers `.github/workflows/release.yml` (`🚀 Release`). Remove `CONSOLE_SCRATCH` after the gate completes.
3. Find the exact tag run and wait for completion:
```bash
gh run list -R "$CONSOLE_REPO" --workflow release.yml --branch "<console-tag>" --limit 1
gh run watch -R "$CONSOLE_REPO" "<console-run-id>" --exit-status
```
4. Block until the published Release is non-draft, the latest endpoint returns the expected tag, and `rustfs-console-<console-tag>.zip` is uploaded, non-empty, and carries a `sha256:` digest:
```bash
gh release view -R "$CONSOLE_REPO" "<console-tag>" --json isDraft,isPrerelease,assets,url
test "$(gh api "repos/${CONSOLE_REPO}/releases/latest" --jq .tag_name)" = "<console-tag>"
test "$(gh api "repos/${CONSOLE_REPO}/releases/tags/<console-tag>" \
--jq '[.assets[] | select(.name == "rustfs-console-<console-tag>.zip" and .state == "uploaded" and .size > 0 and (.digest | startswith("sha256:")))] | length')" -eq 1
```
Treat a missing/mismatched asset, digest, latest tag, or failed/cancelled workflow as BLOCKED. Do not start Phase 1 until the Console gate passes. Record `CONSOLE_TAG`, `CONSOLE_HASH`, Console run URL, and Release URL for the final report.
@@ -0,0 +1,52 @@
# Preview Artifact Acceptance
Read after Phase 3 succeeds. Complete every check below before the parent skill's manual confirmation gate. These checks cover the downloaded artifact, embedded Console, and latest rc client.
## Phase 4 — Run the artifact locally, verify the console
Work inside the session scratchpad directory; never leave stray data dirs.
```bash
gh release download "<preview-tag>" -p "rustfs-macos-aarch64-v<preview-tag>.zip" -D "$SCRATCH"
cd "$SCRATCH" && unzip -o rustfs-*.zip
./rustfs --version # must report the PREVIEW TAG (build::TAG), not the Cargo.toml version, plus expected short SHA
mkdir -p data
RUSTFS_ACCESS_KEY=rustfsadmin RUSTFS_SECRET_KEY=rustfsadmin ./rustfs ./data
```
Defaults: S3 endpoint `:9000`, embedded console `:9001`.
Checks (all must pass):
- `./rustfs --version` reports the preview tag name and the short SHA of `PREVIEW_HASH`. Reporting `<target>` without the `-preview.N` suffix means the build did not embed the tag — treat as FAIL and investigate before proceeding.
- `curl -fsS http://localhost:9000/health/ready` returns ready.
- Startup log shows the embedded console being served (this was the regression that `fix(release): require embedded console assets` guards).
- Open `http://localhost:9001` in the browser: login with `rustfsadmin`/`rustfsadmin`; dashboard renders without JS console errors; create a bucket, upload a file, download it back (byte-identical), delete the object and bucket. Keep the server running for Phase 5.
## Phase 5 — Validate with the latest rc client
`rc` is the RustFS CLI client from <https://github.com/rustfs/cli>.
- Ensure the latest release is installed: compare `rc --version` against `gh api repos/rustfs/cli/releases/latest --jq .tag_name`; update via `brew upgrade rustfs/tap/rc` (or download the release binary).
- Point it at the preview server and run the command matrix, recording PASS/FAIL per command:
```bash
rc alias set preview http://localhost:9000 rustfsadmin rustfsadmin
rc ls preview/
rc mb preview/rel-check
rc cp <local-file> preview/rel-check/
rc stat preview/rel-check/<file>
rc cat preview/rel-check/<file> # matches source
rc cp preview/rel-check/<file> ./out && cmp <local-file> ./out
rc cp -r <local-dir>/ preview/rel-check/dir/
rc find preview/rel-check --name "*"
rc share download preview/rel-check/<file> --expire 1h # presigned URL fetchable via curl
rc rm preview/rel-check/<file> && rc rm -r --force preview/rel-check/dir
rc rb preview/rel-check
rc admin user list preview/
rc admin user add preview/ relcheckuser relchecksecret12
rc admin user remove preview/ relcheckuser
rc alias remove preview
```
- Any FAIL blocks the release. Afterwards stop the server and delete the scratch data directory.
@@ -4,17 +4,16 @@ description: "Prepare the version-file and release-asset bump for an exact RustF
---
# RustFS Release Version Bump
Use this skill to publish a RustFS release (alpha, beta, or stable) with a minimal, auditable diff and a complete ship flow (`edit -> verify -> commit -> push -> PR`).
Use this skill to prepare and verify release version files. Commit, push, and PR steps apply only when included in the user's delivery scope; publishing release tags belongs to `rustfs-release-publish`.
Validated baseline: release pattern used in PR `#2957`.
## Required inputs
- Exact target version, for example `1.0.0-beta.4`.
- Delivery scope:
- Local only (`edit/verify`).
- Local + git (`commit/push`).
- Full GitHub flow (`commit/push/PR`).
- Delivery scope: local (`edit/verify`), git (`commit/push`), or GitHub
(`commit/push/PR`). Derive it from the conversation; when unspecified, prepare
and verify locally without blocking on a delivery question.
If target version is missing or ambiguous, stop and ask before editing.
@@ -23,7 +22,7 @@ Reject any target version containing `-preview`: preview identifiers are tag-onl
## Read before editing
- `AGENTS.md` (root and nearest path-specific files).
- `.github/pull_request_template.md`.
- `.github/pull_request_template.md` only when preparing a PR.
- Current branch status and diff against `origin/main`.
## Default release file scope
@@ -50,8 +49,7 @@ Only drop a file when the current repository release process clearly no longer r
## Step-by-step workflow
1. Confirm intent and isolate scope
- Confirm target version string exactly.
- Confirm whether user requested local-only or full GitHub flow.
- Use the exact target and delivery scope already supplied; ask only for a missing or ambiguous target or a material release-policy choice.
- Inspect current branch and ensure only release-related files are touched for this task.
2. Update workspace versions
@@ -82,18 +80,18 @@ Only drop a file when the current repository release process clearly no longer r
4. Verify before shipping
- Run:
- `make pre-commit`
- If `make pre-commit` fails, return `BLOCKED` with root cause and do not silently widen scope to fix unrelated issues unless user asks.
- If `make pre-commit` fails, fix task-attributable failures and rerun affected checks. Report unresolved required checks as `BLOCKED`; do not silently widen scope to fix unrelated issues.
5. Commit strategy
5. Commit strategy (only when committing is authorized)
- Preferred split when both parts changed:
- `chore(release): prepare <version>` for `Cargo.toml` and `Cargo.lock`.
- `chore(release): align release assets for <version>` for docs and packaging files.
- If user asks for one commit, use one commit.
- Stage only intended release files; do not include unrelated working tree changes.
6. Push and PR
6. Push and PR (only for the authorized delivery scope)
- Push branch:
- `git push -u origin <branch>` (first push), or `git push` (tracking already exists).
- Use the user-requested or configured push remote: `git push -u <push-remote> <branch>` (first push), or `git push` when tracking is already configured.
- Create PR with template headings unchanged:
- `gh pr create --base main --head <branch> --title ... --body-file ...`
- PR title/body must be English.
@@ -12,8 +12,9 @@ matched security surface, the concise security reference under
## Workflow
1. Freeze the exact diff/head and identify the changed trust boundaries.
2. Read [advisory-patterns.md](references/advisory-patterns.md), then apply only
the matching sections. Useful headings are
2. Inspect the headings in [advisory-patterns.md](references/advisory-patterns.md),
then read the matching sections. Read the full map only for a broad security
audit. Useful headings are
auth/admin, IAM/STS/OIDC, policy/plugins, S3/copy/multipart, protocols, paths,
secrets/logging/RPC, browser/CORS/proxy, SSE, Object Lock, and serde.
3. Trace unauthenticated, low-privilege, wrong-action/owner/bucket, malformed,
@@ -108,9 +108,9 @@ Update this file only when an advisory adds or changes a reusable lesson, affect
### Serde deserialization and input validation
- No `#[serde(deny_unknown_fields)]` found across the entire codebase. Lesson: all structs deserialized from untrusted input (S3 API XML/JSON, lifecycle rules, bucket policies, replication configs) should have `#[serde(deny_unknown_fields)]` to reject malformed or adversarial payloads.
- Reject unknown fields in untrusted S3 API XML/JSON, lifecycle, policy, and replication input where compatibility permits. Check the current type and supported payload fixtures; do not infer the repository's current coverage from an older audit. Where extra fields are part of the compatibility contract, validate security-critical values explicitly.
- `#[serde(default)]` on security-critical fields silently accepts missing values as zero/empty. Lesson: when a field has security implications (retention days, permissions, limits), validate the deserialized value explicitly rather than relying on defaults.
- Integer fields deserialized from user input and cast with `as` (e.g., `i32 as u32`) can wrap negative values to large positives. Lesson: validate ranges before casting; use `try_into()` or clamp.
- Integer fields deserialized from user input and cast with `as` (e.g., `i32 as u32`) can wrap negative values to large positives. Lesson: validate ranges before casting; use `try_into()` with a typed error, or clamp only when the domain explicitly requires saturation.
- XML config typos (e.g., `"NoncurentDays"` instead of `"NoncurrentDays"`) are silently accepted when `deny_unknown_fields` is absent. Lesson: strict deserialization prevents silent misconfiguration that could cause data loss or unexpected retention behavior.
## Useful Search Seeds
+28 -37
View File
@@ -1,6 +1,6 @@
---
name: test-coverage-improver
description: Run project coverage checks, rank high-risk gaps, and propose high-impact tests to improve regression confidence for changed and critical code paths before release.
description: Analyze a supplied coverage report or perform an explicitly requested RustFS coverage assessment, rank uncovered risks, and propose focused tests. Do not trigger for ordinary implementation verification, a single regression test, documentation wording, or release preparation without a coverage request.
---
# Test Coverage Improver
@@ -9,58 +9,49 @@ Use this skill when you need a prioritized, risk-aware plan to improve tests fro
## Usage assumptions
- Focus scope is either changed lines/files, a module, or the whole repository.
- Coverage artifact must be generated or provided in a supported format.
- Reuse a supplied coverage artifact when its revision, scope, and format match.
- If required context is missing, call out assumptions explicitly before proposing work.
## Workflow
1. Define scope and baseline
- Confirm target language, framework, and branch.
- Confirm whether the scope is changed files only or full-repo.
- Derive the revision and scope from the request, diff, or supplied report.
- Default to the affected files/module; whole-workspace coverage requires that
scope in the request. Ask only if a wrong scope would change the result.
2. Produce coverage snapshot
- Rust: `cargo llvm-cov` (or `cargo tarpaulin`) with existing repo config.
- JavaScript/TypeScript: `npm test -- --coverage` and read `coverage/coverage-final.json`.
- Python: `pytest --cov=<pkg> --cov-report=json` and read `coverage.json`.
- Collect total, per-file, and changed-line coverage.
2. Obtain coverage evidence
- First inspect a matching existing artifact; do not regenerate it merely
because this skill was selected.
- If measurement is needed, read the Coverage section of
[the testing guide](../../../docs/testing/README.md#coverage), check disk
space/tool availability, and select package/test-scoped `cargo llvm-cov`
using the repository's nextest configuration. `make coverage` measures the
whole workspace (excluding E2E) and is only for that requested scope.
- Collect only metrics the report supports. Missing branch/changed-line
coverage is unknown, not zero.
- If measurement cannot run, continue with code-based test proposals and
mark measured coverage unverified; do not invent a coverage percentage.
3. Rank highest-risk gaps
- Prioritize changed code, branch coverage gaps, and low-confidence boundaries.
- Apply the risk rubric in [coverage-prioritization.md](references/coverage-prioritization.md).
- Keep shortlist to 58 gaps.
- Report up to 58 evidenced gaps; do not pad a small scope.
- For each gap, capture: file, lines, uncovered branches, and estimated risk score.
4. Propose high-impact tests
- For each shortlisted gap, output:
- Intent and expected behavior.
- Normal, edge, and failure scenarios.
- Assertions and side effects to verify.
- Setup needs (fixtures, mocks, integration dependencies).
- Estimated effort (`S/M/L`).
- For each gap, name the behavior and regression, distinguishing assertions,
relevant normal/edge/failure cases, necessary setup, and estimated effort.
- Include only scenarios and setup that apply; reuse shared fixture details.
5. Close with validation plan
- State which gaps remain after proposals.
- Provide concrete verification command and acceptance threshold.
- Give a scoped verification command and behavior-based acceptance criterion;
use a coverage threshold only when the task or repository requires one.
- List assumptions or blockers (environment, fixtures, flaky dependencies).
## Output template
## Report
### Coverage Snapshot
- total / branch coverage
- changed-file coverage
- top missing regions by size
### Top Gaps (ranked)
- `path:line-range` | risk score | why critical
### Test Proposals
- `path:line-range`
- Test name
- scenarios
- assertions
- effort
### Validation Plan
- command
- pass criteria
- remaining risk
Summarize the supported metrics, then combine each ranked gap with its proposed
test and validation. Include source lines only when supplied or inspected;
mark missing metrics or locations as unknown. Do not duplicate gaps and tests
in separate templates or fill empty categories for an otherwise small report.
@@ -1,4 +1,4 @@
interface:
display_name: "Test Coverage Improver"
short_description: "Find top uncovered risk areas and propose high-impact tests."
default_prompt: "Run coverage checks, identify largest gaps, and recommend highest-impact test cases to improve risk coverage."
default_prompt: "Use $test-coverage-improver to analyze coverage for the requested scope, reuse matching reports, and propose tests for evidenced risks."
+5 -2
View File
@@ -5,8 +5,11 @@ description: Debug ILM tiering / lifecycle transition issues — NoSuchVersion o
# Tier / ILM Debugging
Full playbook: [docs/operations/tier-ilm-debugging.md](../../../docs/operations/tier-ilm-debugging.md)
— read it before changing tier code.
Playbook: [docs/operations/tier-ilm-debugging.md](../../../docs/operations/tier-ilm-debugging.md).
Read the section matching the symptom: metadata/`xl.meta`, runtime versionId,
manual jobs, or retained-record recovery. Read the local-first expiry invariant
before changing cleanup ordering. Before a reconcile/disposition action, read
its entire procedure and retain its exact-evidence and confirmation gates.
Quick moves:
+5
View File
@@ -0,0 +1,5 @@
# Bound individual tool outputs retained in context; retrieve relevant ranges
# from task-owned log files when more evidence is needed.
# https://learn.chatgpt.com/docs/config-file/config-reference
tool_output_token_limit = 4000
+1
View File
@@ -47,6 +47,7 @@ script-tests: ## Run shell script tests
bash -n ./scripts/validate_object_data_cache_cold_stampede.sh
$(RUSTFS_PYTHON_BIN) ./scripts/check_object_data_cache_follower_samples.py --self-test
./scripts/validate_object_data_cache_cold_stampede.sh --self-test
./scripts/run_scanner_heal_evidence_case.sh --self-test
.PHONY: test
test: core-deps script-tests ## Run all tests (needs cargo-nextest; RUSTFS_ALLOW_CARGO_TEST_FALLBACK=1 to override)
+16
View File
@@ -8,10 +8,26 @@
"suite": "e2e_test",
"name": "heal_erasure_disk_rebuild_test::tests::test_cluster_root_heal_recovers_remote_shards_after_background_target_restart",
"oracle": "background-target-restart.json",
"evidence": "process-restart",
"unclean_shutdown_marker": false,
"min_objects": 9,
"max_objects": 65,
"topology": {"nodes": 4, "drives_per_node": 1},
"scope": "Target process restart, exact unversioned S3 bodies and replacement-disk shards; not power loss or EC8+4."
},
"background-target-crash": {
"gate": "G14",
"task": "W21",
"lane": "e2e-nightly",
"suite": "e2e_test",
"name": "heal_erasure_disk_rebuild_test::tests::test_cluster_root_heal_recovers_remote_shards_after_background_target_crash",
"oracle": "background-target-crash.json",
"evidence": "process-crash-restart",
"unclean_shutdown_marker": true,
"min_objects": 9,
"max_objects": 65,
"topology": {"nodes": 4, "drives_per_node": 1},
"scope": "Target process killed during partial background rebuild, real unclean-shutdown marker, exact unversioned S3 bodies and replacement-disk shards; not power loss or EC8+4."
}
},
"release_pending": {
+8
View File
@@ -82,6 +82,14 @@ jobs:
cache_key: e2e-odm-config-rollback
test: rc5_rollback_requires_restoring_odm_configuration
artifact: odm-config-rollback
- name: Multipart layouts survive the rc.5 upgrade
cache_key: e2e-multipart-layout-upgrade
test: direct_upgrade_from_rc5_preserves_multipart_layouts
artifact: multipart-layout-upgrade
- name: rc.5 multipart replication baseline
cache_key: e2e-multipart-layout-baseline
test: rc5_baseline_replicates_multipart_layouts
artifact: multipart-layout-baseline
runs-on: ubuntu-latest
timeout-minutes: 60
env:
+1 -1
View File
@@ -17,7 +17,7 @@ jobs:
runs-on: ubuntu-latest
timeout-minutes: 10
steps:
- uses: overtrue/repo-visuals-action@fd79cba437ecfac933d00a69add17eb95d3939c3 # v1.3.1
- uses: overtrue/repo-visuals-action@ee2c632f6ce617e851fb46ea935ee8af762ebb93 # v1.4.0
with:
github-token: ${{ github.token }}
output-branch: star-history
+38 -123
View File
@@ -7,8 +7,11 @@ This file contains repository-wide rules. Use the nearest subdirectory
1. System/developer instructions.
2. The current user request.
3. The nearest `AGENTS.md`.
4. This file.
3. Applicable `AGENTS.md` files, with the nearest file winning conflicts.
4. Selected skills and reference documents.
Nested instructions add to ancestor rules; they do not discard non-conflicting
rules. A skill cannot expand the user's requested scope or grant authorization.
## Operating Model
@@ -21,63 +24,29 @@ This file contains repository-wide rules. Use the nearest subdirectory
- Do not load every skill or inspect unrelated modules preemptively. Select a
skill only when its description directly matches the request or changed
surface.
- Resolve repository workflow skills under `.agents/skills/` when a global
skill has the same name, unless the user explicitly selects another path.
- Avoid repeated reads and equivalent verification commands once enough
evidence exists.
- Search for relevant symbols/headings before reading long files; return only
matching ranges. If output is truncated, narrow the query instead of repeating
a full read. Keep reusable raw logs in task artifacts and report the evidence.
- Reuse authorization already given in the conversation. Resolve routine choices
within that scope and continue independent work while a material question is
pending. Before requesting missing approval, prepare the concrete result that
is already authorized; retain explicit merge and release gates.
## Worktree and Disk Hygiene
## Task-Specific Guidance
- Start implementation from the latest `origin/main` and confirm the requested
change is not already present.
- An existing clean, isolated task worktree is sufficient. Create another
worktree only when the current checkout is shared, dirty with unrelated work,
or belongs to another task.
- Never commit from a shared checkout.
- Use a task-specific branch named `<type>/<topic>`, such as `fix/...`,
`feat/...`, `test/...`, or `docs/...`, unless the user specifies a name.
- Do not include agent, tool, contributor, account, or organization names in
branch names.
- Push to the user-requested remote or the repository's configured push remote.
Do not hard-code or infer a remote from an account name.
- Check free space before artifact-heavy builds, tests, coverage, or downloads.
Re-check before a broad gate when space is tight.
- Remove only task-owned temporary/build artifacts. Never delete another task's
worktree or uncommitted data.
- At handoff, mention disk or cleanup details only when they affected execution
or artifacts/worktrees remain intentionally.
Read only the reference needed for the current task, once per unchanged context:
## Change Style
- Preserve existing control flow unless changing it is required for correctness.
- Prefer a direct local edit over new files, wrappers, managers, or speculative
abstractions.
- Add a helper only when it removes current duplication, names a real domain
boundary, or isolates a non-trivial invariant.
- Remove an in-scope path superseded by the change. If compatibility requires it,
adapt at the boundary to one canonical core and use the repository's
`RUSTFS_COMPAT_TODO` policy.
- Comments explain non-obvious invariants or reasons. Do not narrate code or
record change history.
- Mention unrelated problems when useful; do not fix them in a narrow task.
## Reuse and Boundary Rules
- Before adding helpers, constants, fixtures, or wrappers, search the touched
crate, the domain-owning crate, `crates/utils`, `crates/common`, and relevant
direct dependencies.
- Reuse requires matching semantics: normalization, error types, deadlines,
durability, and compatibility must fit the call site. A narrowly named local
helper is better than forced reuse with different semantics.
- Validate untrusted input at its trust boundary, then trust the validated type.
Values crossing disk, RPC, persistence, or version boundaries remain
untrusted at every consumer.
- Re-check boundary values immediately before destructive actions such as
delete, overwrite, or quorum decisions.
- Every new branch needs a concrete triggering input/state. For decoded or peer
data, corruption and mixed-version input are valid triggers.
- Required values must return a typed error when absent or corrupt; do not use a
default that converts corruption into a plausible result.
- Attach error context once where it is actionable. Do not erase typed errors
below aggregation or quorum layers.
- Before code changes or artifact-heavy work, read [implementation rules](.agents/references/implementation.md).
For a read-only code review, use its change-style and boundary sections as needed.
- Before commits, pushes, PR creation/updates, or posting to PRs/issues/discussions,
read [Git and PR rules](.agents/references/pull-requests.md).
Reuse existing authorization; a reference does not authorize posting, merging, or publishing.
- Preserve unrelated work. Never commit from a shared checkout or delete another task's artifacts.
- Source comments, commits, PR titles, and PR bodies are in English.
## Sources of Truth
@@ -147,73 +116,25 @@ requested adversarial/design reviews, and agent-instruction changes that alter
execution. Ordinary questions, diagnoses, status reports, non-adversarial code
reviews, and low-risk planning do not trigger it.
Risk and review shape:
For applicable work and substantial PR reviews, read the [risk tiers and review shape](.agents/references/adversarial-validation.md).
Load only the matching domain probes; ordinary reviews do not become adversarial
merely because this reference exists.
- **Exempt:** documentation, comments, formatting, or typos with no runtime,
build, test, or agent-execution effect.
- **Mechanical:** renames, moves, test/tooling-only changes, and agent-rule
changes. Run correctness and simplicity lenses.
- **Standard:** localized behavior changes. Run one integrated final-diff pass
covering correctness, simplicity, and test coverage; add only domain lenses
matched by the diff.
- **High risk / substantial PR review:** high risk includes locking,
erasure/quorum/heal, replication, multipart, RPC, lifecycle/tiering,
persistence/fsync, IAM/KMS/auth, cryptography, on-disk/on-wire formats, and
S3-visible semantics. Cover all applicable lenses using exactly two
independent reviewers when delegation is explicitly authorized. Split the
lenses between them. Otherwise perform two fresh sequential passes.
- **Outbound client defaults:** what `TargetClient`, `PutObjectOptions`, or
the remote SDK configuration sends to every replication or migration target
is high risk for every target class even when the change fixes one. Follow
the SOP in `docs/postmortems/2026-09-03-replication-checksum-default-regression.md`:
run the outbound target matrix, document each new env knob in the same PR,
and list verified and unverified target classes in the PR Impact section.
A review has no finding quota; `No findings` is a complete outcome. A request to
find problems is not evidence that a defect exists. Before reporting a candidate,
check callers, invariants, and existing tests for evidence that disproves it.
Findings need `file:line` and a concrete failure or violation of an explicit
requirement. Missing required tests/checks are verification gaps, not proof of a
runtime bug; name the unprotected behavior or unmet gate. Keep optional style or
refactoring preferences out of defect findings unless that review was requested.
Available domain lenses are security, concurrency/durability, compatibility,
and performance. Select `.agents/skills/adversarial-validation/SKILL.md` for an
explicit adversarial request, a high-risk change, or a substantial PR review;
then read only its matching role references. A routine standard pass does not
load the playbook unless the reviewer needs a RustFS-specific probe.
A finding must name a concrete input/state/interleaving and wrong outcome, or a
specific missing regression check, with `file:line`. Resolve it by fixing the
diff or rebutting it with code-path/test/invariant evidence. After a non-trivial
fix, rerun only affected lenses.
Fix or rebut supported findings within the authorized scope. Once the required
passes are complete, stop. Reopen only for changed code, new evidence, an
unresolved finding, or an explicit re-review request; an unchanged diff does not
need another pass at every conversation turn or workflow handoff.
For high-risk PRs, record one concise verdict per covered lens in the PR body.
## Pull Request Lifecycle
- Creating or updating a PR includes one immediate snapshot of checks,
mergeability, reviews, and unresolved threads.
- Unless the user explicitly requests monitoring, a release workflow requires
it, or an automation already owns it, hand off after the PR is open with the
current state and next event to watch. Do not delay ordinary handoff with
fixed quiet-period sleeps.
- For requested monitoring, use event-driven or bounded waits. Report only state
changes, actionable failures, or a meaningful prolonged delay.
- Investigate failures/comments before changing code. Fix task-attributable
issues, rerun affected verification, push, reply or resolve the thread, then
resume the requested monitor.
- Never merge without required reviewer approval or explicit authority.
- After an observed merge, verify the commit reached the base, then clean the
task worktree/branch when safe. Preserve unmerged work for closed PRs unless
deletion was explicitly authorized.
## Git and PR Baseline
- Follow Conventional Commits; keep the subject at most 72 characters.
- Source comments, commits, PR titles, and PR bodies are in English.
- Keep every heading from `.github/pull_request_template.md`; use `N/A` where
needed and include commands actually run.
- Use `--body-file` for multiline `gh pr create`/`gh pr edit` content.
- PR/issue/discussion content must not contain the literal sequence `\n` or
hard-wrapped prose paragraphs.
- Do not include local absolute paths or tool-specific labels/prefixes in GitHub
content.
- Resolve review threads after the underlying issue is fixed. If declining a
suggestion, reply with a short evidence-based reason.
## Security Baseline
- Never commit secrets, credentials, or key material.
@@ -250,12 +171,6 @@ Use `.agents/skills/rustfs-logging-governance/SKILL.md` for logging changes.
- `DataUsageCacheInfo` and `DataUsageEntry` keep their hand-written map
serialization and new fields remain `#[serde(default)]` for older readers.
## Naming
Use Rust API naming: `SCREAMING_SNAKE_CASE` constants/statics, `snake_case`
functions/variables, and `PascalCase` types. Do not rename unrelated existing
violations.
## Scoped Guidance
Before editing, locate the nearest instructions with:
@@ -265,4 +180,4 @@ git ls-files '*AGENTS.md'
```
The nearest file wins for domain invariants. Keep generic workflow and
validation policy in this root file.
validation policy in this root file and its task-specific references.
+1
View File
@@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [Unreleased]
### Fixed
- **Multipart admission queue**: an `UploadPart` waiting for a foreground write permit now waits at most 10 s by default (`RUSTFS_PUT_MULTIPART_FOREGROUND_ADMISSION_WAIT_TIMEOUT_MS`, previously 30 s), so a queued part returns S3 `SlowDown` before the client's socket write timeout drops the connection. Separately, the API listener no longer forces a 4 MiB `SO_RCVBUF` on every accepted socket (kernel autotuning applies; `RUSTFS_HTTP_SOCKET_RECV_BUFFER_BYTES` restores a fixed size), so a queued part no longer lets up to 8 MiB of unread body accumulate in kernel memory per connection, which is what throttled whole nodes under SDK-default multipart concurrency. Fixes #7385.
- **Helm Ingress**: `customAnnotations` are now merged with class-specific annotations (nginx/traefik) instead of being ignored when `ingress.className` is set.
- **Per-pool erasure parity**: Erasure parity (STANDARD and reduced-redundancy) is now resolved independently for every pool instead of reusing the first pool's value. A heterogeneous topology — for example a 4-drive pool plus a 2-drive pool created during expansion — previously inherited the first pool's parity and could resolve to zero data shards in the smaller pool, panicking Reed-Solomon construction on write. Automatic parity now resolves per pool (for example `2+2` in the 4-drive pool and `1+1` in the 2-drive pool). Fixes #4801.
+2 -2
View File
@@ -13,7 +13,7 @@ what Claude Code needs on top: commands and pointers.
cargo build --release --bin rustfs # production binary
cargo check -p <crate> # fast type-check one crate
cargo test -p <crate> # test one crate
cargo fmt --all # format (required before PR)
cargo fmt --all --check # for Rust changes; see AGENTS.md verification tiers
make pre-commit # fast gate: fmt + arch checks + quick-check (NO clippy/tests)
make pre-pr # optional full gate for broad cross-module changes
make build-docker BUILD_OS=ubuntu22.04
@@ -42,5 +42,5 @@ make build-docker BUILD_OS=ubuntu22.04
Repo-wide domain invariants (dual internal metadata keys, defensive UUID
reads, unversioned tier buckets) live in [AGENTS.md](AGENTS.md) under
"Cross-Cutting Domain Invariants" — read them before touching metadata or
"Cross-Cutting Storage Invariants" — read them before touching metadata or
tiering code.
+9
View File
@@ -109,6 +109,15 @@ Star RustFS on GitHub and be instantly notified of new releases.
## Quickstart
> [!IMPORTANT]
> **Pool expansion notice:**
>
> - A single-node single-drive (SNSD) deployment is supported only as a standalone local path. It cannot expand in place or be added as a Pool. To move to a multi-drive topology, create a new deployment and migrate data through S3.
> - Keep an existing multi-drive Pool's endpoints and Erasure Set width unchanged; expand by appending a new Pool. With ellipsis-based expansion, every Pool argument must contain an ellipsis expression and expand to at least two drive endpoints.
> - Single-node multi-drive Pools and multi-node Pools with one drive per node are allowed, subject to valid Erasure Set geometry and EC settings; acceptance does not guarantee host-failure tolerance.
>
> These topology rules follow MinIO, but automatic parity selection differs between the projects. See the [Pool layout compatibility and regression tests](docs/testing/pool-layout-compatibility.md) before expanding a deployment.
To get started with RustFS, follow these steps:
### 1. One-click Installation (Option 1)
+9
View File
@@ -89,6 +89,15 @@ RustFS 是一个基于 Rust 构建的高性能分布式对象存储系统。Rust
## 快速开始
> [!IMPORTANT]
> **Pool 扩容 Notice**
>
> - 单节点单盘(SNSD)部署仅支持使用本地路径独立运行,不支持原地扩容,也不能作为 Pool 加入集群。如需改为多盘拓扑,请创建新部署并通过 S3 迁移数据。
> - 已有多盘 Pool 的端点和 Erasure Set 宽度应保持不变,扩容应追加新的 Pool。使用省略号表达式扩容时,每个 Pool 参数都必须包含省略号表达式,并展开为至少两个磁盘端点。
> - 允许单节点多盘 Pool,也允许多节点、每节点一盘的 Pool,但必须满足 Erasure Set 布局和 EC 配置要求;配置合法不代表能够容忍整台主机故障。
>
> 这些拓扑规则与 MinIO 一致,但两者的默认 parity 选择方式存在差异。扩容前请阅读 [Pool 布局兼容性与回归测试说明](docs/testing/pool-layout-compatibility.md)。
请按照以下步骤快速上手 RustFS
### 1. 一键安装脚本 (选项 1)
+5 -2
View File
@@ -33,8 +33,11 @@ Applies to all paths under `crates/`.
## Type Casting
- Never use `as` for numeric conversions that may truncate or overflow. Use `try_into()` with explicit error handling, or clamp with `value.max(0) as usize` when the domain is bounded.
- `f64 as usize` saturates but is fragile; clamp to `[0, usize::MAX as f64]` first.
- Never use `as` for numeric conversions that may truncate or overflow. Use
`try_into()` with typed error handling; clamp or saturate only when the domain
explicitly requires it.
- Before converting floating-point input to an integer, validate finiteness,
sign, and the destination range. A lower-bound clamp alone is insufficient.
- Treat every `as` cast in a PR review as a potential bug; require justification.
## Testing
+303
View File
@@ -90,6 +90,61 @@ pub struct MrfIntent {
pub attempts: u8,
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct MrfDurableRepairAnchor {
pub kind: MrfKind,
pub bucket: Arc<str>,
pub object: Arc<str>,
pub version_id: Option<[u8; 16]>,
pub scope: Option<MrfScope>,
pub lease: MrfIngressLease,
pub bucket_incarnation_id: Uuid,
}
impl MrfDurableRepairAnchor {
/// Build a dischargeable anchor only when the caller supplies the storage
/// incarnation and the original ingress lease. Legacy replay records lack
/// both pieces and therefore remain fail-closed.
pub fn from_intent(intent: &MrfIntent, bucket_incarnation_id: Uuid) -> Option<Self> {
if bucket_incarnation_id.is_nil() {
return None;
}
let lease = intent.lease?;
let (version_id, scope) = canonical_identity(intent.kind, intent.version_id, intent.scope);
Some(Self {
kind: intent.kind,
bucket: intent.bucket.clone(),
object: intent.object.clone(),
version_id,
scope,
lease,
bucket_incarnation_id,
})
}
pub fn is_proven_by(&self, event: &MrfVerifiedRepairEvent) -> bool {
let Some(lease) = event.lease else {
return false;
};
self.kind == event.kind
&& self.bucket == event.bucket
&& self.object == event.object
&& self.version_id == event.version_id
&& self.scope == event.scope
&& self.lease == lease
&& self.bucket_incarnation_id == event.bucket_incarnation_id
}
}
/// Consume only anchors proven by a complete verified-repair identity. The
/// caller remains responsible for persisting the resulting anchor set before
/// deleting older replay files.
pub fn consume_verified_mrf_repair_events(anchors: &mut Vec<MrfDurableRepairAnchor>, events: &[MrfVerifiedRepairEvent]) -> usize {
let before = anchors.len();
anchors.retain(|anchor| !events.iter().any(|event| anchor.is_proven_by(event)));
before.saturating_sub(anchors.len())
}
#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash)]
pub struct MrfScope {
pub pool_index: u32,
@@ -386,6 +441,27 @@ pub fn try_send_mrf_intent_typed(
}
}
/// Acquire a fresh process-local lease for one durable replay record.
///
/// Journal records deliberately do not persist leases. A replay consumer must
/// call this before submitting the record so a later verified repair event can
/// identify the exact replay admission. Replay does not reserve the live
/// producer coalescer key: the replay queue first deduplicates legacy records,
/// then manager admission owns task-level deduplication with live producers.
pub fn try_rearm_mrf_replay_intent(intent: &mut MrfIntent) -> MrfIngressResult {
if intent.lease.is_some() {
return MrfIngressResult::Enqueued;
}
if intent.bucket.len() > MRF_MAX_IDENTITY_COMPONENT || intent.object.len() > MRF_MAX_IDENTITY_COMPONENT {
return MrfIngressResult::Dropped(MrfDropReason::OversizedIdentity);
}
let (version_id, scope) = canonical_identity(intent.kind, intent.version_id, intent.scope);
intent.version_id = version_id;
intent.scope = scope;
intent.lease = Some(MrfIngressLease::new(NEXT_MRF_LEASE.fetch_add(1, Ordering::Relaxed)));
MrfIngressResult::Enqueued
}
/// Release the ingress key once the consumer owns the intent.
pub fn release_mrf_intent(intent: &MrfIntent) {
release_mrf_identity(intent.kind, &intent.bucket, &intent.object, intent.version_id, intent.scope, intent.lease);
@@ -432,12 +508,33 @@ pub struct MrfRepairedEvent {
pub version_id: Option<[u8; 16]>,
}
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum MrfVerifiedRepairDisposition {
Repaired,
VerifiedHealthy,
AuthoritativelyAbsent,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct MrfVerifiedRepairEvent {
pub kind: MrfKind,
pub bucket: Arc<str>,
pub object: Arc<str>,
pub version_id: Option<[u8; 16]>,
pub scope: Option<MrfScope>,
pub lease: Option<MrfIngressLease>,
pub bucket_incarnation_id: Uuid,
pub disposition: MrfVerifiedRepairDisposition,
}
/// Bound on the repaired-event backlog. Notices are best-effort hints; when
/// the ring is full the oldest are dropped and the affected ledger entries
/// simply expire through their own attempts/age limits.
const MRF_REPAIRED_EVENT_CAP: usize = 4096;
static MRF_REPAIRED_EVENTS: OnceLock<std::sync::Mutex<std::collections::VecDeque<MrfRepairedEvent>>> = OnceLock::new();
static MRF_VERIFIED_REPAIR_EVENTS: OnceLock<std::sync::Mutex<std::collections::VecDeque<MrfVerifiedRepairEvent>>> =
OnceLock::new();
/// Record a legacy notification for compatibility. This is not an
/// acknowledgement of storage verification or durable repair completion.
@@ -478,6 +575,43 @@ pub fn take_mrf_repaired_events_for(bucket: &str) -> Vec<MrfRepairedEvent> {
taken
}
/// Record a storage-owned MRF completion proof. Unlike the legacy repaired
/// event, this identity is complete enough for future durable ledgers to make
/// an exact responsibility decision.
pub fn note_mrf_verified_repair(event: MrfVerifiedRepairEvent) {
let registry = MRF_VERIFIED_REPAIR_EVENTS.get_or_init(|| std::sync::Mutex::new(std::collections::VecDeque::new()));
let Ok(mut events) = registry.lock() else {
return;
};
if events.len() >= MRF_REPAIRED_EVENT_CAP {
events.pop_front();
}
events.push_back(event);
}
/// Take verified repair events recorded for `bucket`, leaving other buckets'
/// proofs in place. Consumers still have to match kind, object, version, scope
/// lease and incarnation before discharging durable responsibility.
pub fn take_mrf_verified_repair_events_for(bucket: &str) -> Vec<MrfVerifiedRepairEvent> {
let Some(registry) = MRF_VERIFIED_REPAIR_EVENTS.get() else {
return Vec::new();
};
let Ok(mut events) = registry.lock() else {
return Vec::new();
};
let mut taken = Vec::new();
let mut retained = std::collections::VecDeque::with_capacity(events.len());
while let Some(event) = events.pop_front() {
if event.bucket.as_ref() == bucket {
taken.push(event);
} else {
retained.push_back(event);
}
}
*events = retained;
taken
}
#[cfg(test)]
mod tests {
use super::*;
@@ -546,6 +680,147 @@ mod tests {
assert_eq!(metadata_scope, None);
}
#[test]
fn durable_repair_anchor_requires_lease_and_bucket_incarnation() {
let mut intent = MrfIntent {
bucket: Arc::from("durable-anchor-bucket"),
object: Arc::from("object"),
version_id: Some([0; 16]),
kind: MrfKind::PartialWrite,
scope: Some(MrfScope {
pool_index: 1,
set_index: 2,
}),
lease: None,
enqueued_at_ms: 0,
attempts: 0,
};
assert!(
MrfDurableRepairAnchor::from_intent(&intent, Uuid::new_v4()).is_none(),
"legacy replay records without the ingress lease must remain anchored"
);
intent.lease = Some(MrfIngressLease::new(7));
assert!(
MrfDurableRepairAnchor::from_intent(&intent, Uuid::nil()).is_none(),
"nil bucket incarnation cannot prove durable successor ownership"
);
let anchor = MrfDurableRepairAnchor::from_intent(&intent, Uuid::new_v4())
.expect("complete identity should create a durable repair anchor");
assert_eq!(anchor.version_id, None, "nil UUID is canonicalized before matching");
assert_eq!(
anchor.scope,
Some(MrfScope {
pool_index: 1,
set_index: 2
})
);
}
#[test]
fn durable_replay_rearm_assigns_a_fresh_dischargeable_lease() {
let unique = Uuid::new_v4();
let mut intent = MrfIntent {
bucket: Arc::from(format!("replay-{unique}")),
object: Arc::from("object"),
version_id: Some([0; 16]),
kind: MrfKind::PartialWrite,
scope: Some(MrfScope {
pool_index: 2,
set_index: 3,
}),
lease: None,
enqueued_at_ms: 1,
attempts: 0,
};
assert_eq!(try_rearm_mrf_replay_intent(&mut intent), MrfIngressResult::Enqueued);
assert_eq!(intent.version_id, None, "nil versions remain canonical during replay");
assert!(intent.lease.is_some(), "replay admission must carry a fresh lease");
assert!(
MrfDurableRepairAnchor::from_intent(&intent, Uuid::new_v4()).is_some(),
"a rearmed replay record can participate in exact durable proof matching"
);
release_mrf_intent(&intent);
}
#[test]
fn verified_repair_events_consume_only_exact_durable_anchors() {
let bucket = Arc::<str>::from("proof-bucket");
let object = Arc::<str>::from("object");
let incarnation = Uuid::new_v4();
let lease = MrfIngressLease::new(11);
let anchor = MrfDurableRepairAnchor {
kind: MrfKind::PartialWrite,
bucket: bucket.clone(),
object: object.clone(),
version_id: Some([3; 16]),
scope: Some(MrfScope {
pool_index: 4,
set_index: 5,
}),
lease,
bucket_incarnation_id: incarnation,
};
let event = MrfVerifiedRepairEvent {
kind: anchor.kind,
bucket,
object,
version_id: anchor.version_id,
scope: anchor.scope,
lease: Some(lease),
bucket_incarnation_id: incarnation,
disposition: MrfVerifiedRepairDisposition::Repaired,
};
for rejected in [
MrfVerifiedRepairEvent {
lease: None,
..event.clone()
},
MrfVerifiedRepairEvent {
lease: Some(MrfIngressLease::new(12)),
..event.clone()
},
MrfVerifiedRepairEvent {
bucket_incarnation_id: Uuid::new_v4(),
..event.clone()
},
MrfVerifiedRepairEvent {
version_id: Some([4; 16]),
..event.clone()
},
MrfVerifiedRepairEvent {
scope: Some(MrfScope {
pool_index: 4,
set_index: 6,
}),
..event.clone()
},
MrfVerifiedRepairEvent {
kind: MrfKind::DecodeFailure,
..event.clone()
},
MrfVerifiedRepairEvent {
bucket: Arc::from("other-bucket"),
..event.clone()
},
MrfVerifiedRepairEvent {
object: Arc::from("other"),
..event.clone()
},
] {
let mut retained = vec![anchor.clone()];
assert_eq!(consume_verified_mrf_repair_events(&mut retained, &[rejected]), 0);
assert_eq!(retained, vec![anchor.clone()]);
}
let mut retained = vec![anchor];
assert_eq!(consume_verified_mrf_repair_events(&mut retained, &[event]), 1);
assert!(retained.is_empty());
}
#[tokio::test]
async fn try_send_delivers_and_respects_capacity() {
let mut receiver = init_mrf_channel().expect("first initialization should succeed");
@@ -610,4 +885,32 @@ mod tests {
assert_eq!(flooded.len(), MRF_REPAIRED_EVENT_CAP);
assert_eq!(flooded[0].object.as_ref(), "object-9", "the oldest notices past the cap are dropped");
}
#[test]
fn verified_repair_events_preserve_full_identity_and_bucket_scope() {
let bucket_incarnation_id = Uuid::new_v4();
let event = MrfVerifiedRepairEvent {
kind: MrfKind::PartialWrite,
bucket: Arc::from("verified-bucket-a"),
object: Arc::from("object-a"),
version_id: Some([4u8; 16]),
scope: Some(MrfScope {
pool_index: 2,
set_index: 3,
}),
lease: Some(MrfIngressLease::new(42)),
bucket_incarnation_id,
disposition: MrfVerifiedRepairDisposition::Repaired,
};
note_mrf_verified_repair(event.clone());
note_mrf_verified_repair(MrfVerifiedRepairEvent {
bucket: Arc::from("verified-bucket-b"),
..event.clone()
});
let taken = take_mrf_verified_repair_events_for("verified-bucket-a");
assert_eq!(taken, vec![event]);
assert!(take_mrf_verified_repair_events_for("verified-bucket-a").is_empty());
assert_eq!(take_mrf_verified_repair_events_for("verified-bucket-b").len(), 1);
}
}
+16 -1
View File
@@ -66,6 +66,11 @@ Current guidance:
- `RUSTFS_BROWSER_REDIRECT_URL` sets the externally reachable browser origin used for OIDC callback, console success redirect, and logout fallback URLs. Configure it to the public scheme and authority without a path, for example `https://console.example.com`. In load-balancer deployments, keep OIDC authorize and callback requests on the same backend node because the in-flight OIDC `state` is local to the RustFS node.
## S3 API environment variables
- `RUSTFS_API_OBJECT_MAX_VERSIONS` caps the number of retained versions for a single object. It defaults to `9223372036854775807`, matching MinIO's practical-unlimited default. Set a positive integer to enforce a lower per-object metadata bound.
- `MINIO_API_OBJECT_MAX_VERSIONS` is accepted as a compatibility alias when the canonical RustFS variable is not set.
## Distributed endpoint locality
- `RUSTFS_LOCAL_ENDPOINT_HOST` identifies this server's host in a distributed `RUSTFS_VOLUMES` topology without resolving every peer during startup. Set it to exactly one host, without a scheme, port, or path. It is accepted only for orchestrated URL topologies and must match at least one endpoint on the RustFS server port; invalid or unmatched values fail startup. Leave it unset to retain DNS-based locality discovery.
@@ -153,14 +158,24 @@ concurrently. Small direct PUTs stay on the legacy path.
- default is `0`.
- `RUSTFS_PUT_MULTIPART_FOREGROUND_ADMISSION_WAIT_TIMEOUT_MS`
- how long an `UploadPart` waits in the bounded queue for a permit before returning S3 `SlowDown`; `0` rejects immediately when the pool is full.
- default is `30000`. Parts wait before body ingest, so SDK-default clients that send every part of an upload concurrently drain through the pool instead of failing.
- default is `10000`. Parts wait before body ingest, so SDK-default clients that send every part of an upload concurrently drain through the pool instead of failing on a full pool.
- RustFS does not read the request body while a part is queued, so the client's socket write stalls for the whole wait and whatever timeout the client or an intermediary has configured competes with this value. Keep it with margin below the shortest such timeout in use (botocore applies its 60 s `connect_timeout` to the body write; the AWS SDK for Java v2 has a 30 s socket write timeout; reverse proxies add their own body timeouts); a wait that outlives the client timeout surfaces as a dropped connection instead of `SlowDown`.
- `RUSTFS_PUT_MULTIPART_FOREGROUND_ADMISSION_MAX_PENDING`
- maximum `UploadPart` requests waiting for a permit at once; parts beyond it return `SlowDown` without waiting.
- default is `0`, which derives 16 times the permit limit (512 at stock settings).
- each queued HTTP/1 part holds whatever unread body the client already pushed into the connection's kernel receive buffer (an HTTP/2 part holds up to its flow-control window in process memory), so this depth also bounds that memory. RustFS leaves the receive buffer to kernel autotuning (see `RUSTFS_HTTP_SOCKET_RECV_BUFFER_BYTES` below), which keeps an unread connection at the kernel's initial size (128 KiB on current Linux).
- `RUSTFS_PUT_FOREGROUND_ADMISSION_ENABLE`, `RUSTFS_PUT_FOREGROUND_ADMISSION_LIMIT`, `RUSTFS_PUT_FOREGROUND_ADMISSION_WAIT_TIMEOUT_MS`
- experimental strict gate that applies to every foreground write regardless of size and replaces the pool above when enabled.
- default is disabled; enabling it with limit `0` disables foreground write admission entirely.
## HTTP listener socket environment variables
- `RUSTFS_HTTP_SOCKET_RECV_BUFFER_BYTES`
- fixed `SO_RCVBUF` for the API listener, inherited by every accepted socket; `0` leaves the receive buffer to kernel autotuning.
- default is `0`. Earlier releases hard-coded 4 MiB, which Linux doubles to 8 MiB and which disables autotuning, so every connection whose body was not being read yet (a multipart part queued for a foreground write permit) could accumulate up to 8 MiB of unread body in kernel memory; at SDK-default multipart concurrency that was enough to push a node into TCP memory pressure.
- with autotuning the per-connection receive ceiling is the kernel's (`net.ipv4.tcp_rmem` max, 6 MiB on stock Linux) instead of the former fixed 8 MiB, so a single very high-bandwidth-delay connection may see a somewhat lower ceiling; raise `net.ipv4.tcp_rmem` first, and set this variable only on kernels without receive-buffer autotuning (illumos/Solaris) or where the sysctl cannot be changed.
- the send buffer stays fixed at 4 MiB because the stock Linux send autotuning ceiling (`net.ipv4.tcp_wmem` max, 4 MiB) is lower than a GB-level response stream needs.
## Remote tier timeout environment variables
- `RUSTFS_TIER_REMOTE_CONNECT_TIMEOUT_SECS`
+12
View File
@@ -90,3 +90,15 @@ pub const ENV_API_MAX_CONNECTIONS: &str = "RUSTFS_API_MAX_CONNECTIONS";
/// Default for `RUSTFS_API_MAX_CONNECTIONS` (`0` = unlimited).
pub const DEFAULT_API_MAX_CONNECTIONS: usize = 0;
/// Maximum retained versions per object.
///
/// The default follows MinIO and is effectively unlimited for practical
/// deployments. Operators can lower it to bound per-object metadata growth.
/// Environment variable: RUSTFS_API_OBJECT_MAX_VERSIONS
/// MinIO-compatible alias: MINIO_API_OBJECT_MAX_VERSIONS
/// Example: RUSTFS_API_OBJECT_MAX_VERSIONS=50000
pub const ENV_API_OBJECT_MAX_VERSIONS: &str = "RUSTFS_API_OBJECT_MAX_VERSIONS";
/// Default for `RUSTFS_API_OBJECT_MAX_VERSIONS`.
pub const DEFAULT_API_OBJECT_MAX_VERSIONS: u64 = 9_223_372_036_854_775_807;
+26 -8
View File
@@ -376,21 +376,39 @@ pub const DEFAULT_PUT_LARGE_FOREGROUND_ADMISSION_WAIT_TIMEOUT_MS: u64 = 250;
///
/// SDK-default multipart clients send every part of an upload concurrently, so
/// a single node routinely sees several times more parts in flight than the
/// permit pool allows. Those parts have not ingested a body yet, so queueing
/// them costs a connection rather than memory or internode streams; the pool
/// still bounds the number of parts being written. The wait is long enough for
/// an ordinary queue to drain on modest hardware, and a part that cannot get a
/// permit within it fails with S3 `SlowDown`/503 for the client to retry.
/// `0` rejects immediately when the pool is full.
/// permit pool allows. A queued part waits before body ingest, so the pool
/// still bounds the number of parts being written, but the wait is not free:
/// RustFS does not read the request body while the part is queued (hyper only
/// sends `100 Continue` once the body is first polled, and the AWS SDKs send
/// the body after a 1-3 s `Expect: 100-continue` grace anyway), so the
/// client's socket write stalls once the kernel buffers fill, and whatever
/// timeout the client or an intermediary has configured decides the outcome.
/// botocore applies its `connect_timeout` (60 s) to the body write, the AWS
/// SDK for Java v2 has a 30 s socket write timeout, and MinIO bounds the same
/// wait with a 10 s request deadline. The wait must leave margin under the
/// shortest of those, not merely fall below an SDK default, so the part
/// receives S3 `SlowDown`/503 for the client to retry instead of losing its
/// connection (issue #7385). `0` rejects immediately when the pool is full.
pub const ENV_PUT_MULTIPART_FOREGROUND_ADMISSION_WAIT_TIMEOUT_MS: &str =
"RUSTFS_PUT_MULTIPART_FOREGROUND_ADMISSION_WAIT_TIMEOUT_MS";
pub const DEFAULT_PUT_MULTIPART_FOREGROUND_ADMISSION_WAIT_TIMEOUT_MS: u64 = 30_000;
pub const DEFAULT_PUT_MULTIPART_FOREGROUND_ADMISSION_WAIT_TIMEOUT_MS: u64 = 10_000;
// A queued part holds the client's body write open for the whole wait. The
// shortest write timeout among mainstream S3 SDKs is the AWS SDK for Java v2's
// 30 s socket write timeout; keep the compiled default at no more than a third
// of it. This locks only the default; the environment variable may still raise
// the wait past any client timeout.
const _: () = assert!(DEFAULT_PUT_MULTIPART_FOREGROUND_ADMISSION_WAIT_TIMEOUT_MS * 3 <= 30_000);
/// Maximum multipart UploadPart requests waiting for a foreground write permit per process.
///
/// Parts beyond this queue depth are rejected with S3 `SlowDown`/503 without
/// waiting, so a genuinely saturated node still fails fast instead of holding
/// an unbounded set of connections open for the whole wait timeout.
/// an unbounded set of connections open for the whole wait timeout. Each
/// queued HTTP/1 part also holds whatever unread body the client already
/// pushed into that connection's kernel receive buffer, and a queued HTTP/2
/// part holds up to its flow-control window in process memory, so the depth
/// bounds socket and window memory as well as connections.
/// `0` derives the depth from the permit limit.
pub const ENV_PUT_MULTIPART_FOREGROUND_ADMISSION_MAX_PENDING: &str = "RUSTFS_PUT_MULTIPART_FOREGROUND_ADMISSION_MAX_PENDING";
pub const DEFAULT_PUT_MULTIPART_FOREGROUND_ADMISSION_MAX_PENDING: usize = 0;
+18
View File
@@ -159,6 +159,24 @@ pub const DEFAULT_HTTP1_HEADER_READ_TIMEOUT: u64 = 75;
pub const ENV_HTTP1_MAX_BUF_SIZE: &str = "RUSTFS_HTTP1_MAX_BUF_SIZE";
pub const DEFAULT_HTTP1_MAX_BUF_SIZE: usize = 64 * 1024; // 64 KB
/// Environment variable for a fixed kernel receive buffer (`SO_RCVBUF`, bytes)
/// on the API listener. Default: 0, which leaves the buffer to kernel
/// autotuning.
///
/// A fixed `SO_RCVBUF` is inherited by every accepted socket and disables
/// receive-buffer autotuning, so a connection whose request body is not being
/// read yet (a multipart part queued for a foreground write permit) lets up to
/// the fixed size of unread body accumulate in kernel memory — Linux doubles
/// the requested value, so the former hard-coded 4 MiB held up to 8 MiB per
/// queued connection (issue #7385). Autotuning keeps an unread connection at
/// the kernel's initial size and grows only connections that are being
/// drained. Set this only on kernels without receive-buffer autotuning
/// (illumos/Solaris) or on very high-bandwidth-delay links where the kernel's
/// autotuning ceiling (`net.ipv4.tcp_rmem` on Linux) is too low and cannot be
/// raised.
pub const ENV_HTTP_SOCKET_RECV_BUFFER_BYTES: &str = "RUSTFS_HTTP_SOCKET_RECV_BUFFER_BYTES";
pub const DEFAULT_HTTP_SOCKET_RECV_BUFFER_BYTES: usize = 0;
/// Environment variable for the S3 request-body inter-chunk read timeout
/// (seconds). Default: 300. Set to 0 to disable.
///
+96 -12
View File
@@ -57,6 +57,8 @@ const RUSTFS_FULL_FEATURE: &str = "full";
const TEST_PORT_MIN: u16 = 20_000;
// Keep allocator ports below the ephemeral range used by bind(..., 0) test helpers.
const TEST_PORT_RANGE: u16 = 10_000;
const TEST_PORT_MIN_ENV: &str = "RUSTFS_E2E_TEST_PORT_MIN";
const TEST_PORT_RANGE_ENV: &str = "RUSTFS_E2E_TEST_PORT_RANGE";
const TEST_PORT_COUNTER_PATH: &str = "/tmp/rustfs_e2e_next_port";
const TEST_PORT_LOCK_DIR: &str = "/tmp/rustfs_e2e_port_allocator.lock";
const TEST_PORT_LOCK_STALE_AFTER: Duration = Duration::from_secs(30);
@@ -99,22 +101,74 @@ impl Drop for PortAllocatorGuard {
}
}
fn advance_test_port(port: u16) -> u16 {
let offset = (port - TEST_PORT_MIN + 1) % TEST_PORT_RANGE;
TEST_PORT_MIN + offset
#[derive(Clone, Copy, Debug, Eq, PartialEq)]
struct TestPortAllocatorConfig {
min: u16,
range: u16,
}
fn seeded_test_port() -> u16 {
let offset = (Uuid::new_v4().as_u128() % u128::from(TEST_PORT_RANGE)) as u16;
TEST_PORT_MIN + offset
impl TestPortAllocatorConfig {
fn max_exclusive(self) -> u32 {
u32::from(self.min) + u32::from(self.range)
}
fn contains(self, port: &u16) -> bool {
(u32::from(self.min)..self.max_exclusive()).contains(&u32::from(*port))
}
}
fn read_next_test_port() -> u16 {
fn parse_test_port_allocator_config(
min_override: Option<&str>,
range_override: Option<&str>,
) -> Result<TestPortAllocatorConfig, Box<dyn std::error::Error + Send + Sync>> {
let min = match min_override {
Some(value) => value
.parse::<u16>()
.map_err(|err| format!("{TEST_PORT_MIN_ENV} must be a valid u16: {err}"))?,
None => TEST_PORT_MIN,
};
let range = match range_override {
Some(value) => value
.parse::<u16>()
.map_err(|err| format!("{TEST_PORT_RANGE_ENV} must be a valid u16: {err}"))?,
None => TEST_PORT_RANGE,
};
if range == 0 {
return Err(format!("{TEST_PORT_RANGE_ENV} must be greater than zero").into());
}
if min < 1024 {
return Err(format!("{TEST_PORT_MIN_ENV} must be at least 1024").into());
}
let max_exclusive = u32::from(min) + u32::from(range);
if max_exclusive > u32::from(u16::MAX) + 1 {
return Err(format!("{TEST_PORT_MIN_ENV} + {TEST_PORT_RANGE_ENV} exceeds u16 port space").into());
}
Ok(TestPortAllocatorConfig { min, range })
}
fn test_port_allocator_config() -> Result<TestPortAllocatorConfig, Box<dyn std::error::Error + Send + Sync>> {
parse_test_port_allocator_config(
std::env::var(TEST_PORT_MIN_ENV).ok().as_deref(),
std::env::var(TEST_PORT_RANGE_ENV).ok().as_deref(),
)
}
fn advance_test_port(port: u16, config: TestPortAllocatorConfig) -> u16 {
let offset = (port - config.min + 1) % config.range;
config.min + offset
}
fn seeded_test_port(config: TestPortAllocatorConfig) -> u16 {
let offset = (Uuid::new_v4().as_u128() % u128::from(config.range)) as u16;
config.min + offset
}
fn read_next_test_port(config: TestPortAllocatorConfig) -> u16 {
stdfs::read_to_string(TEST_PORT_COUNTER_PATH)
.ok()
.and_then(|value| value.trim().parse::<u16>().ok())
.filter(|port| (TEST_PORT_MIN..TEST_PORT_MIN + TEST_PORT_RANGE).contains(port))
.unwrap_or_else(seeded_test_port)
.filter(|port| config.contains(port))
.unwrap_or_else(|| seeded_test_port(config))
}
fn remove_stale_port_allocator_lock() {
@@ -629,11 +683,12 @@ impl RustFSTestEnvironment {
pub async fn find_available_port() -> Result<u16, Box<dyn std::error::Error + Send + Sync>> {
use std::net::TcpListener;
let _guard = PortAllocatorGuard::acquire().await?;
let mut next_port = read_next_test_port();
let config = test_port_allocator_config()?;
let mut next_port = read_next_test_port(config);
for _ in 0..TEST_PORT_RANGE {
for _ in 0..config.range {
let port = next_port;
next_port = advance_test_port(next_port);
next_port = advance_test_port(next_port, config);
write_next_test_port(next_port)?;
if let Ok(listener) = TcpListener::bind(("127.0.0.1", port)) {
@@ -2108,6 +2163,35 @@ mod tests {
);
}
#[test]
fn e2e_port_allocator_uses_default_range() {
assert_eq!(
parse_test_port_allocator_config(None, None).expect("default port allocator config"),
TestPortAllocatorConfig {
min: TEST_PORT_MIN,
range: TEST_PORT_RANGE
}
);
}
#[test]
fn e2e_port_allocator_accepts_explicit_test_range() {
let config = parse_test_port_allocator_config(Some("31000"), Some("128")).expect("explicit port range");
assert_eq!(advance_test_port(31127, config), 31000);
assert!(config.contains(&31000));
assert!(config.contains(&31127));
assert!(!config.contains(&31128));
}
#[test]
fn e2e_port_allocator_rejects_invalid_override() {
assert!(parse_test_port_allocator_config(Some("1023"), Some("1")).is_err());
assert!(parse_test_port_allocator_config(Some("65000"), Some("1000")).is_err());
assert!(parse_test_port_allocator_config(Some("31000"), Some("0")).is_err());
assert!(parse_test_port_allocator_config(Some("not-a-port"), Some("128")).is_err());
}
#[test]
fn resolves_rustfs_binary_in_configured_cargo_target_directory() {
let workspace = Path::new("workspace");
+13 -1
View File
@@ -630,6 +630,10 @@ struct MultipartPart {
body: Bytes,
e_tag: String,
digest: [u8; 16],
/// Plaintext length declared by an SSE-C passthrough sender
/// (`x-rustfs-replication-part-actual-size`); RustFS validates the 5 MiB
/// minimum against it rather than against the stored bytes.
actual_size: Option<usize>,
}
#[derive(Clone)]
@@ -2823,6 +2827,11 @@ impl S3 for FakeBackend {
async fn upload_part(&self, req: S3Request<UploadPartInput>) -> S3Result<S3Response<UploadPartOutput>> {
let fault = request_fault(&req);
let declared_actual_size = req
.headers
.get("x-rustfs-replication-part-actual-size")
.and_then(|value| value.to_str().ok())
.and_then(|value| value.parse::<usize>().ok());
let _body_permit = timeout(MAX_FAULT_DURATION, Arc::clone(&self.body_limit).acquire_owned())
.await
.map_err(|_| s3s::s3_error!(RequestTimeout, "fake target body limiter wait exceeded 30 seconds"))?
@@ -2864,6 +2873,7 @@ impl S3 for FakeBackend {
body,
e_tag: e_tag.clone(),
digest,
actual_size: declared_actual_size,
},
);
Ok(apply_response_fault(
@@ -2933,7 +2943,9 @@ impl S3 for FakeBackend {
if requested_etag != &stored.e_tag {
return Err(s3s::s3_error!(InvalidPart, "part ETag does not match"));
}
if index + 1 != requested_parts.len() && stored.body.len() < MIN_MULTIPART_PART_BYTES {
if index + 1 != requested_parts.len()
&& stored.actual_size.unwrap_or(stored.body.len()) < MIN_MULTIPART_PART_BYTES
{
return Err(s3s::s3_error!(EntityTooSmall, "non-final multipart part is smaller than 5 MiB"));
}
selected.push((*number, stored.clone()));
@@ -58,11 +58,22 @@ mod tests {
struct ScannerHealEvidenceCase {
id: &'static str,
oracle: &'static str,
evidence: &'static str,
unclean_shutdown_marker: bool,
}
const BACKGROUND_TARGET_RESTART_EVIDENCE: ScannerHealEvidenceCase = ScannerHealEvidenceCase {
id: "background-target-restart",
oracle: "background-target-restart.json",
evidence: "process-restart",
unclean_shutdown_marker: false,
};
const BACKGROUND_TARGET_CRASH_EVIDENCE: ScannerHealEvidenceCase = ScannerHealEvidenceCase {
id: "background-target-crash",
oracle: "background-target-crash.json",
evidence: "process-crash-restart",
unclean_shutdown_marker: true,
};
struct RestartEvidenceContext {
@@ -98,6 +109,8 @@ mod tests {
|| case.oracle.contains('/')
|| case.oracle.contains('\\')
|| case.oracle.contains("..")
|| !matches!(case.evidence, "process-restart" | "process-crash-restart")
|| (case.evidence == "process-crash-restart") != case.unclean_shutdown_marker
{
return Err("invalid scanner/heal evidence case".into());
}
@@ -950,6 +963,16 @@ mod tests {
.await?
}
#[tokio::test(flavor = "multi_thread")]
async fn test_cluster_root_heal_recovers_remote_shards_after_background_target_crash()
-> Result<(), Box<dyn Error + Send + Sync>> {
timeout(
Duration::from_secs(420),
run_cluster_root_heal_interruption(InterruptionScenario::BackgroundTargetCrash),
)
.await?
}
#[tokio::test(flavor = "multi_thread")]
async fn test_cluster_root_heal_recovers_remote_shards_after_coordinator_restart() -> Result<(), Box<dyn Error + Send + Sync>>
{
@@ -986,21 +1009,27 @@ mod tests {
enum InterruptionScenario {
IsolatedTargetRestart,
BackgroundTargetRestart,
BackgroundTargetCrash,
BackgroundCoordinatorRestart,
TargetEndpointBlackhole,
}
async fn run_cluster_root_heal_interruption(scenario: InterruptionScenario) -> Result<(), Box<dyn Error + Send + Sync>> {
let server_binary = rustfs_binary_path();
let evidence_run = if scenario == InterruptionScenario::BackgroundTargetRestart {
restart_evidence_run(&server_binary, BACKGROUND_TARGET_RESTART_EVIDENCE)?
} else {
None
let evidence_run = match scenario {
InterruptionScenario::BackgroundTargetRestart => {
restart_evidence_run(&server_binary, BACKGROUND_TARGET_RESTART_EVIDENCE)?
}
InterruptionScenario::BackgroundTargetCrash => {
restart_evidence_run(&server_binary, BACKGROUND_TARGET_CRASH_EVIDENCE)?
}
_ => None,
};
let mut evidence_objects = Vec::new();
let (background_enabled, interruption_node, interruption_kind) = match scenario {
InterruptionScenario::IsolatedTargetRestart => (false, 1, "target_restart"),
InterruptionScenario::BackgroundTargetRestart => (true, 1, "background_target_restart"),
InterruptionScenario::BackgroundTargetCrash => (true, 1, "background_target_crash"),
InterruptionScenario::BackgroundCoordinatorRestart => (true, 0, "coordinator_restart"),
InterruptionScenario::TargetEndpointBlackhole => (false, 1, "target_endpoint_blackhole"),
};
@@ -1067,6 +1096,7 @@ mod tests {
.unwrap_or(4 * 1024 * 1024)
.clamp(1024 * 1024, 16 * 1024 * 1024);
let mut expected_manifests = Vec::with_capacity(online_object_count);
let mut unclean_shutdown_marker_observed = None;
for index in 0..online_object_count {
let key = format!("cluster/online/object-{index:04}.bin");
let payload_seed = u8::try_from(index + 1).expect("clamped object count must fit in u8");
@@ -1433,7 +1463,11 @@ mod tests {
"Restored target endpoint forwarding"
);
} else {
cluster.stop_node(interruption_node)?;
if scenario == InterruptionScenario::BackgroundTargetRestart {
cluster.stop_node_gracefully(interruption_node).await?;
} else {
cluster.stop_node(interruption_node)?;
}
let stopped_count = metadata_count(&replaced_disk, bucket, &expected_manifests);
assert!(
stopped_count > 0 && stopped_count < expected_manifests.len(),
@@ -1449,9 +1483,12 @@ mod tests {
.join(".rustfs.sys")
.join("unclean-shutdown");
if background_enabled {
let marker_exists = unclean_shutdown_marker.is_file();
unclean_shutdown_marker_observed = Some(marker_exists);
let expected_marker = !matches!(scenario, InterruptionScenario::BackgroundTargetRestart);
assert!(
unclean_shutdown_marker.is_file(),
"background restart must retain the real unclean-shutdown marker"
marker_exists == expected_marker,
"background restart/crash lane observed unexpected unclean-shutdown marker state"
);
} else {
match std::fs::remove_file(&unclean_shutdown_marker) {
@@ -1651,13 +1688,14 @@ mod tests {
"server build changed during restart"
);
let evidence = serde_json::json!({
"schema": 1, "case": evidence_context.case.id, "evidence": "process-restart",
"schema": 1, "case": evidence_context.case.id, "evidence": evidence_context.case.evidence,
"run_id": evidence_context.run.run_id, "source_revision": evidence_context.run.source_revision,
"test_build": compiled_test_identity(),
"binary_sha256": evidence_context.run.binary.sha256,
"test_binary_sha256": evidence_context.run.test_binary.sha256,
"topology": {"nodes": cluster.nodes.len(), "drives_per_node": cluster.nodes[0].data_dirs.len()},
"pid_before": target_pid, "pid_after": restarted_pid,
"unclean_shutdown_marker": unclean_shutdown_marker_observed.unwrap_or(false),
"objects": evidence_objects, "node_listings": node_listings,
});
let data = serde_json::to_vec(&evidence)?;
@@ -9055,9 +9055,11 @@ async fn test_replication_check_flags_multipart_only_version_minting_target() ->
.is_some_and(|error| error.contains("CreateMultipartUpload")),
"the failure must name the multipart path: {payload}"
);
// The PutObject leg mirrored, so it is the multipart probe that failed.
// The PutObject leg mirrored, so it is the multipart probe that failed;
// the mutation phases address the id the PUT reported and still run.
assert_eq!(target_report["Phases"]["Put"]["Status"], "OK", "{payload}");
assert_eq!(target_report["Phases"]["DeleteMarker"]["Status"], "SKIPPED", "{payload}");
assert_eq!(target_report["Phases"]["DeleteMarker"]["Status"], "OK", "{payload}");
assert_eq!(target_report["Phases"]["VersionDelete"]["Status"], "OK", "{payload}");
assert_eq!(target_report["Phases"]["Cleanup"]["Status"], "OK", "{payload}");
let probe_key = target
@@ -9245,6 +9247,9 @@ async fn test_replication_check_flags_version_minting_target() -> TestResult {
let target_bucket = "version-fidelity-dst";
target.create_bucket(target_bucket);
target.assign_own_version_ids(true);
// Wasabi shape: the probe version the VersionDelete phase removed answers
// NoSuchVersion to cleanup's second DELETE, which must count as clean.
target.reject_unknown_version_deletes(true);
let mut source_env = RustFSTestEnvironment::new().await?;
let mut env_vars = replication_fast_env();
@@ -10185,3 +10190,199 @@ async fn test_get_object_tagging_proxies_unreplicated_object_to_replication_targ
target.shutdown().await;
Ok(())
}
// ---------------------------------------------------------------------------
// backlog#2363
// ---------------------------------------------------------------------------
/// Wait until the source reports a terminal replication status for `key`.
async fn wait_terminal_replication_status(
client: &Client,
bucket: &str,
key: &str,
ssec: bool,
timeout: Duration,
) -> Result<String, Box<dyn Error + Send + Sync>> {
let customer_key = BASE64_STANDARD.encode_to_string(REPL17_SSEC_KEY);
let customer_key_md5 = sse_customer_key_md5_base64(REPL17_SSEC_KEY);
let deadline = tokio::time::Instant::now() + timeout;
loop {
let request = client.head_object().bucket(bucket).key(key);
let head = if ssec {
request
.sse_customer_algorithm("AES256")
.sse_customer_key(&customer_key)
.sse_customer_key_md5(&customer_key_md5)
.send()
.await?
} else {
request.send().await?
};
let status = head.replication_status().map(|status| status.as_str().to_string());
if matches!(status.as_deref(), Some("COMPLETED") | Some("FAILED")) {
return Ok(status.unwrap_or_default());
}
if tokio::time::Instant::now() >= deadline {
return Err(format!("{bucket}/{key}: replication never reached a terminal status; last {status:?}").into());
}
sleep(Duration::from_millis(250)).await;
}
}
/// backlog#2363: SSE-C ciphertext passthrough of objects the source stored
/// compressed. The replica on a RustFS target must decrypt to the original
/// bytes for a single PUT and for a multipart upload.
#[tokio::test]
async fn test_bucket_replication_sse_c_compressed_passthrough() -> TestResult {
init_logging();
const PART_SIZE: usize = 5 * 1024 * 1024;
let mut source_env = RustFSTestEnvironment::new().await?;
let mut target_env = RustFSTestEnvironment::new().await?;
let mut source_process_env = replication_fast_env();
source_process_env.extend_from_slice(LOOPBACK_REPLICATION_TARGET_ENV);
source_process_env.extend_from_slice(FAST_SCANNER_ENV);
source_process_env.extend_from_slice(&[
("NO_PROXY", "127.0.0.1,localhost"),
("HTTP_PROXY", ""),
("HTTPS_PROXY", ""),
("RUSTFS_COMPRESSION_ENABLED", "true"),
("RUSTFS_COMPRESSION_MULTIPART_ENABLED", "true"),
]);
source_env.start_rustfs_server_with_env(vec![], &source_process_env).await?;
target_env
.start_rustfs_server_without_cleanup_with_env(&[
("NO_PROXY", "127.0.0.1,localhost"),
("HTTP_PROXY", ""),
("HTTPS_PROXY", ""),
])
.await?;
let source_bucket = "ssec-compressed-src";
let target_bucket = "ssec-compressed-dst";
let source_client = source_env.create_s3_client();
let target_client = target_env.create_s3_client();
source_client.create_bucket().bucket(source_bucket).send().await?;
target_client.create_bucket().bucket(target_bucket).send().await?;
enable_bucket_versioning(&source_env, source_bucket).await?;
enable_bucket_versioning(&target_env, target_bucket).await?;
let target_arn = set_replication_target(&source_env, source_bucket, &target_env, target_bucket).await?;
put_bucket_replication(&source_env, source_bucket, &target_arn).await?;
let customer_key = BASE64_STANDARD.encode_to_string(REPL17_SSEC_KEY);
let customer_key_md5 = sse_customer_key_md5_base64(REPL17_SSEC_KEY);
let text = |len: usize, seed: u32| -> Vec<u8> {
let mut out = Vec::with_capacity(len + 64);
let mut line = 0u64;
while out.len() < len {
out.extend_from_slice(format!("ssec compressed passthrough seed={seed} line={line} lorem ipsum dolor\n").as_bytes());
line += 1;
}
out.truncate(len);
out
};
let single_key = "ssec-compressed-single.txt";
let single_body = text(1024 * 1024 + 17, 1);
source_client
.put_object()
.bucket(source_bucket)
.key(single_key)
.content_type("text/plain")
.body(ByteStream::from(single_body.clone()))
.sse_customer_algorithm("AES256")
.sse_customer_key(&customer_key)
.sse_customer_key_md5(&customer_key_md5)
.send()
.await?;
let multipart_key = "ssec-compressed-multipart.txt";
let multipart_parts = [text(PART_SIZE, 2), text(1024 * 1024 + 4096, 3)];
let multipart_body: Vec<u8> = multipart_parts.concat();
let created = source_client
.create_multipart_upload()
.bucket(source_bucket)
.key(multipart_key)
.content_type("text/plain")
.sse_customer_algorithm("AES256")
.sse_customer_key(&customer_key)
.sse_customer_key_md5(&customer_key_md5)
.send()
.await?;
let upload_id = created.upload_id().ok_or("missing multipart upload id")?.to_string();
let mut completed = Vec::new();
for (index, part) in multipart_parts.iter().enumerate() {
let part_number = i32::try_from(index + 1)?;
let uploaded = source_client
.upload_part()
.bucket(source_bucket)
.key(multipart_key)
.upload_id(&upload_id)
.part_number(part_number)
.body(ByteStream::from(part.clone()))
.sse_customer_algorithm("AES256")
.sse_customer_key(&customer_key)
.sse_customer_key_md5(&customer_key_md5)
.send()
.await?;
completed.push(
CompletedPart::builder()
.part_number(part_number)
.set_e_tag(uploaded.e_tag().map(str::to_string))
.build(),
);
}
source_client
.complete_multipart_upload()
.bucket(source_bucket)
.key(multipart_key)
.upload_id(&upload_id)
.multipart_upload(CompletedMultipartUpload::builder().set_parts(Some(completed)).build())
.sse_customer_algorithm("AES256")
.sse_customer_key(&customer_key)
.sse_customer_key_md5(&customer_key_md5)
.send()
.await?;
let mut failures = Vec::new();
for (key, body) in [(single_key, &single_body), (multipart_key, &multipart_body)] {
let status = wait_terminal_replication_status(&source_client, source_bucket, key, true, Duration::from_secs(120)).await?;
if status != "COMPLETED" {
failures.push(format!("{key}: source reports {status}"));
continue;
}
let replica = target_client
.get_object()
.bucket(target_bucket)
.key(key)
.sse_customer_algorithm("AES256")
.sse_customer_key(&customer_key)
.sse_customer_key_md5(&customer_key_md5)
.send()
.await;
match replica {
Ok(replica) => {
let content_length = replica.content_length();
match replica.body.collect().await {
Ok(collected) => {
let bytes = collected.into_bytes();
if bytes.as_ref() != body.as_slice() {
failures.push(format!(
"{key}: replica bytes differ (content_length={content_length:?}, got {} bytes, want {})",
bytes.len(),
body.len()
));
}
}
Err(err) => failures.push(format!("{key}: replica body read failed: {err}")),
}
}
Err(err) => failures.push(format!("{key}: replica GET failed: {err}")),
}
}
assert!(
failures.is_empty(),
"SSE-C compressed passthrough replicas must decrypt to the source bytes: {failures:?}"
);
Ok(())
}
@@ -1473,20 +1473,17 @@ fn layout_cases() -> Vec<LayoutCase> {
true,
),
// SSE-C passthrough replicates the stored ciphertext part by part; a
// compressible first part is stored well below 5 MiB and a standard
// target rejects it with EntityTooSmall. rc.5 fails the same way (see
// `rc5_baseline_replicates_multipart_layouts`), so the outcome is
// recorded rather than asserted here; tracked as rustfs/backlog#2363.
LayoutCase {
assert_replication: false,
..case(
LAYOUT_PLAIN_BUCKET,
"plain/ssec-compressed-multipart-2.txt",
two.clone(),
layout_text(total(&two), 7),
true,
)
},
// compressible first part is stored well below 5 MiB, so the sender
// declares each part's plaintext length and the target validates the
// 5 MiB minimum against it (rustfs/backlog#2363). rc.5 as the sender
// still fails this layout (see `rc5_baseline_replicates_multipart_layouts`).
case(
LAYOUT_PLAIN_BUCKET,
"plain/ssec-compressed-multipart-2.txt",
two.clone(),
layout_text(total(&two), 7),
true,
),
case(
LAYOUT_ENCRYPTED_BUCKET,
"encrypted/single.bin",
@@ -1838,27 +1835,20 @@ async fn direct_upgrade_from_rc5_preserves_multipart_layouts() -> TestResult {
transport.uploaded_parts, expected,
"{label}: stored parts must replicate as the same multipart layout"
);
// The current build can drive an existing object twice (two
// full CreateMultipartUpload/UploadPart/Complete rounds with
// distinct upload ids) while its status is still PENDING; the
// rc.5 baseline drives once. That is a scheduling difference,
// not a layout one, tracked as rustfs/backlog#2362.
assert!(transport.completes >= 1, "{label}: at least one CompleteMultipartUpload");
if transport.completes > 1 {
tracing::warn!(
target: "e2e_test::upgrade_compatibility_test",
object = %label,
completes = transport.completes,
journal = ?transport.journal,
"existing-object replication drove the same object more than once (rustfs/backlog#2362)"
);
}
// An object still PENDING when the next scanner cycle arrives is
// not driven a second time (rustfs/backlog#2362); the journal is
// logged so a duplicate round is visible if this ever regresses.
assert_eq!(
transport.completes, 1,
"{label}: exactly one CompleteMultipartUpload; journal {:?}",
transport.journal
);
assert_eq!(
transport.single_puts, 0,
"{label}: a multipart layout must not go out as a single PutObject"
);
} else {
assert!(transport.single_puts >= 1, "{label}: a single PUT replicates as PutObject");
assert_eq!(transport.single_puts, 1, "{label}: a single PUT replicates as exactly one PutObject");
assert!(transport.uploaded_parts.is_empty(), "{label}: a single PUT must not go out as multipart");
}
if !case.ssec {
@@ -1928,3 +1918,59 @@ async fn rc5_baseline_replicates_multipart_layouts() -> TestResult {
tracing::info!(target: "e2e_test::upgrade_compatibility_test", ?summary, "rc.5 baseline replication outcomes");
Ok(())
}
/// backlog#2362 under the same conditions that reproduced it with the rc.5
/// writer, but with the workspace build on both sides so it runs in the
/// ordinary lane: every pre-existing layout is driven through exactly one
/// upload round even though the scanner re-scans it every second while the
/// first round is still in flight.
#[tokio::test]
async fn existing_object_replication_drives_each_layout_once() -> TestResult {
init_logging();
let server_env = layout_server_env();
let mut env = RustFSTestEnvironment::new().await?;
env.start_rustfs_server_with_env(vec![], &server_env).await?;
let writer = env.create_s3_client();
env.create_test_bucket(LAYOUT_PLAIN_BUCKET).await?;
env.create_test_bucket(LAYOUT_ENCRYPTED_BUCKET).await?;
enable_versioning(&writer, LAYOUT_PLAIN_BUCKET).await?;
enable_versioning(&writer, LAYOUT_ENCRYPTED_BUCKET).await?;
put_default_sse_s3_encryption(&writer, LAYOUT_ENCRYPTED_BUCKET).await?;
let mut cases = layout_cases();
for case in cases.iter_mut() {
layout_write(&writer, case).await?;
let head = layout_head(&writer, case).await?;
case.rc5_etag = head
.e_tag()
.ok_or_else(|| format!("{}: HEAD omitted the ETag", case.label()))?
.trim_matches('"')
.to_string();
}
// The objects come from an earlier process lifetime: the scanner starts
// cold and every object is a candidate at once.
env.restart_server_preserving_data(vec![], &server_env).await?;
let client = env.create_s3_client();
let (_target, transports) = replicate_layouts(&env, &client, &cases).await?;
let mut duplicates = Vec::new();
for (case, transport) in cases.iter().zip(&transports) {
assert_eq!(
transport.status,
"COMPLETED",
"{}: existing-object replication must complete",
case.label()
);
let rounds = if case.is_multipart_layout() {
transport.completes
} else {
transport.single_puts
};
if rounds != 1 {
duplicates.push(format!("{}: {rounds} upload rounds; journal {:?}", case.label(), transport.journal));
}
}
assert!(duplicates.is_empty(), "each existing object must be driven exactly once: {duplicates:?}");
Ok(())
}
+3 -2
View File
@@ -33,6 +33,7 @@ pub mod bucket {
pub use crate::bucket::bucket_target_sys::{
AdvancedPutOptions, BucketTargetError, BucketTargetSys, PutObjectOptions, RemoveObjectOptions, S3ClientError,
SsecPassthroughCapability, TargetClient, VersionIdentityCapability, append_version_id_query,
resolve_delete_api_version_id,
};
}
@@ -415,8 +416,8 @@ pub mod disk {
pub mod error {
pub use crate::error::{
Error, Result, StorageError, classify_system_path_failure_reason, is_err_bucket_not_found, is_err_object_not_found,
is_err_version_not_found,
Error, PoolMetadataError, PoolMetadataFailure, Result, StorageError, classify_system_path_failure_reason,
is_err_bucket_not_found, is_err_object_not_found, is_err_version_not_found,
};
}
@@ -1425,7 +1425,12 @@ fn build_remove_object_headers(version_id: Option<&str>, opts: &RemoveObjectOpti
/// and silently creates a delete marker instead of removing the version, while
/// the source stamps `VersionPurgeStatus=Complete` (backlog#799 B8 / #857).
/// Non-replication callers always pass the version through unchanged.
fn resolve_delete_api_version_id(version_id: Option<String>, opts: &RemoveObjectOptions) -> Option<String> {
/// The `versionId` a replicated DELETE puts on the wire: none for a
/// delete-marker creation (the target mints the marker; the source version
/// travels in the internal headers for RustFS peers), the addressed version
/// otherwise. A generic S3 target given the version id on a marker-creation
/// DELETE would permanently delete that version instead.
pub fn resolve_delete_api_version_id(version_id: Option<String>, opts: &RemoveObjectOptions) -> Option<String> {
if opts.replication_request && opts.replication_delete_marker {
None
} else {
+27 -10
View File
@@ -54,6 +54,9 @@ pub type BucketConfigPublishHook = Box<dyn Fn(&str, &str, Option<(&[u8], OffsetD
pub static BUCKET_CONFIG_PUBLISH_HOOK: std::sync::OnceLock<BucketConfigPublishHook> = std::sync::OnceLock::new();
const BUCKET_METADATA_REFRESH_INTERVAL: Duration = Duration::from_secs(15 * 60);
const LOG_COMPONENT_ECSTORE: &str = "ecstore";
const LOG_SUBSYSTEM_BUCKET_METADATA: &str = "bucket_metadata";
const EVENT_BUCKET_METADATA_LOAD_FAILED: &str = "bucket_metadata_load_failed";
#[cfg(any(test, feature = "test-util"))]
struct ConfigWriteLockProbeState {
@@ -1614,13 +1617,20 @@ impl BucketMetadataSys {
let results = join_all(futures).await;
for (idx, res) in results.into_iter().enumerate() {
for (bucket, res) in buckets.iter().zip(results) {
match res {
Ok(()) => {}
Err(e) => {
error!("Unable to load bucket metadata, will be retried: {:?}", e);
if let Some(bucket) = buckets.get(idx) {
failed_buckets.insert(bucket.clone());
if failed_buckets.insert(bucket.clone()) {
error!(
event = EVENT_BUCKET_METADATA_LOAD_FAILED,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_BUCKET_METADATA,
result = "retry_pending",
bucket = %bucket,
error_code = ?e.code(),
"Unable to load bucket metadata; retry scheduled"
);
}
}
}
@@ -1647,12 +1657,19 @@ impl BucketMetadataSys {
});
}
let results = join_all(futures).await;
for (idx, result) in results.into_iter().enumerate() {
if let Err(err) = result {
error!("Unable to load bucket metadata, will be retried: {:?}", err);
if let Some(bucket) = buckets.get(idx) {
failed_buckets.insert(bucket.clone());
}
for (bucket, result) in buckets.iter().zip(results) {
if let Err(err) = result
&& failed_buckets.insert(bucket.clone())
{
error!(
event = EVENT_BUCKET_METADATA_LOAD_FAILED,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_BUCKET_METADATA,
result = "retry_pending",
bucket = %bucket,
error_code = ?err.code(),
"Unable to load bucket metadata; retry scheduled"
);
}
}
}
@@ -75,6 +75,7 @@ use tracing::{debug, info, instrument, warn};
const EVENT_REPLICATION_WORKER_RESIZE_SKIPPED: &str = "replication_worker_resize_skipped";
const EVENT_REPLICATION_WORKER_RESIZED: &str = "replication_worker_resized";
const EVENT_REPLICATION_BACKPRESSURE: &str = "replication_backpressure";
const EVENT_REPLICATION_IN_FLIGHT_SKIPPED: &str = "replication_in_flight_skipped";
const EVENT_REPLICATION_RESYNC_LOAD_SKIPPED: &str = "replication_resync_load_skipped";
const EVENT_REPLICATION_RESYNC_RECOVERED: &str = "replication_resync_recovered";
const EVENT_REPLICATION_MRF_QUEUE_UNAVAILABLE: &str = "replication_mrf_queue_unavailable";
@@ -1089,6 +1090,9 @@ pub struct ReplicationPool<S: ReplicationStorage> {
workers: RwLock<Vec<Sender<ReplicationOperation>>>,
lrg_workers: RwLock<Vec<Sender<ReplicationOperation>>>,
/// Object versions queued or being replicated right now (backlog#2362).
in_flight: Arc<ReplicationInFlight>,
// MRF (Most Recent Failures) channels
mrf_replica_tx: Sender<ReplicationOperation>,
// Shared among N MRF workers; Arc allows spawning more than one worker.
@@ -1147,6 +1151,7 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
storage,
workers: RwLock::new(Vec::new()),
lrg_workers: RwLock::new(Vec::new()),
in_flight: Arc::new(ReplicationInFlight::default()),
mrf_replica_tx,
mrf_replica_rx: Arc::new(Mutex::new(mrf_replica_rx)),
mrf_save_tx,
@@ -1202,12 +1207,13 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
let active_counter = self.active_lrg_workers.clone();
let storage = self.storage.clone();
let stats = self.stats.clone();
let in_flight = self.in_flight.clone();
let handle = tokio::spawn(async move {
let mut rx = rx;
while let Some(operation) = rx.recv().await {
let _active = ActiveWorkerGuard::new(active_counter.clone());
process_replication_operation(operation, stats.clone(), storage.clone()).await;
process_replication_operation(operation, stats.clone(), storage.clone(), in_flight.clone()).await;
}
});
@@ -1261,12 +1267,13 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
let active_counter = self.active_workers.clone();
let stats = self.stats.clone();
let storage = self.storage.clone();
let in_flight = self.in_flight.clone();
let handle = tokio::spawn(async move {
let mut rx = rx;
while let Some(operation) = rx.recv().await {
let _active = ActiveWorkerGuard::new(active_counter.clone());
process_replication_operation(operation, stats.clone(), storage.clone()).await;
process_replication_operation(operation, stats.clone(), storage.clone(), in_flight.clone()).await;
}
});
@@ -1305,6 +1312,7 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
let active_counter = self.active_mrf_workers.clone();
let stats = self.stats.clone();
let storage = self.storage.clone();
let in_flight = self.in_flight.clone();
let mrf_rx = Arc::clone(&self.mrf_replica_rx);
let handle = tokio::spawn(async move {
@@ -1324,7 +1332,7 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
let Some(operation) = operation else { break };
let _active = ActiveWorkerGuard::new(active_counter.clone());
process_replication_operation(operation, stats.clone(), storage.clone()).await;
process_replication_operation(operation, stats.clone(), storage.clone(), in_flight.clone()).await;
}
});
self.task_handles.lock().await.push(handle);
@@ -1454,6 +1462,24 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
/// Queues a replica task
pub async fn queue_replica_task(&self, ri: ReplicateObjectInfo) -> ReplicationQueueAdmission {
// A version that is already queued or being uploaded is not driven a
// second time: the scanner heal pass sees it as PENDING until the
// first upload lands and would otherwise re-queue it every cycle
// (backlog#2362). The key is released when the worker finishes, or
// below when no worker accepts the task.
if !self.in_flight.try_begin(&ri) {
debug!(
event = EVENT_REPLICATION_IN_FLIGHT_SKIPPED,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_REPLICATION,
bucket = %ri.bucket,
object = %ri.name,
version_id = ?ri.version_id,
op_type = ?ri.op_type,
"Replication task already in flight; not queued again"
);
return ReplicationQueueAdmission::Skipped;
}
let target_arns = ri.dsc.replicate_target_arns();
// If object is large, queue it to a static set of large workers
if should_queue_large_object(ri.size) {
@@ -1484,7 +1510,9 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
let resize = large_worker_backpressure_resize(existing, self.active_lrg_workers(), max_l_workers);
drop(lrg_workers);
// Queue to MRF if worker is busy.
// Queue to MRF if worker is busy. The MRF replay re-enters
// this function, so the version is no longer in flight.
self.in_flight.finish(&ri);
let admission = self.queue_mrf_save_admission(ri.to_mrf_entry(), "large_object").await;
if let Some(resize) = resize {
@@ -1493,6 +1521,7 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
return admission;
}
}
self.in_flight.finish(&ri);
return ReplicationQueueAdmission::Missed;
}
@@ -1501,6 +1530,7 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
let ch = self.worker_queue_channel(&ri.op_type, &ri.bucket, &ri.name, ri.size).await;
let Some(channel) = ch else {
self.in_flight.finish(&ri);
return ReplicationQueueAdmission::Missed;
};
@@ -1512,7 +1542,9 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
self.stats.dec_q(&ri.bucket, ri.size, ri.delete_marker, ri.op_type);
self.stats.dec_target_q(&ri.bucket, &target_arns, ri.size);
// Queue to MRF if all workers are busy.
// Queue to MRF if all workers are busy. The MRF replay re-enters this
// function, so the version is no longer in flight.
self.in_flight.finish(&ri);
let admission = self.queue_mrf_save_admission(ri.to_mrf_entry(), "object").await;
// Try to scale up workers based on priority
@@ -1811,7 +1843,7 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
) {
while let Some(operation) = rx.recv().await {
let _active = ActiveWorkerGuard::new(active_counter.clone());
process_replication_operation(operation, stats.clone(), self.storage.clone()).await;
process_replication_operation(operation, stats.clone(), self.storage.clone(), self.in_flight.clone()).await;
}
}
@@ -1829,7 +1861,7 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
) {
while let Some(operation) = rx.recv().await {
let _active = ActiveWorkerGuard::new(active_counter.clone());
process_replication_operation(operation, stats.clone(), storage.clone()).await;
process_replication_operation(operation, stats.clone(), storage.clone(), self.in_flight.clone()).await;
}
}
@@ -1846,7 +1878,7 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
) {
while let Some(operation) = rx.recv().await {
let _active = ActiveWorkerGuard::new(active_counter.clone());
process_replication_operation(operation, stats.clone(), self.storage.clone()).await;
process_replication_operation(operation, stats.clone(), self.storage.clone(), self.in_flight.clone()).await;
}
}
@@ -2281,6 +2313,64 @@ impl<S: ReplicationStorage> ReplicationPool<S> {
}
}
/// Object versions currently queued or being uploaded, keyed by bucket,
/// object name and version. `queue_replica_task` admits a version only once
/// while it is in flight; the scanner heal pass and MRF replays that arrive
/// in the meantime are `Skipped` instead of driving a second complete upload
/// (backlog#2362). Entries are removed when the worker finishes the task or
/// when no worker accepted it.
#[derive(Debug, Default)]
pub(crate) struct ReplicationInFlight {
keys: std::sync::Mutex<std::collections::HashSet<(String, String, Option<uuid::Uuid>)>>,
}
impl ReplicationInFlight {
fn lock(&self) -> std::sync::MutexGuard<'_, std::collections::HashSet<(String, String, Option<uuid::Uuid>)>> {
self.keys.lock().unwrap_or_else(|poisoned| poisoned.into_inner())
}
/// Claim `ri`; `false` when the same version is already in flight.
fn try_begin(&self, ri: &ReplicateObjectInfo) -> bool {
self.lock().insert((ri.bucket.clone(), ri.name.clone(), ri.version_id))
}
fn finish(&self, ri: &ReplicateObjectInfo) {
self.lock().remove(&(ri.bucket.clone(), ri.name.clone(), ri.version_id));
}
#[cfg(test)]
fn len(&self) -> usize {
self.lock().len()
}
}
/// Releases the in-flight claim when the worker is done with the task,
/// including when replication panics.
struct ReplicationInFlightGuard {
in_flight: Arc<ReplicationInFlight>,
key: ReplicateObjectInfo,
}
impl ReplicationInFlightGuard {
fn new(in_flight: Arc<ReplicationInFlight>, ri: &ReplicateObjectInfo) -> Self {
Self {
in_flight,
key: ReplicateObjectInfo {
bucket: ri.bucket.clone(),
name: ri.name.clone(),
version_id: ri.version_id,
..Default::default()
},
}
}
}
impl Drop for ReplicationInFlightGuard {
fn drop(&mut self) {
self.in_flight.finish(&self.key);
}
}
struct ActiveWorkerGuard {
counter: Arc<AtomicI32>,
}
@@ -2342,10 +2432,12 @@ async fn process_replication_operation<S: ReplicationStorage>(
operation: ReplicationOperation,
stats: Arc<ReplicationStats>,
storage: Arc<S>,
in_flight: Arc<ReplicationInFlight>,
) {
match operation {
ReplicationOperation::Object(obj_info) => {
let _backlog = ReplicationBacklogGuard::for_object(stats, obj_info.as_ref());
let _in_flight = ReplicationInFlightGuard::new(in_flight, obj_info.as_ref());
replicate_object(*obj_info, storage).await;
}
ReplicationOperation::Delete(del_info) => {
@@ -3083,7 +3175,7 @@ pub async fn queue_replication_heal(bucket: &str, oi: ObjectInfo, retry_count: u
// A bucket without a configuration still owes its pending purges an
// answer: the delete worker finishes them locally as abandoned, which
// is what makes the bucket deletable again (rustfs/backlog#2340).
Ok(None) if !oi.version_purge_status.is_empty() => None,
Ok(None) if owes_version_purge(&oi) => None,
Ok(None) => return ReplicationQueueAdmission::Skipped,
Err(err) => {
debug!(
@@ -3161,6 +3253,17 @@ pub async fn queue_replication_metadata(bucket: &str, oi: ObjectInfo, retry_coun
}
}
/// A version purge the persisted state still owes to named targets. Without
/// the target list nothing can be settled, so such a version keeps the
/// ordinary "no configuration, nothing to heal" skip.
fn owes_version_purge(oi: &ObjectInfo) -> bool {
!oi.version_purge_status.is_empty()
&& oi
.version_purge_status_internal
.as_deref()
.is_some_and(|statuses| !statuses.trim().is_empty())
}
/// queue_replication_heal_internal enqueues objects that failed replication OR eligible for resyncing through
/// an ongoing resync operation or via existing objects replication configuration setting.
pub(crate) async fn queue_replication_heal_internal(
@@ -3183,7 +3286,7 @@ pub(crate) async fn queue_replication_heal_internal(
// except a version purge the bucket still owes: its stored decision names
// the targets, and the delete worker settles the ones no longer
// configured as abandoned (rustfs/backlog#2340).
if (rcfg.config.is_none() || rcfg.remotes.is_none()) && oi.version_purge_status.is_empty() {
if (rcfg.config.is_none() || rcfg.remotes.is_none()) && !owes_version_purge(&oi) {
return ReplicationHealQueueResult {
object_info: roi,
admission: ReplicationQueueAdmission::Skipped,
@@ -3718,6 +3821,7 @@ mod tests {
stats: Arc::new(ReplicationStats::new()),
workers: RwLock::new(Vec::new()),
lrg_workers: RwLock::new(Vec::new()),
in_flight: Arc::new(ReplicationInFlight::default()),
mrf_replica_tx,
mrf_replica_rx: Arc::new(Mutex::new(mrf_replica_rx)),
mrf_save_tx,
@@ -3784,6 +3888,90 @@ mod tests {
assert_eq!(current_queue(&pool, "admission-bucket").await, (1, 4096));
}
#[tokio::test]
async fn queue_replica_task_admits_a_version_once_while_it_is_in_flight() {
let pool = new_test_replication_pool(Arc::new(LoadResyncNodeStore::new("node-a", empty_resync_shared_state()))).await;
let (tx, _rx) = mpsc::channel(4);
pool.workers.write().await.push(tx);
let ri = ReplicateObjectInfo {
bucket: "in-flight-bucket".to_string(),
name: "object".to_string(),
version_id: Some(uuid::Uuid::new_v4()),
size: 4096,
op_type: ReplicationType::Object,
..Default::default()
};
assert_eq!(pool.queue_replica_task(ri.clone()).await, ReplicationQueueAdmission::Queued);
// backlog#2362: the scanner heal pass sees the version as PENDING
// until the worker lands it; a second request must not drive it again.
assert_eq!(pool.queue_replica_task(ri.clone()).await, ReplicationQueueAdmission::Skipped);
assert_eq!(current_queue(&pool, "in-flight-bucket").await, (1, 4096));
// Another version of the same key is independent work.
let newer = ReplicateObjectInfo {
version_id: Some(uuid::Uuid::new_v4()),
..ri.clone()
};
assert_eq!(pool.queue_replica_task(newer).await, ReplicationQueueAdmission::Queued);
assert_eq!(pool.in_flight.len(), 2);
// Once the worker finishes, the same version may be queued again
// (for example after a FAILED status).
pool.in_flight.finish(&ri);
assert_eq!(pool.queue_replica_task(ri).await, ReplicationQueueAdmission::Queued);
assert_eq!(current_queue(&pool, "in-flight-bucket").await, (3, 3 * 4096));
}
#[tokio::test]
async fn queue_replica_task_releases_the_version_when_no_worker_accepts_it() {
let pool = new_test_replication_pool(Arc::new(LoadResyncNodeStore::new("node-a", empty_resync_shared_state()))).await;
let ri = ReplicateObjectInfo {
bucket: "no-worker-bucket".to_string(),
name: "object".to_string(),
version_id: Some(uuid::Uuid::new_v4()),
size: 4096,
op_type: ReplicationType::Object,
..Default::default()
};
// No worker channel: the task is missed and must not stay claimed.
assert_eq!(pool.queue_replica_task(ri.clone()).await, ReplicationQueueAdmission::Missed);
assert_eq!(pool.in_flight.len(), 0);
assert_eq!(pool.queue_replica_task(ri.clone()).await, ReplicationQueueAdmission::Missed);
// A full worker channel hands the task to the MRF save path; the MRF
// replay re-enters the queue, so the claim is released here too.
let (tx, _rx) = mpsc::channel(1);
pool.workers.write().await.push(tx);
assert_eq!(pool.queue_replica_task(ri.clone()).await, ReplicationQueueAdmission::Queued);
let overflow = ReplicateObjectInfo {
version_id: Some(uuid::Uuid::new_v4()),
..ri
};
assert_eq!(pool.queue_replica_task(overflow).await, ReplicationQueueAdmission::Queued);
assert_eq!(pool.in_flight.len(), 1, "only the version held by the worker channel stays in flight");
}
#[test]
fn in_flight_guard_releases_the_version_on_drop() {
let in_flight = Arc::new(ReplicationInFlight::default());
let ri = ReplicateObjectInfo {
bucket: "guard-bucket".to_string(),
name: "object".to_string(),
version_id: Some(uuid::Uuid::new_v4()),
..Default::default()
};
assert!(in_flight.try_begin(&ri));
assert!(!in_flight.try_begin(&ri));
{
let _guard = ReplicationInFlightGuard::new(in_flight.clone(), &ri);
assert_eq!(in_flight.len(), 1);
}
assert_eq!(in_flight.len(), 0);
assert!(in_flight.try_begin(&ri));
}
#[tokio::test]
async fn regular_worker_admission_counts_target_backlog_before_receive() {
let pool = new_test_replication_pool(Arc::new(LoadResyncNodeStore::new("node-a", empty_resync_shared_state()))).await;
@@ -5647,6 +5647,17 @@ async fn replicate_multipart_parts_and_complete<S: ReplicationObjectIO>(
};
header_size = 0;
// Passthrough parts are the stored bytes; the replica learns each
// part's plaintext length from this header (backlog#2363).
let mut part_options = PutObjectPartOptions::default();
if obj_opts.raw_data_movement_read && part_info.actual_size > 0 {
rustfs_utils::http::insert_header(
&mut part_options.custom_header,
rustfs_utils::http::SUFFIX_REPLICATION_PART_ACTUAL_SIZE,
part_info.actual_size.to_string(),
);
}
let object_part = cli
.put_object_part(
dst_bucket,
@@ -5655,7 +5666,7 @@ async fn replicate_multipart_parts_and_complete<S: ReplicationObjectIO>(
part_plan.part_number,
part_plan.part_size,
byte_stream,
&PutObjectPartOptions { ..Default::default() },
&part_options,
)
.await
.map_err(|e| std::io::Error::other(e.to_string()))?;
@@ -8243,47 +8254,77 @@ mod tests {
#[tokio::test]
async fn multipart_transport_preserves_legacy_zero_actual_sizes() {
run_transport(4096, None).await;
run_transport(4096, None, false).await;
}
#[tokio::test]
async fn multipart_transport_uploads_an_empty_last_part_without_reading_a_range() {
run_transport(0, None).await;
run_transport(0, None, false).await;
}
#[tokio::test]
async fn multipart_transport_preserves_transformed_unknown_nonempty_parts() {
for unknown_part in [(0, 0), (1, 0), (0, -1), (1, -1)] {
run_transport(4096, Some(unknown_part)).await;
run_transport(4096, Some(unknown_part), false).await;
}
}
#[tokio::test]
async fn multipart_transport_preserves_transformed_empty_tail() {
run_transport(0, Some((1, 0))).await;
run_transport(0, Some((1, 0)), false).await;
}
async fn run_transport(tail_size: usize, unknown_part: Option<(usize, i64)>) {
/// SSE-C passthrough of a compressed object: the stored bytes go out
/// as-is and every UploadPart declares the part's plaintext length
/// (backlog#2363).
#[tokio::test]
async fn multipart_transport_declares_passthrough_part_lengths() {
run_transport(4096, None, true).await;
}
async fn run_transport(tail_size: usize, unknown_part: Option<(usize, i64)>, passthrough: bool) {
const FIRST_SIZE: usize = 5 * 1024 * 1024;
// The stored (compressed ciphertext) bytes of a passthrough part
// are shorter than the plaintext they represent.
const PASSTHROUGH_PLAINTEXT_FACTOR: usize = 4;
let body = Bytes::from([vec![0x35; FIRST_SIZE], vec![0xa7; tail_size]].concat());
let etag = faster_hex::hex_string(rustfs_utils::hash::HashAlgorithm::Md5.hash_encode(&body).as_ref());
let mut user_defined = if unknown_part.is_some() {
HashMap::from([("x-amz-server-side-encryption".to_string(), "AES256".to_string())])
} else {
HashMap::new()
};
if passthrough {
user_defined.insert(rustfs_utils::http::SSEC_ALGORITHM_HEADER.to_string(), "AES256".to_string());
rustfs_utils::http::insert_str(
&mut user_defined,
rustfs_utils::http::SUFFIX_COMPRESSION,
"klauspost/compress/s2".to_string(),
);
}
let plaintext_len = |stored: usize| {
i64::try_from(if passthrough {
stored * PASSTHROUGH_PLAINTEXT_FACTOR
} else {
stored
})
.expect("plaintext size")
};
let source = Arc::new(Source {
info: ObjectInfo {
size: i64::try_from(body.len() + if unknown_part.is_some() { 16 } else { 0 }).expect("stored size"),
actual_size: i64::try_from(body.len()).expect("body size"),
actual_size: plaintext_len(body.len()),
etag: Some(etag.clone()),
version_id: Some(Uuid::new_v4()),
user_defined: Arc::new(if unknown_part.is_some() {
HashMap::from([("x-amz-server-side-encryption".to_string(), "AES256".to_string())])
} else {
HashMap::new()
}),
user_defined: Arc::new(user_defined),
parts: Arc::new(vec![
ObjectPartInfo {
number: 1,
size: FIRST_SIZE + if unknown_part.is_some() { 8 } else { 0 },
actual_size: if let Some((0, size)) = unknown_part {
size
} else if passthrough {
plaintext_len(FIRST_SIZE)
} else if unknown_part.is_some() || tail_size == 0 {
i64::try_from(FIRST_SIZE).expect("first part size")
} else {
@@ -8296,6 +8337,8 @@ mod tests {
size: tail_size + if unknown_part.is_some() { 8 } else { 0 },
actual_size: if let Some((1, size)) = unknown_part {
size
} else if passthrough {
plaintext_len(tail_size)
} else if unknown_part.is_some() {
i64::try_from(tail_size).expect("tail logical size")
} else {
@@ -8374,6 +8417,7 @@ mod tests {
let (put_opts, is_multipart) = replication_put_object_options("STANDARD", &source.info).expect("replication options");
let opts = ObjectOptions {
version_id: source.info.version_id.map(|id| id.to_string()),
raw_data_movement_read: passthrough,
..Default::default()
};
let reader = source
@@ -8456,6 +8500,36 @@ mod tests {
requests[index].headers.get("content-length").expect("part content length"),
expected.len().to_string().as_str()
);
let declared = rustfs_utils::http::get_header(
&requests[index].headers,
rustfs_utils::http::SUFFIX_REPLICATION_PART_ACTUAL_SIZE,
);
if passthrough {
assert_eq!(
declared.as_deref(),
Some(plaintext_len(expected.len()).to_string().as_str()),
"passthrough parts declare their plaintext length"
);
} else {
assert!(declared.is_none(), "decrypted transport carries no passthrough part length");
}
}
if passthrough {
let create = &requests[0];
assert_eq!(
rustfs_utils::http::get_header(&create.headers, rustfs_utils::http::SUFFIX_REPLICATION_COMPRESSION)
.as_deref(),
Some("klauspost/compress/s2"),
"the session carries the source's compression scheme"
);
assert_eq!(
rustfs_utils::http::get_header(
&create.headers,
rustfs_utils::http::SUFFIX_REPLICATION_COMPRESSION_ACTUAL_SIZE
)
.as_deref(),
Some(plaintext_len(body.len()).to_string().as_str())
);
}
let complete = &requests[3];
assert_eq!(complete.method, http::Method::POST);
@@ -247,6 +247,23 @@ pub(crate) fn replication_put_object_options(sc: &str, object_info: &ObjectInfo)
meta.insert(key.to_string(), value.to_string());
}
// A compressed SSE-C object passes through as its stored bytes. The target
// cannot infer the compression layout from ciphertext, so the scheme and
// the plaintext size travel as transport headers; each UploadPart carries
// its own plaintext length (backlog#2363).
if is_ssec && let Some(scheme) = get_str(&object_info.user_defined, rustfs_utils::http::SUFFIX_COMPRESSION) {
insert_header_map(&mut meta, rustfs_utils::http::SUFFIX_REPLICATION_COMPRESSION, scheme);
if let Ok(actual_size) = object_info.get_actual_size()
&& actual_size >= 0
{
insert_header_map(
&mut meta,
rustfs_utils::http::SUFFIX_REPLICATION_COMPRESSION_ACTUAL_SIZE,
actual_size.to_string(),
);
}
}
// Managed SSE replicates as plaintext (the replication reader decrypts via
// the object-encryption resolver) and re-encrypts on the target with the
// target's own KMS. Send only the encryption intent — never the source
@@ -626,6 +643,59 @@ mod tests {
}
}
#[test]
fn compressed_ssec_objects_declare_their_compression_layout_on_the_wire() {
use rustfs_utils::http::{
SUFFIX_ACTUAL_SIZE, SUFFIX_COMPRESSION, SUFFIX_REPLICATION_COMPRESSION, SUFFIX_REPLICATION_COMPRESSION_ACTUAL_SIZE,
insert_str,
};
let mut ssec_compressed = HashMap::from([(SSEC_ALGORITHM_HEADER.to_string(), "AES256".to_string())]);
insert_str(&mut ssec_compressed, SUFFIX_COMPRESSION, "klauspost/compress/s2".to_string());
insert_str(&mut ssec_compressed, SUFFIX_ACTUAL_SIZE, "6295552".to_string());
let object_info = ObjectInfo {
etag: Some("0123456789abcdef0123456789abcdef-2".to_string()),
size: 4321,
actual_size: 6295552,
user_defined: Arc::new(ssec_compressed),
..Default::default()
};
// SSE-C passthrough sends stored bytes: the scheme and the plaintext
// size travel as transport headers, never as the internal key
// (backlog#2363).
let (options, _) = replication_put_object_options("STANDARD", &object_info).expect("ssec put options");
assert_eq!(
get_header_map(&options.user_metadata, SUFFIX_REPLICATION_COMPRESSION).as_deref(),
Some("klauspost/compress/s2")
);
assert_eq!(
get_header_map(&options.user_metadata, SUFFIX_REPLICATION_COMPRESSION_ACTUAL_SIZE).as_deref(),
Some("6295552")
);
assert!(
!options
.user_metadata
.keys()
.any(|key| rustfs_utils::http::is_internal_key(key)),
"internal metadata never leaves the source as plain metadata: {:?}",
options.user_metadata
);
// A compressed object that is not SSE-C is decompressed by the
// replication reader and travels as plaintext: no layout headers.
let mut plain_compressed = HashMap::new();
insert_str(&mut plain_compressed, SUFFIX_COMPRESSION, "klauspost/compress/s2".to_string());
insert_str(&mut plain_compressed, SUFFIX_ACTUAL_SIZE, "6295552".to_string());
let plain = ObjectInfo {
user_defined: Arc::new(plain_compressed),
..object_info
};
let (options, _) = replication_put_object_options("STANDARD", &plain).expect("plain put options");
assert!(get_header_map(&options.user_metadata, SUFFIX_REPLICATION_COMPRESSION).is_none());
assert!(get_header_map(&options.user_metadata, SUFFIX_REPLICATION_COMPRESSION_ACTUAL_SIZE).is_none());
}
#[test]
fn legacy_transformed_single_put_parts_keep_the_previous_replication_route() {
let [_, (_, compressed), (_, encrypted), (_, ssec)] = replication_route_metadata();
+19 -10
View File
@@ -747,18 +747,27 @@ mod tests {
let mut kvs = KVS::new();
kvs.insert(CLASS_STANDARD.to_string(), "EC:2".to_string());
let err = lookup_config_for_pools_with_env(&kvs, &[4, 2], no_env_overrides())
.expect_err("EC:2 must be rejected by the two-drive pool");
assert!(
err.to_string().contains("pool 1") && err.to_string().contains("2 drives"),
"error must identify the rejecting pool: {err}"
);
for drives in [2, 3] {
let err = lookup_config_for_pools_with_env(&kvs, &[4, drives], no_env_overrides())
.expect_err("EC:2 must be rejected by a pool with fewer than four drives per set");
assert!(
err.to_string().contains("pool 1") && err.to_string().contains(&format!("{drives} drives")),
"error must identify the rejecting pool: {err}"
);
}
let cfg =
lookup_config_for_pools_with_env(&kvs, &[4, 4], no_env_overrides()).expect("EC:2 is valid for both four-drive pools");
assert_eq!(cfg.parities_for_sc(STANDARD), Some(vec![2, 2]));
kvs.insert(CLASS_STANDARD.to_string(), "EC:1".to_string());
let cfg = lookup_config_for_pools_with_env(&kvs, &[4, 2], no_env_overrides()).expect("EC:1 is valid for both pools");
assert_eq!(cfg.parity_for_sc(STANDARD, 4), Some(1));
assert_eq!(cfg.parity_for_sc(STANDARD, 2), Some(1));
assert_eq!(cfg.get_parity_for_sc(STANDARD), Some(1));
for drives in [2, 3, 4] {
let cfg =
lookup_config_for_pools_with_env(&kvs, &[4, drives], no_env_overrides()).expect("EC:1 is valid for both pools");
assert_eq!(cfg.parity_for_sc(STANDARD, 4), Some(1));
assert_eq!(cfg.parity_for_sc(STANDARD, drives), Some(1));
assert_eq!(cfg.get_parity_for_sc(STANDARD), Some(1));
}
}
#[test]
File diff suppressed because it is too large Load Diff
+3
View File
@@ -39,6 +39,7 @@ mod capacity_dedup_tests {
..Default::default()
},
disks: disks.clone(),
..Default::default()
};
let total = get_total_usable_capacity(&disks, &info);
@@ -73,6 +74,7 @@ mod capacity_dedup_tests {
..Default::default()
},
disks: disks.clone(),
..Default::default()
};
let total = get_total_usable_capacity(&disks, &info);
@@ -150,6 +152,7 @@ mod capacity_dedup_tests {
..Default::default()
},
disks: disks.clone(),
..Default::default()
};
let total = get_total_usable_capacity(&disks, &info);
+1
View File
@@ -425,6 +425,7 @@ impl From<rustfs_filemeta::Error> for DiskError {
rustfs_filemeta::Error::FileVersionNotFound => DiskError::FileVersionNotFound,
rustfs_filemeta::Error::FileCorrupt => DiskError::FileCorrupt,
rustfs_filemeta::Error::MethodNotAllowed => DiskError::MethodNotAllowed,
rustfs_filemeta::Error::MaxVersionsExceeded => DiskError::MaxVersionsExceeded,
e => DiskError::other(e),
}
}
+132 -5
View File
@@ -23,17 +23,59 @@ use s3s::S3ErrorCode;
pub type Error = StorageError;
pub type Result<T> = core::result::Result<T, Error>;
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum PoolMetadataFailure {
ReadUnavailable,
RecoveryRequired,
TransactionUnknown,
FenceLost,
}
impl PoolMetadataFailure {
fn recovery_hint(self) -> &'static str {
match self {
Self::ReadUnavailable => "read unavailable; retry after the replicas are readable",
Self::TransactionUnknown => "writes remain blocked pending fenced transaction recovery",
Self::RecoveryRequired | Self::FenceLost => {
"writes remain blocked after a recovery-required replica state; restart after all replicas are readable and consistent, with compatible formats"
}
}
}
pub fn as_str(self) -> &'static str {
match self {
Self::ReadUnavailable => "read_unavailable",
Self::RecoveryRequired => "recovery_required",
Self::TransactionUnknown => "transaction_unknown",
Self::FenceLost => "fence_lost",
}
}
}
/// Local control-plane context. Keep the existing storage error wire codes;
/// the HTTP boundary recognizes this typed source, not an error-message prefix.
#[derive(Debug, Clone, thiserror::Error)]
#[error("{operation}: pool metadata {hint} ({reason}, {phase}): {detail}", hint = kind.recovery_hint(), reason = kind.as_str(), detail = source.as_ref().map(ToString::to_string).unwrap_or_default())]
pub struct PoolMetadataError {
pub kind: PoolMetadataFailure,
pub operation: String,
pub phase: &'static str,
pub since: time::OffsetDateTime,
#[source]
pub source: Option<std::sync::Arc<StorageError>>,
}
/// Keeps high-cardinality diagnostic detail in the error source while making
/// the rendered `io::Error` stable for quorum aggregation.
#[derive(Debug)]
struct StableIoContextError {
message: &'static str,
message: std::borrow::Cow<'static, str>,
source: Box<dyn std::error::Error + Send + Sync>,
}
impl std::fmt::Display for StableIoContextError {
fn fmt(&self, formatter: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
formatter.write_str(self.message)
formatter.write_str(&self.message)
}
}
@@ -48,7 +90,7 @@ where
E: Into<Box<dyn std::error::Error + Send + Sync>>,
{
std::io::Error::other(StableIoContextError {
message,
message: message.into(),
source: source.into(),
})
}
@@ -203,6 +245,19 @@ pub enum StorageError {
NotFirstDisk,
#[error("first disk wait")]
FirstDiskWait,
#[error(
"unsupported pool expansion: an existing single-node single-drive (SNSD) deployment cannot be expanded in place (configured {configured_drives} drive endpoints); restart with the original single local path, or create a new multi-drive deployment and migrate data through S3"
)]
UnsupportedSnsdExpansion { configured_drives: usize },
#[error(
"pool topology mismatch: stored {stored_drives} drives with {stored_set_drive_count} drives per erasure set, configured {configured_drives} drives with {configured_set_drive_count} drives per erasure set; an existing pool's drive count and erasure set width cannot be changed in place; restore its original endpoints and RUSTFS_ERASURE_SET_DRIVE_COUNT setting; to expand a multi-drive deployment, append a new pool with at least 2 drive endpoints"
)]
PoolTopologyMismatch {
stored_drives: usize,
stored_set_drive_count: usize,
configured_drives: usize,
configured_set_drive_count: usize,
},
// ── Operational ──────────────────────────────────────────────────
#[error("Storage reached its minimum free drive threshold.")]
@@ -287,6 +342,22 @@ impl From<crate::erasure::coding::ErasureConstructionError> for StorageError {
}
impl StorageError {
pub fn pool_metadata_failure(&self) -> Option<&PoolMetadataError> {
let mut current: Option<&(dyn std::error::Error + 'static)> = Some(self);
while let Some(error) = current {
if let Some(context) = error.downcast_ref::<PoolMetadataError>() {
return Some(context);
}
// io::Error::source skips its boxed context itself.
current = if let Some(io) = error.downcast_ref::<std::io::Error>() {
io.get_ref().map(|inner| inner as &(dyn std::error::Error + 'static))
} else {
error.source()
};
}
None
}
pub fn other<E>(error: E) -> Self
where
E: Into<Box<dyn std::error::Error + Send + Sync>>,
@@ -517,6 +588,7 @@ impl From<rustfs_filemeta::Error> for StorageError {
rustfs_filemeta::Error::FileVersionNotFound => StorageError::FileVersionNotFound,
rustfs_filemeta::Error::FileCorrupt => StorageError::FileCorrupt,
rustfs_filemeta::Error::Unexpected => StorageError::Unexpected,
rustfs_filemeta::Error::MaxVersionsExceeded => StorageError::MaxVersionsExceeded,
rustfs_filemeta::Error::Io(io_error) => io_error.into(),
_ => StorageError::Io(std::io::Error::other(e)),
}
@@ -535,7 +607,19 @@ impl PartialEq for StorageError {
impl Clone for StorageError {
fn clone(&self) -> Self {
match self {
StorageError::Io(e) => StorageError::Io(std::io::Error::new(e.kind(), e.to_string())),
StorageError::Io(e) => {
if let Some(context) = self.pool_metadata_failure() {
Self::Io(std::io::Error::new(
e.kind(),
StableIoContextError {
message: e.to_string().into(),
source: Box::new(context.clone()),
},
))
} else {
StorageError::Io(std::io::Error::new(e.kind(), e.to_string()))
}
}
StorageError::FaultyDisk => StorageError::FaultyDisk,
StorageError::DiskFull => StorageError::DiskFull,
StorageError::VolumeNotFound => StorageError::VolumeNotFound,
@@ -629,6 +713,20 @@ impl Clone for StorageError {
StorageError::ErasureWriteQuorum => StorageError::ErasureWriteQuorum,
StorageError::NotFirstDisk => StorageError::NotFirstDisk,
StorageError::FirstDiskWait => StorageError::FirstDiskWait,
StorageError::UnsupportedSnsdExpansion { configured_drives } => StorageError::UnsupportedSnsdExpansion {
configured_drives: *configured_drives,
},
StorageError::PoolTopologyMismatch {
stored_drives,
stored_set_drive_count,
configured_drives,
configured_set_drive_count,
} => StorageError::PoolTopologyMismatch {
stored_drives: *stored_drives,
stored_set_drive_count: *stored_set_drive_count,
configured_drives: *configured_drives,
configured_set_drive_count: *configured_set_drive_count,
},
StorageError::TooManyOpenFiles => StorageError::TooManyOpenFiles,
StorageError::NoHealRequired => StorageError::NoHealRequired,
StorageError::Lock(e) => StorageError::Lock(e.clone()),
@@ -662,7 +760,8 @@ impl Clone for StorageError {
}
impl StorageError {
fn code(&self) -> StorageErrorCode {
/// Stable classification without error payloads or storage paths.
pub fn code(&self) -> StorageErrorCode {
match self {
StorageError::Io(_) => StorageErrorCode::Io,
StorageError::FaultyDisk => StorageErrorCode::FaultyDisk,
@@ -735,6 +834,11 @@ impl StorageError {
StorageError::ErasureWriteQuorum => StorageErrorCode::ErasureWriteQuorum,
StorageError::NotFirstDisk => StorageErrorCode::NotFirstDisk,
StorageError::FirstDiskWait => StorageErrorCode::FirstDiskWait,
// Topology diagnostics reuse the existing wire code; they are
// not disk errors and must retain their local identity for retry classification.
StorageError::UnsupportedSnsdExpansion { .. } | StorageError::PoolTopologyMismatch { .. } => {
StorageErrorCode::InvalidArgument
}
StorageError::ConfigNotFound => StorageErrorCode::ConfigNotFound,
StorageError::TooManyOpenFiles => StorageErrorCode::TooManyOpenFiles,
StorageError::NoHealRequired => StorageErrorCode::NoHealRequired,
@@ -1215,6 +1319,29 @@ mod tests {
use super::*;
use std::io::{Error as IoError, ErrorKind};
#[test]
fn startup_topology_errors_preserve_identity_and_guidance() {
for error in [
StorageError::UnsupportedSnsdExpansion { configured_drives: 4 },
StorageError::PoolTopologyMismatch {
stored_drives: 4,
stored_set_drive_count: 4,
configured_drives: 8,
configured_set_drive_count: 8,
},
] {
let io_error: IoError = error.clone().into();
let restored = StorageError::from(io_error);
assert_eq!(std::mem::discriminant(&restored), std::mem::discriminant(&error));
assert_eq!(restored.to_string(), error.to_string());
assert_eq!(restored.code(), StorageErrorCode::InvalidArgument);
assert!(
restored.narrow_to_disk().is_err(),
"startup diagnostics must not become disk/quorum errors"
);
}
}
#[test]
fn other_preserves_erasure_construction_source_chain() {
use crate::erasure::coding::ErasureConstructionError;
+156 -5
View File
@@ -25,6 +25,20 @@ pub(crate) const MAX_ERASURE_SET_DRIVE_COUNT: usize = 16;
const SET_SIZES: [usize; 15] = [2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, MAX_ERASURE_SET_DRIVE_COUNT];
const ENV_RUSTFS_ERASURE_SET_DRIVE_COUNT: &str = "RUSTFS_ERASURE_SET_DRIVE_COUNT";
#[derive(Debug, thiserror::Error)]
enum PoolDriveCountError {
#[error(
"Incorrect number of endpoints provided, size {size}; an erasure pool requires at least {} drive endpoints on one or more nodes; for a standalone single-drive deployment, use a single local path without ellipses",
SET_SIZES[0]
)]
BelowMinimum { size: usize },
#[error(
"Incorrect number of endpoints provided, size {size}; {}={set_drive_count} requires at least {set_drive_count} drive endpoints per pool",
ENV_RUSTFS_ERASURE_SET_DRIVE_COUNT
)]
BelowSetWidth { size: usize, set_drive_count: usize },
}
#[derive(Deserialize, Debug, Default)]
pub struct PoolDisksLayout {
cmd_line: String,
@@ -132,7 +146,7 @@ impl DisksLayout {
for arg in args.iter() {
if !has_ellipses(&[arg]) && args.len() > 1 {
return Err(Error::other(
"all args must have ellipses for pool expansion (Invalid arguments specified)",
"all args must have ellipses for pool expansion (Invalid arguments specified); each pool must expand to at least 2 drive endpoints on one or more nodes; a single-drive pool cannot be added to a multi-pool deployment",
));
}
@@ -396,9 +410,11 @@ fn get_set_indexes<T: AsRef<str>>(
}
for &size in total_sizes {
// Check if total_sizes has minimum range upto set_size
if size < SET_SIZES[0] || size < set_drive_count {
return Err(Error::other(format!("Incorrect number of endpoints provided, size {size}")));
if size < SET_SIZES[0] {
return Err(Error::other(PoolDriveCountError::BelowMinimum { size }));
}
if size < set_drive_count {
return Err(Error::other(PoolDriveCountError::BelowSetWidth { size, set_drive_count }));
}
}
@@ -707,7 +723,7 @@ mod test {
arg: "http://rustfs{2...3}/export/set{1...0}",
..Default::default()
},
// Range cannot be smaller than 4 minimum.
// Ranges must use three dots.
TestCase {
num: 4,
arg: "/export{1..2}",
@@ -926,11 +942,146 @@ mod test {
}
}
#[test]
fn pool_expansion_accepts_single_node_multi_drive_pools() {
temp_env::with_var(ENV_RUSTFS_ERASURE_SET_DRIVE_COUNT, Some("0"), || {
for (volumes, drives) in [
(["http://node1:9000/data{1...2}", "http://node2:9000/data{1...2}"], 2),
(["http://node1:9000/data{1...4}", "http://node2:9000/data{1...4}"], 4),
(["http://node{1...4}:9000/data", "http://node5:9000/data{1...4}"], 4),
(["http://node5:9000/data{1...4}", "http://node{1...4}:9000/data"], 4),
] {
let layout = DisksLayout::from_volumes(&volumes).expect("single-node multi-drive pools are valid");
assert!(!layout.legacy);
assert_eq!(layout.pools.len(), 2);
for (index, volume) in volumes.iter().enumerate() {
assert_eq!(layout.get_set_count(index), 1);
assert_eq!(layout.get_drives_per_set(index), drives);
assert_eq!(layout.get_cmd_line(index), *volume);
}
}
});
}
#[test]
fn pool_expansion_accepts_multi_node_single_drive_pools() {
temp_env::with_var(ENV_RUSTFS_ERASURE_SET_DRIVE_COUNT, Some("0"), || {
for nodes in [2, 3, 4] {
let volumes = [
format!("http://pool1-node{{1...{nodes}}}:9000/data"),
format!("http://pool2-node{{1...{nodes}}}:9000/data"),
];
let layout = DisksLayout::from_volumes(&volumes).expect("each node may contribute one drive to a pool");
assert_eq!(layout.pools.len(), 2);
for pool in 0..2 {
assert_eq!(layout.get_set_count(pool), 1);
assert_eq!(layout.get_drives_per_set(pool), nodes);
let expected = (1..=nodes)
.map(|node| format!("http://pool{}-node{node}:9000/data", pool + 1))
.collect::<Vec<_>>();
assert_eq!(layout.pools[pool].layout, vec![expected]);
}
}
});
}
#[test]
fn explicit_endpoints_without_ellipses_form_one_pool() {
temp_env::with_var(ENV_RUSTFS_ERASURE_SET_DRIVE_COUNT, Some("0"), || {
let volumes = ["http://node1:9000/data", "http://node2:9000/data"];
let layout = DisksLayout::from_volumes(&volumes).expect("explicit endpoints form one legacy pool");
assert!(layout.legacy);
assert_eq!(layout.pools.len(), 1);
assert_eq!(layout.pools[0].layout, vec![volumes.to_vec()]);
});
}
#[test]
fn standalone_single_drive_path_remains_supported() {
temp_env::with_var(ENV_RUSTFS_ERASURE_SET_DRIVE_COUNT, Some("0"), || {
let layout = DisksLayout::from_volumes(&["/data"]).expect("standalone single-drive deployment is valid");
assert!(layout.is_single_drive_layout());
assert_eq!(layout.get_single_drive_layout(), "/data");
});
}
#[test]
fn pool_expansion_rejects_plain_single_drive_pool_with_notice() {
temp_env::with_var(ENV_RUSTFS_ERASURE_SET_DRIVE_COUNT, Some("0"), || {
for volumes in [
["http://node{1...2}:9000/data", "http://node3:9000/data"],
["http://node3:9000/data", "http://node{1...2}:9000/data"],
] {
let err = DisksLayout::from_volumes(&volumes).expect_err("a plain endpoint cannot be an expansion pool");
let message = err.to_string();
assert!(message.contains("all args must have ellipses for pool expansion"), "{message}");
assert!(message.contains("at least 2 drive endpoints"), "{message}");
}
});
}
#[test]
fn pool_expansion_rejects_singleton_ellipsis_pool_with_notice() {
temp_env::with_var(ENV_RUSTFS_ERASURE_SET_DRIVE_COUNT, Some("0"), || {
for singleton in ["http://node{3...3}:9000/data", "http://node3:9000/data{1...1}"] {
for volumes in [
vec!["http://node{1...2}:9000/data", singleton],
vec![singleton, "http://node{1...2}:9000/data"],
vec![singleton],
] {
let err = DisksLayout::from_volumes(&volumes).expect_err("a singleton range still contains one drive");
let message = err.to_string();
assert_eq!(err.kind(), std::io::ErrorKind::Other);
assert!(matches!(
err.get_ref().and_then(|source| source.downcast_ref::<PoolDriveCountError>()),
Some(PoolDriveCountError::BelowMinimum { size: 1 })
));
assert!(message.contains("at least 2 drive endpoints"), "{message}");
assert!(message.contains("single local path without ellipses"), "{message}");
}
}
});
}
#[test]
fn explicit_set_size_counts_drives_not_nodes() {
for volume in ["http://node1:9000/data{1...4}", "http://node{1...4}:9000/data"] {
let sets = get_all_sets(2, true, &[volume]).expect("four endpoints can form two two-drive sets");
assert_eq!(sets.iter().map(Vec::len).collect::<Vec<_>>(), vec![2, 2]);
}
}
#[test]
fn undersized_pool_error_identifies_requested_set_size() {
let err =
get_all_sets(4, true, &["http://node{1...2}:9000/data"]).expect_err("two endpoints cannot fill a four-drive set");
let message = err.to_string();
assert_eq!(err.kind(), std::io::ErrorKind::Other);
assert!(matches!(
err.get_ref().and_then(|source| source.downcast_ref::<PoolDriveCountError>()),
Some(PoolDriveCountError::BelowSetWidth {
size: 2,
set_drive_count: 4
})
));
assert!(message.contains("size 2"), "{message}");
assert!(message.contains("RUSTFS_ERASURE_SET_DRIVE_COUNT=4"), "{message}");
}
#[test]
fn layout_errors_do_not_echo_url_credentials() {
for volumes in [
vec!["http://:duplicate-secret@server/path", "http://:duplicate-secret@server/path"],
vec!["http://:ellipsis...secret@server/path"],
vec!["http://server{1...2}/data", "http://:plain-secret@server3/data"],
vec!["http://server{1...2}/data", "http://:singleton-secret@server{3...3}/data"],
] {
let err = DisksLayout::from_volumes(&volumes).unwrap_err();
assert!(!err.to_string().contains("secret"), "layout error leaked endpoint credentials: {err}");
+35
View File
@@ -2432,6 +2432,41 @@ mod test {
assert_eq!(local_endpoints[0].pool_idx, 1);
}
#[tokio::test]
async fn pool_expansion_resolves_single_node_multi_drive_and_multi_node_single_drive_pools() {
for (additional_pool, expected_nodes) in [
("http://rustfs-5.example.invalid:9000/data{1...4}", 5),
("http://rustfs-{5...8}.example.invalid:9000/data", 8),
] {
let layout = temp_env::with_var("RUSTFS_ERASURE_SET_DRIVE_COUNT", Some("0"), || {
DisksLayout::from_volumes(&["http://rustfs-{1...4}.example.invalid:9000/data", additional_pool])
})
.expect("both single-node multi-drive and multi-node single-drive pools should parse");
let (pools, setup_type) = EndpointServerPools::create_server_endpoints_with(
"0.0.0.0:9000",
&layout,
Some(orchestrated_test_policy()),
Some("rustfs-1.example.invalid"),
)
.await
.expect("pool admission must not impose a minimum node count or drives per node");
assert_eq!(setup_type, SetupType::DistErasure);
assert_eq!(pools.0.len(), 2);
assert_eq!(pools.get_nodes().len(), expected_nodes);
for (pool_index, pool) in (0_i32..).zip(&pools.0) {
assert_eq!((pool.set_count, pool.drives_per_set), (1, 4));
assert_eq!(pool.endpoints.as_ref().len(), 4);
for (disk_index, endpoint) in (0_i32..).zip(pool.endpoints.as_ref()) {
assert_eq!(endpoint.pool_idx, pool_index);
assert_eq!(endpoint.set_idx, 0);
assert_eq!(endpoint.disk_idx, disk_index);
}
}
}
}
#[tokio::test]
async fn explicit_local_endpoint_host_fails_closed_for_invalid_context_or_zero_match() {
let args = vec![
+2
View File
@@ -55,6 +55,8 @@ mod set_disk;
mod storage_api_contracts;
mod store;
pub use store::PoolMetaWriteGateStatus;
// pub mod checksum;
mod event;
@@ -20,9 +20,10 @@ use chrono::Utc;
use jiff::Timestamp;
use rustfs_heal_contracts::heal_channel::DriveState;
use rustfs_io_metrics::internode_metrics::global_internode_metrics;
use rustfs_io_metrics::s3_http_metrics::s3_http_metrics_snapshot;
use rustfs_madmin::metrics::{
DiskIOStats, DiskMetric, LastMinute as MadminLastMinute, NetDevLine, NetMetrics, RPCMetrics, RealtimeMetrics,
ScannerCheckpointReport as MadminScannerCheckpointReport,
DiskIOStats, DiskMetric, HttpMetrics, HttpRequestMetric, LastMinute as MadminLastMinute, NetDevLine, NetMetrics, RPCMetrics,
RealtimeMetrics, ScannerCheckpointReport as MadminScannerCheckpointReport,
ScannerLifecycleExpirySnapshot as MadminScannerLifecycleExpirySnapshot,
ScannerLifecycleTransitionSnapshot as MadminScannerLifecycleTransitionSnapshot,
ScannerMaintenanceControlSnapshot as MadminScannerMaintenanceControlSnapshot,
@@ -61,9 +62,10 @@ impl MetricType {
pub const MEM: MetricType = MetricType(1 << 6);
pub const CPU: MetricType = MetricType(1 << 7);
pub const RPC: MetricType = MetricType(1 << 8);
pub const HTTP: MetricType = MetricType(1 << 9);
// MetricsAll must be last.
pub const ALL: MetricType = MetricType((1 << 9) - 1);
pub const ALL: MetricType = MetricType((1 << 10) - 1);
pub fn new(t: u32) -> Self {
Self(t)
@@ -410,6 +412,21 @@ pub async fn collect_local_metrics(types: MetricType, opts: &CollectMetricsOpts)
by_host_name = local_node_name;
}
if types.contains(&MetricType::HTTP) {
real_time_metrics.aggregated.http = Some(HttpMetrics {
collected_at: Timestamp::now(),
requests: s3_http_metrics_snapshot()
.into_iter()
.map(|series| HttpRequestMetric {
method: series.method.to_string(),
operation: series.operation.to_string(),
outcome: series.outcome.to_string(),
total: series.total,
})
.collect(),
});
}
if types.contains(&MetricType::DISK) {
debug!("start get disk metrics");
let mut aggr = DiskMetric {
@@ -585,11 +602,47 @@ mod test {
assert!(t.contains(&MetricType::MEM));
assert!(t.contains(&MetricType::CPU));
assert!(t.contains(&MetricType::RPC));
assert!(t.contains(&MetricType::HTTP));
let disk = MetricType::new(1 << 1);
assert!(disk.contains(&MetricType::DISK));
}
#[tokio::test]
async fn collect_local_metrics_reports_the_same_http_outcome_counters() {
let mut request = rustfs_io_metrics::s3_http_metrics::S3HttpRequestGuard::new("PUT");
request.response(503);
drop(request);
let snapshot = s3_http_metrics_snapshot();
let realtime = collect_local_metrics(MetricType::HTTP, &CollectMetricsOpts::default()).await;
let http = realtime.aggregated.http.as_ref().expect("HTTP selection must report support");
assert_eq!(http.requests.len(), snapshot.len());
for (actual, expected) in http.requests.iter().zip(&snapshot) {
assert_eq!(actual.method, expected.method);
assert_eq!(actual.operation, expected.operation);
assert_eq!(actual.outcome, expected.outcome);
assert_eq!(actual.total, expected.total);
}
assert_eq!(realtime.by_host.len(), 1);
assert_eq!(
realtime
.by_host
.values()
.next()
.expect("local host")
.http
.as_ref()
.expect("host HTTP")
.requests,
http.requests
);
let encoded = rmp_serde::to_vec_named(&realtime).expect("RPC metric map");
let decoded: RealtimeMetrics = rmp_serde::from_slice(&encoded).expect("RPC metric roundtrip");
assert_eq!(decoded.aggregated.http.expect("HTTP field survives RPC").requests, http.requests);
let excluded = collect_local_metrics(MetricType::NET, &CollectMetricsOpts::default()).await;
assert!(excluded.aggregated.http.is_none());
}
#[tokio::test]
async fn collect_local_metrics_reports_internode_net_and_rpc() {
let metrics = global_internode_metrics();
+240 -72
View File
@@ -31,7 +31,7 @@ use lazy_static::lazy_static;
use rustfs_madmin::health::{Cpus, MemInfo, OsInfo, Partitions, ProcInfo, SysConfig, SysErrors, SysServices};
use rustfs_madmin::metrics::RealtimeMetrics;
use rustfs_madmin::net::NetInfo;
use rustfs_madmin::{ItemState, ServerProperties, StorageInfo};
use rustfs_madmin::{ItemState, ServerProperties, StorageInfo, StorageInfoObservation, StorageInfoProbeStatus};
use rustfs_utils::XHost;
use sha2::{Digest, Sha256};
use std::collections::{BTreeMap, BTreeSet, HashMap, hash_map::DefaultHasher};
@@ -53,6 +53,7 @@ const LOG_COMPONENT_ECSTORE: &str = "ecstore";
const LOG_SUBSYSTEM_NOTIFICATION: &str = "notification";
const EVENT_NOTIFICATION_PEER_PROPAGATION: &str = "notification_peer_propagation";
const EVENT_NOTIFICATION_CAPABILITY_PROBE: &str = "notification_capability_probe";
const EVENT_STORAGE_INFO_PROBE: &str = "storage_info_probe";
const SCANNER_ACTIVITY_PROBE_TIMEOUT: Duration = Duration::from_secs(5);
const TIER_DAILY_STATS_PROBE_TIMEOUT: Duration = Duration::from_secs(5);
const TIER_CONFIG_RELOAD_RETRY_BASE: Duration = Duration::from_millis(100);
@@ -140,6 +141,8 @@ pub struct ScannerPublicationLeaseGrant {
/// Cached result from the last successful admin call to a peer.
struct PeerAdminCache {
last_storage_info: Option<StorageInfo>,
/// Wall time is for operators; the monotonic clock bounds cache reuse.
last_storage_success: Option<(SystemTime, Instant)>,
last_server_info: Option<ServerProperties>,
storage_failures: u32,
server_failures: u32,
@@ -163,6 +166,7 @@ impl PeerAdminCache {
fn new() -> Self {
Self {
last_storage_info: None,
last_storage_success: None,
last_server_info: None,
storage_failures: 0,
server_failures: 0,
@@ -175,6 +179,9 @@ impl PeerAdminCache {
/// failure: rather than reporting a stale `online`, the member falls through to
/// the live unknown/degraded/offline classification (rustfs/backlog#1049 P2).
const SERVER_INFO_CACHE_MAX_AGE: Duration = Duration::from_secs(60);
// Diagnostic inventory may bridge a short probe interruption, but never more
// than one minute. Failed probes are marked unknown even within this budget.
const STORAGE_INFO_CACHE_MAX_AGE: Duration = Duration::from_secs(60);
lazy_static! {
pub static ref GLOBAL_NOTIFICATION_SYS: OnceLock<Arc<NotificationSys>> = OnceLock::new();
@@ -1906,6 +1913,7 @@ impl NotificationSys {
for (idx, client) in self.peer_clients.iter().enumerate() {
let endpoints = endpoints.clone();
let cache = self.peer_admin_caches.get(idx);
let topology_host = self.peer_topology_hosts.get(idx);
futures.push(async move {
if let Some(client) = client {
let host = client.host.to_string();
@@ -1916,32 +1924,46 @@ impl NotificationSys {
normalize_and_cache_peer_storage_info(cache, &host, &mut info);
Some(info)
}
Ok(Err(err)) => {
warn!("peer {} storage_info failed: {}", host, err);
handle_peer_failure(cache, &host, &endpoints)
}
Err(_) => {
warn!("peer {} storage_info timed out after {:?}", host, peer_timeout);
handle_peer_failure(cache, &host, &endpoints)
}
Ok(Err(err)) => handle_peer_failure(cache, &host, &endpoints, &err),
Err(_) => handle_peer_failure(cache, &host, &endpoints, &Error::Timeout),
}
} else {
None
topology_host.and_then(|host| {
handle_peer_failure(
cache,
host,
&endpoints,
&Error::RemoteClientUnavailable("storage inventory client is unavailable".to_string()),
)
})
}
});
}
let mut replies = join_all(futures).await;
replies.push(Some(StorageAdminApi::local_storage_info(api).await));
let mut local = StorageAdminApi::local_storage_info(api).await;
local.observations = vec![storage_info_observation(
&runtime_sources::local_node_name().await,
StorageInfoProbeStatus::Succeeded,
false,
Some((SystemTime::now(), Instant::now())),
)];
replies.push(Some(local));
let mut disks = Vec::new();
let mut observations = Vec::new();
for info in replies.into_iter().flatten() {
disks.extend(info.disks);
observations.extend(info.observations);
}
let backend = StorageAdminApi::backend_info(api).await;
rustfs_madmin::StorageInfo { disks, backend }
rustfs_madmin::StorageInfo {
disks,
backend,
observations,
}
}
pub async fn server_info(&self) -> Vec<ServerProperties> {
@@ -3339,56 +3361,80 @@ where
}
}
/// Handle a peer failure for storage_info: return cached data if available,
/// or mark offline only after consecutive failures exceed the threshold.
fn storage_info_observation(
host: &str,
status: StorageInfoProbeStatus,
cached: bool,
last_success: Option<(SystemTime, Instant)>,
) -> StorageInfoObservation {
StorageInfoObservation {
endpoint: host.to_string(),
status,
cached,
last_success_unix_millis: last_success
.and_then(|(wall, _)| wall.duration_since(SystemTime::UNIX_EPOCH).ok())
.and_then(|age| u64::try_from(age.as_millis()).ok()),
snapshot_age_seconds: last_success.map(|(_, monotonic)| monotonic.elapsed().as_secs()),
error_code: None,
}
}
/// An admin RPC failure is missing evidence, not evidence of failed drives.
/// Preserve bounded historical inventory without presenting its states as live.
fn handle_peer_failure(
cache: Option<&Mutex<PeerAdminCache>>,
host: &str,
endpoints: &EndpointServerPools,
error: &Error,
) -> Option<StorageInfo> {
let cache = cache?;
let mut c = match cache.lock() {
Ok(cache) => cache,
Err(poisoned) => {
warn!("peer {host} storage_info cache mutex poisoned");
poisoned.into_inner()
}
};
c.storage_failures += 1;
if let Some(ref cached) = c.last_storage_info
&& c.storage_failures < CONSECUTIVE_FAILURE_THRESHOLD
{
debug!(
event = "peer_probe_failure",
peer = host,
probe = "storage_info",
consecutive_failures = c.storage_failures,
threshold = CONSECUTIVE_FAILURE_THRESHOLD,
"peer storage_info probe failed; returning cached state until the offline threshold is reached"
);
return Some(cached.clone());
}
if c.storage_failures >= CONSECUTIVE_FAILURE_THRESHOLD {
if c.storage_failures == CONSECUTIVE_FAILURE_THRESHOLD {
let mut cache = cache.map(|cache| cache.lock().unwrap_or_else(|poisoned| poisoned.into_inner()));
let last_success = cache.as_ref().and_then(|cache| cache.last_storage_success);
let historical = cache
.as_ref()
.filter(|_| last_success.is_some_and(|(_, when)| when.elapsed() < STORAGE_INFO_CACHE_MAX_AGE))
.and_then(|cache| cache.last_storage_info.clone());
let cached = historical.is_some();
let mut info = historical.unwrap_or_else(|| StorageInfo {
disks: synthesized_disks(host, endpoints, ItemState::Unknown),
..Default::default()
});
if let Some(cache) = &mut cache {
cache.storage_failures = cache.storage_failures.saturating_add(1);
if cache.storage_failures == 1 {
warn!(
event = "peer_marked_offline",
event = EVENT_STORAGE_INFO_PROBE,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_NOTIFICATION,
state = "failed",
peer = host,
probe = "storage_info",
consecutive_failures = c.storage_failures,
threshold = CONSECUTIVE_FAILURE_THRESHOLD,
"reporting peer disks offline after consecutive storage_info failures"
error_code = ?error.code(),
cached,
"Storage inventory probe failed; current drive health is unknown"
);
}
return Some(StorageInfo {
disks: synthesized_disks(host, endpoints, ItemState::Offline),
..Default::default()
});
}
None
for disk in &mut info.disks {
disk.state = rustfs_madmin::ITEM_UNKNOWN.to_string();
disk.runtime_state = Some(rustfs_madmin::ITEM_UNKNOWN.to_string());
disk.offline_duration_seconds = None;
disk.capacity_observation_source = Some(if cached { "snapshot" } else { "missing" }.to_string());
disk.capacity_observation_age_seconds = if cached {
disk.capacity_observation_age_seconds
.zip(last_success)
.map(|(age, (_, when))| age.saturating_add(when.elapsed().as_secs()))
} else {
None
};
disk.local = false;
}
info.observations = vec![storage_info_observation(
host,
StorageInfoProbeStatus::Failed,
cached,
last_success,
)];
info.observations[0].error_code = Some(format!("{:?}", error.code()));
Some(info)
}
fn normalize_and_cache_peer_storage_info(cache: Option<&Mutex<PeerAdminCache>>, host: &str, info: &mut StorageInfo) {
@@ -3397,6 +3443,15 @@ fn normalize_and_cache_peer_storage_info(cache: Option<&Mutex<PeerAdminCache>>,
for disk in &mut info.disks {
disk.local = false;
}
let last_success = (SystemTime::now(), Instant::now());
// The aggregator owns probe provenance, including when an older peer
// returns no observation or a peer sends its own observation fields.
info.observations = vec![storage_info_observation(
host,
StorageInfoProbeStatus::Succeeded,
false,
Some(last_success),
)];
let Some(cache) = cache else {
return;
@@ -3409,16 +3464,20 @@ fn normalize_and_cache_peer_storage_info(cache: Option<&Mutex<PeerAdminCache>>,
poisoned.into_inner()
}
};
if c.storage_failures >= CONSECUTIVE_FAILURE_THRESHOLD {
if c.storage_failures > 0 {
info!(
event = "peer_recovered_online",
event = EVENT_STORAGE_INFO_PROBE,
component = LOG_COMPONENT_ECSTORE,
subsystem = LOG_SUBSYSTEM_NOTIFICATION,
state = "succeeded",
peer = host,
probe = "storage_info",
consecutive_failures = c.storage_failures,
"peer storage_info probe succeeded again; peer disks reported online"
"Storage inventory probe recovered"
);
}
c.last_storage_info = Some(info.clone());
c.last_storage_success = Some(last_success);
c.storage_failures = 0;
}
@@ -4892,6 +4951,7 @@ mod tests {
server_failures: 1,
storage_failures: 0,
last_storage_info: None,
last_storage_success: None,
});
let cache_b = Mutex::new(PeerAdminCache {
last_server_info: Some(build_props("cached-b")),
@@ -4899,6 +4959,7 @@ mod tests {
server_failures: 1,
storage_failures: 0,
last_storage_info: None,
last_storage_success: None,
});
let caches = [cache_a, cache_b];
let endpoints = EndpointServerPools::from(Vec::new());
@@ -5297,13 +5358,78 @@ mod tests {
// --- Tests for handle_peer_failure / handle_server_info_failure caching ---
#[tokio::test]
async fn storage_info_preserves_failed_members_when_no_rpc_client_exists() {
#[derive(Debug)]
struct LocalInventory;
#[async_trait::async_trait]
impl StorageAdminApi for LocalInventory {
type BackendInfo = rustfs_madmin::BackendInfo;
type StorageInfo = StorageInfo;
type Disk = ();
type Error = Error;
async fn backend_info(&self) -> Self::BackendInfo {
Self::BackendInfo::default()
}
async fn storage_info(&self) -> StorageInfo {
panic!("aggregation must query local inventory only")
}
async fn local_storage_info(&self) -> StorageInfo {
StorageInfo::default()
}
async fn disk_set_inventory(
&self,
_: crate::storage_api_contracts::admin::DiskSetSelector,
) -> Result<Vec<Option<Self::Disk>>> {
panic!("admin probe must not access the data plane")
}
fn set_drive_counts(&self) -> Vec<usize> {
Vec::new()
}
}
let sys = NotificationSys {
peer_clients: vec![None],
all_peer_clients: vec![None, None],
peer_topology_hosts: vec!["peer-unavailable".to_string()],
peer_admin_caches: vec![Mutex::new(PeerAdminCache::new())],
tier_config_reload_workers: Default::default(),
};
let info = sys.storage_info(&LocalInventory).await;
let peer = info
.observations
.iter()
.find(|observation| observation.endpoint == "peer-unavailable")
.expect("failed topology member remains visible");
assert_eq!(peer.status, StorageInfoProbeStatus::Failed);
assert!(!peer.cached);
assert_eq!(peer.error_code.as_deref(), Some("RemoteClientUnavailable"));
assert!(
info.observations
.iter()
.any(|observation| observation.status == StorageInfoProbeStatus::Succeeded)
);
}
#[test]
fn handle_peer_failure_first_failure_returns_none_when_no_cache() {
fn handle_peer_failure_first_failure_reports_unknown_inventory_without_cache() {
let cache = Mutex::new(PeerAdminCache::new());
let endpoints = EndpointServerPools::default();
let result = handle_peer_failure(Some(&cache), "peer-1", &endpoints);
assert!(result.is_none());
let result = handle_peer_failure(Some(&cache), "peer-1", &endpoints, &Error::Timeout);
let info = result.expect("failed peer must remain visible without cached disks");
assert!(info.disks.is_empty());
assert_eq!(info.observations[0].status, StorageInfoProbeStatus::Failed);
assert!(!info.observations[0].cached);
assert_eq!(info.observations[0].last_success_unix_millis, None);
assert_eq!(info.observations[0].snapshot_age_seconds, None);
assert_eq!(info.observations[0].error_code.as_deref(), Some("Timeout"));
assert_eq!(cache.lock().unwrap().storage_failures, 1);
}
@@ -5320,6 +5446,7 @@ mod tests {
let cache = Mutex::new(PeerAdminCache {
last_storage_info: Some(cached_info),
last_storage_success: Some((SystemTime::now(), Instant::now())),
last_server_info: None,
storage_failures: 0,
server_failures: 0,
@@ -5327,11 +5454,17 @@ mod tests {
});
let endpoints = EndpointServerPools::default();
// First failure: should return cached data
let result = handle_peer_failure(Some(&cache), "peer-1", &endpoints);
// Historical inventory is available, but its health is not live.
let result = handle_peer_failure(Some(&cache), "peer-1", &endpoints, &Error::Timeout);
let info = result.unwrap();
assert_eq!(info.disks.len(), 1);
assert_eq!(info.disks[0].state, "ok");
assert_eq!(info.disks[0].state, "unknown");
assert_eq!(info.disks[0].runtime_state.as_deref(), Some("unknown"));
assert_eq!(info.disks[0].capacity_observation_source.as_deref(), Some("snapshot"));
assert_eq!(info.disks[0].capacity_observation_age_seconds, None);
assert!(info.observations[0].cached);
assert_eq!(info.observations[0].status, StorageInfoProbeStatus::Failed);
assert!(info.observations[0].last_success_unix_millis.is_some());
assert_eq!(cache.lock().unwrap().storage_failures, 1);
}
@@ -5377,13 +5510,13 @@ mod tests {
);
drop(cached);
let degraded = handle_peer_failure(Some(&cache), "peer-1", &EndpointServerPools::default())
let degraded = handle_peer_failure(Some(&cache), "peer-1", &EndpointServerPools::default(), &Error::Timeout)
.expect("first peer failure must return the cached snapshot");
assert!(degraded.disks.iter().all(|disk| !disk.local));
}
#[test]
fn handle_peer_failure_returns_offline_after_threshold_exceeded() {
fn handle_peer_failure_cache_age_does_not_depend_on_poll_count() {
let cached_info = StorageInfo {
disks: vec![rustfs_madmin::Disk {
endpoint: "disk-0".to_string(),
@@ -5395,6 +5528,7 @@ mod tests {
let cache = Mutex::new(PeerAdminCache {
last_storage_info: Some(cached_info),
last_storage_success: Some((SystemTime::now(), Instant::now())),
last_server_info: None,
storage_failures: CONSECUTIVE_FAILURE_THRESHOLD - 1,
server_failures: 0,
@@ -5402,10 +5536,31 @@ mod tests {
});
let endpoints = EndpointServerPools::default();
// This failure pushes us to the threshold => offline
let result = handle_peer_failure(Some(&cache), "peer-1", &endpoints);
assert!(result.is_some());
assert_eq!(cache.lock().unwrap().storage_failures, CONSECUTIVE_FAILURE_THRESHOLD);
for _ in 0..10 {
let info = handle_peer_failure(Some(&cache), "peer-1", &endpoints, &Error::Timeout).expect("failed probe");
assert_eq!(info.disks.len(), 1);
assert_eq!(info.disks[0].state, "unknown");
assert!(info.observations[0].cached);
}
cache.lock().expect("age cache").last_storage_success =
Some((SystemTime::now() - Duration::from_secs(61), Instant::now() - Duration::from_secs(61)));
let info = handle_peer_failure(Some(&cache), "peer-1", &endpoints, &Error::Timeout).expect("expired probe");
assert!(!info.observations[0].cached);
assert!(info.observations[0].snapshot_age_seconds.expect("known last success") >= 61);
assert!(info.disks.is_empty(), "expired inventory must not be reused");
let mut recovered = StorageInfo {
disks: vec![rustfs_madmin::Disk {
state: "ok".into(),
..Default::default()
}],
..Default::default()
};
normalize_and_cache_peer_storage_info(Some(&cache), "peer-1", &mut recovered);
assert_eq!(recovered.disks[0].state, "ok");
assert_eq!(recovered.observations[0].status, StorageInfoProbeStatus::Succeeded);
assert!(!recovered.observations[0].cached);
assert_eq!(cache.lock().expect("recovered cache").storage_failures, 0);
}
#[test]
@@ -5418,6 +5573,7 @@ mod tests {
let cache = Mutex::new(PeerAdminCache {
last_storage_info: None,
last_storage_success: None,
last_server_info: Some(cached_props),
storage_failures: 0,
server_failures: 0,
@@ -5448,6 +5604,7 @@ mod tests {
let cache = Mutex::new(PeerAdminCache {
last_storage_info: None,
last_storage_success: None,
last_server_info: Some(cached_props),
storage_failures: 0,
server_failures: 0,
@@ -5575,6 +5732,7 @@ mod tests {
let cache = Mutex::new(PeerAdminCache {
last_storage_info: None,
last_storage_success: None,
last_server_info: Some(cached_props),
storage_failures: 0,
server_failures: CONSECUTIVE_FAILURE_THRESHOLD - 1,
@@ -5594,6 +5752,7 @@ mod tests {
// the real per-drive health), not offline (rustfs/backlog#1049 P0-B).
let cache = Mutex::new(PeerAdminCache {
last_storage_info: None,
last_storage_success: None,
last_server_info: None,
storage_failures: 0,
server_failures: CONSECUTIVE_FAILURE_THRESHOLD - 1,
@@ -5622,6 +5781,7 @@ mod tests {
// this is a genuine offline, degraded must not mask it.
let cache = Mutex::new(PeerAdminCache {
last_storage_info: None,
last_storage_success: None,
last_server_info: None,
storage_failures: 0,
server_failures: CONSECUTIVE_FAILURE_THRESHOLD - 1,
@@ -5645,6 +5805,7 @@ mod tests {
fn success_resets_failure_counters_independently() {
let cache = Mutex::new(PeerAdminCache {
last_storage_info: None,
last_storage_success: None,
last_server_info: None,
storage_failures: 2,
server_failures: 2,
@@ -5666,6 +5827,7 @@ mod tests {
fn storage_failures_do_not_affect_server_failures() {
let cache = Mutex::new(PeerAdminCache {
last_storage_info: Some(StorageInfo::default()),
last_storage_success: None,
last_server_info: Some(ServerProperties {
endpoint: "peer-1".to_string(),
state: "online".to_string(),
@@ -5677,7 +5839,7 @@ mod tests {
});
let endpoints = EndpointServerPools::default();
let storage_result = handle_peer_failure(Some(&cache), "peer-1", &endpoints);
let storage_result = handle_peer_failure(Some(&cache), "peer-1", &endpoints, &Error::Timeout);
assert!(storage_result.is_some());
let server_result = handle_server_info_failure(Some(&cache), "peer-1", &endpoints, None);
@@ -5700,8 +5862,10 @@ mod tests {
panic!("poison server cache mutex");
});
let storage_result = handle_peer_failure(Some(&storage_cache), "peer-1", &endpoints);
assert!(storage_result.is_none());
let storage_result = handle_peer_failure(Some(&storage_cache), "peer-1", &endpoints, &Error::Timeout);
let storage = storage_result.expect("poisoned cache must still report the failed peer");
assert_eq!(storage.observations[0].status, StorageInfoProbeStatus::Failed);
assert!(!storage.observations[0].cached);
let server_result = handle_server_info_failure(Some(&server_cache), "peer-1", &endpoints, None);
assert_eq!(server_result.endpoint, "peer-1");
@@ -5712,6 +5876,7 @@ mod tests {
fn poisoned_admin_cache_recovers_on_success_and_resets_failures() {
let storage_cache = Mutex::new(PeerAdminCache {
last_storage_info: None,
last_storage_success: None,
last_server_info: None,
storage_failures: CONSECUTIVE_FAILURE_THRESHOLD - 1,
server_failures: 0,
@@ -5719,6 +5884,7 @@ mod tests {
});
let server_cache = Mutex::new(PeerAdminCache {
last_storage_info: None,
last_storage_success: None,
last_server_info: None,
storage_failures: 0,
server_failures: CONSECUTIVE_FAILURE_THRESHOLD - 1,
@@ -5757,9 +5923,11 @@ mod tests {
},
);
let storage_result = handle_peer_failure(Some(&storage_cache), "peer-1", &endpoints);
let storage_result = handle_peer_failure(Some(&storage_cache), "peer-1", &endpoints, &Error::Timeout);
assert!(storage_result.is_some());
assert_eq!(storage_result.unwrap().disks[0].state, "ok");
let storage = storage_result.expect("failed probe after recovery");
assert_eq!(storage.disks[0].state, "unknown");
assert!(storage.observations[0].cached);
let server_result = handle_server_info_failure(Some(&server_cache), "peer-1", &endpoints, None);
assert_eq!(server_result.state, "online");
@@ -300,11 +300,13 @@ pub(super) fn ensure_rebalance_worker_active(meta: Option<&RebalanceMeta>, expec
let Some(meta) = meta else {
return Err(rebalance_metadata_not_initialized_error(stage));
};
if meta.stopped_at.is_some()
|| meta
.cancel
.as_ref()
.is_some_and(tokio_util::sync::CancellationToken::is_cancelled)
if meta.stopped_at.is_some() || meta.stop_requested {
return Err(Error::OperationCanceled);
}
if meta
.cancel
.as_ref()
.is_some_and(tokio_util::sync::CancellationToken::is_cancelled)
|| !is_rebalance_conflicting_with_decommission(meta)
{
return Err(Error::other(format!("inactive rebalance worker rejected during {stage}: {expected_id}")));
@@ -629,6 +631,7 @@ impl ECStore {
if let Some(meta) = rebalance_meta.as_mut()
&& is_rebalance_conflicting_with_decommission(meta)
{
meta.stop_requested = true;
meta.cancel
.get_or_insert_with(tokio_util::sync::CancellationToken::new)
.cancel();
@@ -643,12 +646,13 @@ impl ECStore {
let Some(meta) = rebalance_meta.as_mut() else {
return Ok(None);
};
if !is_rebalance_conflicting_with_decommission(meta) {
if meta.stopped_at.is_some() || (!is_rebalance_conflicting_with_decommission(meta) && !meta.stop_requested) {
return Ok(None);
}
if meta.id.is_empty() {
return Err(Error::other("active rebalance metadata has no activation id"));
}
meta.stop_requested = true;
meta.cancel
.get_or_insert_with(tokio_util::sync::CancellationToken::new)
.cancel();
@@ -673,7 +677,13 @@ impl ECStore {
let movement_changed = rebalance_movement_snapshot_changed(self.rebalance_meta.read().await.as_ref(), &meta);
{
let mut rebalance_meta = self.rebalance_meta.write().await;
if let Some(current) = rebalance_meta.as_ref()
&& current.id == meta.id
{
meta.cancel = current.cancel.clone();
meta.activation_gate = Arc::clone(&current.activation_gate);
meta.stop_requested = current.stop_requested;
}
*rebalance_meta = Some(meta);
drop(rebalance_meta);
@@ -1188,11 +1198,12 @@ impl ECStore {
let meta = rebalance_meta
.as_mut()
.ok_or_else(|| rebalance_metadata_not_initialized_error("cancel rebalance admission"))?;
if meta.stopped_at.is_some() || !is_rebalance_conflicting_with_decommission(meta) {
if meta.stopped_at.is_some() || (!is_rebalance_conflicting_with_decommission(meta) && !meta.stop_requested) {
return Err(Error::other(format!(
"inactive rebalance rejected while cancelling admission: {expected_id}"
)));
}
meta.stop_requested = true;
meta.cancel
.get_or_insert_with(tokio_util::sync::CancellationToken::new)
.cancel();
@@ -1213,6 +1224,7 @@ impl ECStore {
ensure_rebalance_run_id(rebalance_meta.as_ref(), expected_id, "stop rebalance")?;
}
rebalance_meta.as_mut().map(|meta| {
meta.stop_requested |= is_rebalance_conflicting_with_decommission(meta);
let cancel = meta.cancel.get_or_insert_with(tokio_util::sync::CancellationToken::new);
cancel.cancel();
Arc::clone(&meta.activation_gate)
@@ -1377,6 +1389,79 @@ mod tests {
probe.wait_until_attempted().await;
}
#[test]
fn rebalance_stop_classification_checks_identity_and_explicit_intent() {
let mut meta = RebalanceMeta {
id: "current".to_string(),
cancel: Some(tokio_util::sync::CancellationToken::new()),
pool_stats: vec![RebalanceStats {
participating: true,
info: RebalanceInfo {
status: RebalStatus::Started,
..Default::default()
},
..Default::default()
}],
..Default::default()
};
ensure_rebalance_worker_active(Some(&meta), "current", "test").expect("active worker");
meta.cancel.as_ref().unwrap().cancel();
assert!(
!matches!(
ensure_rebalance_worker_active(Some(&meta), "current", "test"),
Err(Error::OperationCanceled)
),
"a sibling failure is not an operator stop"
);
meta.stop_requested = true;
assert!(matches!(
ensure_rebalance_worker_active(Some(&meta), "current", "test"),
Err(Error::OperationCanceled)
));
assert!(
!matches!(ensure_rebalance_worker_active(Some(&meta), "old", "test"), Err(Error::OperationCanceled)),
"stale identity remains a failure even during stop"
);
assert!(!matches!(
ensure_rebalance_worker_active(None, "current", "test"),
Err(Error::OperationCanceled)
));
}
#[tokio::test]
async fn rebalance_stop_intent_does_not_survive_replacement_run_reload() {
let (_temp_dirs, store) = crate::services::rebalance::test_store_with_persisted_rebalance_meta(RebalanceMeta {
id: "replacement".to_string(),
pool_stats: vec![RebalanceStats {
participating: true,
info: RebalanceInfo {
status: RebalStatus::Completed,
..Default::default()
},
..Default::default()
}],
..Default::default()
})
.await;
let previous_gate = {
let mut meta = store.rebalance_meta.write().await;
let meta = meta.as_mut().unwrap();
meta.id = "previous".to_string();
meta.stop_requested = true;
let cancel = tokio_util::sync::CancellationToken::new();
cancel.cancel();
meta.cancel = Some(cancel);
Arc::clone(&meta.activation_gate)
};
store.load_rebalance_meta().await.expect("reload replacement run");
let meta = store.rebalance_meta.read().await;
let meta = meta.as_ref().unwrap();
assert_eq!(meta.id, "replacement");
assert!(!meta.stop_requested);
assert!(meta.cancel.is_none());
assert!(!Arc::ptr_eq(&previous_gate, &meta.activation_gate));
}
#[tokio::test]
async fn cancel_rebalance_admission_is_id_checked_and_idempotent() {
let rebalance_id = "rebalance-admission-current";
@@ -1415,6 +1500,59 @@ mod tests {
.await
.expect("retrying admission cancellation should be idempotent");
assert!(cancel.is_cancelled());
let err = store
.update_pool_stats_batch_for_rebalance(0, "bucket".to_string(), &[&FileInfo::default()], rebalance_id)
.await
.expect_err("stop racing with a final stats update must cancel that update");
assert!(matches!(err, Error::OperationCanceled), "operator stop lost its cancellation type: {err}");
}
#[tokio::test]
async fn prepare_rebalance_stop_preserves_intent_when_worker_stops_before_reload() {
let id = "stop-worker-before-reload";
let cancel = tokio_util::sync::CancellationToken::new();
let (_temp_dirs, store) = crate::services::rebalance::test_store_with_persisted_rebalance_meta(RebalanceMeta {
id: id.to_string(),
cancel: Some(cancel.clone()),
pool_stats: vec![RebalanceStats {
participating: true,
info: RebalanceInfo {
status: RebalStatus::Stopped,
..Default::default()
},
..Default::default()
}],
..Default::default()
})
.await;
let gate = {
let mut meta = store.rebalance_meta.write().await;
let meta = meta.as_mut().expect("local rebalance metadata");
meta.pool_stats[0].info.status = RebalStatus::Started;
Arc::clone(&meta.activation_gate)
};
assert_eq!(
store.prepare_rebalance_stop().await.expect("prepare the same run stop"),
Some(id.to_string())
);
{
let meta = store.rebalance_meta.read().await;
let meta = meta.as_ref().expect("reloaded stop target");
assert!(Arc::ptr_eq(&gate, &meta.activation_gate), "reload must retain the drained run's gate");
assert!(meta.cancel.as_ref().is_some_and(|token| token.is_cancelled()));
}
store
.stop_rebalance_for_id(Some(id))
.await
.expect("finish the stop after the worker's terminal event");
store
.load_rebalance_meta()
.await
.expect("reload the acknowledged durable stop");
let meta = store.rebalance_meta.read().await;
let meta = meta.as_ref().expect("durable stopped metadata");
assert!(meta.stopped_at.is_some(), "a successful stop must retain its durable timestamp");
assert_eq!(meta.pool_stats[0].info.status, RebalStatus::Stopped);
}
#[tokio::test]
@@ -2031,7 +2169,10 @@ mod tests {
let err = acquire_persisted_rebalance_run_guard(set_disks, active.id.as_str(), "cross-node stale snapshot")
.await
.expect_err("persisted stop must fence a node that missed stop propagation");
assert!(err.to_string().contains("inactive rebalance worker rejected"));
assert!(
matches!(err, Error::OperationCanceled),
"a durable remote stop cancels the same run: {err}"
);
}
#[test]
+10 -17
View File
@@ -19,11 +19,11 @@ use super::meta::{
use super::migration::{RebalanceMigrationBackend, migrate_entry_version};
use super::worker::{
RebalanceEntryCleanupResult, RebalanceEntryTask, load_rebalance_bucket_configs, rebalance_max_attempts,
resolve_rebalance_bucket_error, resolve_rebalance_entry_cleanup_delete_result, resolve_rebalance_file_info_versions_result,
resolve_rebalance_migrate_result_error, resolve_rebalance_stats_update_result, resolve_rebalance_worker_result,
run_rebalance_listing_with_retry, should_cleanup_rebalance_source_entry, should_count_rebalance_version_complete,
should_defer_rebalance_entry_failure, should_skip_rebalance_delete_marker, wait_rebalance_entry_tasks,
with_rebalance_entry_context,
record_rebalance_error, resolve_rebalance_bucket_error, resolve_rebalance_entry_cleanup_delete_result,
resolve_rebalance_file_info_versions_result, resolve_rebalance_migrate_result_error, resolve_rebalance_stats_update_result,
resolve_rebalance_worker_result, run_rebalance_listing_with_retry, should_cleanup_rebalance_source_entry,
should_count_rebalance_version_complete, should_defer_rebalance_entry_failure, should_skip_rebalance_delete_marker,
wait_rebalance_entry_tasks, with_rebalance_entry_context,
};
use super::{
EVENT_REBALANCE_BUCKET, EVENT_REBALANCE_ENTRY, EVENT_REBALANCE_STATE, LOG_COMPONENT_ECSTORE, LOG_SUBSYSTEM_REBALANCE,
@@ -676,10 +676,8 @@ impl ECStore {
}
error!("rebalance_entry: data movement admission failed: {err}");
let mut first_err = entry_error.lock().await;
if first_err.is_none() {
*first_err = Some(err);
callback_rx.cancel();
}
record_rebalance_error(&mut first_err, err);
callback_rx.cancel();
return;
}
@@ -721,10 +719,8 @@ impl ECStore {
if let Err(err) = &result {
error!("rebalance_entry: rebalance entry failed: {err}");
let mut first_err = entry_error.lock().await;
if first_err.is_none() {
*first_err = Some(err.clone());
callback_rx.cancel();
}
record_rebalance_error(&mut first_err, err.clone());
callback_rx.cancel();
}
debug!(
event = EVENT_REBALANCE_ENTRY,
@@ -793,10 +789,7 @@ impl ECStore {
deferred_error = Some(last_error);
}
Ok(_) => {}
Err(err) if worker_error.is_none() => {
worker_error = Some(err);
}
Err(_) => {}
Err(err) => record_rebalance_error(&mut worker_error, err),
}
}
let entry_error = entry_error.lock().await.clone();
@@ -643,16 +643,12 @@ pub(super) fn should_skip_start_rebalance(cancel_attached: bool, in_progress: bo
cancel_attached && in_progress
}
pub(super) fn is_rebalance_stopped_terminal_event(terminal_event: &RebalanceTerminalEvent) -> bool {
matches!(terminal_event, RebalanceTerminalEvent::Stopped { .. })
}
pub(super) fn should_preserve_rebalance_stopped_state(
meta_stopped: bool,
status: RebalStatus,
terminal_event: &RebalanceTerminalEvent,
) -> bool {
(meta_stopped || status == RebalStatus::Stopped) && !is_rebalance_stopped_terminal_event(terminal_event)
(meta_stopped || status == RebalStatus::Stopped) && matches!(terminal_event, RebalanceTerminalEvent::Completed { .. })
}
pub(super) fn resolve_rebalance_participants(pool_stats: &[RebalanceStats], pool_count: usize) -> Vec<bool> {
@@ -920,7 +916,7 @@ pub(super) fn clear_rebalance_cancel_token(meta: Option<&mut RebalanceMeta>) ->
pub(super) fn stop_rebalance_state(meta: &mut RebalanceMeta, now: OffsetDateTime) {
clear_rebalance_cancel_token(Some(meta));
if meta.stopped_at.is_none() && is_rebalance_in_progress(meta) {
if meta.stopped_at.is_none() && (meta.stop_requested || is_rebalance_in_progress(meta)) {
apply_stopped_at(meta, now);
} else if meta.stopped_at.is_some() {
mark_started_rebalance_pools_stopping(meta);
@@ -19,14 +19,14 @@ use super::meta::{
complete_rebalance_pools_at_goal, complete_rebalance_pools_with_empty_queue, defer_bucket_in_rebalance_queue,
ensure_rebalance_not_decommissioning, ensure_valid_rebalance_pool_index, first_rebalance_bucket,
has_deferred_rebalance_error, is_rebalance_actively_running, is_rebalance_conflicting_with_decommission,
is_rebalance_in_progress, is_rebalance_meta_replaceable_for_new_id, is_rebalance_stopped_terminal_event,
mark_rebalance_bucket_done, merge_rebalance_bucket_lists, merge_rebalance_meta, next_rebal_bucket_from_stat,
percent_free_ratio, rebalance_goal_reached, rebalance_meta_load_no_data_error, rebalance_meta_load_unknown_format_error,
rebalance_meta_load_unknown_version_error, rebalance_requires_worker_activation, record_rebalance_cleanup_warning_in_meta,
remove_rebalanced_buckets_from_queue, resolve_next_rebalance_bucket, resolve_rebalance_participants,
should_accept_rebalance_stats_update, should_ignore_rebalance_data_usage_cache, should_pool_participate,
should_preserve_rebalance_stopped_state, should_skip_start_rebalance, stop_rebalance_meta_snapshot, stop_rebalance_state,
take_bucket_from_rebalance_queue, validate_init_rebalance_state, validate_start_rebalance_state,
is_rebalance_in_progress, is_rebalance_meta_replaceable_for_new_id, mark_rebalance_bucket_done, merge_rebalance_bucket_lists,
merge_rebalance_meta, next_rebal_bucket_from_stat, percent_free_ratio, rebalance_goal_reached,
rebalance_meta_load_no_data_error, rebalance_meta_load_unknown_format_error, rebalance_meta_load_unknown_version_error,
rebalance_requires_worker_activation, record_rebalance_cleanup_warning_in_meta, remove_rebalanced_buckets_from_queue,
resolve_next_rebalance_bucket, resolve_rebalance_participants, should_accept_rebalance_stats_update,
should_ignore_rebalance_data_usage_cache, should_pool_participate, should_preserve_rebalance_stopped_state,
should_skip_start_rebalance, stop_rebalance_meta_snapshot, stop_rebalance_state, take_bucket_from_rebalance_queue,
validate_init_rebalance_state, validate_start_rebalance_state,
};
use super::migration::{
MigrationBackend, MigrationVersionResult, migrate_entry_version, migrate_entry_version_with_retry_wait,
@@ -1676,6 +1676,30 @@ fn test_resolve_rebalance_stats_update_result_passthrough() {
assert!(resolve_rebalance_stats_update_result(Ok(()), 0, "bucket", "object").is_ok());
}
#[test]
fn test_rebalance_stop_preserves_cancellation_through_entry_context() {
let err = resolve_rebalance_stats_update_result(Err(Error::OperationCanceled), 0, "bucket", "object")
.expect_err("canceled stats update");
let err = with_rebalance_entry_context("stats", "bucket", "object", err);
assert!(matches!(err, Error::OperationCanceled));
assert!(matches!(
classify_rebalance_terminal_event(Some(Err(err)), OffsetDateTime::now_utc()),
RebalanceTerminalEvent::Stopped { .. }
));
}
#[tokio::test]
async fn test_rebalance_stop_does_not_hide_later_entry_failure() {
let tasks = Arc::new(tokio::sync::Mutex::new(vec![
tokio::spawn(async { Err(Error::OperationCanceled) }),
tokio::spawn(async { Err(Error::ErasureWriteQuorum) }),
]));
let err = wait_rebalance_entry_tasks(0, tasks)
.await
.expect_err("entry I/O failure must survive sibling cancellation");
assert!(matches!(err, Error::ErasureWriteQuorum));
}
#[test]
fn test_resolve_rebalance_stats_update_result_wraps_error_context() {
let err = resolve_rebalance_stats_update_result(Err(Error::SlowDown), 2, "bucket-a", "obj.txt")
@@ -2365,9 +2389,9 @@ fn test_resolve_rebalance_terminal_error_wraps_signal_failure_context() {
}
#[test]
fn test_resolve_rebalance_bucket_error_prefers_entry_error() {
fn test_resolve_rebalance_bucket_error_prefers_real_failure_over_entry_cancellation() {
let err = resolve_rebalance_bucket_error(Some(Error::OperationCanceled), Some(Error::SlowDown)).unwrap_err();
assert!(matches!(err, Error::OperationCanceled));
assert!(matches!(err, Error::SlowDown));
}
#[test]
@@ -2512,19 +2536,6 @@ fn test_apply_rebalance_terminal_event_stopped_clears_error() {
assert_eq!(last_error, None);
}
#[test]
fn test_is_rebalance_stopped_terminal_event_only_matches_stopped_variant() {
let stopped = RebalanceTerminalEvent::Stopped {
msg: "stopped".to_string(),
};
let completed = RebalanceTerminalEvent::Completed {
msg: "completed".to_string(),
};
assert!(is_rebalance_stopped_terminal_event(&stopped));
assert!(!is_rebalance_stopped_terminal_event(&completed));
}
#[test]
fn test_should_preserve_rebalance_stopped_state_when_meta_marked_stopped() {
let event = RebalanceTerminalEvent::Completed {
@@ -2535,13 +2546,14 @@ fn test_should_preserve_rebalance_stopped_state_when_meta_marked_stopped() {
}
#[test]
fn test_should_preserve_rebalance_stopped_state_when_pool_already_stopped() {
fn test_rebalance_stop_does_not_hide_real_terminal_failure() {
let event = RebalanceTerminalEvent::Failed {
msg: "failed".to_string(),
last_error: "boom".to_string(),
};
assert!(should_preserve_rebalance_stopped_state(false, RebalStatus::Stopped, &event));
assert!(!should_preserve_rebalance_stopped_state(false, RebalStatus::Stopped, &event));
assert!(!should_preserve_rebalance_stopped_state(true, RebalStatus::Started, &event));
}
#[test]
@@ -2716,6 +2728,32 @@ async fn test_start_rebalance_for_id_rejects_stopped_metadata() {
assert!(err.to_string().contains("was stopped before start"));
}
#[test]
fn test_rebalance_stop_intent_blocks_activation_before_durable_timestamp() {
let mut meta = RebalanceMeta {
id: "stopping".to_string(),
stop_requested: true,
pool_stats: vec![RebalanceStats {
participating: true,
buckets: vec!["pending".to_string()],
info: RebalanceInfo {
status: RebalStatus::Started,
..Default::default()
},
..Default::default()
}],
..Default::default()
};
let outcome = commit_local_rebalance_worker_activation(&mut meta, "stopping", CancellationToken::new())
.expect("stop must prevent activation without a new error");
assert_eq!(outcome, RebalanceLocalActivationOutcome::NotStartedTerminal);
assert!(meta.cancel.is_none());
assert!(meta.stopped_at.is_none());
let bytes = rmp_serde::to_vec_named(&meta).expect("encode legacy-compatible metadata");
let reloaded: RebalanceMeta = rmp_serde::from_slice(&bytes).expect("decode metadata");
assert!(!reloaded.stop_requested, "operator intent is local, not a new persisted field");
}
#[test]
fn test_stopped_activation_state_prevents_worker_token_commit() {
let mut meta = RebalanceMeta {
@@ -57,7 +57,7 @@ pub(super) fn commit_local_rebalance_worker_activation(
meta.id
)));
}
if meta.stopped_at.is_some() || !is_rebalance_in_progress(meta) {
if meta.stopped_at.is_some() || meta.stop_requested || !is_rebalance_in_progress(meta) {
return Ok(RebalanceLocalActivationOutcome::NotStartedTerminal);
}
meta.cancel = Some(cancel);
@@ -143,6 +143,10 @@ pub struct DiskStat {
pub struct RebalanceMeta {
#[serde(skip)]
pub cancel: Option<CancellationToken>, // To be invoked on rebalance-stop
/// Local operator intent, scoped to this run ID; a worker failure also cancels
/// `cancel`, so the token alone cannot identify an administrative stop.
#[serde(skip)]
pub stop_requested: bool,
#[serde(skip)]
pub activation_gate: std::sync::Arc<tokio::sync::RwLock<()>>,
#[serde(skip)]
+22 -14
View File
@@ -38,6 +38,17 @@ pub(super) fn resolve_rebalance_worker_result<T>(
pub(super) type RebalanceEntryTask = tokio::task::JoinHandle<Result<RebalanceEntryOutcome>>;
/// Preserve the first real failure even when another task observes cancellation
/// first. Cancellation is an outcome only when no entry or worker failed.
pub(super) fn record_rebalance_error(first_error: &mut Option<Error>, err: Error) {
if first_error
.as_ref()
.is_none_or(|first| is_err_operation_canceled(first) && !is_err_operation_canceled(&err))
{
*first_error = Some(err);
}
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub(super) enum RebalanceEntryCleanupResult {
Completed { warning: Option<String> },
@@ -65,16 +76,12 @@ pub(super) async fn wait_rebalance_entry_tasks(
}
Ok(Err(err)) => {
error!("rebalance entry task failed for set {}: {}", set_idx, err);
if first_error.is_none() {
first_error = Some(err);
}
record_rebalance_error(&mut first_error, err);
}
Err(err) => {
let err = Error::other(format!("rebalance entry task join error for set {set_idx}: {err}"));
error!("{}", err);
if first_error.is_none() {
first_error = Some(err);
}
record_rebalance_error(&mut first_error, err);
}
}
}
@@ -135,6 +142,9 @@ pub(super) fn resolve_rebalance_stats_update_result(
object_name: &str,
) -> Result<()> {
result.map_err(|err| {
if is_err_operation_canceled(&err) {
return err;
}
Error::other(format!(
"rebalance stats update failed for pool {pool_idx} bucket {bucket} object {object_name}: {err}"
))
@@ -214,16 +224,11 @@ pub(super) fn resolve_rebalance_terminal_error(primary_err: Error, signal_result
}
}
pub(super) fn resolve_rebalance_bucket_error(entry_error: Option<Error>, worker_error: Option<Error>) -> Result<()> {
if let Some(err) = entry_error {
return Err(err);
}
pub(super) fn resolve_rebalance_bucket_error(mut entry_error: Option<Error>, worker_error: Option<Error>) -> Result<()> {
if let Some(err) = worker_error {
return Err(err);
record_rebalance_error(&mut entry_error, err);
}
Ok(())
entry_error.map_or(Ok(()), Err)
}
pub(super) fn resolve_rebalance_bucket_result(
@@ -362,6 +367,9 @@ pub(super) fn ensure_rebalance_listing_disks_available(has_disks: bool, bucket:
}
pub(super) fn with_rebalance_entry_context(stage: &str, bucket: &str, object_name: &str, err: Error) -> Error {
if is_err_operation_canceled(&err) {
return err;
}
Error::other(format!("rebalance entry {stage} failed for {bucket}/{object_name}: {err}"))
}
+1
View File
@@ -6650,6 +6650,7 @@ async fn get_storage_info(disks: &[Option<DiskStore>], eps: &[Endpoint]) -> rust
total_sets,
..Default::default()
},
..Default::default()
}
}
pub async fn stat_all_dirs(disks: &[Option<DiskStore>], bucket: &str, prefix: &str) -> Vec<Option<DiskError>> {
+15 -4
View File
@@ -2353,11 +2353,22 @@ mod tests {
.await
.expect("quorum boundary heal should return a mapped result");
*store.pools[0].disk_set[0].disks.write().await = original_quorum_disks;
let quorum_err = quorum_err
.as_ref()
.expect("heal must fail closed when capacity admission cannot verify pool metadata");
let quorum_failure = quorum_err
.pool_metadata_failure()
.expect("capacity admission failure should preserve typed pool metadata context");
assert_eq!(
quorum_failure.kind,
crate::error::PoolMetadataFailure::ReadUnavailable,
"read-only capacity admission failure must remain retryable"
);
assert_eq!(quorum_failure.operation, "target capacity admission failed");
assert_eq!(quorum_failure.phase, "pool_read");
assert!(
quorum_err.as_ref().is_some_and(|err| err
.to_string()
.contains("pool metadata writes remain blocked after a recovery-required replica state")),
"heal must fail closed when capacity admission cannot verify pool metadata, got {quorum_err:?}"
store.pool_meta_writes_ready().await,
"read-only capacity admission failure must not latch the pool metadata writer"
);
shutdown.cancel();
}
+162 -8
View File
@@ -14,8 +14,8 @@
use super::*;
use crate::core::pools::{
PoolMetaBootstrapAuthority, PoolMetaReplicaState, PoolMetaWriteState, load_pool_meta_identity_observing,
local_decommission_queue_prefix, persist_pool_meta_identity_for_startup, pool_meta_has_active_decommission,
PoolMetaBootstrapAuthority, PoolMetaReplicaState, PoolMetaWriteState, local_decommission_queue_prefix,
persist_pool_meta_identity_for_startup, pool_meta_has_active_decommission,
};
use crate::runtime::instance::InstanceContext;
use crate::runtime::sources as runtime_sources;
@@ -103,7 +103,10 @@ const REBALANCE_INITIAL_RESUME_DELAY: Duration = Duration::from_secs(10);
const REBALANCE_RESUME_RETRY_DELAY: Duration = Duration::from_secs(10);
fn should_retry_format_load(err: &Error) -> bool {
!matches!(err, Error::CorruptedFormat)
!matches!(
err,
Error::CorruptedFormat | Error::UnsupportedSnsdExpansion { .. } | Error::PoolTopologyMismatch { .. }
)
}
fn should_auto_start_rebalance_after_init(decommission_running: bool, rebalance_resume_required: bool) -> bool {
@@ -150,14 +153,11 @@ async fn load_pool_meta_for_startup<S>(
where
S: EcstoreObjectIO,
{
load_pool_meta_identity_observing(pools.clone(), write_state)
.await
.map_err(|err| Error::other(format!("store init failed during load_pool_meta_identity: {err}")))?;
let mut meta = PoolMeta::default();
let replica_state = meta
.load_no_lock_from_replicas_observing(pools, write_state)
.load_for_startup_observing(pools, write_state)
.await
.map_err(|err| Error::other(format!("store init failed during load_pool_meta: {err}")))?;
.map_err(|err| Error::other_with_context("store init failed during load_pool_meta", err))?;
write_state.observe_replicas(replica_state);
write_state
.ensure_missing_metadata_can_initialize()
@@ -766,6 +766,33 @@ impl ECStore {
});
}
let recovery_store = self.clone();
let recovery_rx = rx.clone();
tokio::spawn(async move {
let mut delay = std::time::Duration::from_secs(5);
loop {
tokio::select! {
_ = recovery_rx.cancelled() => return,
_ = tokio::time::sleep(delay) => {}
}
let result = tokio::select! {
_ = recovery_rx.cancelled() => return,
result = tokio::time::timeout(std::time::Duration::from_secs(30), recovery_store.recover_pool_meta_transaction()) => result,
};
delay = match result {
Ok(Ok(_)) => std::time::Duration::from_secs(5),
failure => {
let error = match failure {
Ok(Err(error)) => error,
_ => Error::Timeout,
};
recovery_store.record_pool_meta_recovery_failure(error);
(delay * 2).min(std::time::Duration::from_secs(60))
}
};
}
});
runtime_sources::init_bucket_monitor_for_current_endpoints();
crate::bucket::bucket_target_sys::BucketTargetSys::get().start_heartbeat();
@@ -1784,6 +1811,33 @@ mod tests {
assert!(should_retry_format_load(&StorageError::FirstDiskWait));
}
#[test]
fn test_should_retry_format_load_rejects_permanent_topology_errors() {
for error in [
StorageError::UnsupportedSnsdExpansion { configured_drives: 4 },
StorageError::PoolTopologyMismatch {
stored_drives: 4,
stored_set_drive_count: 4,
configured_drives: 8,
configured_set_drive_count: 8,
},
] {
assert!(!should_retry_format_load(&error), "topology errors require operator action: {error}");
}
for error in [
StorageError::DiskNotFound,
StorageError::Timeout,
StorageError::RemoteNotInitialized,
StorageError::NotFirstDisk,
StorageError::other(std::io::Error::from(std::io::ErrorKind::ConnectionRefused)),
] {
assert!(
should_retry_format_load(&error),
"transient failures retain their existing retry path: {error}"
);
}
}
#[test]
fn test_should_auto_start_rebalance_after_init_allows_active_rebalance_without_decommission() {
assert!(should_auto_start_rebalance_after_init(false, true));
@@ -2463,6 +2517,106 @@ mod tests {
shutdown.cancel();
}
#[tokio::test]
#[serial_test::serial(storage_class_env)]
async fn pool_metadata_preflight_recovery_preserves_single_and_multi_pool_public_mutations() {
for layout in [vec![4], vec![4, 4]] {
let temp_dir = tempfile::tempdir().unwrap();
let (_ctx, store, shutdown) =
without_storage_class_env(build_isolated_test_store(temp_dir.path(), "pool-meta-retry", &layout)).await;
crate::bucket::metadata_sys::init_bucket_metadata_sys(Arc::clone(&store), Vec::new()).await;
let bucket = format!("pool-meta-retry-{}", Uuid::new_v4());
store.make_bucket(&bucket, &MakeBucketOptions::default()).await.unwrap();
let mut saved_disks = Vec::new();
for set in &store.pools[0].disk_set {
let mut disks = set.disks.write().await;
let count = disks.len();
saved_disks.push((set.clone(), std::mem::replace(&mut *disks, vec![None; count])));
}
let indices = (0..layout.len()).collect::<Vec<_>>();
let err = store.save_current_pool_meta_for_test(&indices).await.unwrap_err();
assert_eq!(
err.pool_metadata_failure().unwrap().kind,
crate::error::PoolMetadataFailure::ReadUnavailable
);
for (set, disks) in saved_disks {
*set.disks.write().await = disks;
}
store.save_current_pool_meta_for_test(&indices).await.unwrap();
assert!(store.pool_meta_writes_ready().await);
let payload = b"pool metadata recovery payload".to_vec();
store
.put_object(&bucket, "put", &mut PutObjReader::from_vec(payload.clone()), &ObjectOptions::default())
.await
.unwrap();
let mut reader = store
.get_object_reader(&bucket, "put", None, HeaderMap::new(), &ObjectOptions::default())
.await
.unwrap();
let mut actual = Vec::new();
reader.stream.read_to_end(&mut actual).await.unwrap();
assert_eq!(actual, payload);
drop(reader);
store.delete_object(&bucket, "put", ObjectOptions::default()).await.unwrap();
assert!(crate::error::is_err_object_not_found(
&store
.get_object_info(&bucket, "put", &ObjectOptions::default())
.await
.unwrap_err()
));
let upload = store
.new_multipart_upload(&bucket, "multipart", &ObjectOptions::default())
.await
.unwrap();
let part = store
.put_object_part(
&bucket,
"multipart",
&upload.upload_id,
1,
&mut PutObjReader::from_vec(payload.clone()),
&ObjectOptions::default(),
)
.await
.unwrap();
store
.clone()
.complete_multipart_upload(
&bucket,
"multipart",
&upload.upload_id,
vec![crate::storage_api_contracts::multipart::CompletePart {
part_num: part.part_num,
etag: part.etag,
..Default::default()
}],
&ObjectOptions::default(),
)
.await
.unwrap();
let mut reader = store
.get_object_reader(&bucket, "multipart", None, HeaderMap::new(), &ObjectOptions::default())
.await
.unwrap();
actual.clear();
reader.stream.read_to_end(&mut actual).await.unwrap();
assert_eq!(actual, payload);
drop(reader);
let upload = store
.new_multipart_upload(&bucket, "abort", &ObjectOptions::default())
.await
.unwrap();
store
.abort_multipart_upload(&bucket, "abort", &upload.upload_id, &ObjectOptions::default())
.await
.unwrap();
assert!(store.pool_meta_writes_ready().await);
shutdown.cancel();
}
}
#[cfg(feature = "test-util")]
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
#[serial_test::serial(storage_class_env)]
+253 -10
View File
@@ -109,6 +109,21 @@ pub(crate) async fn connect_load_init_formats_with_instance_ctx(
let fresh_bootstrap_proven = should_init_erasure_disks(&errs);
let formats_present = formats.iter().flatten().count();
let mut format_quorum = (formats_present > 0).then(|| select_format_erasure_in_quorum(&formats, 0));
// A resized pool may never reach quorum under its new endpoint count.
// Diagnose a valid, unambiguous stored layout before migration or waiting.
// A healthy quorum still takes precedence over foreign minority formats;
// conflicting or malformed observations retain their existing error path.
if format_quorum.as_ref().is_some_and(Result::is_err)
&& let Some(reference) = formats.iter().flatten().next()
&& formats.iter().flatten().all(|format| {
format.shared_identity() == reference.shared_identity()
&& reference.erasure.sets.iter().flatten().any(|id| *id == format.erasure.this)
})
&& let Err(err @ (Error::UnsupportedSnsdExpansion { .. } | Error::PoolTopologyMismatch { .. })) =
check_format_erasure_value_for_topology(reference, formats.len(), set_drive_count)
{
return Err(err);
}
if format_quorum.as_ref().is_none_or(Result::is_err)
&& errs.iter().any(|error| {
matches!(
@@ -661,15 +676,18 @@ fn check_format_erasure_value_for_topology(format: &FormatV3, format_count: usiz
.len()
.checked_mul(set_drive_count_in_format)
.ok_or_else(|| Error::other("erasure set drive count overflow"))?;
if format_count != format_drive_count {
return Err(Error::other(format!(
"formats length for erasure.sets does not match: got {format_count}, expected {format_drive_count}"
)));
if format_drive_count == 1 && format_count > 1 {
return Err(Error::UnsupportedSnsdExpansion {
configured_drives: format_count,
});
}
if set_drive_count_in_format != set_drive_count {
return Err(Error::other(format!(
"erasure set length for set_drive_count does not match: got {set_drive_count_in_format}, expected {set_drive_count}"
)));
if format_count != format_drive_count || set_drive_count_in_format != set_drive_count {
return Err(Error::PoolTopologyMismatch {
stored_drives: format_drive_count,
stored_set_drive_count: set_drive_count_in_format,
configured_drives: format_count,
configured_set_drive_count: set_drive_count,
});
}
Ok(())
}
@@ -877,6 +895,10 @@ mod tests {
use serial_test::serial;
async fn local_disks(count: usize) -> (tempfile::TempDir, Vec<Option<DiskStore>>) {
local_disks_with_set_width(count, count).await
}
async fn local_disks_with_set_width(count: usize, set_width: usize) -> (tempfile::TempDir, Vec<Option<DiskStore>>) {
let temp_dir = tempfile::tempdir().expect("temporary disk root should be created");
let mut endpoints = Vec::with_capacity(count);
for disk_index in 0..count {
@@ -887,8 +909,8 @@ mod tests {
let mut endpoint =
Endpoint::try_from(path.to_str().expect("temporary disk path should be UTF-8")).expect("endpoint should parse");
endpoint.set_pool_index(0);
endpoint.set_set_index(0);
endpoint.set_disk_index(disk_index);
endpoint.set_set_index(disk_index / set_width);
endpoint.set_disk_index(disk_index % set_width);
endpoints.push(endpoint);
}
@@ -912,6 +934,21 @@ mod tests {
(temp_dir, disks)
}
async fn format_bytes(disks: &[Option<DiskStore>]) -> Vec<Option<Vec<u8>>> {
let mut snapshots = Vec::with_capacity(disks.len());
for disk in disks {
let disk = disk.as_ref().expect("snapshot disk should exist");
// Inspect bytes even when the disk wrapper rejects a format whose
// stored slot differs from the attempted new endpoint geometry.
match tokio::fs::read(disk.path().join(RUSTFS_META_BUCKET).join(FORMAT_CONFIG_FILE)).await {
Ok(data) => snapshots.push(Some(data)),
Err(err) if err.kind() == std::io::ErrorKind::NotFound => snapshots.push(None),
Err(err) => panic!("format snapshot failed: {err}"),
}
}
snapshots
}
async fn write_legacy_format(disk: &Option<DiskStore>, format: &FormatV3) {
write_legacy_bytes(disk, bytes::Bytes::from(format.to_json().expect("legacy format should serialize"))).await;
}
@@ -1116,6 +1153,212 @@ mod tests {
);
}
#[tokio::test]
async fn single_drive_format_rejects_in_place_expansion_without_writes() {
for configured_drives in [2, 4] {
for first_disk in [false, true] {
let (_temp_dir, mut disks) = local_disks(configured_drives).await;
let mut original = FormatV3::new(1, 1);
original.erasure.this = original.erasure.sets[0][0];
save_format_file(&disks[0], &Some(original))
.await
.expect("SNSD format should be written");
let before = format_bytes(&disks).await;
let err = connect_load_init_formats(first_disk, &mut disks, 1, configured_drives, None)
.await
.expect_err("an existing SNSD deployment cannot expand in place");
let message = err.to_string();
assert!(message.contains("SNSD"), "expected a single-drive expansion error: {message}");
assert!(message.contains("migrate data through S3"), "expected actionable guidance: {message}");
assert_eq!(format_bytes(&disks).await, before, "neither old nor new formats may be written");
}
}
}
#[tokio::test]
async fn existing_pool_rejects_drive_count_or_set_width_changes_without_writes() {
for (stored_sets, stored_width, configured_sets, configured_width) in
[(1, 4, 1, 6), (1, 4, 1, 8), (1, 4, 1, 2), (1, 4, 2, 2), (2, 2, 1, 4)]
{
for first_disk in [false, true] {
let (_temp_dir, mut disks) =
local_disks_with_set_width(configured_sets * configured_width, configured_width).await;
let original = FormatV3::new(stored_sets, stored_width);
for (disk, disk_id) in disks.iter().zip(original.erasure.sets.iter().flatten()) {
let mut format = original.clone();
format.erasure.this = *disk_id;
save_format_file(disk, &Some(format))
.await
.expect("existing format should be written");
}
let before = format_bytes(&disks).await;
let err = connect_load_init_formats(first_disk, &mut disks, configured_sets, configured_width, None)
.await
.expect_err("an existing pool's geometry is immutable");
let message = err.to_string();
assert!(message.contains("pool topology mismatch"), "expected a topology error: {message}");
assert!(
message.contains(&format!("stored 4 drives with {stored_width} drives per erasure set")),
"expected stored geometry: {message}"
);
assert!(message.contains("append a new pool"), "expected expansion guidance: {message}");
assert_eq!(format_bytes(&disks).await, before, "rejection must not rewrite any format");
}
}
}
#[tokio::test]
async fn subquorum_existing_layout_with_missing_drives_is_not_expansion() {
let (_temp_dir, mut disks) = local_disks(1).await;
let mut original = FormatV3::new(1, 4);
original.erasure.this = original.erasure.sets[0][0];
save_format_file(&disks[0], &Some(original))
.await
.expect("existing format should be written");
disks.extend([None, None, None]);
for first_disk in [false, true] {
assert!(matches!(
connect_load_init_formats(first_disk, &mut disks, 1, 4, None).await,
Err(Error::ErasureReadQuorum)
));
}
}
#[tokio::test]
async fn conflicting_layouts_without_quorum_are_not_expansion_proof() {
let (_temp_dir, mut disks) = local_disks(2).await;
for (index, (disk, width)) in disks.iter().zip([4, 2]).enumerate() {
let mut format = FormatV3::new(1, width);
format.erasure.this = format.erasure.sets[0][index];
save_format_file(disk, &Some(format))
.await
.expect("existing format should be written");
}
disks.extend([None, None]);
let result = connect_load_init_formats(true, &mut disks, 1, 4, None).await;
assert!(matches!(result, Err(Error::ErasureReadQuorum)), "conflicting layout result: {result:?}");
}
#[tokio::test]
async fn existing_format_quorum_ignores_single_drive_outlier() {
let (_temp_dir, mut disks) = local_disks(3).await;
let majority = FormatV3::new(1, 3);
for (index, disk) in disks.iter().enumerate() {
// Slot zero lets the SNSD outlier pass the disk wrapper's own
// slot check, so quorum selection must exclude the parsed format.
let mut format = if index == 0 { FormatV3::new(1, 1) } else { majority.clone() };
format.erasure.this = format.erasure.sets[0][index];
save_format_file(disk, &Some(format))
.await
.expect("existing format should be written");
}
let loaded = connect_load_init_formats(true, &mut disks, 1, 3, None)
.await
.expect("a foreign SNSD outlier must not block a healthy majority");
assert_eq!(loaded.shared_identity(), majority.shared_identity());
assert!(disks[0].is_none(), "the foreign single-drive format must be quarantined");
}
#[tokio::test]
async fn multi_drive_pool_expansion_preserves_existing_format() {
let (_original_dir, mut disks) = local_disks(4).await;
let (_new_dir, mut new_disks) = local_disks(4).await;
let original = connect_load_init_formats(true, &mut disks, 1, 4, None)
.await
.expect("original multi-drive pool should initialize");
let before = format_bytes(&disks).await;
let added = connect_load_init_formats(true, &mut new_disks, 1, 4, Some(original.id))
.await
.expect("a new multi-drive pool should initialize with the existing deployment ID");
assert_eq!(added.id, original.id);
assert_ne!(added.erasure.sets, original.erasure.sets);
assert_eq!(format_bytes(&disks).await, before);
assert_eq!(
connect_load_init_formats(true, &mut disks, 1, 4, Some(original.id))
.await
.expect("the original pool should restart with unchanged geometry"),
original
);
assert_eq!(
connect_load_init_formats(true, &mut new_disks, 1, 4, Some(original.id))
.await
.expect("the new pool should restart with its own format"),
added
);
}
#[tokio::test]
async fn store_startup_rejects_pool_resize_before_retry_loop() {
use crate::layout::endpoints::{EndpointServerPools, PoolEndpoints};
use tokio_util::sync::CancellationToken;
for (stored_width, configured_width) in [(1, 4), (4, 8)] {
let (_temp_dir, disks) = local_disks(configured_width).await;
let original = FormatV3::new(1, stored_width);
for (disk, disk_id) in disks.iter().zip(&original.erasure.sets[0]) {
let mut format = original.clone();
format.erasure.this = *disk_id;
save_format_file(disk, &Some(format))
.await
.expect("old format should be written");
}
let before = format_bytes(&disks).await;
let endpoints = disks.iter().flatten().map(|disk| disk.endpoint()).collect::<Vec<_>>();
let pools = EndpointServerPools::from(vec![PoolEndpoints {
legacy: true,
set_count: 1,
drives_per_set: configured_width,
endpoints: Endpoints::from(endpoints),
cmd_line: "test-pool".to_string(),
platform: String::new(),
}]);
let shutdown = CancellationToken::new();
let result = temp_env::async_with_vars(
[
(storageclass::STANDARD_ENV, None::<&str>),
(storageclass::RRS_ENV, None::<&str>),
(storageclass::OPTIMIZE_ENV, None::<&str>),
(storageclass::INLINE_BLOCK_ENV, None::<&str>),
],
tokio::time::timeout(
std::time::Duration::from_secs(5),
crate::store::ECStore::new_with_instance_ctx(
"127.0.0.1:0".parse().expect("test address"),
pools,
shutdown.clone(),
Arc::new(InstanceContext::new()),
),
),
)
.await;
shutdown.cancel();
let err = result
.expect("invalid topology must abort without the format retry backoff")
.expect_err("resize must fail");
match stored_width {
1 => assert!(matches!(err, Error::UnsupportedSnsdExpansion { configured_drives: 4 }), "{err}"),
_ => assert!(
matches!(
err,
Error::PoolTopologyMismatch {
stored_drives: 4,
configured_drives: 8,
..
}
),
"{err}"
),
}
assert_eq!(format_bytes(&disks).await, before, "failed store startup must not write formats");
}
}
#[tokio::test]
async fn existing_format_load_rejects_conflicting_formats_without_a_majority() {
let (_temp_dir, mut disks) = two_local_disks_with_missing_third().await;
+25
View File
@@ -527,6 +527,31 @@ impl Default for ScannerDataMovementPauseStatus {
}
}
#[derive(Clone, Debug, PartialEq, Eq, serde::Serialize)]
pub struct PoolMetaWriteGateStatus {
pub writes_ready: bool,
pub write_blocked: bool,
pub transaction_aborted: bool,
pub pool_meta_absent: bool,
pub identity_initialized: Option<bool>,
pub identity_needs_repair: bool,
pub cluster_epoch: Option<u64>,
}
impl Default for PoolMetaWriteGateStatus {
fn default() -> Self {
Self {
writes_ready: true,
write_blocked: false,
transaction_aborted: false,
pool_meta_absent: false,
identity_initialized: None,
identity_needs_repair: false,
cluster_epoch: None,
}
}
}
fn offset_unix_seconds(value: OffsetDateTime) -> u64 {
u64::try_from(value.unix_timestamp()).unwrap_or(0)
}
+8 -8
View File
@@ -526,12 +526,8 @@ impl ECStore {
if self.single_pool() {
self.apply_decommission_target_mutation_fence(0, object, &mut opts, mutation_fence)
.await;
return self
.run_decommission_capacity_admitted_mutation(0, None, None, || async {
self.pools[0].new_multipart_upload(bucket, object, &opts).await
})
.await
.map(|res| (res, 0, opts.expected_bucket_incarnation_id));
let result = self.pools[0].new_multipart_upload(bucket, object, &opts).await?;
return Ok((result, 0, opts.expected_bucket_incarnation_id));
}
if opts.data_movement && opts.version_id.is_some() {
@@ -658,7 +654,9 @@ impl ECStore {
) -> Result<PartInfo> {
check_put_object_part_args(bucket, object, upload_id)?;
let (mut opts, _bucket_lifecycle_guard) = self.guard_multipart_bucket_incarnation(bucket, opts).await?;
opts.decommission_capacity_admission = crate::bucket::metadata_sys::object_store_if_initialized_in(&self.ctx).await;
if !self.single_pool() {
opts.decommission_capacity_admission = crate::bucket::metadata_sys::object_store_if_initialized_in(&self.ctx).await;
}
let opts = &opts;
if self.single_pool() {
@@ -982,7 +980,9 @@ impl ECStore {
) -> Result<ObjectInfo> {
check_complete_multipart_args(bucket, object, upload_id)?;
let (mut opts, _bucket_lifecycle_guard) = self.guard_multipart_bucket_incarnation(bucket, opts).await?;
opts.decommission_capacity_admission = crate::bucket::metadata_sys::object_store_if_initialized_in(&self.ctx).await;
if !self.single_pool() {
opts.decommission_capacity_admission = crate::bucket::metadata_sys::object_store_if_initialized_in(&self.ctx).await;
}
let opts = &opts;
if self.single_pool() {
+42 -8
View File
@@ -3123,6 +3123,9 @@ impl ECStore {
Fut: std::future::Future<Output = Result<T>>,
{
let (lock_object, target_object) = objects;
if self.single_pool() {
return operation(opts).await;
}
let (capacity_guard, has_active_decommission) = if capacity_releasing {
self.acquire_decommission_capacity_release_fence_with_active_source().await?
} else {
@@ -3220,6 +3223,9 @@ impl ECStore {
F: FnOnce(HealOpts) -> Fut,
Fut: std::future::Future<Output = Result<T>>,
{
if self.single_pool() {
return operation(opts).await;
}
let (capacity_guard, has_active_decommission) = self
.acquire_external_decommission_capacity_fence_with_active_source(&[target_pool_idx], "heal")
.await?;
@@ -4162,7 +4168,9 @@ impl ECStore {
.select_put_object_pool_idx(bucket, object.as_str(), data.size(), &opts)
.await?;
let mut opts = opts;
opts.decommission_capacity_admission = crate::bucket::metadata_sys::object_store_if_initialized_in(&self.ctx).await;
if !self.single_pool() {
opts.decommission_capacity_admission = crate::bucket::metadata_sys::object_store_if_initialized_in(&self.ctx).await;
}
self.pools[idx]
.put_object_with_old_current_size(bucket, object.as_str(), data, &opts)
.await
@@ -4170,6 +4178,24 @@ impl ECStore {
#[instrument(level = "trace", skip(self))]
pub(super) async fn handle_get_object_info(&self, bucket: &str, object: &str, opts: &ObjectOptions) -> Result<ObjectInfo> {
self.get_object_info_snapshot(bucket, object, opts, false).await
}
/// Return metadata for DELETE preflight, including an explicitly addressed
/// delete marker. Read APIs must keep using `get_object_info`; authorization
/// and Object Lock enforcement still belong to the caller and locked delete.
#[instrument(level = "trace", skip_all)]
pub async fn get_object_info_for_delete(&self, bucket: &str, object: &str, opts: &ObjectOptions) -> Result<ObjectInfo> {
self.get_object_info_snapshot(bucket, object, opts, true).await
}
async fn get_object_info_snapshot(
&self,
bucket: &str,
object: &str,
opts: &ObjectOptions,
allow_delete_marker: bool,
) -> Result<ObjectInfo> {
check_object_args(bucket, object)?;
let object = encode_dir_object(object);
@@ -4180,6 +4206,8 @@ impl ECStore {
let info = if self.single_pool() {
self.pools[0].get_object_info(bucket, object.as_str(), &opts).await?
} else if allow_delete_marker {
self.get_latest_object_info_with_idx(bucket, object.as_str(), &opts).await?.0
} else {
self.get_latest_accessible_object_info_with_idx(bucket, object.as_str(), &opts)
.await?
@@ -4340,8 +4368,10 @@ impl ECStore {
object_lock_config_snapshot: dst_opts.object_lock_config_snapshot.clone(),
..Default::default()
};
put_opts.decommission_capacity_admission =
crate::bucket::metadata_sys::object_store_if_initialized_in(&self.ctx).await;
if !self.single_pool() {
put_opts.decommission_capacity_admission =
crate::bucket::metadata_sys::object_store_if_initialized_in(&self.ctx).await;
}
return if let Some(reader) = src_info.put_object_reader.as_mut() {
self.pools[pool_idx]
.put_object(dst_bucket, &dst_object, reader, &put_opts)
@@ -4376,8 +4406,10 @@ impl ECStore {
object_lock_config_snapshot: dst_opts.object_lock_config_snapshot.clone(),
..Default::default()
};
put_opts.decommission_capacity_admission =
crate::bucket::metadata_sys::object_store_if_initialized_in(&self.ctx).await;
if !self.single_pool() {
put_opts.decommission_capacity_admission =
crate::bucket::metadata_sys::object_store_if_initialized_in(&self.ctx).await;
}
return self.pools[pool_idx]
.put_object(dst_bucket, &dst_object, reader, &put_opts)
.await;
@@ -4422,7 +4454,10 @@ impl ECStore {
object_lock_config_snapshot: dst_opts.object_lock_config_snapshot.clone(),
..Default::default()
};
put_opts.decommission_capacity_admission = crate::bucket::metadata_sys::object_store_if_initialized_in(&self.ctx).await;
if !self.single_pool() {
put_opts.decommission_capacity_admission =
crate::bucket::metadata_sys::object_store_if_initialized_in(&self.ctx).await;
}
if let Some(put_object_reader) = src_info.put_object_reader.as_mut() {
return self.pools[pool_idx]
@@ -5057,7 +5092,7 @@ impl ECStore {
}
}
let _capacity_fence = if latest_marker_objects.iter().any(|creates_marker| *creates_marker) {
let _capacity_fence = if !self.single_pool() && latest_marker_objects.iter().any(|creates_marker| *creates_marker) {
let target_pool_indices = (0..self.pools.len()).collect::<Vec<_>>();
match self
.acquire_external_decommission_capacity_fence(&target_pool_indices, "batch_delete")
@@ -5375,7 +5410,6 @@ impl ECStore {
// self-deadlocked on the inner commits.
let object_name = object.as_str();
if self.single_pool() {
opts.decommission_capacity_admission = Some(Arc::clone(&self));
return self.pools[0]
.clone()
.restore_transitioned_object(bucket, object_name, &opts)
+5 -1
View File
@@ -1146,7 +1146,11 @@ impl ECStore {
}
let backend = StorageAdminApi::backend_info(self).await;
rustfs_madmin::StorageInfo { backend, disks }
rustfs_madmin::StorageInfo {
backend,
disks,
..Default::default()
}
}
#[instrument(skip(self))]
+5
View File
@@ -37,6 +37,9 @@ pub enum Error {
#[error("Method not allowed")]
MethodNotAllowed,
#[error("You've exceeded the limit on the number of versions you can create on this object")]
MaxVersionsExceeded,
#[error("Unexpected error")]
Unexpected,
@@ -86,6 +89,7 @@ impl PartialEq for Error {
(Error::FileCorrupt, Error::FileCorrupt) => true,
(Error::DoneForNow, Error::DoneForNow) => true,
(Error::MethodNotAllowed, Error::MethodNotAllowed) => true,
(Error::MaxVersionsExceeded, Error::MaxVersionsExceeded) => true,
(Error::FileNotFound, Error::FileNotFound) => true,
(Error::FileVersionNotFound, Error::FileVersionNotFound) => true,
(Error::VolumeNotFound, Error::VolumeNotFound) => true,
@@ -111,6 +115,7 @@ impl Clone for Error {
Error::FileCorrupt => Error::FileCorrupt,
Error::DoneForNow => Error::DoneForNow,
Error::MethodNotAllowed => Error::MethodNotAllowed,
Error::MaxVersionsExceeded => Error::MaxVersionsExceeded,
Error::VolumeNotFound => Error::VolumeNotFound,
Error::Io(e) => Error::Io(std::io::Error::new(e.kind(), e.to_string())),
Error::RmpSerdeDecode(s) => Error::RmpSerdeDecode(s.clone()),
+134 -14
View File
@@ -34,11 +34,14 @@ use rustfs_utils::http::{
};
use s3s::header::X_AMZ_RESTORE;
use serde::{Deserialize, Serialize};
#[cfg(test)]
use std::cell::Cell;
use std::cmp::Ordering;
use std::collections::BTreeMap;
use std::convert::TryFrom;
use std::hash::Hasher;
use std::io::{Read, Write};
use std::sync::atomic::{AtomicUsize, Ordering as AtomicOrdering};
use std::{collections::HashMap, io::Cursor};
use time::OffsetDateTime;
use time::format_description::well_known::Rfc3339;
@@ -67,8 +70,46 @@ const _XL_FLAG_INLINE_DATA: u8 = 1 << 2;
const META_DATA_READ_DEFAULT: usize = 4 << 10;
const MSGP_UINT32_SIZE: usize = 5;
/// Max object versions per object, default is 10000
const DEFAULT_OBJECT_MAX_VERSIONS: usize = 10000;
/// Default max object versions per object, aligned with MinIO's default.
pub const DEFAULT_OBJECT_MAX_VERSIONS: usize = if usize::BITS >= 64 {
9_223_372_036_854_775_807
} else {
usize::MAX
};
static OBJECT_MAX_VERSIONS: AtomicUsize = AtomicUsize::new(DEFAULT_OBJECT_MAX_VERSIONS);
#[cfg(test)]
thread_local! {
static OBJECT_MAX_VERSIONS_OVERRIDE: Cell<Option<usize>> = const { Cell::new(None) };
}
#[inline]
pub fn object_max_versions() -> usize {
#[cfg(test)]
if let Some(limit) = OBJECT_MAX_VERSIONS_OVERRIDE.with(Cell::get) {
return limit;
}
OBJECT_MAX_VERSIONS.load(AtomicOrdering::Relaxed)
}
pub fn set_object_max_versions(limit: usize) -> Result<()> {
if limit == 0 {
return Err(Error::other("object max versions must be greater than 0"));
}
OBJECT_MAX_VERSIONS.store(limit, AtomicOrdering::Relaxed);
Ok(())
}
#[cfg(test)]
fn set_object_max_versions_override_for_test(limit: Option<usize>) -> Option<usize> {
OBJECT_MAX_VERSIONS_OVERRIDE.with(|override_limit| {
let previous = override_limit.get();
override_limit.set(limit);
previous
})
}
/// Returns the inline data map key for a version_id. "null" for null version.
pub(crate) fn data_key_for_version(version_id: Option<Uuid>) -> String {
@@ -460,18 +501,6 @@ impl FileMeta {
return Err(Error::other("file meta version invalid"));
}
// check max versions limit
if self.versions.len() + 1 > DEFAULT_OBJECT_MAX_VERSIONS {
return Err(Error::other(
"You've exceeded the limit on the number of versions you can create on this object",
));
}
if self.versions.is_empty() {
self.versions.push(FileMetaShallowVersion::try_from(version)?);
return Ok(());
}
let vid = version.get_version_id();
let vid_is_null = vid.is_none() || vid == Some(Uuid::nil());
let existing_idx = if vid_is_null {
@@ -490,6 +519,15 @@ impl FileMeta {
return self.set_idx(fidx, version);
}
if self.versions.len() >= object_max_versions() {
return Err(Error::MaxVersionsExceeded);
}
if self.versions.is_empty() {
self.versions.push(FileMetaShallowVersion::try_from(version)?);
return Ok(());
}
let new_shallow = FileMetaShallowVersion::try_from(version)?;
let insert_pos = self
.versions
@@ -1330,6 +1368,88 @@ mod test {
}
}
struct ObjectMaxVersionsRestore {
previous: Option<usize>,
}
impl Drop for ObjectMaxVersionsRestore {
fn drop(&mut self) {
set_object_max_versions_override_for_test(self.previous);
}
}
fn with_object_max_versions_for_test<R>(limit: usize, test: impl FnOnce() -> R) -> R {
let previous = set_object_max_versions_override_for_test(Some(limit));
let _restore = ObjectMaxVersionsRestore { previous };
test()
}
#[test]
fn add_version_filemata_rejects_new_version_above_configured_limit() {
with_object_max_versions_for_test(2, || {
let mut fm = FileMeta::new();
fm.add_version_filemata(valid_object_version(Uuid::from_u128(1), vec![10, 20]))
.expect("add first version within limit");
fm.add_version_filemata(valid_object_version(Uuid::from_u128(2), vec![10, 20]))
.expect("add second version at limit");
let err = fm
.add_version_filemata(valid_object_version(Uuid::from_u128(3), vec![10, 20]))
.expect_err("new version above limit must fail");
assert_eq!(err, Error::MaxVersionsExceeded);
assert_eq!(fm.versions.len(), 2, "failed insert must not mutate version list");
});
}
#[test]
fn add_version_filemata_allows_same_version_replacement_at_limit() {
with_object_max_versions_for_test(2, || {
let mut fm = FileMeta::new();
let target = Uuid::from_u128(10);
fm.add_version_filemata(valid_object_version(target, vec![10, 20]))
.expect("add target version");
fm.add_version_filemata(valid_object_version(Uuid::from_u128(20), vec![10, 20]))
.expect("add peer version at limit");
fm.add_version_filemata(valid_object_version(target, vec![30, 40]))
.expect("same version replacement at limit must succeed");
assert_eq!(fm.versions.len(), 2);
let replaced = fm
.versions
.iter()
.find(|version| version.header.version_id == Some(target))
.expect("target version must remain present")
.parse_version_meta()
.expect("parse replaced version");
assert_eq!(replaced.object.expect("object version").part_sizes, vec![30, 40]);
});
}
#[test]
fn add_version_allows_null_version_replacement_at_limit() {
with_object_max_versions_for_test(1, || {
let mut fm = FileMeta::new();
let mut first = FileInfo::new("object", 2, 2);
first.mod_time = Some(OffsetDateTime::now_utc());
first.version_id = None;
fm.add_version(first).expect("add initial null version");
let mut replacement = FileInfo::new("object", 2, 2);
replacement.mod_time = Some(OffsetDateTime::now_utc());
replacement.version_id = None;
replacement.size = 42;
fm.add_version(replacement)
.expect("null version replacement at limit must succeed");
assert_eq!(fm.versions.len(), 1);
assert_eq!(fm.versions[0].header.version_id, Some(Uuid::nil()));
let replaced = fm.versions[0].parse_version_meta().expect("parse null replacement");
assert_eq!(replaced.object.expect("object version").size, 42);
});
}
#[test]
fn add_version_filemata_uses_canonical_equal_time_order() {
let mod_time = OffsetDateTime::from_unix_timestamp(1_700_000_000).expect("valid test timestamp");
+78 -9
View File
@@ -313,6 +313,7 @@ impl HealManager {
completed_status_entry.outcome = Some(Arc::new(task.get_outcome().await));
}
let terminal_completion = !matches!(completed_status, HealTaskStatus::Retrying { .. });
let completed_status_for_verified_events = completed_status_entry.clone();
// Keep retry ownership continuous: status snapshots acquire
// these locks in the same active -> retrying order.
let mut retrying_heals_guard = if let (Some((request, _, error)), Some(cancel_token)) =
@@ -358,6 +359,15 @@ impl HealManager {
tests::pause_completed_retention_handoff(&task_id).await;
if completed_task.is_some() {
let notice_targets = if terminal_completion {
take_mrf_repair_notice_targets(&mrf_repair_notice_targets_clone, &task_id)
} else {
Vec::new()
};
if terminal_completion {
release_mrf_repair_notice_targets(&notice_targets);
}
publish_verified_mrf_repair_events(&notice_targets, &completed_status_for_verified_events);
// update statistics
let mut stats = statistics_clone.write().await;
match completed_status {
@@ -372,14 +382,6 @@ impl HealManager {
}
stats.update_running_tasks(usize_to_u64_saturated(active_count));
drop(stats);
if terminal_completion {
let notice_targets = take_mrf_repair_notice_targets(&mrf_repair_notice_targets_clone, &task_id);
// Neither task status nor the diagnostic outcome
// window supplies a storage-owned repair receipt.
// Release only the ingress lease for rediscovery;
// preserve the producer's existing retry hints.
release_mrf_repair_notice_targets(notice_targets);
}
}
if let (Some((retry_request, retry_delay, retry_error)), Some(retry_cancel_token)) =
@@ -705,7 +707,7 @@ fn move_mrf_repair_notice_targets(
}
}
fn release_mrf_repair_notice_targets(targets: Vec<MrfRepairNoticeTarget>) {
fn release_mrf_repair_notice_targets(targets: &[MrfRepairNoticeTarget]) {
for target in targets {
rustfs_common::mrf_channel::release_mrf_identity(
target.kind,
@@ -718,6 +720,73 @@ fn release_mrf_repair_notice_targets(targets: Vec<MrfRepairNoticeTarget>) {
}
}
pub(super) fn mrf_verified_repair_event_for_target(
target: &MrfRepairNoticeTarget,
outcome: &crate::heal::outcome::HealObjectOutcome,
) -> Option<rustfs_common::mrf_channel::MrfVerifiedRepairEvent> {
use crate::heal::outcome::{HealObjectDisposition, HealObjectKind};
use rustfs_common::mrf_channel::{MrfKind, MrfVerifiedRepairDisposition};
let disposition = match outcome.disposition {
HealObjectDisposition::Repaired => MrfVerifiedRepairDisposition::Repaired,
HealObjectDisposition::VerifiedHealthy => MrfVerifiedRepairDisposition::VerifiedHealthy,
HealObjectDisposition::AuthoritativelyAbsent => MrfVerifiedRepairDisposition::AuthoritativelyAbsent,
_ => return None,
};
if target.kind != MrfKind::PartialWrite {
return None;
}
let expected_kind = HealObjectKind::Object;
if outcome.identity.kind != expected_kind
|| outcome.identity.bucket.as_str() != target.bucket.as_ref()
|| outcome.identity.object.as_str() != target.object.as_ref()
{
return None;
}
let version_id = target.version_id.filter(|bytes| *bytes != [0; 16]);
let expected_version = version_id.map(|bytes| uuid::Uuid::from_bytes(bytes).to_string());
if outcome.identity.version_id != expected_version {
return None;
}
let expected_pool = target.scope.and_then(|scope| usize::try_from(scope.pool_index).ok());
let expected_set = target.scope.and_then(|scope| usize::try_from(scope.set_index).ok());
if outcome.identity.pool_index != expected_pool || outcome.identity.set_index != expected_set {
return None;
}
let bucket_incarnation_id = outcome.identity.bucket_incarnation_id?;
Some(rustfs_common::mrf_channel::MrfVerifiedRepairEvent {
kind: target.kind,
bucket: target.bucket.clone(),
object: target.object.clone(),
version_id,
scope: target.scope,
lease: target.lease,
bucket_incarnation_id,
disposition,
})
}
pub(super) fn publish_verified_mrf_repair_events(targets: &[MrfRepairNoticeTarget], completed: &CompletedHealStatus) {
if completed.status != HealTaskStatus::Completed {
return;
}
let Some(outcome) = completed.outcome.as_ref() else {
return;
};
if outcome.execution != crate::heal::outcome::HealExecutionOutcome::Completed {
return;
}
for target in targets {
if let Some(event) = outcome
.objects
.iter()
.find_map(|object| mrf_verified_repair_event_for_target(target, object))
{
rustfs_common::mrf_channel::note_mrf_verified_repair(event);
}
}
}
pub(super) fn heal_request_set_key_for_task(task: &HealTask) -> Option<String> {
match &task.heal_type {
HealType::ErasureSet { set_disk_id, .. } => Some(set_disk_id.clone()),
+185
View File
@@ -1094,6 +1094,191 @@ fn queued_request_id_for_dedup_key_tracks_the_representative() {
assert!(queue.queued_request_id_for_dedup_key(&first_key).is_none());
}
#[test]
fn mrf_verified_repair_event_requires_positive_exact_identity() {
use crate::heal::outcome::{HealObjectIdentity, HealObjectKind, HealObjectOutcome};
use rustfs_common::mrf_channel::{MrfKind, MrfScope, MrfVerifiedRepairDisposition};
let version = uuid::Uuid::new_v4();
let incarnation = uuid::Uuid::new_v4();
let target = MrfRepairNoticeTarget {
bucket: Arc::from("bucket"),
object: Arc::from("object"),
version_id: Some(*version.as_bytes()),
kind: MrfKind::PartialWrite,
scope: Some(MrfScope {
pool_index: 1,
set_index: 2,
}),
lease: None,
};
let matching = HealObjectOutcome {
identity: HealObjectIdentity {
kind: HealObjectKind::Object,
bucket: "bucket".to_string(),
object: "object".to_string(),
version_id: Some(version.to_string()),
bucket_incarnation_id: Some(incarnation),
pool_index: Some(1),
set_index: Some(2),
},
disposition: HealObjectDisposition::Repaired,
detail: None,
};
let event = mrf_verified_repair_event_for_target(&target, &matching).expect("matching positive receipt should publish");
assert_eq!(event.kind, MrfKind::PartialWrite);
assert_eq!(event.bucket.as_ref(), "bucket");
assert_eq!(event.object.as_ref(), "object");
assert_eq!(event.version_id, Some(*version.as_bytes()));
assert_eq!(
event.scope,
Some(MrfScope {
pool_index: 1,
set_index: 2
})
);
assert_eq!(event.lease, None);
assert_eq!(event.bucket_incarnation_id, incarnation);
assert_eq!(event.disposition, MrfVerifiedRepairDisposition::Repaired);
assert!(
mrf_verified_repair_event_for_target(
&MrfRepairNoticeTarget {
kind: MrfKind::DecodeFailure,
..target.clone()
},
&matching
)
.is_none(),
"only receipt-producing partial-write object heals can publish verified events today"
);
for rejected in [
HealObjectOutcome {
disposition: HealObjectDisposition::Unknown,
..matching.clone()
},
HealObjectOutcome {
identity: HealObjectIdentity {
bucket_incarnation_id: None,
..matching.identity.clone()
},
..matching.clone()
},
HealObjectOutcome {
identity: HealObjectIdentity {
object: "other".to_string(),
..matching.identity.clone()
},
..matching.clone()
},
HealObjectOutcome {
identity: HealObjectIdentity {
pool_index: Some(3),
..matching.identity.clone()
},
..matching
},
] {
assert!(
mrf_verified_repair_event_for_target(&target, &rejected).is_none(),
"legacy, incomplete or mismatched outcomes must not discharge MRF responsibility"
);
}
}
#[test]
fn completed_mrf_notice_publishes_only_verified_positive_events() {
use crate::heal::outcome::{HealObjectIdentity, HealObjectKind, HealObjectOutcome, HealTaskOutcome};
use rustfs_common::mrf_channel::{MrfKind, MrfScope, take_mrf_verified_repair_events_for};
let bucket = Arc::<str>::from("verified-mrf-completed-bucket");
let _ = take_mrf_verified_repair_events_for(bucket.as_ref());
let version = uuid::Uuid::new_v4();
let incarnation = uuid::Uuid::new_v4();
let matching_target = MrfRepairNoticeTarget {
bucket: bucket.clone(),
object: Arc::from("object-a"),
version_id: Some(*version.as_bytes()),
kind: MrfKind::PartialWrite,
scope: Some(MrfScope {
pool_index: 1,
set_index: 2,
}),
lease: None,
};
let mismatch_target = MrfRepairNoticeTarget {
object: Arc::from("object-b"),
..matching_target.clone()
};
let mut outcome = HealTaskOutcome::default();
outcome.execution = HealExecutionOutcome::Completed;
outcome.coverage = crate::heal::outcome::HealTraversalCoverage::Complete;
outcome.record(HealObjectOutcome {
identity: HealObjectIdentity {
kind: HealObjectKind::Object,
bucket: bucket.to_string(),
object: "object-a".to_string(),
version_id: Some(version.to_string()),
bucket_incarnation_id: Some(incarnation),
pool_index: Some(1),
set_index: Some(2),
},
disposition: HealObjectDisposition::VerifiedHealthy,
detail: None,
});
outcome.record(HealObjectOutcome {
identity: HealObjectIdentity {
kind: HealObjectKind::Object,
bucket: bucket.to_string(),
object: "object-b".to_string(),
version_id: Some(version.to_string()),
bucket_incarnation_id: None,
pool_index: Some(1),
set_index: Some(2),
},
disposition: HealObjectDisposition::Repaired,
detail: None,
});
let completed = CompletedHealStatus {
outcome: Some(Arc::new(outcome)),
..completed_retention_fixture(SystemTime::now())
};
publish_verified_mrf_repair_events(&[matching_target.clone(), mismatch_target], &completed);
let events = take_mrf_verified_repair_events_for(bucket.as_ref());
assert_eq!(events.len(), 1);
assert_eq!(events[0].object.as_ref(), "object-a");
assert_eq!(events[0].lease, None);
assert_eq!(events[0].bucket_incarnation_id, incarnation);
let failed = CompletedHealStatus {
status: HealTaskStatus::Failed {
error: "terminal failure".to_string(),
},
..completed.clone()
};
publish_verified_mrf_repair_events(std::slice::from_ref(&matching_target), &failed);
assert!(
take_mrf_verified_repair_events_for(bucket.as_ref()).is_empty(),
"failed terminal tasks must not publish a verified repair event"
);
let mut completed_with_errors_outcome = completed.outcome.as_ref().expect("completed outcome").as_ref().clone();
completed_with_errors_outcome.execution = crate::heal::outcome::HealExecutionOutcome::CompletedWithErrors;
let completed_with_errors = CompletedHealStatus {
outcome: Some(Arc::new(completed_with_errors_outcome)),
..completed
};
publish_verified_mrf_repair_events(std::slice::from_ref(&matching_target), &completed_with_errors);
assert!(
take_mrf_verified_repair_events_for(bucket.as_ref()).is_empty(),
"non-success canonical outcomes must not publish a verified repair event"
);
}
#[test]
fn test_priority_queue_ordering() {
let mut queue = PriorityHealQueue::new();
+75 -12
View File
@@ -36,7 +36,7 @@
use super::{DiskStore, HealDiskExt as _, local_disk_map_read};
use crate::heal::manager::{HealManager, MrfRepairNoticeTarget};
use metrics::{counter, gauge};
use rustfs_common::mrf_channel::{MRF_MAX_ATTEMPTS, MrfIntent};
use rustfs_common::mrf_channel::{MRF_MAX_ATTEMPTS, MrfIngressResult, MrfIntent};
use rustfs_heal_contracts::heal_channel::{HealAdmissionDropReason, HealAdmissionResult};
use std::collections::{HashSet, VecDeque};
use std::sync::Arc;
@@ -524,9 +524,8 @@ struct MrfRuntime {
/// waiting out an admission backoff must not re-fsync every local disk
/// twice a second.
dirty: bool,
/// True while a journal snapshot exists on disk that no longer reflects
/// an all-consumed pending set; the next idle tick removes it (MinIO
/// deletes its `list.bin` after replay for the same reason).
/// True while a journal snapshot exists on disk that may still be needed
/// for replay or cleanup.
journal_on_disk: bool,
/// Earliest instant a full-admission retry may proceed.
backoff_until: Option<tokio::time::Instant>,
@@ -703,9 +702,9 @@ async fn replay_into(
}
},
};
let mut intents = Vec::new();
let (decoded, truncated) = decode_journal(&data);
intents.extend(decoded);
let replayed = decoded.len();
let intents = decoded;
if truncated > 0 {
tracing::warn!(
target: "rustfs::heal::mrf",
@@ -713,8 +712,7 @@ async fn replay_into(
"MRF journal had a torn tail; truncated records were discarded"
);
}
counter!("rustfs_heal_mrf_replayed_total").increment(u64::try_from(intents.len()).unwrap_or(u64::MAX));
let replayed = intents.len();
counter!("rustfs_heal_mrf_replayed_total").increment(u64::try_from(replayed).unwrap_or(u64::MAX));
let replay_bytes = intents
.iter()
.fold(0usize, |total, intent| total.saturating_add(intent.estimated_bytes()));
@@ -740,6 +738,15 @@ async fn replay_into(
// stays armed in `queue` for the consumer's retry loop.
if backoff_until.is_none() {
while let Some(mut intent) = queue.pop_front() {
if !matches!(
rustfs_common::mrf_channel::try_rearm_mrf_replay_intent(&mut intent),
MrfIngressResult::Enqueued
) {
queue.push_back(intent);
rearm_incomplete = true;
*backoff_until = Some(tokio::time::Instant::now());
break;
}
match submit_mrf_heal_request(manager, &intent).await {
Ok(HealAdmissionResult::Accepted) | Ok(HealAdmissionResult::Merged) => {}
Ok(HealAdmissionResult::Full) | Ok(HealAdmissionResult::Dropped(HealAdmissionDropReason::QueueFull)) => {
@@ -747,10 +754,28 @@ async fn replay_into(
if intent.attempts < MRF_MAX_ATTEMPTS {
queue.push_back(intent);
*backoff_until = Some(tokio::time::Instant::now());
} else {
rearm_incomplete = true;
counter!("rustfs_heal_mrf_dropped_total", "reason" => "attempts_exhausted").increment(1);
rustfs_common::mrf_channel::release_mrf_intent(&intent);
}
break;
}
Ok(HealAdmissionResult::Dropped(_)) => {
rustfs_common::mrf_channel::release_mrf_intent(&intent);
}
Err(_) => {
intent.attempts = intent.attempts.saturating_add(1);
if intent.attempts < MRF_MAX_ATTEMPTS {
queue.push_back(intent);
*backoff_until = Some(tokio::time::Instant::now());
} else {
rearm_incomplete = true;
counter!("rustfs_heal_mrf_dropped_total", "reason" => "attempts_exhausted").increment(1);
rustfs_common::mrf_channel::release_mrf_intent(&intent);
}
break;
}
Ok(HealAdmissionResult::Dropped(_)) | Err(_) => {}
}
}
}
@@ -825,7 +850,11 @@ async fn run_mrf_consumer(manager: Arc<HealManager>, mut receiver: mpsc::Receive
}
}
_ = flush_tick.tick() => {
match tick_action(runtime.dirty, runtime.queue.depth(), runtime.journal_on_disk) {
match tick_action(
runtime.dirty,
runtime.queue.depth(),
runtime.journal_on_disk,
) {
TickAction::Flush => {
runtime.flush().await;
runtime.dispatch(manager.as_ref()).await;
@@ -838,8 +867,8 @@ async fn run_mrf_consumer(manager: Arc<HealManager>, mut receiver: mpsc::Receive
runtime.dispatch(manager.as_ref()).await;
}
TickAction::DeleteJournal => {
// All intents consumed: remove the journal so a restart
// replays nothing (mirrors MinIO's post-replay unlink).
// All replayed intents have either been accepted,
// merged, or replaced by a pending successor snapshot.
if delete_journals().await {
runtime.journal_on_disk = false;
gauge!("rustfs_heal_mrf_journal_bytes").set(0.0);
@@ -936,6 +965,40 @@ mod tests {
);
}
#[test]
fn durable_replay_acquires_a_fresh_lease_before_manager_admission() {
let unique = uuid::Uuid::new_v4();
let original = intent(&format!("replay-{unique}"), "object", 0);
assert!(original.lease.is_none(), "legacy journal records do not persist process leases");
let mut queue = MrfQueue::new(2, usize::MAX);
assert_eq!(queue.try_push_typed(original.clone()), MrfQueuePushResult::Enqueued);
assert_eq!(
queue.try_push_typed(original),
MrfQueuePushResult::Coalesced,
"legacy duplicates are one durable responsibility before a lease is assigned"
);
let mut replay = queue.pop_front().expect("one deduplicated replay record");
assert_eq!(
rustfs_common::mrf_channel::try_rearm_mrf_replay_intent(&mut replay),
MrfIngressResult::Enqueued
);
assert!(replay.lease.is_some(), "manager admission must receive the replay lease");
assert!(
rustfs_common::mrf_channel::MrfDurableRepairAnchor::from_intent(&replay, uuid::Uuid::new_v4()).is_some(),
"the replay identity must be usable by the durable proof consumer"
);
let mut encoded = Vec::new();
assert!(encode_intent(&replay, &mut encoded));
let (decoded, truncated) = decode_journal(&encoded);
assert_eq!(truncated, 0);
assert_eq!(decoded.len(), 1);
assert!(
decoded[0].lease.is_none(),
"process-local leases must not enter the durable journal format"
);
rustfs_common::mrf_channel::release_mrf_intent(&replay);
}
#[test]
fn replay_can_arm_more_records_than_live_queue_budget() {
let mut queue = MrfQueue::new(1, intent("bucket", "object-0", 0).estimated_bytes());
+67
View File
@@ -91,6 +91,29 @@ pub struct HealObjectOutcome {
pub detail: Option<String>,
}
#[derive(Debug, Clone, PartialEq, Eq)]
pub struct HealObjectReceipt {
pub identity: HealObjectIdentity,
pub disposition: HealObjectDisposition,
}
impl HealObjectReceipt {
pub(crate) fn verified_for(&self, expected: &HealObjectIdentity) -> bool {
matches!(
self.disposition,
HealObjectDisposition::Repaired
| HealObjectDisposition::VerifiedHealthy
| HealObjectDisposition::AuthoritativelyAbsent
) && self.identity.kind == expected.kind
&& self.identity.bucket == expected.bucket
&& self.identity.object == expected.object
&& self.identity.version_id == expected.version_id
&& self.identity.pool_index == expected.pool_index
&& self.identity.set_index == expected.set_index
&& self.identity.bucket_incarnation_id.is_some()
}
}
impl HealObjectOutcome {
fn retained_bytes(&self) -> usize {
size_of::<Self>()
@@ -470,4 +493,48 @@ mod canonical_outcome_tests {
assert_eq!(outcome.counters.processed, u64::MAX);
assert_eq!(outcome.coverage, HealTraversalCoverage::Partial);
}
#[test]
fn positive_receipt_requires_exact_identity_and_bucket_incarnation() {
let expected = item(HealObjectDisposition::Unknown).identity;
let mut receipt = HealObjectReceipt {
identity: expected.clone(),
disposition: HealObjectDisposition::Repaired,
};
assert!(
!receipt.verified_for(&expected),
"a positive storage receipt without bucket incarnation must remain untrusted"
);
let incarnation = Uuid::new_v4();
receipt.identity.bucket_incarnation_id = Some(incarnation);
assert!(receipt.verified_for(&expected));
receipt.identity.version_id = Some("older-version".to_string());
assert!(
!receipt.verified_for(&expected),
"a storage receipt for a different object/version tuple must not clear the requested responsibility"
);
receipt.identity = HealObjectIdentity {
bucket_incarnation_id: Some(incarnation),
pool_index: Some(1),
..expected.clone()
};
assert!(
!receipt.verified_for(&expected),
"a storage receipt for a different erasure location must not clear the requested responsibility"
);
receipt.identity = HealObjectIdentity {
bucket_incarnation_id: Some(incarnation),
..expected
};
receipt.disposition = HealObjectDisposition::Unknown;
assert!(
!receipt.verified_for(&receipt.identity),
"legacy success without a positive disposition remains unknown"
);
}
}
+73 -1
View File
@@ -15,12 +15,13 @@
use crate::{Error, Result};
use async_trait::async_trait;
use base64_simd::URL_SAFE_NO_PAD;
use rustfs_heal_contracts::heal_channel::{HealOpts, HealScanMode};
use rustfs_heal_contracts::heal_channel::{DriveState, HealOpts, HealScanMode};
use rustfs_madmin::heal_commands::HealResultItem;
use serde::{Deserialize, Serialize};
use std::sync::Arc;
use tracing::{debug, error, warn};
use super::outcome::{HealObjectDisposition, HealObjectIdentity, HealObjectKind, HealObjectReceipt};
use super::progress::stable_generation;
use super::storage_api::owner::{EcstoreHealLifecycleExpiryContext, ecstore_load_admin_data_usage_from_backend_cached};
use super::storage_api::storage::{
@@ -67,6 +68,23 @@ impl HealLifecycleExpiryContext {
}
}
#[derive(Debug, Default)]
pub struct HealStorageObjectResult {
pub item: HealResultItem,
pub error: Option<Error>,
pub receipt: Option<HealObjectReceipt>,
}
impl From<(HealResultItem, Option<Error>)> for HealStorageObjectResult {
fn from((item, error): (HealResultItem, Option<Error>)) -> Self {
Self {
item,
error,
receipt: None,
}
}
}
const LOG_COMPONENT_HEAL: &str = "heal";
const LOG_SUBSYSTEM_STORAGE: &str = "storage";
const EVENT_HEAL_STORAGE_OBJECT_IO: &str = "heal_storage_object_io";
@@ -374,6 +392,16 @@ pub trait HealStorageAPI: Send + Sync {
opts: &HealOpts,
) -> Result<(HealResultItem, Option<Error>)>;
async fn heal_object_with_receipt(
&self,
bucket: &str,
object: &str,
version_id: Option<&str>,
opts: &HealOpts,
) -> Result<HealStorageObjectResult> {
self.heal_object(bucket, object, version_id, opts).await.map(Into::into)
}
/// Heal bucket using ecstore
async fn heal_bucket(&self, bucket: &str, opts: &HealOpts) -> Result<HealResultItem>;
@@ -1062,6 +1090,50 @@ impl HealStorageAPI for ECStoreHealStorage {
}
}
async fn heal_object_with_receipt(
&self,
bucket: &str,
object: &str,
version_id: Option<&str>,
opts: &HealOpts,
) -> Result<HealStorageObjectResult> {
let (item, error) = self.heal_object(bucket, object, version_id, opts).await?;
let receipt = if error.is_none() && !opts.dry_run {
let ok_drive_state = DriveState::Ok.to_string();
let all_after_drives_ok = item.after.drives.iter().all(|drive| drive.state == ok_drive_state);
match (
self.ecstore.bucket_incarnation_id(bucket).await,
item.drives_reported(),
item.drives_healed(),
all_after_drives_ok,
) {
(Ok(bucket_incarnation_id), Some(_), Some(drives_healed), true) => {
let disposition = if drives_healed > 0 {
HealObjectDisposition::Repaired
} else {
HealObjectDisposition::VerifiedHealthy
};
Some(HealObjectReceipt {
identity: HealObjectIdentity {
kind: HealObjectKind::Object,
bucket: bucket.to_string(),
object: object.to_string(),
version_id: version_id.map(ToOwned::to_owned),
bucket_incarnation_id: Some(bucket_incarnation_id),
pool_index: opts.pool,
set_index: opts.set,
},
disposition,
})
}
_ => None,
}
} else {
None
};
Ok(HealStorageObjectResult { item, error, receipt })
}
async fn heal_bucket(&self, bucket: &str, opts: &HealOpts) -> Result<HealResultItem> {
debug!(
target: "rustfs::heal::storage",
+21 -1
View File
@@ -17,7 +17,7 @@ use crate::heal::{
erasure_healer::target_outcomes_complete,
outcome::{
HealAbortReason, HealDeferredReason, HealFailureClass, HealObjectDisposition, HealObjectIdentity, HealObjectKind,
HealObjectOutcome, HealTaskOutcome,
HealObjectOutcome, HealObjectReceipt, HealTaskOutcome,
},
progress::HealProgress,
resume::{
@@ -592,6 +592,26 @@ impl HealTask {
Some(self.outcome_identity(bucket, object, version, self.options.pool_index, self.options.set_index))
}
pub(super) async fn record_verified_storage_receipt(
&self,
expected: HealObjectIdentity,
receipt: Option<HealObjectReceipt>,
) -> bool {
let Some(receipt) = receipt else {
return false;
};
if !receipt.verified_for(&expected) {
return false;
}
let mut outcome = self.outcome.write().await;
outcome.record(HealObjectOutcome {
identity: receipt.identity,
disposition: receipt.disposition,
detail: None,
});
true
}
async fn record_deferred_object(&self, reason: HealDeferredReason) {
if let Some(identity) = self.single_object_identity() {
let mut outcome = self.outcome.write().await;
+8 -2
View File
@@ -163,7 +163,7 @@ impl HealTask {
set: self.options.set_index,
};
let heal_fut = self.storage.heal_object(bucket, object, version_id, &heal_opts);
let heal_fut = self.storage.heal_object_with_receipt(bucket, object, version_id, &heal_opts);
let heal_result = if self.source == HealRequestSource::ReadRepair {
let result = heal_fut.await;
if self.cancel_token.is_cancelled() {
@@ -176,7 +176,9 @@ impl HealTask {
};
match heal_result {
Ok((result, error)) => {
Ok(storage_result) => {
let result = storage_result.item;
let error = storage_result.error;
if let Some(e) = error {
if self.skip_dangling_delete_grace_error(bucket, object, &e).await {
return Ok(());
@@ -264,6 +266,10 @@ impl HealTask {
let mut progress = self.progress.write().await;
progress.update_object_progress(1, 1, 0, 0, object_size);
}
let expected_identity =
self.outcome_identity(bucket, object, version_id, self.options.pool_index, self.options.set_index);
self.record_verified_storage_receipt(expected_identity, storage_result.receipt)
.await;
self.record_result_item(result).await;
Ok(())
}
+103
View File
@@ -14,6 +14,7 @@
use super::super::{DiskOption, DiskStore, Endpoint, new_disk};
use super::*;
use crate::heal::storage::HealStorageObjectResult;
mod deferred_retry;
@@ -1048,6 +1049,7 @@ struct MockStorage {
object_exists_by_name: Mutex<HashMap<String, MockObjectExists>>,
heal_object_outcome: Mutex<Option<MockHealObjectOutcome>>,
heal_object_outcomes: Mutex<HashMap<String, VecDeque<MockHealObjectOutcome>>>,
heal_object_receipts: Mutex<HashMap<String, VecDeque<HealObjectReceipt>>>,
format_no_heal_required: Mutex<bool>,
format_error: Mutex<Option<Error>>,
global_format_calls: Mutex<u32>,
@@ -1151,6 +1153,90 @@ async fn execute_emits_heal_trace_task_state() {
assert_eq!(trace_attr_string(&completed, "state").as_deref(), Some("completed"));
}
fn object_receipt(object: &str, version_id: Option<&str>, disposition: HealObjectDisposition) -> HealObjectReceipt {
HealObjectReceipt {
identity: HealObjectIdentity {
kind: HealObjectKind::Object,
bucket: "bucket-a".to_string(),
object: object.to_string(),
version_id: version_id.map(ToOwned::to_owned),
bucket_incarnation_id: Some(Uuid::new_v4()),
pool_index: None,
set_index: None,
},
disposition,
}
}
#[tokio::test]
async fn object_heal_records_matching_positive_storage_receipt() {
let storage = Arc::new(MockStorage {
heal_object_receipts: Mutex::new(HashMap::from([(
"object-a".to_string(),
VecDeque::from([object_receipt("object-a", Some("version-a"), HealObjectDisposition::Repaired)]),
)])),
..Default::default()
});
let task = HealTask::from_request(
HealRequest::object("bucket-a".to_string(), "object-a".to_string(), Some("version-a".to_string())),
storage,
);
task.execute().await.expect("mock object heal should complete");
let outcome = task.get_outcome().await;
assert_eq!(outcome.counters.healed, 1);
assert_eq!(outcome.counters.unknown, 0);
let object = outcome.objects.front().expect("positive receipt should be recorded");
assert_eq!(object.identity.object, "object-a");
assert_eq!(object.identity.version_id.as_deref(), Some("version-a"));
assert!(object.identity.bucket_incarnation_id.is_some());
assert_eq!(object.disposition, HealObjectDisposition::Repaired);
}
#[tokio::test]
async fn object_heal_rejects_mismatched_or_legacy_storage_receipts() {
let storage = Arc::new(MockStorage {
heal_object_receipts: Mutex::new(HashMap::from([(
"object-a".to_string(),
VecDeque::from([object_receipt(
"object-a",
Some("old-version"),
HealObjectDisposition::Repaired,
)]),
)])),
..Default::default()
});
let task = HealTask::from_request(
HealRequest::object("bucket-a".to_string(), "object-a".to_string(), Some("version-a".to_string())),
storage,
);
task.execute()
.await
.expect("a mismatched receipt must not fail the legacy heal result");
let outcome = task.get_outcome().await;
assert_eq!(outcome.counters.healed, 0);
assert_eq!(outcome.counters.unknown, 1);
assert_eq!(
outcome
.objects
.front()
.expect("legacy fallback should be recorded")
.disposition,
HealObjectDisposition::Unknown
);
let legacy = HealTask::from_request(
HealRequest::object("bucket-a".to_string(), "object-b".to_string(), None),
Arc::new(MockStorage::default()),
);
legacy.execute().await.expect("legacy mock object heal should complete");
let legacy_outcome = legacy.get_outcome().await;
assert_eq!(legacy_outcome.counters.healed, 0);
assert_eq!(legacy_outcome.counters.unknown, 1);
}
async fn recv_trace_task_state(trace: &mut TraceSubscription, task_id: &str, state: &str) -> TraceEvent {
for _ in 0..32 {
let event = tokio::time::timeout(Duration::from_secs(1), trace.recv())
@@ -1408,6 +1494,23 @@ impl HealStorageAPI for MockStorage {
))
}
async fn heal_object_with_receipt(
&self,
bucket: &str,
object: &str,
version_id: Option<&str>,
opts: &HealOpts,
) -> Result<HealStorageObjectResult> {
let (item, error) = self.heal_object(bucket, object, version_id, opts).await?;
let receipt = self
.heal_object_receipts
.lock()
.unwrap()
.get_mut(object)
.and_then(VecDeque::pop_front);
Ok(HealStorageObjectResult { item, error, receipt })
}
async fn heal_bucket(&self, bucket: &str, opts: &HealOpts) -> Result<HealResultItem> {
self.bucket_heal_calls.lock().unwrap().push(bucket.to_string());
self.bucket_heal_opts.lock().unwrap().push(*opts);
+431 -1
View File
@@ -29,7 +29,17 @@ use rustfs_heal::heal::{
storage::{ECStoreHealStorage, HealStorageAPI},
};
use serial_test::serial;
use std::{path::Path, process::Command, sync::Arc, time::Duration};
#[cfg(unix)]
use std::{
fs::{File, OpenOptions},
io::Write,
};
use std::{
path::{Path, PathBuf},
process::{Command, Stdio},
sync::Arc,
time::Duration,
};
mod storage_api;
@@ -110,6 +120,48 @@ fn journal_record(kind: u8, bucket: &str, object: &str, version: Option<[u8; 16]
body
}
fn scoped_journal_record(
kind: u8,
bucket: &str,
object: &str,
version: Option<[u8; 16]>,
attempts: u8,
pool_index: u32,
set_index: u32,
) -> Vec<u8> {
let mut body = vec![1u8, 2, kind, attempts];
body.extend_from_slice(&1_700_000_000_000u64.to_le_bytes());
match version {
Some(bytes) => {
body.push(1);
body.extend_from_slice(&bytes);
}
None => body.push(0),
}
body.extend_from_slice(&pool_index.to_le_bytes());
body.extend_from_slice(&set_index.to_le_bytes());
body.extend_from_slice(
&u32::try_from(bucket.len())
.expect("fixture bucket length must fit journal format")
.to_le_bytes(),
);
body.extend_from_slice(
&u32::try_from(object.len())
.expect("fixture object length must fit journal format")
.to_le_bytes(),
);
body.extend_from_slice(bucket.as_bytes());
body.extend_from_slice(object.as_bytes());
let mut hasher = crc_fast::Digest::new(crc_fast::CrcAlgorithm::Crc32IsoHdlc);
hasher.update(&body);
body.extend_from_slice(
&u32::try_from(hasher.finalize())
.expect("CRC32 must fit the journal checksum field")
.to_le_bytes(),
);
body
}
fn write_journal_path_to_disks(disk_paths: &[std::path::PathBuf], relative_path: &str, data: &[u8]) {
for path in disk_paths {
let journal = path.join(META_BUCKET).join(relative_path);
@@ -118,6 +170,27 @@ fn write_journal_path_to_disks(disk_paths: &[std::path::PathBuf], relative_path:
}
}
#[cfg(unix)]
fn write_journal_path_to_disks_synced(disk_paths: &[std::path::PathBuf], relative_path: &str, data: &[u8]) {
for path in disk_paths {
let journal = path.join(META_BUCKET).join(relative_path);
let parent = journal.parent().expect("journal parent");
std::fs::create_dir_all(parent).expect("create journal dir");
let mut file = OpenOptions::new()
.create(true)
.truncate(true)
.write(true)
.open(&journal)
.expect("open synced journal fixture");
file.write_all(data).expect("write synced journal fixture");
file.sync_all().expect("sync journal fixture");
File::open(parent)
.expect("open journal parent for sync")
.sync_all()
.expect("sync journal parent");
}
}
fn write_journal_to_disks(disk_paths: &[std::path::PathBuf], data: &[u8]) {
write_journal_path_to_disks(disk_paths, JOURNAL_REL, data);
}
@@ -128,6 +201,12 @@ fn journal_exists_on_all_disks(disk_paths: &[std::path::PathBuf], relative_path:
.all(|path| Path::new(path).join(META_BUCKET).join(relative_path).exists())
}
fn journal_matches_on_all_disks(disk_paths: &[PathBuf], relative_path: &str, expected: &[u8]) -> bool {
disk_paths
.iter()
.all(|path| std::fs::read(path.join(META_BUCKET).join(relative_path)).is_ok_and(|actual| actual == expected))
}
async fn wait_until<F, Fut>(deadline: Duration, mut probe: F) -> bool
where
F: FnMut() -> Fut,
@@ -259,6 +338,72 @@ async fn authoritative_journal_is_not_merged_with_legacy_mirror() {
!Path::new(path).join(META_BUCKET).join(JOURNAL_REL).exists()
&& !Path::new(path).join(META_BUCKET).join(SCOPED_JOURNAL_REL).exists()
}));
let scoped_v2 = scoped_journal_record(1, "scoped-v2-bucket", "scoped-v2-object", None, 0, 3, 7);
let stale_legacy = journal_record(1, "stale-legacy-bucket", "stale-legacy-object", None, 0);
write_journal_path_to_disks(&disk_paths, SCOPED_JOURNAL_REL, &scoped_v2);
write_journal_path_to_disks(&disk_paths, JOURNAL_REL, &stale_legacy);
assert_eq!(
mrf_queue::replay_journal_once(&manager).await,
1,
"a scoped v2 authoritative epoch must not be merged with a stale v1 legacy mirror"
);
assert_eq!(
manager.operations_snapshot().await.queued_by_source.mrf,
3,
"only the three authoritative/scoped-only epochs should have reached the manager"
);
assert!(disk_paths.iter().all(|path| {
!Path::new(path).join(META_BUCKET).join(JOURNAL_REL).exists()
&& !Path::new(path).join(META_BUCKET).join(SCOPED_JOURNAL_REL).exists()
}));
}
/// The authoritative journal carries the full replay responsibility identity.
/// A stale legacy mirror must not collapse same-object records that differ by
/// kind or erasure-set scope after restart.
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
#[serial]
async fn authoritative_journal_replay_preserves_kind_and_scope_identity() {
let (disk_paths, storage) = heal_env().await;
register_local_disks(&disk_paths, "mrf-authoritative-identity-test").await;
let mut authoritative = scoped_journal_record(3, "identity-bucket", "same-object", None, 0, 3, 7);
authoritative.extend(scoped_journal_record(3, "identity-bucket", "same-object", None, 0, 3, 8));
authoritative.extend(journal_record(2, "identity-bucket", "same-object", None, 0));
authoritative.extend(journal_record(1, "identity-bucket", "same-object", Some([4u8; 16]), 0));
let stale_legacy = journal_record(3, "identity-bucket", "stale-legacy-object", None, 0);
write_journal_path_to_disks(&disk_paths, SCOPED_JOURNAL_REL, &authoritative);
write_journal_path_to_disks(&disk_paths, JOURNAL_REL, &stale_legacy);
let manager = make_manager(storage);
let replayed = mrf_queue::replay_journal_once(&manager).await;
assert_eq!(
replayed, 4,
"all authoritative kind/scope identities must decode before manager admission"
);
let snapshot = manager.operations_snapshot().await;
assert_eq!(
snapshot.queued_by_source.mrf, 4,
"same-object MRF replay must retain distinct kind and scope responsibilities"
);
assert_eq!(
snapshot.queued_by_priority.normal, 2,
"the two scoped partial-write records must remain independently queued"
);
assert_eq!(
snapshot.queued_by_priority.high, 1,
"metadata corruption must not merge with object repair responsibility"
);
assert_eq!(
snapshot.queued_by_priority.urgent, 1,
"decode-failure repair must not merge with object repair responsibility"
);
assert!(disk_paths.iter().all(|path| {
!Path::new(path).join(META_BUCKET).join(JOURNAL_REL).exists()
&& !Path::new(path).join(META_BUCKET).join(SCOPED_JOURNAL_REL).exists()
}));
}
/// If replay reaches a full heal-manager queue, the old journal remains the
@@ -348,6 +493,135 @@ fn mrf_journal_child_process_fixture() {
std::process::exit(77);
}
#[test]
fn mrf_successor_flush_child_process_fixture() {
let Ok(root) = std::env::var("RUSTFS_MRF_SUCCESSOR_FLUSH_CHILD_ROOT") else {
return;
};
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("child runtime should build");
runtime.block_on(async {
let (disk_paths, storage) = heal_env_at(Some(Path::new(&root))).await;
register_local_disks(&disk_paths, "mrf-successor-flush-child").await;
let mut startup = journal_record(1, "successor-bucket", "first-object", None, 0);
startup.extend(journal_record(1, "successor-bucket", "second-object", None, 0));
write_journal_path_to_disks(&disk_paths, SCOPED_JOURNAL_REL, &startup);
write_journal_path_to_disks(&disk_paths, JOURNAL_REL, &startup);
let manager = Arc::new(HealManager::new(
storage,
Some(HealConfig {
queue_size: 1,
heal_interval: Duration::from_secs(3600),
enable_auto_heal: false,
..Default::default()
}),
));
mrf_queue::spawn_mrf_consumer(manager.clone());
let expected_successor = journal_record(1, "successor-bucket", "second-object", None, 2);
let flushed = wait_until(Duration::from_secs(10), || async {
manager.operations_snapshot().await.queued_by_source.mrf == 1
&& journal_matches_on_all_disks(&disk_paths, SCOPED_JOURNAL_REL, &expected_successor)
&& journal_matches_on_all_disks(&disk_paths, JOURNAL_REL, &expected_successor)
})
.await;
assert!(
flushed,
"child process must publish the pending successor snapshot before the delete phase"
);
});
std::process::exit(78);
}
#[test]
#[cfg(unix)]
fn mrf_successor_flush_waiting_child_process_fixture() {
let Ok(root) = std::env::var("RUSTFS_MRF_SUCCESSOR_KILL_CHILD_ROOT") else {
return;
};
let ready_path = std::env::var("RUSTFS_MRF_SUCCESSOR_KILL_READY")
.map(PathBuf::from)
.expect("ready marker path should be provided");
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("child runtime should build");
runtime.block_on(async {
let (disk_paths, storage) = heal_env_at(Some(Path::new(&root))).await;
register_local_disks(&disk_paths, "mrf-successor-kill-child").await;
let mut startup = journal_record(1, "service-kill-bucket", "first-object", None, 0);
startup.extend(journal_record(1, "service-kill-bucket", "second-object", None, 0));
write_journal_path_to_disks(&disk_paths, SCOPED_JOURNAL_REL, &startup);
write_journal_path_to_disks(&disk_paths, JOURNAL_REL, &startup);
let manager = Arc::new(HealManager::new(
storage,
Some(HealConfig {
queue_size: 1,
heal_interval: Duration::from_secs(3600),
enable_auto_heal: false,
..Default::default()
}),
));
mrf_queue::spawn_mrf_consumer(manager.clone());
let expected_successor = journal_record(1, "service-kill-bucket", "second-object", None, 2);
let flushed = wait_until(Duration::from_secs(10), || async {
manager.operations_snapshot().await.queued_by_source.mrf == 1
&& journal_matches_on_all_disks(&disk_paths, SCOPED_JOURNAL_REL, &expected_successor)
&& journal_matches_on_all_disks(&disk_paths, JOURNAL_REL, &expected_successor)
})
.await;
assert!(
flushed,
"child process must publish the pending successor snapshot before it can be killed"
);
std::fs::write(&ready_path, b"ready").expect("write ready marker");
loop {
tokio::time::sleep(Duration::from_secs(60)).await;
}
});
}
#[test]
#[cfg(unix)]
fn mrf_authoritative_fsync_waiting_child_process_fixture() {
let Ok(root) = std::env::var("RUSTFS_MRF_FSYNC_KILL_CHILD_ROOT") else {
return;
};
let ready_path = std::env::var("RUSTFS_MRF_FSYNC_KILL_READY")
.map(PathBuf::from)
.expect("ready marker path should be provided");
let runtime = tokio::runtime::Builder::new_current_thread()
.enable_all()
.build()
.expect("child runtime should build");
runtime.block_on(async {
let (disk_paths, _storage) = heal_env_at(Some(Path::new(&root))).await;
register_local_disks(&disk_paths, "mrf-fsync-kill-child").await;
let mut startup = journal_record(1, "fsync-kill-bucket", "first-object", None, 0);
startup.extend(journal_record(1, "fsync-kill-bucket", "second-object", None, 0));
write_journal_path_to_disks(&disk_paths, SCOPED_JOURNAL_REL, &startup);
write_journal_path_to_disks(&disk_paths, JOURNAL_REL, &startup);
let successor = journal_record(1, "fsync-kill-bucket", "second-object", None, 2);
write_journal_path_to_disks_synced(&disk_paths, SCOPED_JOURNAL_REL, &successor);
assert!(
journal_matches_on_all_disks(&disk_paths, SCOPED_JOURNAL_REL, &successor)
&& journal_matches_on_all_disks(&disk_paths, JOURNAL_REL, &startup),
"child process must reach the canonical-fsync/stale-legacy boundary"
);
std::fs::write(&ready_path, b"ready").expect("write ready marker");
loop {
tokio::time::sleep(Duration::from_secs(60)).await;
}
});
}
/// A journal published by a different OS process must remain a durable anchor
/// when the restarted process can only admit a prefix of the replayed intents.
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
@@ -390,3 +664,159 @@ async fn journal_replay_retains_child_process_anchor_when_manager_is_full() {
"replay must retain the child-published journal until a successor snapshot can replace it"
);
}
/// If a process crashes after flushing a smaller successor snapshot but before
/// deleting the startup anchor, the restarted process must replay the
/// successor tail rather than losing it or merging it with stale records.
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
#[serial]
async fn journal_replay_survives_successor_flush_before_delete() {
let temp_dir = tempfile::tempdir().expect("successor-flush MRF root");
let status = Command::new(std::env::current_exe().expect("test binary path"))
.arg("mrf_successor_flush_child_process_fixture")
.arg("--exact")
.arg("--nocapture")
.env("RUSTFS_MRF_SUCCESSOR_FLUSH_CHILD_ROOT", temp_dir.path())
.status()
.expect("child MRF successor fixture should start");
assert_eq!(status.code(), Some(78), "child process did not reach the successor flush boundary");
let (disk_paths, storage) = heal_env_at(Some(temp_dir.path())).await;
let expected_successor = journal_record(1, "successor-bucket", "second-object", None, 2);
assert!(
journal_matches_on_all_disks(&disk_paths, SCOPED_JOURNAL_REL, &expected_successor),
"restarted process must see the pending successor snapshot"
);
let restarted = make_manager(storage);
let replayed = mrf_queue::replay_journal_once(&restarted).await;
assert_eq!(replayed, 1, "restart after successor flush must replay only the still-pending tail");
assert_eq!(
restarted.operations_snapshot().await.queued_by_source.mrf,
1,
"the successor tail must be accepted after restart"
);
assert!(
disk_paths.iter().all(|path| {
!Path::new(path).join(META_BUCKET).join(JOURNAL_REL).exists()
&& !Path::new(path).join(META_BUCKET).join(SCOPED_JOURNAL_REL).exists()
}),
"a fully consumed successor snapshot may be deleted after restart replay"
);
}
/// A service-style hard kill after successor flush must be equivalent to a
/// crash at the flush-before-delete boundary: restart may replay the smaller
/// successor snapshot, but must not lose or merge stale startup records.
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
#[serial]
#[cfg(unix)]
async fn journal_replay_survives_service_kill_after_successor_flush() {
let temp_dir = tempfile::tempdir().expect("successor-kill MRF root");
let ready = temp_dir.path().join("successor-flushed.ready");
let mut child = Command::new(std::env::current_exe().expect("test binary path"))
.arg("mrf_successor_flush_waiting_child_process_fixture")
.arg("--exact")
.arg("--nocapture")
.env("RUSTFS_MRF_SUCCESSOR_KILL_CHILD_ROOT", temp_dir.path())
.env("RUSTFS_MRF_SUCCESSOR_KILL_READY", &ready)
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.expect("child MRF successor fixture should start");
let ready_seen = wait_until(Duration::from_secs(10), || {
let ready = ready.clone();
async move { ready.exists() }
})
.await;
assert!(ready_seen, "child process did not reach the successor flush boundary");
child.kill().expect("kill child fixture");
let status = child.wait().expect("wait for killed child fixture");
assert!(!status.success(), "child fixture must be terminated instead of exiting cleanly");
let (disk_paths, storage) = heal_env_at(Some(temp_dir.path())).await;
let expected_successor = journal_record(1, "service-kill-bucket", "second-object", None, 2);
assert!(
journal_matches_on_all_disks(&disk_paths, SCOPED_JOURNAL_REL, &expected_successor),
"restarted process must see the successor snapshot produced before the kill"
);
let restarted = make_manager(storage);
let replayed = mrf_queue::replay_journal_once(&restarted).await;
assert_eq!(replayed, 1, "restart after service kill must replay only the still-pending tail");
assert_eq!(
restarted.operations_snapshot().await.queued_by_source.mrf,
1,
"the successor tail must be accepted after service kill restart"
);
assert!(
disk_paths.iter().all(|path| {
!Path::new(path).join(META_BUCKET).join(JOURNAL_REL).exists()
&& !Path::new(path).join(META_BUCKET).join(SCOPED_JOURNAL_REL).exists()
}),
"a fully consumed successor snapshot may be deleted after service-kill restart replay"
);
}
/// A hard kill between the authoritative successor fsync and the legacy mirror
/// rewrite must prefer the canonical successor tail over the stale legacy
/// startup epoch. This models the mixed-version boundary conservatively: new
/// readers must not merge epochs, while the old mirror remains crash-visible.
#[tokio::test(flavor = "multi_thread", worker_threads = 4)]
#[serial]
#[cfg(unix)]
async fn journal_replay_survives_sigkill_after_authoritative_successor_fsync_before_legacy_mirror() {
let temp_dir = tempfile::tempdir().expect("fsync-kill MRF root");
let ready = temp_dir.path().join("authoritative-synced.ready");
let mut child = Command::new(std::env::current_exe().expect("test binary path"))
.arg("mrf_authoritative_fsync_waiting_child_process_fixture")
.arg("--exact")
.arg("--nocapture")
.env("RUSTFS_MRF_FSYNC_KILL_CHILD_ROOT", temp_dir.path())
.env("RUSTFS_MRF_FSYNC_KILL_READY", &ready)
.stdout(Stdio::null())
.stderr(Stdio::null())
.spawn()
.expect("child MRF fsync fixture should start");
let ready_seen = wait_until(Duration::from_secs(10), || {
let ready = ready.clone();
async move { ready.exists() }
})
.await;
assert!(ready_seen, "child process did not reach the authoritative fsync boundary");
child.kill().expect("kill child fixture");
let status = child.wait().expect("wait for killed child fixture");
assert!(!status.success(), "child fixture must be terminated instead of exiting cleanly");
let (disk_paths, storage) = heal_env_at(Some(temp_dir.path())).await;
let expected_successor = journal_record(1, "fsync-kill-bucket", "second-object", None, 2);
let stale_startup = {
let mut startup = journal_record(1, "fsync-kill-bucket", "first-object", None, 0);
startup.extend(journal_record(1, "fsync-kill-bucket", "second-object", None, 0));
startup
};
assert!(
journal_matches_on_all_disks(&disk_paths, SCOPED_JOURNAL_REL, &expected_successor),
"restarted process must see the fsynced authoritative successor"
);
assert!(
journal_matches_on_all_disks(&disk_paths, JOURNAL_REL, &stale_startup),
"legacy mirror intentionally remains at the stale startup epoch"
);
let restarted = make_manager(storage);
let replayed = mrf_queue::replay_journal_once(&restarted).await;
assert_eq!(replayed, 1, "new reader must replay only the authoritative successor tail");
assert_eq!(
restarted.operations_snapshot().await.queued_by_source.mrf,
1,
"the successor tail must be accepted after the fsync-boundary restart"
);
assert!(
disk_paths.iter().all(|path| {
!Path::new(path).join(META_BUCKET).join(JOURNAL_REL).exists()
&& !Path::new(path).join(META_BUCKET).join(SCOPED_JOURNAL_REL).exists()
}),
"a fully consumed authoritative successor may clean both epochs after restart replay"
);
}
@@ -1,5 +1,7 @@
use criterion::{Criterion, criterion_group, criterion_main};
use rustfs_io_metrics::{MetricsCollector, PerformanceMetrics, record_get_object_request_started};
use rustfs_io_metrics::{record_s3_op, s3_http_metrics::S3HttpRequestGuard};
use rustfs_s3_ops::S3Operation;
use std::hint::black_box;
use std::sync::Arc;
use std::time::Duration;
@@ -8,6 +10,17 @@ fn bench_record_get_object_request_started(c: &mut Criterion) {
c.bench_function("record_get_object_request_started", |b| b.iter(record_get_object_request_started));
}
fn bench_s3_http_outcomes(c: &mut Criterion) {
c.bench_function("s3_http_handler_counter", |b| b.iter(|| record_s3_op(black_box(S3Operation::PutObject))));
c.bench_function("s3_http_handler_counter_with_outcome", |b| {
b.iter(|| {
let mut request = S3HttpRequestGuard::new(black_box("PUT"));
request.in_scope(|| record_s3_op(black_box(S3Operation::PutObject)));
request.response(black_box(200));
})
});
}
fn bench_update_concurrent_requests(c: &mut Criterion) {
let metrics = PerformanceMetrics::new();
@@ -37,6 +50,7 @@ fn bench_metrics_collector_record_io_operation(c: &mut Criterion) {
criterion_group!(
benches,
bench_record_get_object_request_started,
bench_s3_http_outcomes,
bench_update_concurrent_requests,
bench_metrics_collector_record_io_operation
);
+1 -4
View File
@@ -241,10 +241,7 @@ impl AdaptiveTTL {
// 1. Item is cold (low access count)
// 2. Age is significant (> 50% of TTL)
// 3. No recent accesses
if access_count <= self.cold_threshold && age > current_ttl / 2 {
return true;
}
false
access_count <= self.cold_threshold && age > current_ttl / 2
}
/// Calculate priority score for an item.
+1
View File
@@ -226,6 +226,7 @@ pub mod lock_metrics;
pub mod performance;
pub mod process_lock_metrics;
pub mod s3_api_metrics;
pub mod s3_http_metrics;
pub mod sampler;
pub mod system_path_metrics;
pub mod timeout_metrics;
+1
View File
@@ -43,6 +43,7 @@ fn s3_op_counters() -> &'static [AtomicU64] {
/// This mirrors MinIO, which never labels its default operation counters with
/// bucket. The `op` dimension is bounded (<= 122 variants).
pub fn record_s3_op(op: S3Operation) {
crate::s3_http_metrics::observe_s3_http_operation(op);
if let Some(counter) = s3_op_counters().get(op.metric_index()) {
counter.fetch_add(1, Ordering::Relaxed);
}
+254
View File
@@ -0,0 +1,254 @@
// 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.
//! External S3 HTTP outcomes, including requests rejected before S3 dispatch.
//! Admin snapshots and metric exporters share these counters. The older
//! operation counter counts handler entries and is not an HTTP denominator.
use rustfs_s3_ops::S3Operation;
use std::cell::Cell;
use std::sync::atomic::{AtomicU64, Ordering};
use std::sync::{LazyLock, OnceLock};
const METRIC: &str = "rustfs_s3_http_requests_total";
const METHODS: [&str; 10] = [
"GET", "PUT", "POST", "DELETE", "HEAD", "OPTIONS", "PATCH", "CONNECT", "TRACE", "OTHER",
];
const OUTCOMES: [&str; 8] = ["1xx", "2xx", "3xx", "4xx", "5xx", "unknown", "service_error", "cancelled"];
const UNKNOWN_OPERATION: usize = S3Operation::ALL.len();
static COUNTERS: LazyLock<HttpOutcomeCounters> = LazyLock::new(HttpOutcomeCounters::new);
tokio::task_local! {
static CURRENT_OPERATION: Cell<usize>;
}
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct S3HttpMetricSnapshot {
pub method: &'static str,
pub operation: &'static str,
pub outcome: &'static str,
pub total: u64,
}
struct OutcomeCounter {
total: AtomicU64,
exported: OnceLock<metrics::Counter>,
}
struct HttpOutcomeCounters(Box<[OutcomeCounter]>);
impl HttpOutcomeCounters {
fn new() -> Self {
Self(
std::iter::repeat_with(|| OutcomeCounter {
total: AtomicU64::new(0),
exported: OnceLock::new(),
})
.take(METHODS.len() * (UNKNOWN_OPERATION + 1) * OUTCOMES.len())
.collect(),
)
}
fn record(&self, method: usize, operation: usize, outcome: usize) {
let counter = &self.0[(method * (UNKNOWN_OPERATION + 1) + operation) * OUTCOMES.len() + outcome];
counter.total.fetch_add(1, Ordering::Relaxed);
counter
.exported
.get_or_init(|| {
counter!(METRIC, "method" => METHODS[method], "op" => operation_label(operation), "outcome" => OUTCOMES[outcome])
})
.increment(1);
}
fn snapshot(&self) -> Vec<S3HttpMetricSnapshot> {
// Individual series are monotonic; a concurrent snapshot is not a
// transaction across series. Rates must compare consecutive samples.
self.0
.iter()
.enumerate()
.filter_map(|(index, counter)| {
let total = counter.total.load(Ordering::Relaxed);
(total != 0).then(|| S3HttpMetricSnapshot {
method: METHODS[index / OUTCOMES.len() / (UNKNOWN_OPERATION + 1)],
operation: operation_label(index / OUTCOMES.len() % (UNKNOWN_OPERATION + 1)),
outcome: OUTCOMES[index % OUTCOMES.len()],
total,
})
})
.collect()
}
}
fn operation_label(index: usize) -> &'static str {
S3Operation::ALL.get(index).map_or("unknown", |op| op.as_str())
}
pub(crate) fn observe_s3_http_operation(op: S3Operation) {
let _ = CURRENT_OPERATION.try_with(|current| {
// Internal operations must not overwrite the external request's first
// dispatched operation. No task-local scope means non-HTTP work.
if current.get() == UNKNOWN_OPERATION {
current.set(op.metric_index());
}
});
}
/// An external request is counted exactly once: at response headers, at a
/// service error, or when its future is dropped before producing a response.
/// Body-stream failures after headers use the existing streaming metrics.
pub struct S3HttpRequestGuard {
method: usize,
operation: usize,
finished: bool,
}
impl S3HttpRequestGuard {
pub fn is_active() -> bool {
CURRENT_OPERATION.try_with(|_| ()).is_ok()
}
pub fn new(method: &str) -> Self {
Self {
method: METHODS.iter().position(|known| *known == method).unwrap_or(METHODS.len() - 1),
operation: UNKNOWN_OPERATION,
finished: false,
}
}
/// Attribute existing operation instrumentation without changing S3
/// handlers or propagating metric labels through storage/RPC contracts.
pub fn in_scope<T>(&mut self, f: impl FnOnce() -> T) -> T {
CURRENT_OPERATION.sync_scope(Cell::new(self.operation), || {
let result = f();
self.operation = CURRENT_OPERATION.with(Cell::get);
result
})
}
pub fn response(&mut self, status: u16) {
let outcome = match status {
100..=599 => usize::from(status / 100 - 1),
_ => 5,
};
self.finish(outcome);
}
pub fn service_error(&mut self) {
self.finish(6);
}
fn finish(&mut self, outcome: usize) {
if !self.finished {
COUNTERS.record(self.method, self.operation, outcome);
self.finished = true;
}
}
}
impl Drop for S3HttpRequestGuard {
fn drop(&mut self) {
self.finish(7);
}
}
pub fn s3_http_metrics_snapshot() -> Vec<S3HttpMetricSnapshot> {
COUNTERS.snapshot()
}
#[cfg(test)]
mod tests {
use super::*;
use metrics::with_local_recorder;
use metrics_util::debugging::DebuggingRecorder;
#[test]
fn outcome_counters_distinguish_partial_and_complete_write_failure() {
let counters = HttpOutcomeCounters::new();
let recorder = DebuggingRecorder::new();
with_local_recorder(&recorder, || {
for _ in 0..99 {
counters.record(1, S3Operation::PutObject.metric_index(), 1);
}
counters.record(1, S3Operation::PutObject.metric_index(), 4);
for _ in 0..100 {
counters.record(1, UNKNOWN_OPERATION, 4);
}
});
let snapshot = counters.snapshot();
assert_eq!(snapshot.iter().map(|series| series.total).sum::<u64>(), 200);
assert_eq!(
snapshot
.iter()
.find(|s| s.operation == S3Operation::PutObject.as_str() && s.outcome == "5xx")
.expect("write failure")
.total,
1
);
assert_eq!(
snapshot
.iter()
.find(|s| s.operation == "unknown")
.expect("pre-dispatch failures")
.total,
100
);
let exported = recorder.snapshotter().snapshot().into_vec();
assert_eq!(exported.len(), 3);
for (key, _, _, _) in exported {
let labels: Vec<_> = key.key().labels().map(|label| label.key()).collect();
assert_eq!(labels, ["method", "op", "outcome"]);
}
}
#[test]
fn request_guard_preserves_operation_across_polls_and_finishes_once() {
let totals = || {
s3_http_metrics_snapshot()
.into_iter()
.filter(|series| series.method == "CONNECT")
.map(|series| ((series.operation, series.outcome), series.total))
.collect::<std::collections::BTreeMap<_, _>>()
};
let before = totals();
let mut request = S3HttpRequestGuard::new("CONNECT");
request.in_scope(|| observe_s3_http_operation(S3Operation::PutObject));
request.in_scope(|| {
assert!(S3HttpRequestGuard::is_active());
observe_s3_http_operation(S3Operation::GetObject);
});
assert!(!S3HttpRequestGuard::is_active());
request.response(204);
request.response(503);
request.service_error();
drop(request);
let after = totals();
let key = (S3Operation::PutObject.as_str(), "2xx");
assert_eq!(after[&key] - before.get(&key).copied().unwrap_or_default(), 1);
assert_eq!(after.values().sum::<u64>() - before.values().sum::<u64>(), 1);
}
#[test]
fn request_operation_is_scoped_and_first_dispatch_wins() {
let mut request = S3HttpRequestGuard::new("PUT");
request.in_scope(|| {
observe_s3_http_operation(S3Operation::PutObject);
observe_s3_http_operation(S3Operation::GetObject);
});
assert_eq!(request.operation, S3Operation::PutObject.metric_index());
observe_s3_http_operation(S3Operation::GetObject);
let other = S3HttpRequestGuard::new("attacker-controlled-method");
assert_eq!(other.method, METHODS.len() - 1);
assert_eq!(other.operation, UNKNOWN_OPERATION);
}
}
+6 -3
View File
@@ -51,14 +51,17 @@ prior key versions would go green.
The lane creates real keys under unique names (`behavior-kv2-*`,
`behavior-transit-*`) and does not remove them, so a dev Vault accumulates them
across runs. Clear them out periodically — against a dev server only:
across runs. On a dev server, remove only exact keys confirmed to belong to the
current task. A shared prefix does not prove ownership; preserve another run's
keys and leave ambiguous keys for the operator.
```bash
vault list -format=json transit/keys | jq -r '.[] | select(startswith("behavior-transit-"))' | while read -r k; do vault write "transit/keys/$k/config" deletion_allowed=true >/dev/null && vault delete "transit/keys/$k"; done
vault write transit/keys/<task-owned-transit-key>/config deletion_allowed=true
vault delete transit/keys/<task-owned-transit-key>
```
```bash
vault list -format=json secret/metadata/rustfs/kms/keys | jq -r '.[] | select(startswith("behavior-kv2-"))' | xargs -I{} vault kv metadata delete secret/rustfs/kms/keys/{}
vault kv metadata delete secret/rustfs/kms/keys/<task-owned-kv2-key>
```
## Local Key Export for SSE-S3 Migration Tests
+60
View File
@@ -188,6 +188,30 @@ pub enum BackendByte {
pub struct StorageInfo {
pub disks: Vec<Disk>,
pub backend: BackendInfo,
/// Missing observations from older nodes are unknown, never proof of health.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub observations: Vec<StorageInfoObservation>,
}
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[serde(rename_all = "snake_case")]
pub enum StorageInfoProbeStatus {
Succeeded,
Failed,
#[default]
#[serde(other)]
Unknown,
}
#[derive(Clone, Debug, Default, Serialize, Deserialize, PartialEq, Eq)]
#[serde(default)]
pub struct StorageInfoObservation {
pub endpoint: String,
pub status: StorageInfoProbeStatus,
pub cached: bool,
pub last_success_unix_millis: Option<u64>,
pub snapshot_age_seconds: Option<u64>,
pub error_code: Option<String>,
}
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
@@ -879,6 +903,7 @@ mod tests {
},
],
backend: BackendInfo::default(),
..Default::default()
};
assert_eq!(storage_info.disks.len(), 2);
@@ -886,6 +911,40 @@ mod tests {
assert_eq!(storage_info.disks[1].state, "offline");
}
#[test]
fn storage_info_observation_is_additive_and_unknown_for_old_peers() {
#[derive(Serialize, Deserialize)]
struct LegacyStorageInfo {
disks: Vec<Disk>,
backend: BackendInfo,
}
let old = LegacyStorageInfo {
disks: Vec::new(),
backend: BackendInfo::default(),
};
let encoded = rmp_serde::to_vec_named(&old).expect("legacy map");
let decoded: StorageInfo = rmp_serde::from_slice(&encoded).expect("old peer response");
assert!(decoded.observations.is_empty());
let mut new = decoded;
new.observations.push(StorageInfoObservation {
endpoint: "node2:9000".into(),
status: StorageInfoProbeStatus::Failed,
cached: true,
last_success_unix_millis: Some(1_700_000_000_000),
snapshot_age_seconds: Some(5),
error_code: Some("Timeout".into()),
});
let encoded = rmp_serde::to_vec_named(&new).expect("new map");
let legacy: LegacyStorageInfo = rmp_serde::from_slice(&encoded).expect("old reader ignores new fields");
assert!(legacy.disks.is_empty());
let roundtrip: StorageInfo = rmp_serde::from_slice(&encoded).expect("new reader preserves observation");
assert_eq!(roundtrip.observations, new.observations);
let unknown: StorageInfoObservation =
serde_json::from_str(r#"{"endpoint":"node2","status":"future_state"}"#).expect("future state remains unknown");
assert_eq!(unknown.status, StorageInfoProbeStatus::Unknown);
assert_eq!(unknown.snapshot_age_seconds, None);
}
#[test]
fn test_backend_disks_new() {
let backend_disks = BackendDisks::new();
@@ -1391,6 +1450,7 @@ mod tests {
let storage_info = StorageInfo {
disks: vec![],
backend: BackendInfo::default(),
..Default::default()
};
let backend_info = BackendInfo::default();
let mem_stats = MemStats::default();
+110
View File
@@ -997,10 +997,56 @@ pub struct Metrics {
pub cpu: Option<CPUMetrics>,
#[serde(rename = "rpc", skip_serializing_if = "Option::is_none")]
pub rpc: Option<RPCMetrics>,
/// Absent means this node did not report HTTP outcomes, not zero traffic.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub http: Option<HttpMetrics>,
}
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
pub struct HttpMetrics {
#[serde(rename = "collected")]
pub collected_at: Timestamp,
pub requests: Vec<HttpRequestMetric>,
}
#[derive(Clone, Debug, Serialize, Deserialize, PartialEq, Eq)]
pub struct HttpRequestMetric {
pub method: String,
pub operation: String,
pub outcome: String,
pub total: u64,
}
impl HttpMetrics {
fn merge(&mut self, other: &Self) {
self.collected_at = self.collected_at.max(other.collected_at);
let mut totals = std::collections::BTreeMap::new();
for series in self.requests.drain(..).chain(other.requests.iter().cloned()) {
let total = totals
.entry((series.method, series.operation, series.outcome))
.or_insert(0_u64);
*total = total.saturating_add(series.total);
}
self.requests = totals
.into_iter()
.map(|((method, operation, outcome), total)| HttpRequestMetric {
method,
operation,
outcome,
total,
})
.collect();
}
}
impl Metrics {
pub fn merge(&mut self, other: &Self) {
if let Some(http) = &other.http {
match &mut self.http {
Some(existing) => existing.merge(http),
None => self.http = Some(http.clone()),
}
}
if let Some(scanner) = other.scanner.as_ref() {
match self.scanner {
Some(ref mut s_scanner) => s_scanner.merge(scanner),
@@ -1473,6 +1519,70 @@ mod tests {
Timestamp::constant(1_700_000_000, 123_456_000)
}
#[test]
fn http_metrics_merge_preserves_outcomes_and_missing_node_support() {
#[derive(Serialize, Deserialize, Default)]
#[serde(default)]
struct LegacyMetrics {
rpc: Option<RPCMetrics>,
}
let old_map = rmp_serde::to_vec_named(&LegacyMetrics::default()).expect("legacy map");
assert!(rmp_serde::from_slice::<Metrics>(&old_map).expect("new reader").http.is_none());
let missing: Metrics = serde_json::from_str("{}").expect("old node metrics");
assert!(missing.http.is_none());
let mut combined = RealtimeMetrics::default();
for (host, successes, failures) in [("node1", 99, 1), ("node2", 0, 100)] {
let metrics = Metrics {
http: Some(HttpMetrics {
collected_at: fixed_timestamp(),
requests: [("2xx", successes), ("5xx", failures)]
.into_iter()
.map(|(outcome, total)| HttpRequestMetric {
method: "PUT".into(),
operation: "s3:PutObject".into(),
outcome: outcome.into(),
total,
})
.collect(),
}),
..Default::default()
};
let encoded = rmp_serde::to_vec_named(&metrics).expect("peer metric map");
let old_reader: LegacyMetrics = rmp_serde::from_slice(&encoded).expect("old reader ignores HTTP field");
assert!(old_reader.rpc.is_none());
let decoded: Metrics = rmp_serde::from_slice(&encoded).expect("peer metric roundtrip");
combined.merge(RealtimeMetrics {
aggregated: decoded,
by_host: HashMap::from([(host.into(), metrics)]),
hosts: vec![host.into()],
..Default::default()
});
}
let aggregate = combined.aggregated.http.as_ref().expect("HTTP support");
assert_eq!(
aggregate
.requests
.iter()
.find(|s| s.outcome == "5xx")
.expect("failures")
.total,
101
);
assert_eq!(aggregate.requests.iter().map(|s| s.total).sum::<u64>(), 200);
assert_eq!(combined.by_host["node2"].http.as_ref().expect("node2").requests[1].total, 100);
combined.aggregated.merge(&missing);
assert_eq!(
combined
.aggregated
.http
.as_ref()
.expect("supported peers remain")
.requests
.len(),
2
);
}
#[test]
fn admin_metrics_timestamps_serialize_as_rfc3339_utc() {
let timestamp = fixed_timestamp();
+7 -7
View File
@@ -15,14 +15,14 @@ Keep changes narrow and source-driven.
## Source of Truth
Before changing behavior, read these files first:
Start with the file that owns the changed behavior; follow callers and shared
types only as needed:
- `src/scan.rs`
- `src/capacity_manager.rs`
- `src/capacity_scope.rs`
- `src/types.rs`
- `../../rustfs/src/capacity/service.rs`
- `../config/src/constants/capacity.rs`
- Scan/sampling: `src/scan.rs`.
- Refresh and per-disk cache state: `src/capacity_manager.rs`.
- Scope propagation: `src/capacity_scope.rs`; shared data shapes: `src/types.rs`.
- Admin integration: `../../rustfs/src/capacity/service.rs`.
- Configuration/defaults: `../config/src/constants/capacity.rs`.
Do not treat shell scripts or old docs as the authoritative behavior definition when the Rust code says otherwise.
+48 -2
View File
@@ -38,6 +38,7 @@ use rustfs_utils::path::{SLASH_SEPARATOR, path_join_buf};
use tokio::time::{Duration, Instant, sleep, timeout};
use tracing::{debug, warn};
use crate::raw_page_index::{RawEnumerationPageIndex, RawEnumerationPageOwnerStatus};
use crate::storage_api::owner::HTTPPreconditions;
use crate::{
BUCKET_META_PREFIX, EcstoreError as Error, EcstoreResult as StorageResult, RUSTFS_META_BUCKET, ReplicationConfig,
@@ -535,6 +536,10 @@ pub struct DataUsageEntryInfo {
pub name: String,
pub parent: String,
pub entry: DataUsageEntry,
/// Durable bucket incarnation that produced this bucket root. Missing
/// values are legacy/unproven and must not authorize cold-bucket reuse.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub bucket_incarnation: Option<uuid::Uuid>,
/// Registry generation used to classify this root entry. Older remote
/// workers omit it; callers must reject that result when a frozen cycle
/// requires generation fencing.
@@ -601,6 +606,8 @@ pub struct DataUsageCacheInfo {
pub scan_checkpoint: Option<DataUsageScanCheckpoint>,
#[serde(default)]
pub scan_raw_enumeration_cursor: Option<DataUsageRawEnumerationCursor>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub scan_raw_enumeration_page_index: Option<RawEnumerationPageIndex>,
#[serde(default)]
pub scan_identity: Option<DataUsageScanIdentity>,
#[serde(default)]
@@ -650,6 +657,11 @@ pub struct DataUsageCacheInfo {
/// structural plan remains reusable across ordinary bucket writes.
#[serde(default)]
pub scan_execution_digest: Option<DataUsageScanPlanDigest>,
/// Durable bucket incarnations captured for a complete set aggregate.
/// Missing or nil entries are legacy/unproven and cannot authorize
/// skipping an unselected bucket in a later scoped set scan.
#[serde(default, skip_serializing_if = "HashMap::is_empty")]
pub scan_bucket_incarnations: HashMap<String, uuid::Uuid>,
}
impl Serialize for DataUsageCacheInfo {
@@ -661,6 +673,7 @@ impl Serialize for DataUsageCacheInfo {
// appended by newer scanner versions during rolling upgrades.
let field_count = 16
+ usize::from(self.scan_raw_enumeration_cursor.is_some())
+ usize::from(self.scan_raw_enumeration_page_index.is_some())
+ usize::from(self.scan_identity.is_some())
+ usize::from(self.scan_progress.is_some())
+ usize::from(self.scan_coverage_receipt.is_some())
@@ -672,7 +685,8 @@ impl Serialize for DataUsageCacheInfo {
+ usize::from(self.lkg_last_update.is_some())
+ usize::from(self.lkg_leader_epoch.is_some())
+ usize::from(self.lkg_scan_plan_digest.is_some())
+ usize::from(self.scan_execution_digest.is_some());
+ usize::from(self.scan_execution_digest.is_some())
+ usize::from(!self.scan_bucket_incarnations.is_empty());
let mut state = serializer.serialize_map(Some(field_count))?;
state.serialize_entry("name", &self.name)?;
state.serialize_entry("next_cycle", &self.next_cycle)?;
@@ -687,6 +701,9 @@ impl Serialize for DataUsageCacheInfo {
if let Some(cursor) = &self.scan_raw_enumeration_cursor {
state.serialize_entry("scan_raw_enumeration_cursor", cursor)?;
}
if let Some(index) = &self.scan_raw_enumeration_page_index {
state.serialize_entry("scan_raw_enumeration_page_index", index)?;
}
if let Some(identity) = self.scan_identity {
state.serialize_entry("scan_identity", &identity)?;
}
@@ -729,6 +746,9 @@ impl Serialize for DataUsageCacheInfo {
if let Some(scan_execution_digest) = self.scan_execution_digest {
state.serialize_entry("scan_execution_digest", &scan_execution_digest)?;
}
if !self.scan_bucket_incarnations.is_empty() {
state.serialize_entry("scan_bucket_incarnations", &self.scan_bucket_incarnations)?;
}
state.end()
}
}
@@ -895,6 +915,7 @@ impl DataUsageCache {
&& self.info.scan_progress.is_none()
&& self.info.scan_checkpoint.is_none()
&& self.info.scan_raw_enumeration_cursor.is_none()
&& self.info.scan_raw_enumeration_page_index.is_none()
&& self.info.scan_resume_after.is_none()
&& self.info.scan_coverage_receipt.is_none()
&& self.info.scan_plan_digest == Some(scan_plan_digest)
@@ -922,12 +943,17 @@ impl DataUsageCache {
if self.validated_raw_enumeration_cursor().is_none() {
self.info.scan_raw_enumeration_cursor = None;
}
if self.validated_raw_enumeration_page_index().is_none() {
self.info.scan_raw_enumeration_page_index = None;
}
let cursor_is_valid = (self.info.scan_checkpoint.is_none()
&& self.info.scan_raw_enumeration_cursor.is_none()
&& self.info.scan_raw_enumeration_page_index.is_none()
&& self.info.scan_resume_after.is_none()
&& self.info.scan_coverage_receipt.is_none())
|| self.validated_scan_frontier().is_some()
|| self.info.scan_raw_enumeration_cursor.is_some();
|| self.info.scan_raw_enumeration_cursor.is_some()
|| self.info.scan_raw_enumeration_page_index.is_some();
if !cursor_is_valid {
self.info.scan_progress = None;
}
@@ -949,6 +975,7 @@ impl DataUsageCache {
self.info.scan_resume_after = None;
self.info.scan_checkpoint = None;
self.info.scan_raw_enumeration_cursor = None;
self.info.scan_raw_enumeration_page_index = None;
self.info.scan_coverage_receipt = None;
}
// Old readers do not understand coverage sweeps. An absent plan makes
@@ -1026,6 +1053,25 @@ impl DataUsageCache {
.then_some(cursor)
}
pub(crate) fn validated_raw_enumeration_page_index(&self) -> Option<&RawEnumerationPageIndex> {
let index = self.info.scan_raw_enumeration_page_index.as_ref()?;
if self.info.scan_progress.is_none()
|| !self.info.scan_identity.is_some_and(|identity| identity.is_valid())
|| self.info.source.is_none()
|| index.committed_entries().is_err()
|| index.indexed_entries().is_err()
{
return None;
}
let parent = match index.status() {
RawEnumerationPageOwnerStatus::Unsupported => return None,
RawEnumerationPageOwnerStatus::Building { parent, .. } | RawEnumerationPageOwnerStatus::Ready { parent, .. } => {
parent
}
};
path_is_in_bucket_scope(&self.info.name, &parent).then_some(index)
}
/// Seal only the frontier supplied by completed traversal, never a restored cursor.
pub(crate) fn seal_scan_frontier(&mut self, frontier: Option<&str>) -> Result<(), serde_json::Error> {
if self.info.scan_progress.is_none() {
@@ -1179,6 +1179,7 @@ fn test_new_data_usage_cache_msgpack_round_trips_and_supports_old_reader() {
7,
[7; 32],
)),
scan_raw_enumeration_page_index: Some(raw_page_index_fixture("bucket/prefix", &["entry-a"], false)),
snapshot_complete: true,
scan_plan_digest: Some(TEST_PLAN_DIGEST),
scan_execution_digest: Some(DataUsageScanPlanDigest([42; 32])),
@@ -1207,6 +1208,7 @@ fn test_new_data_usage_cache_msgpack_round_trips_and_supports_old_reader() {
.map(|cursor| cursor.last_entry.as_deref()),
Some(Some("last-object"))
);
assert!(current.info.scan_raw_enumeration_page_index.is_some());
assert!(current.info.snapshot_complete);
assert_eq!(current.info.scan_plan_digest, Some(TEST_PLAN_DIGEST));
assert_eq!(current.info.scan_execution_digest, Some(DataUsageScanPlanDigest([42; 32])));
@@ -1260,6 +1262,24 @@ fn cache_with_raw_cursor(cursor: DataUsageRawEnumerationCursor) -> DataUsageCach
}
}
fn raw_page_index_fixture(parent: &str, entries: &[&str], complete: bool) -> RawEnumerationPageIndex {
let mut index = RawEnumerationPageIndex::new(parent, 2).expect("raw page index should initialize");
let generation = index.generation().expect("raw page index should expose generation");
let outcome = if complete {
index.ingest_owner_entries(entries.iter().map(|entry| (*entry).to_string()), entries.len().max(1), generation)
} else {
index.ingest_partial_owner_entries(entries.iter().map(|entry| (*entry).to_string()), entries.len().max(1), generation)
}
.expect("raw page index fixture should ingest entries");
if outcome.ready_to_commit {
let generation = index.generation().expect("raw page index should expose commit generation");
index
.commit_building_page(generation)
.expect("raw page index fixture should commit ready page");
}
index
}
#[test]
fn raw_enumeration_cursor_validation_requires_bucket_identity_and_bounded_marker() {
let valid = DataUsageRawEnumerationCursor::new("bucket/raw".to_string(), Some("entry-001".to_string()), 1, [8; 32]);
@@ -1346,6 +1366,44 @@ fn prepare_bucket_checkpoint_preserves_only_valid_raw_enumeration_cursor() {
assert!(cache.info.scan_progress.is_some());
}
#[test]
fn prepare_bucket_checkpoint_preserves_only_valid_raw_page_index() {
let identity = valid_scan_identity();
let source = DataUsageCacheSource::new(1, 2);
let page_index = raw_page_index_fixture("bucket/raw", &["entry-001"], false);
let mut cache = DataUsageCache {
info: DataUsageCacheInfo {
name: "bucket".to_string(),
leader_epoch: 1,
source: Some(source),
cache_key_format: DATA_USAGE_CACHE_KEY_FORMAT,
scan_identity: Some(identity),
tier_registry_generation: Some(9),
scan_progress: Some(DataUsageScanProgress {
started_plan: TEST_PLAN_DIGEST,
requested_plan: TEST_PLAN_DIGEST,
}),
scan_raw_enumeration_page_index: Some(page_index.clone()),
..Default::default()
},
..Default::default()
};
assert_eq!(
cache.prepare_bucket_checkpoint("bucket", 1, 1, source, TEST_PLAN_DIGEST, identity),
DataUsageCachePrepareOutcome::Reused
);
assert_eq!(cache.info.scan_raw_enumeration_page_index, Some(page_index));
let invalid = raw_page_index_fixture("other/raw", &["entry-001"], false);
cache.info.scan_raw_enumeration_page_index = Some(invalid);
assert_eq!(
cache.prepare_bucket_checkpoint("bucket", 1, 1, source, TEST_PLAN_DIGEST, identity),
DataUsageCachePrepareOutcome::Reused
);
assert!(cache.info.scan_raw_enumeration_page_index.is_none());
assert!(cache.info.scan_progress.is_some());
}
/// Deterministic, fully populated cache used to pin the persisted
/// `.usage-cache.bin` wire bytes. Every map/set holds at most one element
/// so the map-encoded `marshal_msg` output is byte-stable.
+3
View File
@@ -60,6 +60,7 @@ use uuid::Uuid;
pub mod data_usage_define;
pub mod error;
pub mod prefix_usage;
pub mod raw_page_index;
mod remote_scanner;
pub mod runtime_config;
pub mod scanner;
@@ -68,6 +69,8 @@ pub mod scanner_folder;
#[cfg(test)]
mod scanner_heal_admission_baseline;
pub mod scanner_io;
#[doc(hidden)]
pub mod segment_invalidation;
pub mod sleeper;
pub(crate) mod storage_api;
mod workload_admission;
File diff suppressed because it is too large Load Diff
@@ -195,6 +195,7 @@ fn test_usage(bucket: &str, objects: usize) -> DataUsageEntryInfo {
name: bucket.to_string(),
parent: crate::DATA_USAGE_ROOT.to_string(),
entry,
bucket_incarnation: Some(Uuid::from_u128(7)),
tier_registry_generation: Some(0),
}
}

Some files were not shown because too many files have changed in this diff Show More