Skip to content

fix: delete the upload path that dropped four headers and gained nothing (#362) - #363

Merged
scttfrdmn merged 2 commits into
mainfrom
fix/cargoship-transporter-362
Aug 5, 2026
Merged

scttfrdmn merged 2 commits into
mainfrom
fix/cargoship-transporter-362

Conversation

@scttfrdmn

Copy link
Copy Markdown
Owner

Closes #362.

PutObject had two implementations. The CargoShip transporter branch already carried three bypasses with long comments explaining what cargoships3.Archive cannot express — a Content-Encoding, the configured encryption headers, a per-object storage class. This issue found the fourth, which was not bypassed but silently wrong.

The fourth limitation

Content-Type was written into Archive.Metadata under a "content-type" key. That is S3 user metadata, not the header. Measured through the endpoint on file.txt:

path stored Content-Type
transporter application/octet-stream
direct text/plain

detectContentType computed the right value one line earlier in both cases. Since the transporter was reachable only below multipart.threshold, that was every object under 32 MiB on the shipped defaults — which is every object a FUSE mount writes.

Why deletion rather than a fourth bypass

The transporter was unreachable at or above the threshold: PutObject returns into putObjectMultipart first, and that function never referenced a transporter (grep count zero). So its 64 MiB multipart BufferProvider was installed on a path that only ever performed single-part uploads.

That buffer lives in a sync.Pool, which is cleared at every GC cycle — so it was re-allocated on the first PUT after each collection rather than amortized:

total alloc
20 PUTs, no GC between 3.4 MiB
20 PUTs, forced GC after each 837.2 MiB

It also inverted GOMEMLIMIT. 300 difftest iterations, transporter on: 768 MiB limit → 751 MiB alloc / 4 GCs; 384 MiB limit → 3570 MiB / 28 GCs. Transporter off: 285 MiB at both limits. A tighter limit means more pool clears.

Throughput gave nothing back — 30 PUTs per size against the in-process endpoint:

size on off
4 KiB 327µs 243µs 35% slower
1 MiB 2.851ms 2.624ms 8% slower
8 MiB 20.531ms 20.786ms a wash

A local endpoint is not evidence against BBR over a real network, but the sizes where BBR could matter never reached the branch.

It further stamped four metadata keys on every small object, two structurally empty (cargoship-original-size always "0", cargoship-compression-type always ""), plus cargoship-created-by and a cargoship-upload-time timestamp that made otherwise-identical objects differ.

Four silently-wrong headers against no reachable benefit is a subtraction.

What's removed

storage.s3.use_cargoship, s3.Config.EnableCargoShipOptimization, ClientManager.GetTransporter, ClientManager.IsCargoShipEnabled, cargoShipCanEncrypt, and the branch itself. ConvertTierToCargoShipStorageClass stays — it has its own unit tests and CargoShip's awsconfig types are still used for tier mapping.

The config key is removed rather than deprecated, and the loader decodes strictly, so a file still setting it fails at startup naming the key. Same reasoning as the removed security.encryption booleans and the cost_optimization block: an operator who set it did so believing their uploads took a different path, and an error is the one way that belief gets re-examined. The fuzz corpus seed for the key was converted to a rejectedByLoader case rather than deleted.

Tests

internal/storage/s3/upload_path_test.go pins the boundary rather than the path, so a future second upload path has to satisfy these rather than inherit an untested seam:

  • the detected Content-Type reaches the stored object, parameterized over four suffixes × both sides of the multipart threshold
  • the stored user-metadata key set is exactly {objectfs-sha256} — an exact set, not a cargoship- prefix check, since a prefix check would pass for any future path stamping its own provenance under a different name
  • caller-supplied metadata survives PutObject's meta argument (this is how vfs carries modes and ownership)

All three fail on the pre-change code and were verified by mutation: dropping ContentType from the input, stamping a foreign metadata key, and dropping the caller's keys each fail the corresponding test.

testaws.TestServer.ObjectContentType was added to read the header specifically, deliberately separate from ObjectMetadata, since confusing the two is the defect.

One test nearly shipped passing for the wrong reason. The first draft set MultipartChunkSize to 1 MiB, below the AWS uploader's 5 MiB part minimum, so every CargoShip upload failed with part size must be at least 5242880 bytes and fell back to the direct path — which sets the header correctly. It was green against the broken code. Caught by reading the CargoShip optimization failed, falling back to standard S3 warning in the output of a run that was supposed to be failing.

Verification

PutObject had two implementations. The CargoShip transporter branch already
carried three bypasses explaining what cargoships3.Archive cannot express — a
Content-Encoding, the configured encryption headers, a per-object storage
class — and #362 found the fourth, which was not bypassed but silently wrong:
Content-Type was written into Archive.Metadata, which is S3 user metadata, not
the header. Measured through the endpoint, file.txt stored as
application/octet-stream on that path and text/plain on the direct one, with
detectContentType having computed the right value one line earlier in both.

There was nothing on the other side. The transporter was reachable only below
MultipartThreshold, since PutObject returns into putObjectMultipart first and
that function never referenced a transporter — so its 64 MiB multipart
BufferProvider served an upload shape a mount cannot produce, and sync.Pool
released that buffer at every GC: 20 PUTs allocated 3.4 MiB with no GC between
them and 837 MiB with one after each, which also inverted GOMEMLIMIT.
Throughput was 35% slower at 4 KiB and a wash at 8 MiB.

So it is deleted rather than given a fourth bypass, along with
storage.s3.use_cargoship, s3.Config.EnableCargoShipOptimization,
GetTransporter, IsCargoShipEnabled, and cargoShipCanEncrypt. The config key is
removed rather than deprecated and the loader is strict, so a file still
setting it fails at startup naming the key — an operator who set it believed
their uploads took a different path, and an error is the one way that belief
gets re-examined. ConvertTierToCargoShipStorageClass stays.

upload_path_test.go now pins the boundary rather than the path: Content-Type
reaches the stored object on both sides of the threshold, the stored metadata
key set is exactly what ObjectFS wrote, and caller metadata survives. All three
fail on the old code and were verified by mutation. The first draft passed for
the wrong reason — a 1 MiB chunk size is below the AWS uploader's 5 MiB part
minimum, so every CargoShip upload failed and fell back to the path that sets
the header correctly.
@scttfrdmn scttfrdmn added type: bug Something isn't working as expected priority: medium Important but not urgent area: s3 S3 backend integration and operations area: buffer Write buffering and memory management cargoship: integration CargoShip integration work labels Aug 5, 2026
@scttfrdmn
scttfrdmn merged commit 611b343 into main Aug 5, 2026
33 checks passed
@scttfrdmn
scttfrdmn deleted the fix/cargoship-transporter-362 branch August 5, 2026 22:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

area: buffer Write buffering and memory management area: s3 S3 backend integration and operations cargoship: integration CargoShip integration work priority: medium Important but not urgent type: bug Something isn't working as expected

Projects

None yet

Development

Successfully merging this pull request may close these issues.

s3: CargoShip's 64 MiB upload buffer is allocated per GC cycle, and 4 KiB PUTs pay for all of it

1 participant