Repository navigation
fix: the fan-out decision belongs to the object, not the write config - #234
Merged
Merged
Conversation
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 belowmin_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
GetObjectalready 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 aContent-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_CORRUPTIONon 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.errFanOutOnEncodedObjectis a bare sentinel rather than a typed error because it is a routing signal, not a failure, and it must not reachtranslateError— an unrecognized error classifies as a service failure and would degrades3-readson a read that is about to succeed.Acceptance criteria
read_amplification_test.goCompression.Enabledtoggled, asserting the fan-out is unchangedEvery test verified against a mutation
Not assumed to have teeth — each was run against a deliberately broken build.
TestFanOutIsDecidedByTheObjectNotTheConfigissued 1 GETs ... want 8TestFanOutOnACompressedObjectFallsBackAndStaysCorrectreturned bytes that do not match body[0:2097152]— wrong bytes with every request succeedingDATA_CORRUPTION: the object is shorter than the read's sizeon a readable objectTestFanOutFallbackLeavesNoHealthErrorsErrCodeStorageReadleft 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:
s3-readsnever reaches the threshold in consecutive errors, because the whole-object re-read that follows every fallback records a success.ConsecutiveErrors == 0—RecordSuccessdecrements, 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 degradeds3-readsrefuses reads at the top ofGetObjectand one compressed object takes unrelated, perfectly readable objects offline with it.TestFanOutOnAnUncompressedObjectCostsNoExtraHeadpins 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.mddescribed the bucket-wide behavior as current; it now describes what compressed objects give up and records what was fixed. The now-wrong comment inconfig_seam_test.go("Compression gates the parallel path off entirely") is corrected.Verification
go test -race ./...— exit 0, all packagesgolangci-lint run --new-from-merge-base=origin/main— 0 issues (oneusestdlibvarsfix applied)