Repository navigation
feat(s3): serve ranged reads of a framed object from its frames (#185 stage 3) - #516
Conversation
…stage 3) Stages 1 and 2 made a compressed object seekable; this is what makes a ranged read of one cheap. A 4 KiB read of a 1 MiB ~50%-compressible object went from transferring the whole 1,074,071-byte stored body to 134,554 bytes: the frame index plus the one frame covering the offset. The saving scales with the object rather than the read. readFramed sizes its first request from the objectfs-seekable descriptor the write path records, parses the index, and fetches the frames covering the range as one Range — CompressFramed lays frames down contiguously, so a contiguous span of content is a contiguous span of stored bytes. Both encoded arms of GetObject's switch try it: the 206 arm, and the 416 arm that a large well-compressed object is most often read through. Integrity is per frame and, for a partial read, stronger than what it replaces. The whole-content objectfs-sha256 cannot be checked by a read that deliberately never holds the whole content, so DecodeFrames verifies each frame's SHA-256 against the index instead — covering exactly the bytes returned, at frame granularity. A read covering every frame is sent down the whole-object path, which restores the whole-content check and is also the cheaper request. A frame that does not match its hash is non-retryable DATA_CORRUPTION rather than a fallback: the whole-object path is not a second opinion, since the same damaged bytes are in that stream too. Every other decline is counted with its reason, because none of them fails. A declined framed read still returns the object byte for byte, so the failure mode is a silent return to whole-object transfer with no evidence attached. Hence seekable_reads, seekable_read_bytes, seekable_whole_fallbacks and seekable_last_fallback_reason, each decline logged at warn rather than debug, and an object that was never framed left uncounted so the number does not become a measure of how much of the bucket is unframed. An overwrite between the index fetch and the frame fetch is otherwise entirely silent — both succeed, the lengths add up, and the frames are decoded against an index that no longer describes them. The two ETags are compared and a mismatch falls back. ETag comparison rather than If-Match, per CLAUDE.md's rule about establishing capabilities by probing: a store that accepts a precondition and ignores it is indistinguishable from one that honours it, and a comparison of two values this process holds cannot be silently dropped. Tests: a 50-case sweep either side of every frame boundary, aimed at the frame-relative slice, whose failure mode is a uniform shift that errors nothing and has the right length; the byte budget on both discovery routes, derived from the object's own index; all five fallback reasons reached with real damaged fixtures and the recorded reason asserted, since every one of these states declines and a table checking only "a fallback happened" would pass with every reason wired to the same string; the uncounted no-descriptor case; the mid-read overwrite, made deterministic with Fault.OnFire; and the damaged-frame hard error. Two existing tests asserted the pre-framing invariant and both had said in their own comments that this was the change on which to revisit them rather than quietly satisfy them, so both are revisited: read_amplification_test's whole-body-was-transferred check becomes a budget, and parallel_read_encoding_test's "an unranged GET was issued" is inverted to "every GET was ranged". Both gain a guard asserting the fixture actually framed, so neither can pass vacuously. Filed #514: above parallel_read_threshold the fan-out is attempted first and abandoned on finding the object encoded, and the chunks already launched have by then transferred bytes framing would have avoided — 98% of the stored body in the worst measured case. Bounded by concurrency x chunk size and correct in every case, but it defeats framing where framing is worth most.
…ted (#185) A mutation run over stage 3 caught 12 of 18 seeded defects. The five survivors and what each needed: - A read at exactly offset == UncompressedSize. This is the last request of every full-file read, and an off-by-one there is invisible to a correctness test because the whole-object fallback returns the same empty slice. The assertion is the request count and the fallback counter, not the bytes. - Damaged frames. The existing test asserted a corruption error, which the fallback path also produces: reading the object whole fails its own objectfs-sha256 check over the same damaged bytes. It now asserts which check fired, via the message and the frame-level details only the framed path has. - Open-ended reads (size <= 0). Resolving the length to UncompressedSize instead of UncompressedSize-offset still returns correct bytes, because FramesCovering clamps; it just fetches every frame to the end of the object. Asserted as a transfer budget. - A non-zstd body carrying a seekable descriptor, read past the end of its stored body. That 416 route is where the post-index decoder check is the only decoder check there is; the previous fixture took the 206 route and was declined by the pre-fetch check instead. - DecodeFrames and FrameDecoder had no direct tests at all. The body-length guard is unreachable from the backend, which computes the Range from the same index, so it is tested against the function: truncated, over-long, the whole object, and empty, each asserted to wrap ErrIndexCorrupt rather than to fail some later frame hash.
CI pins golangci-lint v2.12.2, which reports eight findings this branch introduced. None is a defect; all eight are house style. The three `tparallel` findings are the interesting ones. Each of the three tests they name shares one backend and asserts on that backend's request log and metrics, so their subtests cannot run in parallel — the transfer budget a subtest checks is only meaningful if no other subtest is issuing requests into the same recorder. `paralleltest` reports that at the range statement and `tparallel` reports it at the function declaration, so a test that legitimately cannot parallelise needs a suppression in both places.
|
The That is the unlocked Worth noting what the stack adds: the body is being read on the transport's goroutine via So this PR needs #515 in |
…an be verified This is #515's change to internal/testaws/recorder.go, unmodified except for its comment, and it is here only so that stage 3 gets a CI signal that means something. The canonical fix is #515, and the CHANGELOG entry stays there rather than being duplicated here — whichever merges first makes the other's copy a no-op. The reason it cannot wait: this branch's `test` job failed twice in a row on that race, in a file this branch does not touch. Locally the race reports about one run in twenty; under CI's load, with the ~1000 lines of extra parallel test this branch adds, it is reliable. So without the fix there is no way to tell a real stage-3 regression from the flake, which makes the whole gate uninformative. The comment is updated with what those two failures taught: the interleaving that actually happens is the proxy forwarding the request body to the upstream on the transport's goroutine, via transferWriter.doBodyCopy, while a test calls GETs(). The comment previously recorded only the two dead ends for forcing it deliberately and described the detector as weak, which understates it — weak locally, reliable under load.
The comment described the detector as weak — about one run in twenty locally — and listed only the two dead ends for forcing the interleaving deliberately. #516's `test` job then failed on this race twice in a row, on a branch touching only internal/compression and internal/storage/s3, which says two things the comment did not. Under load the race is not rare. The extra parallel test load of an unrelated branch was enough to make it reliable, and the report it produces names a file that branch's author never touched — the expensive kind of flake, since the first hour goes into an innocent diff. And the interleaving that actually occurs is a third route, neither of the two the comment ruled out: the reverse proxy forwarding the request body to the upstream on the transport's own goroutine, via transferWriter.doBodyCopy, while a test calls GETs(). That is the window this lock closes, so it belongs in the stack sketch rather than the persistConn.writeLoop frame that was there. Comment only; no behaviour change.
|
Green: 42 pass, 1 skip, no failures. Worth recording what the sequence proves, because it is a cleaner experiment than I would
Two consecutive failures rules out coincidence, and the only delta in the third run is the It also corrects something I had written down too generously. I called The carried commit ( Stage 3 is now verified by the gate rather than by my laptop, which was the point. |
* fix(testaws): lock the request-body byte counter (data race) go test -race ./... failed about one run in twenty with a race inside the harness, not in anything under test: Read at 0x... by goroutine N: recorder.snapshot() <- TestServer.GETs() Previous write by goroutine M: countingBody.Read() <- persistConn.writeLoop() countingBody increments a field of a Request that has already been published, and snapshot copies that struct, so the increment has to be under the recorder mutex. It was not. The recorder in-flight wait does not cover it, which is why this survived the round of work that added that wait. The wait covers what the handler goroutine does between publish and serve; the body is not read by the handler. The reverse proxy hands it to its transport, which forwards it from its own writeLoop goroutine, and the transport returns from RoundTrip on the response headers -- so the response can arrive, the handler return, and serve() settle the request while writeLoop is still counting. No new test. The existing concurrency test reports it at -count=30, and a deliberate reproduction was tried and dropped rather than committed unverified: a faulted request never reaches the proxy so its body is never read through the wrapper, and net/http drains an unread body inside its own body type, below the wrapper. The window is specifically "upstream answered early", which the emulator does not do on request. The comment on countingBody records both the reproduction command and why there is nothing sharper. * docs(testaws): record what two CI failures taught about this race The comment described the detector as weak — about one run in twenty locally — and listed only the two dead ends for forcing the interleaving deliberately. #516's `test` job then failed on this race twice in a row, on a branch touching only internal/compression and internal/storage/s3, which says two things the comment did not. Under load the race is not rare. The extra parallel test load of an unrelated branch was enough to make it reliable, and the report it produces names a file that branch's author never touched — the expensive kind of flake, since the first hour goes into an innocent diff. And the interleaving that actually occurs is a third route, neither of the two the comment ruled out: the reverse proxy forwarding the request body to the upstream on the transport's own goroutine, via transferWriter.doBodyCopy, while a test calls GETs(). That is the window this lock closes, so it belongs in the stack sketch rather than the persistConn.writeLoop frame that was there. Comment only; no behaviour change.
…s own backoff (#519) main is red. TestTheAccelerateEndpointComesBackWithinTheBackoff failed its vacuity guard — "acceleration is still active, so nothing was withdrawn and this test cannot observe a recovery" — and that diagnosis was wrong. The withdrawal did happen; the log line immediately above the failure is "Retrying S3 Transfer Acceleration after backoff backoff=25ms". The 25ms backoff had already expired by the time the guard looked. So the guard conflated two states it cannot tell apart: never withdrawn, and withdrawn and already recovered. Reading Active is also what performs the open→half-open transition that sets it back to true — TestAccelerationStatsDoesNotReportAStateItJust- Changed asserts that exact mechanism from the other side — so under load the guard could cause the recovery it exists to rule out, then blame the gate for a fault that was the clock's. The fix is to assert on something monotonic. Fallbacks counts exactly this withdrawal and only ever counts up, so no amount of elapsed time can make it lie in either direction. Verified by mutation: dropping the injected fault leaves the guard firing with the right message, so it still catches the vacuous run it exists for. 20 runs under -race with the sibling acceleration test alongside it, clean. Only this one assertion needed it. The file's four other Active reads are safe on purpose: three are in tests configuring a one-hour retry, where the gate cannot reopen underneath them, and the fourth deliberately sleeps 2*retry and asserts the post-transition state. Exposed rather than caused by #516: that PR added ~1000 lines of parallel test to this package, and the extra load is what made a 25ms window get missed. The same load made the #515 race deterministic in the same job. No CHANGELOG entry — this is a test precondition, with no user-facing behaviour attached.
…ver existed (#523) The next release is 0.15.0, not the 0.16.0 the milestone was titled. Four lines in the Unreleased section described the CargoShip upload-path removal as having happened "in v0.15.0" — it shipped in 0.12.0 (#362, 2026-08-08) — and CLAUDE.md repeated the claim. A fifth said a tier defect was "the v0.15.0 defect"; that one was v0.10.1. No v0.15.0 tag, changelog section, or module-proxy entry has ever existed, so the number is free and skipping it would have preserved five wrong references to justify a milestone title. Promotes Unreleased to [0.15.0] - 2026-09-17: seekable compression framing end to end (#185, via #509/#513/#516) and the GoReleaser convergence (#502) with what it let us delete. Bumps the version constant, which is the authority the changelog link test and the packaging tests read. Also corrects the signing claims across four documents (#505). README.md, docs/index.md and docs-platform/guide/getting-started.md all said the project "does not sign releases yet"; #501 signs checksums.txt keylessly with cosign. Each now states the two positions separately, because neither covers the other: the release is signed, the .deb and .rpm files are not. The verify command is the one release.yml both runs and prints into the notes — a bundle, not the --certificate/--signature pair a first draft of this invented. README's claim that the apt/yum repository is "built and tested on every pull request" also went with #520, which deleted that machinery.
Stage 3 of #185. Stage 1 (#509) added the frame-index format, stage 2 (#513) made the
upload path frame a compressed object and store a seekable descriptor with it. This is
the half that makes any of it pay: a ranged read of a framed object now fetches only
the frames covering the requested span, instead of the whole object.
What changes
ReadRangeon a compressed object used to have one answer: fetch the entire object,decompress it, slice. For a 1 GiB object that is 1 GiB of transfer to serve a 4 KiB
read. When the object carries a seekable descriptor, the read path now:
FramesCovering),DecodeFrames) and slices the result frame-relative.Anything without a usable descriptor falls back to the whole-object path unchanged, and
the reason is recorded in
SeekableLastFallbackReasonso an operator can tell why aread was expensive rather than only that it was.
The two decisions worth review
The decoder answers for the object, not for the configured codec. An earlier draft
keyed the read path on
Settings.Algorithm, which meant changingalgorithmin theconfig made every already-written compressed object unreadable.
buildDecoders()nowbuilds a decoder per supported algorithm regardless of what is enabled, and
FrameDecoderis looked up by the object's own stored encoding. A read must not dependon how the writer happens to be configured today.
Corruption fails closed rather than falling back. If a fetched frame does not match
the index stored with it, the read returns an error naming the frames and the span. It
does not quietly re-fetch the whole object — that would turn a detected integrity
failure into a slow success, which is the one outcome the index exists to prevent.
DecodeFramesalso validates the body length against the index before decodinganything, so a hostile or damaged index cannot drive the output allocation.
Verification
Beyond the tests: a 19-mutation run over the read path and the frame decoder, all 19
caught. Five of those mutations survived the first pass and are the reason
internal/compression/decode_frames_test.goexists — notably, deleting the body-lengthcheck produced a build the entire S3 suite still passed, because the backend computes
its Range from the same index it then validates against, so the guard is unreachable
from that direction and had to be tested against the function.
Three tests carry
//nolint:tparalleland//nolint:paralleltest: they share onebackend and assert on its request log, and a transfer budget is only meaningful if no
sibling subtest is issuing requests into the same recorder.
Local gate: build-tags 7/7, cross-build 6/6,
-raceclean, golangci-lint v2.12.2 cleanagainst the merge base, gosec matching the baseline exactly, and coverage above floor
for every package touched (
internal/compression88.6% → 94.2%, floor 90;internal/storage/s387.5%, floor 81).Not in this stage
Emitting a real
0xEZstandard Seekable Format seek table for third-party interop.The index here is ObjectFS's own; interop is a deliberate non-goal this milestone and
is noted on #185.
Refs #185