Skip to content

Read the parts of a multipart upload (GetPart) - #74

Open
marvin-hansen wants to merge 5 commits into
carverauto:mainfrom
marvin-hansen:main
Open

marvin-hansen wants to merge 5 commits into
carverauto:mainfrom
marvin-hansen:main

Conversation

@marvin-hansen

Copy link
Copy Markdown
Contributor

Closes #71

Reads one part of a multipart upload, or a byte range of it, while the upload is in progress or after it completed: Amazon S3's GetPart (announced 2026-11-29). OpenSpec change: openspec/changes/add-get-part (proposal, design, spec deltas for reported-operations and high-level-client).

What changes

  • longshore_s3 store: S3::get_part and S3::get_part_with read part N of an upload into the caller's buffer within a Limit and end with a report, as get does. The answer gains the upload's state, Answer::upload_status() (InProgress, Completed), from x-amz-multipart-upload-status. A 2xx answer without it was not answered as a GetPart (a store that does not know the call may take it for ListParts or GetObject?partNumber), and its bytes are not the part; the docs say so.
    • A whole part asks for its checksums; a CRC-64/NVME the store returns is checked, a mismatch fetched again within the limit and reported as verified: Some(false) if it persists. A range is not checked.
    • Refused before sending: a part number outside 1..=10,000, a backward range, Google Cloud Storage (no such call).
    • The query is part=&partNumber=N&uploadId=X, as SigV4 signs a valueless key, written by the same code as UploadPart's.
  • Shareable client: Client::get_part with a lent buffer and a Budget; on a client with a cache it goes to the origin. A refusal's error document (NoSuchPart, NoSuchUpload) is in the buffer. Upload::upload_id() gives an upload stream's id once it has begun, so a writer can hand it to a reader.
  • In-tree test server (longshore_http_client): answers GetPart in progress (from the stored part) and once completed (from the object, whose parts' lengths are kept beside it): 200/206/416, the part's ETag, its CRC-64/NVME when asked, IN_PROGRESS/COMPLETED, NoSuchPart, NoSuchUpload. Accepts part& and part=&.
  • Cache: no code change; a test pins that GetPart is relayed to the origin whole under every mode, never served from what the cache holds.
  • docs/client.md: how a reader follows an upload while it is written, and what each refusal tells it.

First principles: nothing allocates after setup (the store tests run under the allocation guard), the body lands in the caller's buffer without a copy, the request is signed over its head only. Outcome stays 2,632 bytes (the new field fits in padding); a test now states that size.

Tests

  • store_s3_get_part (8): in progress; completed; a range with its Content-Range; 416 past the part's end; NoSuchPart vs NoSuchUpload; a store answering without the state; a damaged part read again, and damage every time reported; a cut-short body and a reset read again; a deadline. Every request's SigV4 signature is verified by the server.
  • client_upload follow: a reader follows an upload stream part by part (in progress, not stored yet, completed, past the last, aborted).
  • client_routed: a routed client's get_part reaches the origin and never the shard.
  • cache_transparent: GetPart relayed whole, in progress and completed, both query forms, under each mode.
  • gcs_sim: refused on Google Cloud Storage.
  • Full suites of longshore_s3, longshore_http_client, longshore_s3_cache and the facade; docs with -D warnings; license headers. In the rust:1-bookworm container: CI's fmt and clippy steps (all feature sets and the explored build), and the S3 store and HTTP pool explorations.

Open before the change is archived

  • 4.1: check against Amazon S3 itself (needs an AWS account): whether the state is on every answer, which query form is taken, whether If-Match/versionId are honoured, whether a part's CRC-64/NVME comes back after a full-object checksum.
  • 4.2: what RustFS answers a GetPart.

🤖 Generated with Claude Code

marvin-hansen and others added 5 commits December 3, 2026 09:42
Issue carverauto#71. GetPart (Amazon S3, 2026-11-29) reads a part of an upload in
progress or completed: get_part on the store and the client, reported as
get is, with the upload's state in the answer, Upload::upload_id for a
reader that follows a writer, and the in-tree server answering it.
Checked with the Miniature Guide to Critical Thinking: unverified claims
marked as assumptions with a task each, the follow protocol made exact,
and RustFS's answer and Amazon S3's own recorded before archiving.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A GET of `key?part&partNumber=N&uploadId=X` (or `part=&`, as SigV4 signs
it) reads one part of a multipart upload, or a range of it, as Amazon S3
answers it: from the part its UploadPart stored while the upload is in
progress, and from the object once it completed, whose parts' lengths
are now kept beside it and cleared by every other write. The answer says
the upload's state in x-amz-multipart-upload-status, gives the part's
ETag, its CRC-64/NVME when asked for a whole part, 206 with a
Content-Range of the part for a range, 416 past its end, and NoSuchPart
or NoSuchUpload. Scripted damage and short bodies apply to it as to any
read.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…leted

S3::get_part and get_part_with read part N of a multipart upload, or a
range of it, into the caller's buffer within a limit, and end with a
report as get does. The answer gains the upload's state
(Answer::upload_status, from x-amz-multipart-upload-status); a 2xx
without it was not answered as a GetPart, and its bytes are not the
part. A whole part asks for its checksums and its CRC-64/NVME is checked,
a mismatch fetched again within the limit. A part number outside 1 to
10,000, a backward range and Google Cloud Storage are refused before
sending. The query is part=&partNumber=N&uploadId=X, as SigV4 signs it,
written by the same code as UploadPart's.

Client::get_part does the same through the shareable client with a lent
buffer and a budget, and goes to the origin on a client with a cache;
Upload::upload_id gives a stream's upload id once it has begun, for a
reader to follow it. Tested on the simulator under the allocation guard:
in progress, completed, ranges, 416, NoSuchPart and NoSuchUpload, a store
without the state, damage, a short body, a reset and a deadline, a
reader following an upload stream to its end and to its abort, and a
routed client that never asks its shard. A test states the size of
Outcome, so that a field added to an answer is seen.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
A GetPart through the cache is relayed to the origin and answered as the
origin answers it under each mode, in progress and after completion, the
object read through the cache first so that a part served from what the
cache holds would show. docs/client.md tells how a reader follows an
upload while it is written. Every task is done but checking Amazon S3
and RustFS themselves (4.1, 4.2).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
S3::get_part and Client::get_part read a part of a multipart upload, or
a range of it, while the upload is in progress or after it completed,
and report the upload's state with the store's answer. The in-tree
server answers GetPart, and the cache relays it whole. Checking Amazon
S3 and RustFS themselves (tasks 4.1, 4.2) remains before the change is
archived.

Revert this merge (git revert -m 1) to take it out.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

@mfreeman451 mfreeman451 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed PR #74 (GetPart). The core store/client implementation is clean, zero-allocation, and fits cleanly into the existing Exact/Report path (keeping Outcome at 2,632 bytes). Left inline comments on the issues and edge cases found:

  • Cache relay (longshore_s3_cache): falling through to Kind::Forward buffers responses in a single cache block (default 1 MiB, max 16 MiB) — smaller than real S3 multipart parts (≥ 5 MiB) — and requires write permission for read-only keys under Cache::with_keys.
  • S3::get_part_with / design.md: docs state a caller can pass a versionId through headers: &Options, which isn't possible because versionId is a query parameter, not a request header.
  • In-tree test server: non-consecutive completed parts silently serve the wrong part's bytes; query parsing breaks if part isn't first or uploadId isn't last (e.g. &x-id=GetPart); wrong-key in-progress lookups return NoSuchPart instead of NoSuchUpload; backward Range handling diverges from server/reads.rs; and versioned delete markers retain stale upload/part_lens in Digest.
  • Docs & tests: docs/client.md follow example doesn't check answer.verified() before accepting bytes; missing tests for malformed x-amz-multipart-upload-status and S3::get_part_with; and QUERY_MAX multipart prefix sizing is now at zero headroom.

}

#[test]
fn get_part_is_relayed_whole_and_never_served_from_the_cache() {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Relying on Kind::Forward with no cache code change has two real-world gaps for S3 clients sending GetPart through longshore_s3_cache:

  1. Single-block response cap: Kind::Forward (write.rs / relay.rs submit_whole) buffers the origin response into a single cache block (w.into). BLOCK_DEFAULT is 1 MiB (BLOCK_MOST is 16 MiB), whereas real Amazon S3 multipart parts are at least 5 MiB (up to 5 GiB). Under default settings, a whole-part GetPart against real S3 will overflow the block buffer and fail — this test passes only because the simulated parts are a few bytes. (Contrast with uncached GetObject in pass.rs, which streams block-by-block.)
  2. Read-only keys denied 403: access.rs:98-105 computes let write = !matches!(request.kind, Kind::GetObject | Kind::HeadObject | Kind::ListV2);, so Kind::Forward requires write permission. A read-only key calling GetPart through a cache configured with Cache::with_keys will be refused 403 even though GetPart is a GET read.

(longshore::Client::get_part bypasses the cache shards directly so it isn't affected, but external S3 clients going through the cache will hit both.)


/// [`S3::get_part`], also sending `headers`, as [`S3::get_with`] does:
/// a condition or a version id the store may or may not honour for a
/// part, which its answer then says.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

headers: &Options only carries HTTP request headers, so a caller cannot send a versionId through get_part_with — in S3, versionId is a query parameter (?versionId=...), while x-amz-version-id is a response-only header. (Compare get_with, which encodes expect.version via version_query.)

Documented GetPart request headers like x-amz-request-payer and x-amz-expected-bucket-owner (or trying If-Match) can be passed via headers; the doc comment here and openspec/changes/add-get-part/design.md:133-136 should be updated so they don't claim versionId can be sent this way.

// Kept for a `GetPart` of the completed upload.
if let Some(slot) = self.find(upload.path) {
let o = &mut self.objects[slot];
(o.upload, o.part_lens, o.parts) = (id, lens, count as u8);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assemble records lens[k] by position k in listed without checking that the completed part numbers are consecutive 1..=count, and get_part::find_part indexes o.part_lens[n as usize - 1]. If an upload completes with non-consecutive part numbers (e.g., parts 2 and 4), GetPart for partNumber=1 silently serves part 2's bytes, partNumber=2 serves part 4's bytes, and partNumber=4 returns NoSuchPart.

As design.md notes, Amazon S3 doesn't support GetPart on uploads completed with non-consecutive part numbers. Checking listed[..count].iter().enumerate().all(|(k, (n, _, _))| *n == k as u32 + 1) before setting o.upload = id (leaving o.upload = 0 otherwise) avoids silently returning the wrong part's bytes.

.filter(|id| *id != 0);
// `part` has no value: `part&` as S3's examples write it, `part=&`
// as SigV4 signs it.
if method == b"GET" && (query.starts_with(b"part=&") || query.starts_with(b"part&")) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This assumes part / part= is always the first query parameter and uploadId= is always last (after(query, b"uploadId=") takes the entire tail of query). Any parameter after uploadId= — such as AWS SDK's &x-id=GetPart — or reordered parameters (?part&uploadId=sim-upload-1&partNumber=1) causes u32::from_str_radix to fail and returns 404 NoSuchUpload.

Splitting query on b'&' (as server/query.rs already does) handles arbitrary parameter order and extra params like x-id, and also lets get_part.rs:52 reject malformed values like partNumber=1abc instead of parsing the leading digits.

/// with.
fn find_part(&self, asked: &Asked<'_>, n: u32) -> Result<Found, &'static str> {
let id = asked.id.ok_or("NoSuchUpload")?;
if self.uploads.contains(&id) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

self.uploads.contains(&id) only checks that id is an active upload somewhere on the server, not that it belongs to asked.path. Requesting GetPart for a different key with an active uploadId falls through to self.find(...) and returns NoSuchPart instead of NoSuchUpload (unlike the completed-upload path at line 101, which checks &o.target[..o.target_len] == asked.path and returns NoSuchUpload).

let range = match (c.suffix, c.range) {
(Some(0), _) if len > 0 => return self.s3_error(io, i, &INVALID_RANGE),
(Some(k), _) if len > 0 => Some((len.saturating_sub(k), len - 1)),
(None, Some((a, _))) if a >= len && len > 0 => {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Missing a <= b guard compared to server/reads.rs:112 (c.range.is_some_and(|(a, b)| a <= b && a >= o.len)). As written, a syntactically invalid backward range like Range: bytes=500-100 (with len = 200) returns 416 InvalidRange, while Range: bytes=100-50 falls through to _ => None and returns 200 OK. Adding a <= b keeps this consistent with reads.rs and RFC 9110 §14.1.2.

d.add(&tags_count);
// What a `GetPart` of the upload it was completed from reads.
d.add(&upload);
if *upload != 0 {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When versioning is enabled, delete_version in server/deletes.rs:62-74 converts an object slot into a delete marker (o.kept.marker = true, o.used stays true) without clearing o.upload = 0. Since Digest hashes upload and part_lens[..parts] whenever used is true and *upload != 0, a delete marker over a completed multipart object hashes differently from a delete marker over a plain PUT even though find_part checks o.live() and never reads those fields.

Clearing o.upload = 0 in delete_version (or guarding if *upload != 0 && !kept.marker here) keeps the model-checker state digest canonical.

Comment thread docs/client.md
let End::Answered(answer) = read.expect("an error means nothing was sent").end() else { break };
match (answer.status(), answer.upload_status()) {
// Part `number` is in `body`; in progress, it may still be replaced.
(200, Some(UploadStatus::InProgress | UploadStatus::Completed)) => number += 1,

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider checking answer.verified() != Some(false) here before accepting the part bytes. When every retry fails CRC-64/NVME verification, get_part still returns End::Answered(answer) with status() == 200, upload_status() == Some(...), and verified() == Some(false) — so a caller following this snippet as written would silently consume corrupted bytes and move on to number + 1.

));
let a = read_once(&mut w, 3, &upload, 2);
assert_eq!((a.status(), a.body_len()), (200, 13));
assert_eq!(a.upload_status(), None);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Two small coverage gaps:

  • This tests an absent x-amz-multipart-upload-status header (upload_status() == None), but there's no test for an unknown or empty x-amz-multipart-upload-status value asserting a.malformed() && a.upload_status().is_none() (specified in task 1.1 and implemented in s3/exact.rs:342).
  • S3::get_part_with (passing custom headers through Options) isn't exercised by any test.

digits[at] = b'0' + (v % 10) as u8;
v /= 10;
}
let mut prefix = [0u8; 32];

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: with lead = b"part=&", b"part=&partNumber=10000&uploadId=".len() is now exactly 32 bytes — leaving zero bytes of headroom in s3/consts.rs:28's let multipart = 32 + 3 * UPLOAD_ID_MAX; (currently safe only because VERSION_ID_MAX dominates QUERY_MAX at 3082), and the doc comment on QUERY_MAX still only mentions partNumber=10000&uploadId=. Expressing the 32 as b"part=&partNumber=10000&uploadId=".len() and updating that comment would keep the invariant self-documenting.

@mfreeman451

Copy link
Copy Markdown
Contributor

Ran task 4.1 against a real Amazon S3 general-purpose bucket in us-east-1 (2026-12-03) using both this PR's longshore_s3::client::Client and raw SigV4 HTTPS probes.

1. longshore_s3 live S3 verification

Case Status upload_status crc64 / verified Notes
In-progress whole part (5 MiB, FULL_OBJECT) 200 Some(InProgress) Some(...) / Some(true) 5 MiB bytes match, ETag, AES256
In-progress range 100..=199 206 Some(InProgress) None / None ContentRange { 100..=199 / 5242880 }, bytes match
In-progress range past end 416 None None InvalidRange
In-progress missing part 404 None None NoSuchPart
In-progress part replaced (upload_part #1 again) 200 Some(InProgress) Some(...) / Some(true) New ETag, new CRC-64/NVME, updated bytes match
Completed whole parts 1 (5 MiB) & 2 (2 KiB) 200 Some(Completed) None / None Exact byte match (no CRC-64/NVME returned once completed; see below)
Completed range 10..=29 of part 2 206 Some(Completed) None / None ContentRange { 10..=29 / 2048 }, bytes match
Completed range past end 416 None None InvalidRange
Completed past-last part (#3) 404 None None NoSuchPart
Aborted upload 404 None None 200 InProgress before abort → 404 NoSuchUpload after
Upload::upload_id() streaming follow 404 → 200 → 200 InProgress → Completed Some(true) in progress, None completed None before write, Some(id) once first part goes out; bytes match
Non-consecutive completed upload (parts 1 & 3) 405 None None UnsupportedOperation for parts 1, 2, and 3

2. Answers to task 4.1 open questions

  • Query form (part= vs part): Amazon S3 accepts all of ?part&partNumber=1&uploadId=X, ?part=&partNumber=1&uploadId=X (what longshore_s3 sends), reordered ?uploadId=X&partNumber=1&part, and ?part&partNumber=1&uploadId=X&x-id=GetPart.
  • x-amz-multipart-upload-status presence: Present on every 200 and 206 (IN_PROGRESS / COMPLETED), and absent on every error response (404 NoSuchPart, 404 NoSuchUpload, 416 InvalidRange, 405 UnsupportedOperation, 400 InvalidArgument). This confirms the PR's rule that a 2xx without upload_status was not answered as GetPart.
  • If-Match, If-None-Match, and versionId: All three are explicitly rejected with 400 InvalidArgument (both in-progress and completed, matching or wrong value):
    • if-match header is not supported for this operation.
    • if-none-match header is not supported for this operation.
    • versionId query parameter is not supported for this operation.
    • On a versioned bucket, overwriting the key with a new version v2 still allows GetPart on v1's uploadId (without versionId), returning 200 COMPLETED and x-amz-version-id: <v1>.
  • Part CRC-64/NVME after FULL_OBJECT checksum:
    • In progress: S3 returns x-amz-checksum-crc64nvme on GetPart (even when checksums = false and no checksum was sent on UploadPart), and longshore_s3 reports verified: Some(true).
    • Completed (FULL_OBJECT CRC-64/NVME or checksums = false): S3 does not return x-amz-checksum-crc64nvme even with x-amz-checksum-mode: ENABLED, so longshore_s3 reports crc64: None, verified: None (never falsely Some(false)). Note that the in-tree test server (server/get_part.rs:115) currently returns CRC-64/NVME on completed parts, which differs from real S3.
    • COMPOSITE (tested with SHA256): S3 returns x-amz-checksum-sha256 on both in-progress and completed GetPart.
  • Wrong key with an active in-progress uploadId: S3 returns 404 NoSuchUpload (matching the earlier inline comment on server/get_part.rs:69).

This branch has not been deployed

No deployments
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.

feat: add support for new GetPart API

2 participants