Repository navigation
fix: a mount reads every compression algorithm it can write (#230) - #243
Merged
Merged
Conversation
…red one A bucket outlives its configuration. Objects accumulate across mounts, across releases, and across whatever `compression.algorithm` was set to at the time, so the algorithm a mount is configured to *write* says nothing about the algorithm of the object in front of it. The read path did not accept that. `Compressor` held exactly one codec and `Decompress` compared the object's stored `Content-Encoding` against that codec's token, returning the data unchanged on any mismatch — so a mount could read back only what it was currently configured to write. Switching `algorithm: zstd` to `lz4` made every existing zstd object unreadable, and so did `enabled: false`, which is how an operator turns compression off after deciding the read amplification was not worth it. That is the change most likely to be made and least likely to be expected to break anything: turning compression off stops new objects being compressed, it does not make the existing ones uncompressed. Nobody got wrong bytes. `checkFullyDecoded` cross-checks the decoded length against the recorded `objectfs-original-size` and fails closed, so the four readings in the issue produced one correct result and three DATA_CORRUPTION errors rather than three raw frames with exit status 0. But that guard was compensating for a dispatch that could have succeeded — every codec was already linked into the same binary. `Compressor` now holds a decoder per Content-Encoding token, built at construction from `pkg/compression.SupportedAlgorithms` rather than listed by hand. The derivation is the fix rather than the map: #230's actual shape was a set of encoders and a set of decoders maintained independently, and a hand-listed table would reintroduce exactly that. Keyed on the token because that is what the object carries; `ContentEncoding()` is a separate method from `Algorithm()` precisely so a codec may have them differ. `Decompress` returns a second value reporting whether a codec was found. False with a nil error means the bytes came back untouched, and only the caller can say what that means: a foreign coding is another tool's format and passing it through is what every S3 client does, while an ObjectFS-compressed object arriving undecoded is an integrity failure. `checkFullyDecoded` is where those are told apart, because `objectfs-original-size` is only in hand there. A body its own declared codec *rejects* is now reported as non-retryable corruption rather than a bare wrapped error the retry layer would take at face value — retrying decodes the same frame and fails the same way. Tests, at both layers: - `internal/compression` — the full write × read matrix from SupportedAlgorithms in both directions, a disabled compressor that still decodes, the derivation itself (every writable token has a decoder), and the two failure modes separated: unknown token passes through, claimed token over a bad body errors. - `internal/storage/s3` — the issue's failure table generalized, one object per writable algorithm read by every algorithm and by a disabled mount, with an assertion that the stored object actually compressed so a pass cannot come from an object that was never encoded. Plus the ranged-read shape, which is where a silent failure hides best: `checkFullyDecoded` deliberately does not fire on a partial read, since a short range is legitimately short. Two existing tests changed rather than being added to, and both were asserting the old behavior: - `TestUndecodableObjectFailsClosed`'s "cannot decode" case used `lz4`, which is now decodable; it would have been asserting that a readable object is refused. Replaced with `br` — a registered coding ObjectFS does not implement, which is the realistic version: a bucket shared with a tool that writes brotli. - `TestRoundTripAcrossACodecChange` accepted a fail-closed read as an acceptable outcome. It is a failure now. There is no configuration of this mount that legitimately cannot read an object this mount's codecs can decode. Verified by mutation, five mutants, all caught: M1 dispatch on the configured codec (the original defect) 32 subtests M2 decoder table hand-listed as zstd only 19 subtests M3 swallow a corrupt frame, return the bytes 1 M4 a disabled compressor decodes nothing 7 subtests M5 backend gates the decode on its own encoding 14 subtests `docs/features/compression.md` said "do not change `algorithm` once a bucket holds compressed objects" and named the fail-closed error as the consequence. It now says the algorithm is safe to change and `enabled: false` is safe, dates that to v0.11.0, and keeps the one-way door that is real: the *format*, not the algorithm — a compressed object is still only readable by something that understands its Content-Encoding. Three stale comments corrected in the same pass, in `backend.go`'s fail-closed rationale, `vfs/errors.go`'s ErrIntegrity, and the compression package's own doc: a codec mismatch is no longer among the ways to reach an integrity error, and saying it is would send an operator to change a setting that cannot help. Closes #230
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 #230.
The defect
A bucket outlives its configuration.
Compressorheld exactly one codec andDecompresscompared the object's storedContent-Encodingagainst that codec's token, returning the data unchanged on any mismatch — so a mount could read back only what it was currently configured to write.The issue's verified table, one object written
algorithm: zstdand read by four backends differing only in that field:algorithm: zstdalgorithm: gzipDATA_CORRUPTIONalgorithm: lz4DATA_CORRUPTIONenabled: falseDATA_CORRUPTIONThe last row is the one that matters most. Setting
enabled: falseis how an operator turns compression off after deciding the read amplification was not worth it — the change most likely to be made and least likely to be expected to break anything. Turning compression off stops new objects being compressed; it does not make the existing ones uncompressed.Nobody got wrong bytes:
checkFullyDecodedcross-checks the decoded length againstobjectfs-original-sizeand fails closed. But that guard was compensating for a dispatch that could have succeeded — every codec was already linked into the same binary.The fix
Compressorholds a decoder per Content-Encoding token, built at construction frompkg/compression.SupportedAlgorithmsrather than listed by hand. The derivation is the fix rather than the map: #230's actual shape was a set of encoders and a set of decoders maintained independently, and a hand-listed table would reintroduce exactly that. Adding an algorithm toSupportedAlgorithmsmakes it readable with no second edit.Decompressgained a second return reporting whether a codec was found, because two cases have to be told apart and only the caller can do it:decoded=false, no error. A coding ObjectFS does not implement belongs to whatever tool wrote it, andaws s3 cphands back the same bytes.checkFullyDecodedis what refuses it if the object is one ObjectFS compressed, and it can tell, because only those carryobjectfs-original-size.DATA_CORRUPTION, rather than the bare wrapped error the retry layer would previously have taken at face value. Retrying decodes the same frame and fails the same way.Tests, at both layers
internal/compression/decoders_test.go— the write × read matrix fromSupportedAlgorithmsin both directions; a disabled compressor that still decodes; the derivation itself (every writable token has a decoder, sorted, no empty token); the two failure modes separated.internal/storage/s3/compression_algorithm_change_test.go— the issue's table generalized to every writable algorithm × (every algorithm + disabled), through a real HTTP endpoint. It asserts the stored object actually compressed before reading it back, so a pass cannot come from an object that was never encoded. Plus the ranged-read shape, which is where a silent failure hides best:checkFullyDecodeddeliberately does not fire on a partial read, because a short range is legitimately short and the length alone cannot distinguish it from a still-encoded body.Two existing tests changed rather than added to, both asserting the old behavior:
TestUndecodableObjectFailsClosed's "cannot decode" case usedlz4, now decodable — it would have asserted that a readable object is refused. Replaced withbr: a registered coding ObjectFS does not implement, which is the realistic version (a bucket shared with a tool that writes brotli).TestRoundTripAcrossACodecChangeaccepted a fail-closed read as acceptable. It is a failure now. There is no configuration of this mount that legitimately cannot read an object this mount's codecs can decode.Mutation verification
Per the project's practice of breaking the code and watching the test fail rather than predicting a signature. Five mutants, all caught:
M5 is the one that matters for test placement: it confirms the S3-layer tests are not riding on the compression package's coverage.
Documentation
docs/features/compression.mdsaid "do not changealgorithmonce a bucket holds compressed objects" and named the fail-closed error as the consequence. It now says the algorithm is safe to change andenabled: falseis safe, dates that to v0.11.0, and keeps the one-way door that is real: the format, not the algorithm — a compressed object is still only readable by something that understands itsContent-Encoding, which is cost #1 on that page.Three stale comments corrected in the same pass —
backend.go's fail-closed rationale,vfs/errors.go'sErrIntegrity, and the compression package's own doc. A codec mismatch is no longer among the ways to reach an integrity error, and saying it is would send an operator to change a setting that cannot help. What can still reach it: a coding ObjectFS does not implement, and a header stripped after the write — aCopyObjector a tier transition does not carry it.Gates
go build ./...,go vet ./...cleango test -race ./internal/... ./pkg/...all passgolangci-lint run --new-from-merge-base=origin/main→ 0 issuesinternal/compression88.6% (floor raised 87 → 88),internal/storage/s382.3% (floor 81)