Repository navigation
Description
Summary
A compressed object cannot be read partially. zstd's default single-frame output must be decoded from the start, so any ranged read of a compressed object requires fetching and decoding the whole object. Framing the stream as a sequence of independently-decodable frames plus a skippable-frame index makes ranged reads fetch only the frames covering the requested bytes.
Why this is worth doing
The read path currently handles compressed objects by re-fetching whole (internal/storage/s3/backend.go:416-427 and the encoded re-fetch above it). That is correct — v0.10.1 fixed the version that dispatched on the write config and silently returned raw zstd frames with exit status 0 — but it means a compressed object is a whole-object-read object.
The v0.10.0 audit measured what that costs when it was applied bucket-wide (fixed 4 KiB read against real S3, us-west-2):
| object size | penalty |
|---|---|
| 16 MiB | 15.6× |
| 64 MiB | 43.0× |
| 256 MiB | 216.5× |
Those figures were for the C4 defect, where the config flag forced whole-object reads for every object in the bucket including uncompressed ones. That is fixed — the decision is now per-object, from the object's own Content-Encoding. But for an object that genuinely is compressed, the amplification is unchanged, and it scales with object size: a 4 KiB read of a compressed 10 GiB object transfers 10 GiB.
This is the structural reason compression defaults to off. Seekable framing is what would let it default to on for large objects without making random reads pathological.
What it takes
klauspost/[email protected] (already a dependency) has every primitive needed. No new dependency.
Format. Compress in fixed-size uncompressed blocks — each block becomes its own zstd frame, independently decodable. Append a skippable frame (magic 0x184D2A5x) holding the index: for each frame, compressed size and uncompressed size. A reader fetches the trailing index, computes which frames cover [offset, offset+size), issues one ranged GET spanning them, decodes only those, and slices.
Block size is the tradeoff: smaller means finer granularity and worse ratio; larger means better ratio and more waste per small read. Somewhere in 1–4 MiB is the usual answer, and it should be configurable but with a default that is not a guess — pick it from a measurement on a representative object.
Compatibility. A seekable stream is still a valid zstd stream — zstd -d and any standard decoder read it correctly, ignoring the skippable frame. So this does not make objects less portable than they already are.
What makes this a format change, not an optimization
This changes the bytes stored. That brings requirements the current compression path does not have:
-
A format-version metadata key. Something like
objectfs-compression-format: seekable-v1. Without it, a reader cannot tell a seekable object from a single-frame one except by parsing, and the two need different read strategies. -
Old objects must stay readable. Every object written before this exists is single-frame. The read path needs both strategies, chosen from the metadata key, indefinitely — not behind a migration deadline. A migration tool is fine; a migration requirement is not.
-
The SHA-256 contract.
objectfs-sha256is recorded over the whole uncompressed content andverifyChecksumonly runs when the buffer holds all of it (backend.go:459-466). A ranged read of a seekable object holds some frames, never the whole file — so it cannot verify against the whole-object hash. This is the important design question in the issue: either- store a per-frame hash in the index, so a partial read verifies exactly what it fetched, or
- accept that ranged reads of compressed objects are unverified, which weakens the integrity contract that v0.10.1 established and would have to be stated in the documentation.
Per-frame hashes are the right answer. Integrity is priority ci(deps): Bump actions/setup-go from 4 to 5 #1 for this project and the whole point of seekable framing is to make partial reads of compressed objects normal — so making them the one read that is not verified would be backwards. The index already exists as a place to put them; the cost is 32 bytes per frame.
-
Interaction with the range-aware cache. The cache is keyed on
(key, chunkIndex, etag). Frame boundaries and cache chunk boundaries will not align. Worth deciding whether the cache stores decoded bytes (simple, aligns with the existing key) or frames (avoids re-decode on a repeat read). Decoded is probably right; noting it so it is a decision rather than an accident. -
Multipart uploads. A part boundary must not split a frame if a reader is to fetch frames by range without stitching across parts. Frame size and part size need to be compatible, or the index needs to record part offsets too.
Sequencing and prerequisites
- Depends on Wire up the compression analyzer: ObjectFS re-compresses the formats research data is already stored in #184 (wiring the content analyzer). There is no point framing an object that should not have been compressed at all, and the analyzer decides that. Also: whichever formats the analyzer skips are exactly the large files where seekable framing would matter most, so Wire up the compression analyzer: ObjectFS re-compresses the formats research data is already stored in #184 may shrink this issue's payoff considerably. Worth measuring after Wire up the compression analyzer: ObjectFS re-compresses the formats research data is already stored in #184 lands before committing to this.
- Substrate needs Range GET for any of this to be testable in-process. Filed upstream; it is P0 there for the same reason.
- Compression is opt-in and off by default, so nothing regresses while this is unbuilt.
Testing
- Round-trip fuzz: arbitrary bytes → seekable compress → PUT → ranged GET at fuzzed
(offset, size)→ assert byte-identity against the same range of the original. Extend the existing round-trip fuzzer rather than adding a parallel one. - Assert bytes transferred, not latency: a 4 KiB read of a compressed 64 MiB object must issue a ranged GET covering one or two frames. Latency alone would pass on a fast link with a whole-object fetch, which is the trap the C4 tests were written to avoid.
- Read a seekable object with
zstd -dto confirm the skippable frame is ignored and the output is identical. - Read a pre-existing single-frame object after the change, to confirm the format-version fallback works.
Activity
scttfrdmn commentedon Sep 15, 2026
Both prerequisites this issue names are now met, and the substrate one is measured rather than read off a closed issue.
#184 is closed, so the content analyzer is wired. The issue notes that may shrink this one's payoff — whichever formats the analyzer skips are the large files where seekable framing would matter most — so that measurement is still owed before committing to the full format change.
Substrate honours Range GET as of v0.111.0 (substrate#396, closed). Probed in-process against
internal/testawsrather than inferred from the issue state, because all three primitives this design needs are separable and only one of them is what "supports Range" usually means:The middle one is the one worth calling out. Reading the skippable index frame is a suffix range —
bytes=-N— because the index sits at the end and its length is not known before it is read. A backend that implementsbytes=a-band notbytes=-Nwould pass a naive range test and still make the index unreadable. It works, andContent-Rangereports the resolved absolute offsets.The third matters for the fallback path:
backend.go'scase ranged && isInvalidRange(err)arm depends on a range past the end being refused, not silently clamped. A backend that clamped would turn an EOF read into a short read of real bytes.So this is testable in-process now, which the "assert bytes transferred, not latency" requirement above depends on — that assertion needs a request recorder, and
testawscounts every request through its proxy.scttfrdmn commentedon Sep 15, 2026
Answering the open sequencing question above — "#184 may shrink this issue's payoff considerably … worth measuring after #184 lands before committing to this."
It does not shrink it. Measured by running
Analyze/AlreadyCompressedover each format's leading bytes rather than by readingclassifyByMagic:AlreadyCompressedtruetruefalsefalseBAM coming back
trueis the one result worth knowing and it was not obvious: BAM is bgzf, which is a gzip container, so it carries gzip magic and #184's gate skips it without anyone having added BAM to the list. It is skipped correctly and for free.Everything #184 skips is a format that was never a candidate for seekable framing — an object stored raw is already served by range, so it has no amplification to remove. So the set #184 removed from this issue's scope is empty, and the two sets it leaves behind are different problems:
Compressruns a full codec pass, the output is no smaller, and thelen(compressed) >= len(data)fallback stores the original. They are never stored compressed, so seekable framing never applies to them either. That wasted pass is Compression: settle the entropy gate with a measurement, and decide whether the three selectors have a caller #410, not this issue.So the payoff stands and lands where the issue said it would. It is worth stating that this establishes which objects reach the compressed path, not what ratio they achieve — a ratio measurement still needs a real corpus, because the padding in this probe was synthetic. (For the same reason, ignore the
ContentClassvalues it reported: ASCII padding madeclassifyByContentanswertextfor the binary formats. That is an artifact of the probe's own input, not a classifier defect.)Prerequisites are therefore both settled: #184 closed without narrowing this, and substrate's Range GET is verified in-process (previous comment).
scttfrdmn commentedon Sep 15, 2026
CargoShip already shipped this format, and it changes four of the decisions above
This issue was written without knowing that
scttfrdmn/cargoshiphas an identical mechanism inproduction as "Random-access frame index (format 2.1)" — cargoship#436 (frame table and per-file
offsets), #439 (per-frame checksums), #492 (offsets recorded for unframed chunks too), and #502
(cutting frames inside a large file), all closed.
docs/reference/format/compression.mdin that repois the specification. The consequence is not "adopt it wholesale" — the container is different in a
way that matters — but three questions this issue leaves open are already answered upstream, and one
of the answers is a correctness refinement this issue got wrong.
What transfers, what does not, and what is now measured rather than guessed:
The per-frame hash is over the compressed bytes, and it is checked before the decoder runs
Item 3 above says "store a per-frame hash in the index, so a partial read verifies exactly what it
fetched" without saying which bytes it covers. That ambiguity is the whole design. cargoship#439
resolved it:
chunks[].frames[].checksumis the SHA-256 of the frame's compressed bytes — exactlywhat a ranged
GETof[compressed_offset, compressed_size)returns — and the documented readprocedure is fetch → verify → decode, in that order.
Hashing the compressed side is strictly better than hashing the decoded side, for three reasons that
are not about convenience:
attacker-controlled length fields; the uncompressed-side hash can only be checked after that code
has already run on unverified input.
quirk as a hard error rather than as silent corruption. A store that clamps an unsatisfiable range
instead of refusing it, that serves
bytes=a-boff by a byte, or that serves a range from adifferent generation of an overwritten object, all fail the frame hash. This is the property that
makes the whole design safe to attempt optimistically on any endpoint — see the capability section.
over bytes already in the buffer.
Adopt cargoship's field set unchanged:
compressed_offset,compressed_size,uncompressed_offset,uncompressed_size,checksum. Frames tile the object contiguously and each begins with the zstdmagic
0x28 0xB5 0x2F 0xFD, so the two offsets are derivable by prefix sum and are stored anywaybecause a corrupted index that disagrees with itself is then detectable.
Verified locally against
klauspost/[email protected]andzstd(1) 1.5.7rather than assumed: aconcatenation of
EncodeAlloutputs plus a skippable frame decodes byte-identically throughDecoder.DecodeAlland throughzstd -d; one frame lifted out of the middle by its[compressed_offset, compressed_size)decodes in isolation to exactly itsuncompressed_sizebytes;and
sha256.Sum256of those extracted bytes equals the recorded frame checksum.zstd -lreportsFrames 18 Skips 1, i.e. the index frame is seen and skipped.One correction to "no new dependency" above.
klauspost/[email protected]exports noskippable-frame writer —
skippableFrameandcalcSkippableFrameinzstd/frameenc.goareunexported and reachable only through
WithEncoderPadding. So ObjectFS emits the 8-byte header itself(4-byte little-endian magic
0x184D2A50 | id, 4-byte little-endian payload length), which is trivialbut is code we own rather than a library call. The reader side is exported and sufficient:
zstd.Header.DecodefillsSkippable,SkippableID,SkippableSize, andHeaderSizefrom the first8 bytes. Still no new dependency; the claim just needed narrowing.
The index crux: cargoship's answer does not transfer, and neither does this issue's
cargoship puts the index in the manifest — a sidecar object it already owns and already fetches
once per archive. ObjectFS has no sidecar. An ObjectFS object is a standalone S3 object, and the only
out-of-band space is S3 user metadata. Three candidate locations, with the arithmetic that decides
between them:
User metadata alone is arithmetically impossible.
internal/vfs/xattr.goputs the real numbers onthis:
s3UserMetadataLimit = 2048(S3 rejects an over-budget PUT rather than truncating),reservedMetadataBytes = 290forobjectfs-mode/uid/gid/mtime/sha256/original-sizeat theirwidest, leaving
XattrBudget = 1758bytes for extended attributes — andxattr_test.gore-derivesthat rather than hardcoding it. A minimal index record is
compressed_size(4) +uncompressed_size(4) + SHA-256 (32) = 40 bytes, which is 56 bytes base64'd. 1758 bytes therefore holds 31
frames — a 31 MiB object at 1 MiB frames — and only by spending the entire extended-attribute budget,
so compressed files would have no xattrs at all. Metadata cannot hold the index. It is a fine place for
a fixed-size descriptor.
A trailing skippable frame scales but is the wrong end of the object. This issue's plan. It costs
one extra suffix-range
GET, which is verified to work (see my earlier comment: substrate v0.111.0honours
bytes=-Nand reports resolved absolute offsets inContent-Range).A leading skippable frame is better here, and the reason is a property of ObjectFS's write path
that cargoship does not share. cargoship streams a tar pipeline through the encoder, so it cannot
know the index until the stream is finished and the index must therefore trail. ObjectFS does not
stream:
Compressor.Compress(src []byte) ([]byte, error)takes the whole buffer, andprepareUpload(internal/storage/s3/backend.go:964) compresses before the multipart dispatch atbackend.go:883, so the entire compressed object is in memory at write time regardless of size. Theindex can be written first. That matters because most reads of a file start at offset 0, so a single
prefix
GET bytes=0-Kcan carry the index and the first data frames — one request where a trailingindex needs two. Verified: a leading skippable frame is skipped correctly by both
Decoder.DecodeAllandzstd -d, andzstd.Header.Decode(obj[:8])reads the index length out of thefirst 8 bytes, so
Kcan be over-fetched and corrected in one hop.The resolution is both, with the object as the authority. The index lives in a leading skippable
frame. A fixed-size descriptor — format version, frame size, frame count, index length, index
SHA-256 — lives in one user-metadata key (
objectfs-seekable, ~28 bytes base64-packed, ~56 bytesagainst the 2 KB limit including the
x-amz-meta-prefix). The descriptor is an accelerator, never theauthority, and the reason is a bug class this repo has already been bitten by twice:
SetObjectMetadatais a
CopyObjectwithMetadataDirective=REPLACE, which discards everything not restated — the samemechanism that made a
chmodcapable of droppingContent-Encodingand rendering a compressed objectpermanently unreadable (see the comment at
backend.go:1014). A tier transition does the same. If thedescriptor is authoritative, a
chmodsilently turns a seekable object into a whole-object-read object;if the object carries the index, losing the descriptor costs one round trip. The implementation must
still restate
objectfs-seekableinSetObjectMetadataalongsideContent-Encoding— but theconsequence of forgetting is then performance, not correctness.
Adding a reserved key changes
reservedMetadataBytes, soXattrBudgetdrops from 1758 to roughly1700. That is a user-visible number:
xattr_test.goasserts the arithmetic andREADME.mdstates 1758in prose. Both must move in the same commit.
A reader learns the object is seekable from a response it was already getting
The read dispatch at
backend.go:400–480already establishes seekability without a wasted round trip,and this is worth spelling out because it is the part that looks like it needs a HEAD and does not.
getObjectRangerecordsmetadata = result.Metadatafrom theGetObjectresponse(
backend.go:701) — and S3 returnsx-amz-meta-*andContent-Encodingon a 206 exactly as on a200. Probed, not read from documentation, against real AWS S3 in
us-west-2:Same four probes against substrate v0.111.0 through
internal/testawsgive identical answers, so thisis testable in-process.
So the existing dispatch keeps its shape, and both of its arms already have the descriptor in hand:
case ranged && err == nil && read.contentEncoding != ""— the speculative ranged GET landed insidea compressed body. Today it re-fetches whole. It becomes: if
read.metadatacarriesobjectfs-seekable, fetch the index (one prefix GET) and then the covering frames, instead ofre-fetching whole. The wasted bytes are the misaligned
sizebytes of compressed body thespeculative request already returned — bounded by the kernel's read buffer, 131072 bytes by default
(
internal/fuse/read_path_test.go:164), against the whole stored object today.case ranged && isInvalidRange(err)— the range fell past the end of a short compressed body. Italready calls
HeadObject, andinfo.Metadataalready carries the descriptor. No new request.Keep the speculative-range-first order. Making the first request a prefix or suffix range would
penalise the overwhelmingly common uncompressed object to benefit the rare compressed one, which is
audit finding C4's mistake in the opposite direction.
One requirement this issue does not have and needs. A framed read is two requests — index, then
frames — so an overwrite landing between them yields an index describing generation 1 and frames from
generation 2: every request succeeds, the lengths add up, and the assembled buffer never existed. This
is exactly the race
objectRead.etagwas introduced for on the parallel-read path(
backend.go:637–644). Pass the index fetch's ETag asIf-Matchon the frame fetch. And note thatthe per-frame compressed-side hash catches this even where
If-Matchis unhonoured — generation2's frame bytes will not match generation 1's recorded hash — so the conditional-GET support recorded
in
docs/design/conditional-write-compatibility.md(Wasabi ignoresIf-Match; Ceph RGW rejects thequoted ETag it just returned) is a performance nicety here rather than the guarantee. The guarantee is
the hash.
Frame size: not 16 MiB, not 1–4 MiB, and probably not a constant
This issue guessed 1–4 MiB. cargoship chose 16 MiB. Both are right for their own cost model and
neither transfers, because the index cost is amortised in cargoship and paid per object here.
cargoship fetches one manifest per archive and gets the frame index for every chunk in it; ObjectFS
pays for an index on the cold read of each object, so index size is a first-order term for us and a
rounding error for them.
The ratio arm of the tradeoff is much flatter than this issue assumed, and two independent measurements
agree:
SpeedDefault(ratio 3.67).go+.md, 16.5 MB (ratio 4.61)(Percentages are stored size against a single-frame encode of the same bytes. The FASTQ corpus is
synthetic — random ACGT with locally-repetitive headers and position-degrading quality strings — and is
a model of read locality, not a real corpus; label it as such. The repo-text row is real data and is
the pessimistic end, because concatenated Go and CHANGELOG text is self-similar across megabytes and a
frame boundary throws that window away. Negative values at 4 MiB and above are real and reproducible:
frame boundaries occasionally help.)
scttfrdmn/lith'sbench/results/framesize-curve.csvcorroborates the flat end, on real AWS,cold, with bytes counted through the CloudTrail ledger — 1985 small files packed by cargoship at 16/8/4/1
MiB frames gives
archive_MBof 13.1, 13.1, 13.1, 13.2. Under 1% of ratio across a 16× range of framesize, while the single-file cold read falls from 3.30 MB to 0.90 MB.
So frame size is decided by bytes transferred and index size, not by ratio. For an object of
uncompressed size
S, ratior, frame sizeF, and a 40-byte index record, the cold read of oneframe costs
40·S/F(index) +F/r(frame) bytes. That is U-shaped, minimised atF = √(40·S·r):Fminimising cold-read bytesFcargoship's 16 MiB is the optimum for a ~2 TiB single object under ObjectFS's per-object index cost.
For the 10 GiB object this issue's opening table is about, the fixed-
Fcurve (128 KiB kernel read,worst case straddling two frames) is:
FToday the same read transfers the whole 2.72 GiB stored body: 22,303×. So any point on this curve
is three to four orders of magnitude better than the status quo, which is the honest framing — the
default is worth ~2× against a neighbouring choice, not 200×.
Two consequences. First, frame at fixed uncompressed-size boundaries, because an ObjectFS object
is one file and there are no file boundaries inside it to cut at; cargoship#502 arrived at the same
place from the other direction, adding
maybeCutMidFileso a large file inside an archive is not oneunseekable multi-GB frame. Second, derive
Ffrom the object's uncompressed size at write timerather than shipping one constant, recording the chosen
Fin the descriptor and index so the readernever needs to know the rule. Rounded to a power of two,
F = clamp(2^round(log2 √(40·S·r)), 256 KiB, 16 MiB)withrtaken from the compression already performed reproduces the table above.The measurement that settles this is not a ratio benchmark. It is: replay a real read trace against
framed objects at
F ∈ {256 KiB … 16 MiB}on a real corpus of the population my earlier commentidentified (FASTQ, SAM, VCF, CSV/TSV, uncompressed NetCDF and TIFF), counting bytes transferred
and requests through
testaws's recording proxy, with a cold and a warm index. The open input isthe read-size distribution: the amplification denominator is the kernel's
MaxRead, and the wholecurve shifts if real workloads read 128 KiB or 1 MiB at a time. Nobody has measured that here.
Which kind of capability this is
Per
CLAUDE.md, the classification is not uniform across this feature, and saying so precisely is thepoint:
endpoint that ignores
Rangeand returns 200 with the whole body loses nothing that framing wasgoing to give it — it already sent every byte — so the reader decodes whole and verifies against
objectfs-sha256, which is today's behaviour and is correct.match its recorded hash, an index whose bytes do not match the descriptor's hash, or an index that
disagrees with itself, is
ErrCodeDataCorruption— never a quiet fall back to a whole-object fetchthat happens to work. No path may return bytes from a compressed object that were verified by
neither the frame hash nor the whole-object hash.
The probe is per-response, not per-endpoint, and it needs no request of its own. A store that
ignores
Rangereports itself:wholeObjectResponse(backend.go:763) already reads the total afterthe slash in
Content-Rangeand returnswhole = truefor a sub-range request answered with the wholebody. That is the probe. This differs from conditional write deliberately, and the difference is worth
recording next to
docs/design/conditional-write-compatibility.md: there, "accepted and ignored" isindistinguishable from "honoured" until a race is lost, which is why it needs
BackendCapabilitiesand a fail-closed default. Here the response itself carries the evidence, and anything it does not
carry — a clamped range, an off-by-one range, bytes from another generation — is caught by the frame
hash. So no
BackendCapabilitiesfield is required for this, and no compatibility matrix gates it.That is the design property to protect in review: if a change makes the frame hash optional, the
capability becomes probed-and-fail-closed like conditional write, and the matrix comes back.
One thing that must not be silent. Falling back to a whole-object fetch is safe for integrity — the
whole-object hash is the stronger attestation — and catastrophic for performance, since it restores the
216× amplification in the table above. A silent safe-but-slow fallback is precisely audit finding C4's
sibling in the parallel-read gate: "it fails quietly … nothing failed and nothing was logged"
(
backend.go:377). Every fallback needs a counter and aWarn, and a test that asserts the counter.What the implementation touches
internal/compression/zstd.go(87 lines today,Compress/Decompressover whole buffers). Add aframing encoder and a frame-index type.
Compressstays as it is for the non-framed path; the framedpath is
for each F-byte window: EncodeAllaccumulating(compressed_size, uncompressed_size, sha256(frame)), plus the 8-byte skippable header emitted by hand. AddDecompressFramefor thesingle-frame decode, which is
DecodeAllover one frame's bytes with the invariant that the result isexactly
uncompressed_size—DecodeAllover a concatenation would silently decode a neighbour. Theframe index belongs in
internal/compression, not ininternal/storage/s3: it is a property of theformat, and
internal/vfswill want it for the cache.internal/storage/s3/backend.go.prepareUpload(line 964) choosesF, frames, and writes theleading index frame plus
objectfs-seekable; it already computes the uncompressed SHA-256 first(line 969), which is the ordering the contract below depends on.
SetObjectMetadata(line 1014)restates
objectfs-seekablealongsideContent-Encoding.GetObject's two encoded arms (lines~440–480) gain the index-then-frames path.
sliceRange's call site (line 580) needs the frame-relativeoffset
offset − frame.uncompressed_offsetrather than the current whole-object offset — this is wherea double-applied offset will be introduced if it is introduced anywhere, and
FuzzSliceRangeis theright place to catch it.
checkFullyDecoded(line 2358) computeswholeObject := offset == 0 && (size <= 0 || size >= want)and compareslen(data)againstobjectfs-original-size; a framed partial readholds one frame's bytes, so this must compare against the frame's
uncompressed_sizeon that path orit will report a correct read as "still encoded".
The
objectfs-sha256contract.objectfs-sha256keeps its exact current meaning: SHA-256 over thewhole uncompressed content, computed before any encoding. Do not redefine it. What changes is the
coverage statement, and it changes in one direction only:
verifyChecksumruns iffread.whole(backend.go:568), i.e. a partial read of acompressed object is unverified — and cannot occur, because such a read re-fetches whole. The
contract holds by construction.
index before decode.
verifyChecksumstill runs on whole reads, unchanged. The invariant "nocompressed bytes are returned unverified" must now be enforced explicitly instead of falling out of
the design, so it needs a test that fails when the frame verification is deleted — verified by
mutation, not by inspection.
object-writable, so like
objectfs-sha256they detect corruption, truncation, and misdelivery, nottampering by someone holding
s3:PutObject.SECURITY.mdalready anticipates this work — "A readthat covers less than the whole object is not verified … Per-chunk checksums belong with the
seekable-framing work, which changes the stored layout" — and that bullet is rewritten by this
issue, while the "not a defence against a bucket an attacker can write to" paragraph below it stands
verbatim.
internal/cache. Item 4 above stands and the answer stays "decoded bytes": the cache key is(key, chunkIndex, etag)and decoded bytes align with it, while caching frames would need a secondkey space. The addition is that the index wants its own cache entry keyed on
(key, etag)— thewarm column in the table above is the whole payoff, and the ETag in the key is what makes an overwrite
invalidate it.
Item 5 above (multipart part boundaries) is wrong and should be struck. A ranged
GETis servedover the assembled object; part boundaries are not visible to it and a frame may straddle one freely.
What is true is the narrower thing already recorded elsewhere in this repo and in cargoship's own
reader guidance: a multipart ETag is not a content hash, so it is usable as a generation token for
If-Matchand never as an integrity check.Requirements from this issue that stand unchanged
testawscounts every request through its recordingproxy, so a 128 KiB read of a framed 64 MiB object must be asserted to transfer one or two frames'
worth of compressed bytes plus at most one index. Latency would pass on a fast link with a
whole-object fetch, which is the trap the C4 tests exist to avoid.
(offset, size)against the same range of the original bytes, extending theexisting round-trip fuzzer. Add the degenerate cases the arithmetic above will get wrong: a range
entirely inside one frame, a range straddling exactly two, a range ending on a frame boundary, a
read at
S-1, and a zero-length read.zstd -dmust still read the object. Verified above for both a leading and a trailing skippableframe with zstd 1.5.7; it needs to be a test, run against the CLI where available and against
klauspostalways.object with no
objectfs-seekableand no leading skippable frame takes the existing whole-objectpath forever. A migration tool is fine; a migration deadline is not.
objectfs-seekabledescriptor rather than a separateobjectfs-compression-format. Version lives in both the descriptor and the index frame, because thedescriptor can be lost by a
CopyObject.Genuinely open
size. Closed by instrumenting a real mount, not by reasoning about
MaxRead.synthetic; the repo-text row is real but is not scientific data. Closed by running the sweep over
actual FASTQ/SAM/VCF/CSV files.
Fshould be derived per object or fixed. The closed form argues derived; thecounter-argument is that a derived
Fmakes stored bytes depend on a formula that will change, andthe descriptor records
Fso a change is readable but not retroactive. Closed by deciding how muchthe ~2× at the curve's edges is worth against one fewer moving part.
objectfs-sha256should also be recorded in the index frame, so thatan object surviving a
CopyObjectthat dropped its metadata is still fully verifiable. Costs 32bytes. Leaning yes; it makes the object self-verifying, which is the same argument that put the index
in the object rather than in metadata.
Interoperability with cargoship and lith: one direction, and only if cargoship changes
ObjectFS should not read cargoship-written objects. A cargoship chunk is a tar stream inside a
.tar.zst, itsuncompressed_offsetis a position in that tar stream, and its index is in a manifestat a different key. Reading one would mean implementing tar-in-object presentation and manifest
discovery — a different feature, not a format decision. An ObjectFS object is one file, and its
uncompressed_offsetis a position in that file's own content. The coordinate spaces are not the samespace.
lith could read ObjectFS-written objects, and that is the direction worth enabling, because the
per-frame record layout would be byte-identical. What differs is only the locator: cargoship's index
is in a manifest, ObjectFS's is in a leading skippable frame. A reader that implements one index parser
and two locators serves both. Documenting the record layout as a shared thing — rather than each
project inventing its own field names — is the cheap part, and it is worth doing in the same change.
scttfrdmn commentedon Sep 16, 2026
Two corrections to the design comment above, both found by checking the library rather than reasoning about it, plus one open interop question. Stage 1 is up as #509.
zstd.Header.AppendTois exported. The design comment says klauspost/compress exports no skippable-frame writer and that objectfs therefore has to emit the 8-byte header itself. That is wrong at the version this repo is actually on.Header.AppendTois exported as of v1.20.0 and is the exact inverse ofHeader.Decode, which is what the reader side uses — so the writer and reader now go through the same library's understanding of the header instead of a hand-rolled encoder on one side and a parser on the other.skippableFrameandcalcSkippableFramedo remain unexported, which is probably what the original note was looking at.The version in the comment is wrong too:
go.modis on klauspost/compress v1.20.0, not v1.18.0.Open: skippable ID 0xE and the Zstandard Seekable Format. #509 uses ID 0xD, not 0xE, and the reason is worth recording as a decision rather than leaving as a detail. 0x184D2A5E is claimed by convention for the Zstandard Seekable Format's seek table, and that format is not what this is: its per-frame checksum is a 32-bit XXH64 truncation over each frame's decompressed bytes, which is both weaker than SHA-256 and on the wrong side of the decoder to protect it — the frame has already been decompressed by the time the checksum can be evaluated. objectfs hashes the compressed bytes precisely so a hostile frame never reaches the decompressor. Claiming 0xE would mean two incompatible layouts answering to one ID, and a reader that guessed wrong would misparse rather than cleanly decline, so 0xD plus an in-payload
"OFSI"magic it is.The open question is whether objectfs should additionally emit a real 0xE seek table for third-party interop (
zstdseek, and anything else that speaks that convention). It would be strictly additive — a second skippable frame — but it duplicates the frame table in a weaker form, and a reader trusting the 0xE table would be doing unverified ranged reads over the same object. Not doing it in this milestone; filing it separately if a concrete consumer turns up.feat(compression): seekable zstd framing, format layer (#185)
test(compression): strconv.Itoa, not a helper behind a build constraint
feat(compression): seekable zstd framing, format layer (#185) (#509)
feat(compression): frame compressed uploads and record a seekable des…
scttfrdmn commentedon Sep 16, 2026
Stages 1 and 2 are in
main.700098b, the format layer:FrameIndex, its skippable-frame encoding,DeriveFrameSize,the three-window ratio estimate.
57fb108, the write path: compressed uploads are emitted as independent frames with aleading index, and the backend records an
objectfs-seekabledescriptor in user metadata.No read is faster yet. Framing changes what gets stored; the reader is still whole-object. What the
two merged stages buy is that objects written from now on are seekable when the reader lands, rather
than needing a rewrite. A framed object is an ordinary zstd stream — the index is a skippable frame —
so the existing whole-object path,
aws s3 cpandzstd -dall decode one byte for byte, which is whatmade it safe to ship the halves separately.
Stage 3 — the read path, remaining
GetObject's two encoded arms take an index-then-frames path: read the descriptor from the responsemetadata it already has,
GET bytes=0-(IndexLength-1)for the index, then only the framesFramesCoveringnames.sliceRange's call site needs the frame-relative offset,offset - frame.UncompressedOffset(
FramesCovering's second return). This is the off-by-one that would make every ranged read on aframed object return shifted bytes.
checkFullyDecodedmust compare against the frame'sUncompressedSizeon the framed-partial path.Against the object's size it reports a correct partial read as still-encoded.
If-Match, so a concurrent overwrite cannot spliceframes from two generations.
disagrees — needs a counter and a
Warn. A silent fallback is the failure mode of the whole feature:it stays correct and quietly stops being fast. A test asserts the counter, not the log.
The win is asserted in bytes transferred, via
ts.BytesRead(key)(internal/testaws/recorder.go:679),not in latency.
TestFramedObjectServesRangedReadsalready logs today's amplification as the baseline tomeasure against.
Recorded as deliberate, not forgotten
No real
0xEZstandard Seekable Format seek table for third-party interop this milestone. The index isObjectFS's own format; a reader outside this project sees a valid zstd stream and nothing more.
scttfrdmn commentedon Sep 17, 2026
Stage 3 is up as #516 — the read path, which is the stage that makes stages 1 and 2 pay
for themselves.
Where the three stages stand
internal/compression)A ranged read of a compressed object no longer fetches the whole object. It resolves the
span to the frames covering it, issues one ranged GET for exactly those frames, decodes
them and slices frame-relative. Objects without a usable descriptor take the old path,
and
SeekableLastFallbackReasonrecords why — so an expensive read is diagnosable ratherthan just slow.
Two design points settled in stage 3
The decoder is chosen by the object, not by the configuration. An earlier draft looked
up the decoder from
Settings.Algorithm, which meant flippingalgorithmin the configmade every already-written compressed object unreadable. Decoders are now built for every
supported algorithm regardless of what is enabled, and the lookup key is the object's
own stored encoding. A read must not depend on how the writer is configured today.
A frame that disagrees with its index is an error, not a fallback. Falling back to the
whole object on a checksum mismatch would convert a detected integrity failure into a slow
success. Per this project's stated order — integrity first — the read fails closed and
names the frames and the span.
DecodeFramesalso checks the body length against the indexbefore decoding, so a damaged or hostile index cannot drive the output allocation.
That second one is also a lesson about the test suite: 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 through that
path. It had to be tested against the function directly, which is what
internal/compression/decode_frames_test.gois for. A 19-mutation run over the read pathand the frame decoder now catches all 19; five survived the first pass and are the reason
that file and four S3 tests exist.
Deliberately not in this milestone
Emitting a real
0xEZstandard Seekable Format skippable frame so third-party zstd toolscan seek these objects. The index here is ObjectFS's own and is read only by ObjectFS.
Interop is worth doing, but it is additive to a format that now works end to end, so it
belongs to its own issue rather than holding up the stage that removes the read
amplification. Happy to file it if you want it tracked separately.
Related, found on the way
amplification this issue exists to remove, arriving by a different route.
internal/testaws's request-body byte counter, found by the-racerun for this branch. Green, and independent of this work.feat(s3): serve ranged reads of a framed object from its frames (#185 …
scttfrdmn commentedon Sep 17, 2026
All three stages are merged. Seekable framing is complete end to end.
The measured result, on a 1 MiB ~50%-compressible object: a 4 KiB read 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, so at the 256 KiB
frame-size floor a small read of a 10 GiB compressed object costs the index plus one frame no
matter how large the object is. That is the read amplification this issue was opened about.
What was settled along the way, and is worth not relitigating
every conformant decoder must ignore, so
zstd -d,aws s3 cp, and the pre-existingwhole-object read path all return the file byte for byte. Objects written by earlier versions
are untouched.
frame size is derived as
sqrt(40 * size * ratio)clamped to [256 KiB, 16 MiB] rather thanfixed. Neither Seekable zstd framing so a ranged read fetches only the frames it covers #185's original 1–4 MiB guess nor CargoShip's 16 MiB was adopted, because each
is right for a different cost model.
read on
Settings.Algorithm, which made every already-written compressed object unreadablethe moment
algorithmchanged. A read must not depend on how the writer is configured today.as non-retryable
DATA_CORRUPTION, not worked around by re-fetching the whole object — thewhole-object path is not a second opinion, since the same damaged bytes are in that stream too.
A read covering every frame is deliberately routed to the whole-object path, which restores
the whole-content
objectfs-sha256check for whole-file reads and is also the cheaper request.correct bytes, so the failure mode is not an error anyone sees but a silent return to
whole-object transfer. Hence
seekable_reads,seekable_read_bytes,seekable_whole_fallbacks, andseekable_last_fallback_reason, all at warn rather than debug.Follow-ups, both filed
0xE) seek table so third-party zstd toolingcan seek these objects. Deliberately not done here: it is additive to a format that now works,
and doing it in the same milestone would have meant two new things to be wrong at once. Its
first open question is whether a consumer exists, since the bytes are spent on every object.
parallel_read_thresholdstill attempts the parallel fan-out first andabandons it on finding the object encoded, having already transferred bytes framing would have
avoided. Bounded by
parallel_read_concurrency * read_chunk_sizeand correct in every case,but it is this issue's own amplification arriving by a different route.
I would close this as complete, with #518 and #514 carrying the remainder. Leaving that to you
since #514 in particular is the same cost centre and you may prefer this stay open until it is
dealt with.
scttfrdmn commentedon Sep 17, 2026
Closed as complete: all three stages are merged (#509 frame-index format, #513 upload path, #516 ranged read) and the measured result is in the issue above — a 4 KiB read of a 1 MiB ~50%-compressible object went from 1,074,071 bytes transferred to 134,554.
Shipping in 0.15.0 (#523), not the 0.16.0 this milestone was originally titled. The milestone has been renamed: the four changelog lines that made 0.16.0 look like the next number were describing the #362 upload-path removal, which actually shipped in 0.12.0.
Two follow-ons were filed off this work and are deliberately out of scope here: #514 (an abandoned parallel-read fan-out still transfers most of the body framing exists to avoid) and #518 (emit a standard Zstandard Seekable Format table — its own recommendation is not to build it until a consumer is named).
release: cut 0.15.0, and correct four references to a release that ne…
perf(s3): probe the fan-out with one chunk instead of a full wave (#514…