Repository navigation
Read the parts of a multipart upload (GetPart) - #74
marvin-hansen wants to merge 5 commits into
Conversation
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
left a comment
There was a problem hiding this comment.
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 toKind::Forwardbuffers 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 underCache::with_keys. S3::get_part_with/design.md: docs state a caller can pass aversionIdthroughheaders: &Options, which isn't possible becauseversionIdis 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
partisn't first oruploadIdisn't last (e.g.&x-id=GetPart); wrong-key in-progress lookups returnNoSuchPartinstead ofNoSuchUpload; backwardRangehandling diverges fromserver/reads.rs; and versioned delete markers retain staleupload/part_lensinDigest. - Docs & tests:
docs/client.mdfollow example doesn't checkanswer.verified()before accepting bytes; missing tests for malformedx-amz-multipart-upload-statusandS3::get_part_with; andQUERY_MAXmultipart prefix sizing is now at zero headroom.
| } | ||
|
|
||
| #[test] | ||
| fn get_part_is_relayed_whole_and_never_served_from_the_cache() { |
There was a problem hiding this comment.
Relying on Kind::Forward with no cache code change has two real-world gaps for S3 clients sending GetPart through longshore_s3_cache:
- Single-block response cap:
Kind::Forward(write.rs/relay.rssubmit_whole) buffers the origin response into a single cache block (w.into).BLOCK_DEFAULTis 1 MiB (BLOCK_MOSTis 16 MiB), whereas real Amazon S3 multipart parts are at least 5 MiB (up to 5 GiB). Under default settings, a whole-partGetPartagainst real S3 will overflow the block buffer and fail — this test passes only because the simulated parts are a few bytes. (Contrast with uncachedGetObjectinpass.rs, which streams block-by-block.) - Read-only keys denied 403:
access.rs:98-105computeslet write = !matches!(request.kind, Kind::GetObject | Kind::HeadObject | Kind::ListV2);, soKind::Forwardrequires write permission. A read-only key callingGetPartthrough a cache configured withCache::with_keyswill be refused 403 even thoughGetPartis aGETread.
(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. |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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&")) { |
There was a problem hiding this comment.
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) { |
There was a problem hiding this comment.
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 => { |
There was a problem hiding this comment.
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 { |
There was a problem hiding this comment.
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.
| 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, |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
Two small coverage gaps:
- This tests an absent
x-amz-multipart-upload-statusheader (upload_status() == None), but there's no test for an unknown or emptyx-amz-multipart-upload-statusvalue assertinga.malformed() && a.upload_status().is_none()(specified in task 1.1 and implemented ins3/exact.rs:342). S3::get_part_with(passing custom headers throughOptions) isn't exercised by any test.
| digits[at] = b'0' + (v % 10) as u8; | ||
| v /= 10; | ||
| } | ||
| let mut prefix = [0u8; 32]; |
There was a problem hiding this comment.
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.
|
Ran task 4.1 against a real Amazon S3 general-purpose bucket in 1.
|
| 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=vspart): Amazon S3 accepts all of?part&partNumber=1&uploadId=X,?part=&partNumber=1&uploadId=X(whatlongshore_s3sends), reordered?uploadId=X&partNumber=1&part, and?part&partNumber=1&uploadId=X&x-id=GetPart. x-amz-multipart-upload-statuspresence: Present on every200and206(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 a2xxwithoutupload_statuswas not answered asGetPart.If-Match,If-None-Match, andversionId: All three are explicitly rejected with400 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
v2still allowsGetPartonv1'suploadId(withoutversionId), returning200 COMPLETEDandx-amz-version-id: <v1>.
- Part CRC-64/NVME after
FULL_OBJECTchecksum:- In progress: S3 returns
x-amz-checksum-crc64nvmeonGetPart(even whenchecksums = falseand no checksum was sent onUploadPart), andlongshore_s3reportsverified: Some(true). - Completed (
FULL_OBJECTCRC-64/NVME orchecksums = false): S3 does not returnx-amz-checksum-crc64nvmeeven withx-amz-checksum-mode: ENABLED, solongshore_s3reportscrc64: None, verified: None(never falselySome(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 withSHA256): S3 returnsx-amz-checksum-sha256on both in-progress and completedGetPart.
- In progress: S3 returns
- Wrong key with an active in-progress
uploadId: S3 returns404 NoSuchUpload(matching the earlier inline comment onserver/get_part.rs:69).
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 forreported-operationsandhigh-level-client).What changes
longshore_s3store:S3::get_partandS3::get_part_withread part N of an upload into the caller's buffer within aLimitand end with a report, asgetdoes. The answer gains the upload's state,Answer::upload_status()(InProgress,Completed), fromx-amz-multipart-upload-status. A 2xx answer without it was not answered as aGetPart(a store that does not know the call may take it forListPartsorGetObject?partNumber), and its bytes are not the part; the docs say so.verified: Some(false)if it persists. A range is not checked.part=&partNumber=N&uploadId=X, as SigV4 signs a valueless key, written by the same code asUploadPart's.Client::get_partwith a lent buffer and aBudget; 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.longshore_http_client): answersGetPartin progress (from the stored part) and once completed (from the object, whose parts' lengths are kept beside it): 200/206/416, the part'sETag, its CRC-64/NVME when asked,IN_PROGRESS/COMPLETED,NoSuchPart,NoSuchUpload. Acceptspart&andpart=&.GetPartis 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.
Outcomestays 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 itsContent-Range; 416 past the part's end;NoSuchPartvsNoSuchUpload; 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_uploadfollow: a reader follows an upload stream part by part (in progress, not stored yet, completed, past the last, aborted).client_routed: a routed client'sget_partreaches the origin and never the shard.cache_transparent:GetPartrelayed whole, in progress and completed, both query forms, under each mode.gcs_sim: refused on Google Cloud Storage.longshore_s3,longshore_http_client,longshore_s3_cacheand the facade; docs with-D warnings; license headers. In therust:1-bookwormcontainer: 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
If-Match/versionIdare honoured, whether a part's CRC-64/NVME comes back after a full-object checksum.GetPart.🤖 Generated with Claude Code