Skip to content

feat(s3): serve ranged reads of a framed object from its frames (#185 stage 3) - #516

Merged
scttfrdmn merged 5 commits into
mainfrom
feat/seekable-zstd-read-path
Sep 17, 2026
Merged

scttfrdmn merged 5 commits into
mainfrom
feat/seekable-zstd-read-path

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

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

ReadRange on 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:

  1. resolves the requested span to the frames covering it (FramesCovering),
  2. issues one ranged GET for exactly those frames' compressed bytes,
  3. decodes them (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 SeekableLastFallbackReason so an operator can tell why a
read 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 changing algorithm in the
config made every already-written compressed object unreadable. buildDecoders() now
builds a decoder per supported algorithm regardless of what is enabled, and
FrameDecoder is looked up by the object's own stored encoding. A read must not depend
on 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.
DecodeFrames also validates the body length against the index before decoding
anything, 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.go exists — notably, deleting the body-length
check 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:tparallel and //nolint:paralleltest: they share one
backend 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, -race clean, golangci-lint v2.12.2 clean
against the merge base, gosec matching the baseline exactly, and coverage above floor
for every package touched (internal/compression 88.6% → 94.2%, floor 90;
internal/storage/s3 87.5%, floor 81).

Not in this stage

Emitting a real 0xE Zstandard 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

…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.
@scttfrdmn

Copy link
Copy Markdown
Owner Author

The test job failed here, and it is not this branch. The race report:

Previous write at 0x00c007349cd0 by goroutine 14800:
  internal/testaws.(*countingBody).Read()   recorder.go:389
  net/http/httputil.(*noopCloseReader).Read()
  io.discard.ReadFrom()
  net/http.(*transferWriter).doBodyCopy()   transfer.go:417

Read at 0x00c007349cd0 by goroutine 2090:
  internal/testaws.(*recorder).snapshot()   recorder.go:589
  internal/testaws.(*TestServer).GETs()     recorder.go:645
  ...TestRecorderLogsARequestBeforeItsCallerCanObserveTheResponse

That is the unlocked *c.n += int64(n) in internal/testaws's request-body byte counter,
racing the recorder's own snapshot — the defect #515 fixes, on a file this branch does
not touch. The test that tripped it is a pre-existing test, so main is flaky today and
this PR simply drew the short straw; nothing in the seekable read path is implicated.

Worth noting what the stack adds: the body is being read on the transport's goroutine via
doBodyCopy, below httputil.ReverseProxy. #515's own comment records two dead ends I hit
trying to force that interleaving deliberately, and this is the route that actually occurs
in practice — the proxy forwarding a request body while a test calls GETs() on the
recorder. The window is real and reachable from the existing suite under load, not
hypothetical.

So this PR needs #515 in main before its test job can be trusted green. #515 is green
(42 pass / 1 skip) and MERGEABLE/CLEAN. I have not merged it — it is not mine to merge.
Rerunning the failed job here to establish whether the race is flaky or deterministic on
linux; either way the fix is #515 rather than anything in this diff.

…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.
scttfrdmn added a commit that referenced this pull request Sep 17, 2026
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.
@scttfrdmn

Copy link
Copy Markdown
Owner Author

Green: 42 pass, 1 skip, no failures.

Worth recording what the sequence proves, because it is a cleaner experiment than I would
have designed on purpose. Three runs of this branch's test job:

head internal/testaws change test
c09da82 none FAIL — data race
c09da82 (rerun) none FAIL — same race, same lines
c9c89f8 #515's lock, carried pass

Two consecutive failures rules out coincidence, and the only delta in the third run is the
lock. So the failure was never in the seekable read path, and #515 is the fix rather than a
plausible-looking suspect.

It also corrects something I had written down too generously. I called main flaky; two for
two says that is not the right word. Locally this race reports about one run in twenty, but
under CI's load — with the ~1000 lines of additional parallel test this branch adds — it is
reliable. main passes today because it does not carry that load, not because it is sound.
Any branch that adds test weight to that job can expect this, and the report it produces
names internal/testaws, which its author will not have touched.

The carried commit (c9c89f8) is #515's recorder.go verbatim — I diffed the two branches
to zero so they cannot drift. Its CHANGELOG entry stays on #515 rather than being duplicated
here, which is also the one file the two PRs would otherwise have conflicted on. Whichever
merges first makes the other's copy a no-op.

Stage 3 is now verified by the gate rather than by my laptop, which was the point.

scttfrdmn added a commit that referenced this pull request Sep 17, 2026
* 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.
@scttfrdmn
scttfrdmn merged commit dc69e64 into main Sep 17, 2026
43 checks passed
scttfrdmn added a commit that referenced this pull request Sep 17, 2026
…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.
scttfrdmn added a commit that referenced this pull request Sep 17, 2026
…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.
@scttfrdmn
scttfrdmn deleted the feat/seekable-zstd-read-path 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.

1 participant