Skip to content

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

Closed
scttfrdmn wants to merge 3 commits into
feat/seekable-zstd-frame-formatfrom
feat/seekable-zstd-write-path
Closed

scttfrdmn wants to merge 3 commits into
feat/seekable-zstd-frame-formatfrom
feat/seekable-zstd-write-path

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Stage 2 of #185: the write path. Stacked on #509 (feat/seekable-zstd-frame-format) — that PR
has to merge first, and this PR's base is set to its branch so the diff shown here is only stage 2.

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

…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

Copy link
Copy Markdown
Owner Author

This PR runs no CI. ci.yml filters pull_request to branches: [main], and this PR's base is
feat/seekable-zstd-frame-format, so gh pr checks 511 returns exactly one row — dependabot,
skipping. Filed as #512 with the one-line fix. Protection on main still holds; what is missing is
review-time signal, so here is the gate run locally against 661522c.

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) --new-from-merge-base=origin/feat/seekable-zstd-frame-format — 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

The coverage numbers are measured over the three packages alone, so they exclude cross-package
contributions and are a lower bound on what CI will report — comfortably above the floors either way,
but not CI's exact figure (internal/fuse compiles a different file on linux, which is why a floor is
never ratcheted from a local run).

The absent CI was not hypothetical

build-tags (integration) failed. itoa is declared in skip_compressed_bench_test.go, which
carries //go:build !integration; descriptor_test.go carries no constraint of its own and called
it, so go vet -tags=integration ./... failed with undefined: itoa. Everything else was green —
-race over the whole repo, coverage, and both golangci-lint versions all exercise a single cell of
the tag matrix. Fixed in 661522c by using strconv.Itoa.

That is one real defect found by a job this PR does not run, on a diff that had already passed a
10/10 mutation suite. It is the argument for #512.

Mutation

10/10 caught, and the tree restored clean afterwards:

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

The second row is the one worth naming. It survived the first run: TestParseSeekableDescriptorRejectsGarbage
hardcoded an index length of 2648, copied from descriptor.go's own doc-comment example, which was
itself wrong — 2664 is the consistent length for 64 frames. So a dozen rows were rejected by the
self-consistency check before reaching the check they were named for, and the version check could be
deleted outright with the test still green. Fixed structurally rather than by correcting the constant:
every row now asserts which check fired, and both index lengths are computed from indexPayloadLen
rather than transcribed.

@scttfrdmn

Copy link
Copy Markdown
Owner Author

Closed as a side effect of merging #509 with --delete-branch: deleting a branch closes every PR that targets it, and the base could not be retargeted afterwards (Cannot change the base branch of a closed pull request).

Reopened as #513 against main — the same three commits rebased, no force-push. The verification record in the comment above still applies; it is repeated in #513's description.

@scttfrdmn
scttfrdmn deleted the feat/seekable-zstd-write-path branch September 17, 2026 04:49
scttfrdmn added a commit that referenced this pull request Sep 18, 2026
ci.yml and security.yml both filtered their pull_request trigger on
`branches: [main]`, so a pull request stacked on a feature branch started
none of their jobs — not test, not lint, not coverage, not Security Scan,
not one of the twelve build-tags/cross-build cells.

Nothing failed, and that is what made it invisible for as long as it
lasted. The checks never existed, so `gh pr checks` returned one row,
`dependabot  skipping`, and the pull request read as green because nothing
was red rather than because anything had passed. #511 was reviewed in that
state.

The window also closes at exactly the moment it stops being useful.
GitHub retargets a stacked pull request to main when its parent merges, so
CI first runs after review has already happened against zero signal — the
gap is invisible while it matters and gone by the time anyone would look.

security.yml is not named in #512 but carried the same filter, and it
matters more there: Security Scan is a required status check on main, so
the filtered-out trigger was a check that is supposed to be able to block
a merge and could not report at all.

The push trigger keeps its `branches: [main]` in both files. That one is a
different question with a correct answer — it stops a feature-branch push
from duplicating the pull request's own run — so it is left alone rather
than removed for symmetry.

TestNoPullRequestTriggerFiltersItsBaseBranch walks .github/workflows/ and
fails on a branches or branches-ignore filter under pull_request or
pull_request_target. Walked rather than enumerated on purpose: naming the
two files that had the bug checks the two files that had the bug, and the
next workflow to arrive with `branches: [main]` copied out of a README is
the case a hard-coded list cannot see. It carries a floor on the file
count and a non-vacuity guard on the trigger count, the latter because
yaml.v2 parses the key `on` as the boolean true — a map[string]any lookup
finds nothing and passes every file.
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