Skip to content

feat(compression): frame compressed uploads and record a seekable descriptor (#185 stage 2) - #513

Merged
scttfrdmn merged 3 commits into
mainfrom
feat/seekable-zstd-upload-path
Sep 16, 2026
Merged

scttfrdmn merged 3 commits into
mainfrom
feat/seekable-zstd-upload-path

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Stage 2 of #185: the write path. Stage 1 (#509) is merged, so this targets main directly and
the diff is stage 2 alone.

Supersedes #511, which GitHub closed when #509's branch was deleted on merge. Same three commits,
rebased onto main; #511's comment carries the full local verification record, repeated at the
bottom here.

What this does

Compressed uploads are now emitted as a sequence of independent zstd frames with a leading index,
and the backend records a fixed-size descriptor of that layout in S3 user metadata under
objectfs-seekable.

No read gets faster in this PR. The read path is stage 3. What this stage buys is that objects
written from now on are seekable when that lands, instead of needing a rewrite.

Why it is safe to ship ahead of the reader

A framed object is an ordinary zstd stream. The index is a skippable frame, so a plain decode walks
straight past it: this backend's existing whole-object path, checkFullyDecoded, verifyChecksum,
aws s3 cp and zstd -d all decode a framed object byte for byte with no changes. That is asserted
directly — TestFramedUploadStoresADescriptorThatDescribesTheObject reads a framed object back
through the unmodified whole-object path and compares.

The descriptor

version/frameSize/frameCount/indexLength, e.g. 1/262144/16/744 — 15 bytes typical, 36 at the
widest possible value. It is an accelerator, never the authority: the index inside the object is.
A SetObjectMetadata (CopyObject with MetadataDirective=REPLACE) discards every key it does not
restate, and the caller doing a chmod is internal/vfs, which knows nothing about framing. So the
descriptor is in backendOwnedMetaKeys alongside the checksum and original size — a caller's value
is dropped silently rather than rejected (a caller round-tripping metadata from HeadObject must still
be able to write), and the object's own value is restated on every rewrite. If it is ever lost
anyway, the cost is one round trip, not a correctness problem.

No configuration flag

Framing engages or it doesn't, on measurable properties of the object. The five declines:
compression itself declined; the object is one frame or smaller; the framed body came out no smaller
than the input; the frame count would exceed the format's limit; the object is below the compression
minimum.

Frame size is sqrt(40 * size * ratio) clamped to [256 KiB, 16 MiB] — the index-record cost against
the read-amplification cost. Because F goes as the square root of the ratio, the ratio estimate
has to be wrong by 4x to move F by one power-of-two step, which is what makes a sampled estimate
viable at all. The sample is three windows, not a prefix: prefix-only sampling got a 1 MiB
incompressible head wrong by 0.19x and a 1 MiB compressible head by 15x — about two powers of two of
frame size. Both cases are permanent regression rows in
TestEstimateRatioIsCloseEnoughForDeriveFrameSize.

The cost is stored size, and it is real

Independent frames mean no cross-frame back-references. Under a mixed workload with read locality
the loss is under 1%; on self-similar text at the 256 KiB floor it can reach ~20%. The CHANGELOG
entry says so plainly rather than quoting only the good number.

Also

  • The extended-attribute budget drops to 1694 bytes per object, from 1758. internal/vfs
    reserves MaxSeekableDescriptorLen against the format's wire widths (uint32 per field), not
    against the current policy limits — a policy limit can be relaxed in a patch release, a wire width
    cannot change without a format version. README updated in both places.
  • TestParseSeekableDescriptorRejectsGarbage now asserts which check rejected each row. The first
    version hardcoded an index length of 2648, copied from this file's own doc-comment example which
    was itself wrong; 2664 is the consistent length for 64 frames, so a dozen rows were being rejected
    by the self-consistency check before reaching the check they were named for. A mutation that
    disabled the version check entirely left the test green. A table of rejections is the test shape
    most prone to passing for the wrong reason, because every wrong reason is still a rejection.

Verification

  • go test -race ./internal/compression/ ./internal/vfs/ ./internal/storage/s3/ — ok
  • Mutation: 10/10 caught across the descriptor's self-consistency and version checks,
    MaxSeekableDescriptorLen's derivation, DescribeFrameIndex's frame count, prefix-vs-three-window
    sampling, both framing declines, descriptor storage, backend ownership, and the xattr reservation
  • golangci-lint clean at CI's pinned 2.12.2 with --new-from-merge-base (which caught four
    misspell findings local 2.13.2 passed), gosec matches .github/gosec-baseline.txt exactly
  • Backend-level coverage through internal/testaws: descriptor↔object agreement, 9 ranged reads over
    frame boundaries, three declines, caller-write refusal, chmod survival

Deliberately not in this milestone

A real 0xE Zstandard Seekable Format seek table for third-party interop. Recorded as a decision,
not an oversight.

Refs #185

Verification, repeated from #511

Run locally against the pre-rebase tree, then re-run after rebasing onto main
(go build ./..., go vet -tags=integration ./..., -race over the three packages — all clean).

CI job Local result
test go test -race ./... — no failures
lint golangci-lint 2.12.2 (CI's pin, not this machine's 2.13.2) with --new-from-merge-base — 0 issues
Security Scan gosec SARIF against .github/gosec-baseline.txt — 12 findings, 8 (rule, file) groups, matches exactly
coverage internal/compression 94.0% (floor 90), internal/vfs 98.5% (98), internal/storage/s3 87.3% (81)
build-tags ×7 go vet -tags= for aws_s3 benchmark distributed e2e integration fuse_mount s3compat — all ok
cross-build ×6 CGO_ENABLED=0 build + go vet for linux/{amd64,arm64,arm7,386} and darwin/{amd64,arm64} — all ok

Those coverage figures are measured over the three packages alone, so they exclude cross-package
contributions and are a lower bound on CI's number — above the floors either way, but not a substitute
for CI's measurement.

The build-tags (integration) cell is why the third commit exists. itoa is declared in
skip_compressed_bench_test.go, behind //go:build !integration; descriptor_test.go has no
constraint of its own and called it, so go vet -tags=integration ./... failed with
undefined: itoa while -race over the whole repo, coverage, both golangci-lint versions, and a
10/10 mutation run were all green. They exercise one cell of the tag matrix. #511 ran no CI at all
because ci.yml filters pull_request to branches: [main] — filed as #512, and this PR does not have
that problem.

Mutation: 10/10 caught, tree restored clean.

caught  descriptor self-consistency check never fires
caught  unknown format version is accepted
caught  MaxSeekableDescriptorLen reserved against policy limits, not wire widths
caught  DescribeFrameIndex miscounts frames by one
caught  ratio estimated from a prefix instead of three windows
caught  single-frame objects are framed anyway
caught  a framed body larger than the input is kept
caught  descriptor is computed but never stored
caught  descriptor is not backend-owned, so a caller can set it
caught  descriptor width not reserved in the xattr budget

…ptor (#185)

Stage 2 of #185: the write path. A zstd object spanning more than one frame is
now stored framed — a leading skippable frame carrying the index, then the
content frames — and the object gains an `objectfs-seekable` metadata key
holding version/frameSize/frameCount/indexLength so a reader can fetch the
index in one correctly-sized request.

No read gets faster in this commit, deliberately. The read path still decodes
the whole stored body; framing is landing on its own because it changes the
stored bytes of every compressible object a mount writes, and that has to be
proven correct through the *unchanged* reader before anything is built on it.
A framed object is a legal zstd stream — the index rides in a skippable frame
every conformant decoder ignores — so the existing whole-object path,
checkFullyDecoded and verifyChecksum all work untouched, which is what makes
the split safe rather than a half-feature.

Three things worth calling out.

No config flag. Framing is chosen automatically for zstd above one frame and
declined in five ordinary cases (compression off, non-zstd codec, below
MinSize, already-compressed content, framed body no smaller than the input).
The trade is stored size — under 1% on data with read locality, ~20% on
self-similar text at the 256 KiB floor — against up to four orders of
magnitude of read amplification. That is a decision worth making once here
rather than a knob whose wrong value is invisible in both directions.

The ratio estimator samples three windows, not a prefix. Its first form
trial-encoded the first 1 MiB, and the doc comment claimed the ratio had to be
wrong by 4x before DeriveFrameSize's answer moved. Measured: a file with an
incompressible header came out 15x off and one with a compressible header 5x
off — two powers of two of frame size, past what F's square root absorbs.
Head/middle/tail for the same total encode cost brings the worst case to 0.49x
on the ratio, 0.70x on the frame size. Both cases are now table rows.

The xattr budget drops 1758 -> 1694. The 64 bytes are the descriptor's widest
form, reserved on every object whether or not it is framed, and derived from
compression.MaxSeekableDescriptorLen rather than written down. S3 rejects an
over-budget metadata write instead of truncating it, so a reservation that is
only usually right becomes a setfattr that succeeds and a flush that fails.

The ratio test derives frame sizes at synthetic sizes {1 GiB..1 TiB} rather
than at the fixture's own size. At any size a test can allocate, DeriveFrameSize
clamps to MinFrameSize and every ratio in the table — right or wrong by 15x —
produces exactly 262144, so the first version of that test was comparing two
constants. TestDeriveFrameSizeVariesOverTheSizesTheRatioTestUses is the guard
against that returning silently.
A mutation run disabled ParseSeekableDescriptor's version check entirely and
TestParseSeekableDescriptorRejectsGarbage still passed. The cause was a wrong
number, copied twice.

The table hard-coded an index length of 2648, taken from this file's own
doc-comment example. 2648 is not the consistent index length for 64 frames --
skippableHeaderSize + indexPayloadLen(64) is 2664 -- so the self-consistency
check rejected those rows before any of them reached the check they were named
for. The `unknown version` row was therefore proving nothing about versions, and
`index length disagrees with frame count` was off by 16 rather than by one.

Fixed in three places and structurally rather than by correcting the constant:

- Every row now carries a substring of the error it must produce, so a row that
  is rejected for the wrong reason fails. This is the class of defect a table of
  rejections is most prone to, because every wrong reason is still a rejection.
- The index lengths are computed from indexPayloadLen, not written down, and the
  two that are about the index length say so (off by one, and correct-for-65).
- The doc comment's example is now a consistent descriptor, with a note that the
  number is load-bearing, since that comment is where the wrong one came from.

The backend test's caller-supplied value is now a named constant holding a
well-formed descriptor for a different object, which is the stronger adversary: a
malformed one would be caught by the reader's parse even with the ownership
filter removed.
`go vet -tags=integration ./...` failed with `undefined: itoa`. The helper is declared in
skip_compressed_bench_test.go, which carries `//go:build !integration`; descriptor_test.go carries no
constraint of its own, so it compiled under every combination CI actually reached on this branch and
none of the ones it did not.

Nothing local caught it. `go test -race ./...`, per-package coverage, and golangci-lint at both
2.12.2 and 2.13.2 all exercise exactly one cell of the tag matrix, and a test file's own build tags
say nothing about what its dependencies require.

CI would have caught it in `build-tags (integration)`, except that this PR is based on a feature
branch and ci.yml filters `pull_request` to `branches: [main]`, so it ran no jobs at all — filed as
#512.

Refs #185
@scttfrdmn
scttfrdmn merged commit 57fb108 into main Sep 16, 2026
43 checks passed
@scttfrdmn
scttfrdmn deleted the feat/seekable-zstd-upload-path branch September 16, 2026 23:54
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.
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