Skip to content

fix: the fan-out decision belongs to the object, not the write config - #234

Merged
scttfrdmn merged 1 commit into
mainfrom
fix/228-object-keyed-fanout
Aug 3, 2026
Merged

scttfrdmn merged 1 commit into
mainfrom
fix/228-object-keyed-fanout

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #228.

The defect

The gate selecting the parallel range-read path asked b.compressor.Enabled(), which reports the local write configuration and says nothing about the object named by the key. Configuring compression therefore turned fan-out off for every object in the bucket — objects never compressed, objects below min_size, objects where compression did not help, objects written by other tools.

Declining the fan-out for a compressed object is right: a zstd or gzip frame must be decoded from its start, so there is no set of independent ranges to assemble. The defect was the scope, and who paid for it. Most research data does not compress (#184), so the objects that gained nothing from compression were the same ones losing parallel reads because of it — v0.10.0's headline feature switched off bucket-wide by an unrelated setting.

This is audit finding C4 one line above C4's own fix, and it survived for the reason C4 did not: it fails quietly. C4 moved bytes that did not need moving, which a byte-count assertion catches. This merely declined an optimization — nothing failed, nothing was logged.

The fix

The decision is now the object's, by the approach #228 argued for. Where GetObject already needs a HEAD for the chunk arithmetic, the encoding answer comes free with it. Otherwise the fan-out is attempted and abandoned when a chunk's response carries a Content-Encoding, which keeps the cost on compressed objects — which already pay a whole-object fetch — rather than adding a HEAD to every large read.

One thing the issue got wrong, in the direction that matters. #228 says "not a correctness problem — reads return the right bytes either way." One route does not. A compressed object read at an offset past the end of its stored body produces nothing but 416s, so no chunk ever sees a response header to learn the encoding from — and the recorded finding for an unsatisfiable range is "the object shrank mid-read", which is right when the object is not encoded and reports DATA_CORRUPTION on a perfectly readable object when it is. This is ordinary rather than exotic: the stored body is a fraction of the size the caller was told, so reads land past its end constantly. One HEAD after the fan-out has already failed distinguishes the two readings, only for the reads that hit the ambiguity.

errFanOutOnEncodedObject is a bare sentinel rather than a typed error because it is a routing signal, not a failure, and it must not reach translateError — an unrecognized error classifies as a service failure and would degrade s3-reads on a read that is about to succeed.

Acceptance criteria

  • A read above the threshold of an uncompressed object fans out even with compression enabled
  • A read above the threshold of a compressed object does not fan out, and returns correct bytes
  • Test asserts the number and shape of GETs against the substrate endpoint, in the style of read_amplification_test.go
  • A test that would have caught the original: same object, same read, Compression.Enabled toggled, asserting the fan-out is unchanged

Every test verified against a mutation

Not assumed to have teeth — each was run against a deliberately broken build.

test mutation result
TestFanOutIsDecidedByTheObjectNotTheConfig restore the v0.10.0 config-keyed gate fails only the compression-on case: issued 1 GETs ... want 8
TestFanOutOnACompressedObjectFallsBackAndStaysCorrect remove the per-chunk encoding check (the naive always-fan-out fix) returned bytes that do not match body[0:2097152] — wrong bytes with every request succeeding
same remove the HEAD disambiguation DATA_CORRUPTION: the object is shorter than the read's size on a readable object
TestFanOutFallbackLeavesNoHealthErrors classify the 416 as ErrCodeStorageRead left s3-reads holding a failure: "STORAGE_READ: S3 refused the requested byte range"

The health test was rewritten because its first two forms had no teeth, and that was found by measuring rather than by reasoning. Both of these pass with the 416 deliberately misclassified:

  1. "read the object repeatedly and check none of the reads errors" — s3-reads never reaches the threshold in consecutive errors, because the whole-object re-read that follows every fallback records a success.
  2. ConsecutiveErrors == 0 — RecordSuccess decrements, and the abandoned sibling chunks record successes too, so the counter is back at zero by the time the read returns even though the failures were counted on the way through.

The mutation produced ConsecutiveErrors=0, state=healthy, LastErrorMessage="STORAGE_READ: S3 refused the requested byte range" — so the recorded error is the only durable witness at this scale. The test comment records that, so the next person does not reach for the counter. What makes this worth pinning is not one read: it is a mount reading many compressed objects with no successes to spare in between, where a degraded s3-reads refuses reads at the top of GetObject and one compressed object takes unrelated, perfectly readable objects offline with it.

TestFanOutOnAnUncompressedObjectCostsNoExtraHead pins the cost side of the design choice #228 asked for a decision on, so adding a HEAD to the common path cannot regress silently.

Docs

Cost 3 in docs/features/compression.md described the bucket-wide behavior as current; it now describes what compressed objects give up and records what was fixed. The now-wrong comment in config_seam_test.go ("Compression gates the parallel path off entirely") is corrected.

Verification

  • go test -race ./... — exit 0, all packages
  • golangci-lint run --new-from-merge-base=origin/main — 0 issues (one usestdlibvars fix applied)
  • Pre-commit hooks clean, no files modified

The gate selecting the parallel range-read path asked b.compressor.Enabled(),
which reports the local write configuration and says nothing about the object
named by the key. So configuring compression turned fan-out off for every
object in the bucket — objects never compressed, objects below min_size,
objects where compression did not help, objects written by other tools.

Declining the fan-out for a compressed object is right: a zstd or gzip frame
must be decoded from its start, so there is no set of independent ranges to
assemble. The defect was the scope, and who paid for it. Most research data
does not compress, so the objects that gained nothing from compression were
the same ones losing parallel reads because of it — v0.10.0's headline feature
switched off bucket-wide by an unrelated setting.

This is audit finding C4 one line above C4's own fix, and it survived for the
reason C4 did not: it fails quietly. C4 moved bytes that did not need moving,
which a byte-count assertion catches. This merely declined an optimization.

The decision is now the object's. Where GetObject already needs a HEAD for the
chunk arithmetic, the encoding answer comes free with it. Otherwise the fan-out
is attempted and abandoned when a chunk's response carries a Content-Encoding,
which keeps the cost on compressed objects — which already pay a whole-object
fetch — rather than adding a HEAD to every large read. That is the approach
#228 argued for.

The subtle case is a compressed object read at an offset past the end of its
stored body. The stored body is a fraction of the size the caller was told, so
this is ordinary rather than exotic, and it produces nothing but 416s: no chunk
ever sees a response header to learn the encoding from. The recorded finding
for an unsatisfiable range is "the object shrank mid-read", which is right when
the object is not encoded and reports DATA_CORRUPTION on a readable object when
it is. One HEAD after the fan-out has already failed distinguishes them, only
for the reads that hit the ambiguity.

errFanOutOnEncodedObject is a bare sentinel rather than a typed error because
it is a routing signal, not a failure, and it must not reach translateError —
an unrecognized error classifies as a service failure and would degrade
s3-reads on a read that is about to succeed.

Four tests, each verified against a mutation rather than assumed to have teeth:

  - TestFanOutIsDecidedByTheObjectNotTheConfig runs the same read of the same
    uncompressed object with Compression.Enabled both ways and asserts eight
    GETs each time. Restoring the old gate fails only the compression-on case,
    which is the shape the defect had.
  - TestFanOutOnACompressedObjectFallsBackAndStaysCorrect reads at two offsets
    — inside the stored body and past its end — asserting correct bytes and an
    unranged GET. Removing the per-chunk encoding check returns wrong bytes
    with every request succeeding, which is what a naive always-fan-out fix
    does; removing the HEAD disambiguation reports DATA_CORRUPTION.
  - TestFanOutFallbackLeavesNoHealthErrors asserts s3-reads holds no recorded
    failure. Two weaker forms were written first and both passed with the 416
    deliberately classified as a service failure: a later read still succeeds
    because s3-reads never reaches the threshold in consecutive errors, and
    ConsecutiveErrors returns to zero because RecordSuccess decrements and the
    whole-object re-read supplies one. LastErrorMessage is the only durable
    witness at this scale. The comment records what the mutation produced.
  - TestFanOutOnAnUncompressedObjectCostsNoExtraHead pins the cost side of the
    design choice, so adding a HEAD to the common path cannot regress silently.

Also corrects the now-wrong comment in config_seam_test.go and cost 3 in
docs/features/compression.md, which described the bucket-wide behavior as
current.

Closes #228
@scttfrdmn
scttfrdmn enabled auto-merge (squash) August 3, 2026 02:32
@scttfrdmn
scttfrdmn merged commit 5aafd53 into main Aug 3, 2026
23 checks passed
@scttfrdmn
scttfrdmn deleted the fix/228-object-keyed-fanout branch September 20, 2026 05:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Parallel range reads are disabled bucket-wide when compression is merely configured

1 participant