Repository navigation
feat(catalog/rest): resend keyed requests within the idempotency key lifetime - #2679
AynSiddiqui wants to merge 13 commits into
Conversation
…lifetime Create one Idempotency-Key and body per call and reuse them for resends after a 500, 502, 503 or 504, a timeout or a connection error. Never resend after a 4xx; a transaction refreshed after a 409 is a new call with a new key. Resend only while idempotency-key-lifetime parses and is positive, counted from the first attempt, and stop when the next delay would reach it. A commit that cannot be resent returns ErrCommitStateUnknown. Hold net/http's own replay of keyed requests with a body, including 307/308 redirects, to the same window. A keyed DELETE has no body, so its transport replay stays unbounded; this is documented. Plan and task POSTs use the same policy instead of their own retry loop: they no longer resend on 408 or 429, send a generated key only when a lifetime is advertised, and count a caller-supplied key's UUIDv7 age against the window. Part of apache#2443 Signed-off-by: Ayaan <[email protected]>
|
I tested Once the key had expired, the catalog checked the snapshot requirement again. The first commit had already advanced the snapshot, so the catalog returned 409. It applied the commit exactly once, but Could |
zeroshade
left a comment
There was a problem hiding this comment.
Thanks — the shape here is good: one key and body per call, resends limited to 5xx/timeouts/connection errors, and GetBody bounding net/http's own replays is a nice touch. go test -race ./catalog/rest/... passes on d14541fe.
Blocking — a resend that lands after the key expires reports ErrCommitFailed for a commit that was applied
I can reproduce what @shihchengwei-lab reported without pausing the process: with idempotency-key-lifetime PT1S, the first CommitTable attempt is applied and the connection drops; the resend leaves inside the window (elapsed + wait < lifetime, design point d) but reaches the server after it has expired, so the server re-checks requirements and returns 409. CommitTable then returns CommitFailedException: requirement failed, wrapping ErrCommitFailed. Since ErrCommitFailed means "refresh and try again" and table commits now retry conflicts by default, the caller can replay a commit that already landed.
Once any resend has gone out, a commit's outcome is ambiguous whatever the final response is. Could send (for withCommitState() calls) map any error after attempt > 0 to ErrCommitStateUnknown, wrapping the server error? Rechecking the window after the timer fires is worth adding too, but on its own it can't close the gap left by transit time. A test with a transport that delays the second attempt past the lifetime and answers 409 would pin it.
Smaller observations (non-blocking):
- Plan and task POSTs used to retry 5xx/408/429 unconditionally; against servers that don't advertise
idempotency-key-lifetime(most, today) they now never resend. The release note covers it, but it's a real resilience change for scan planning; please confirm that's intended. newKeyedCallusesuuid.MustParseon the caller key and relies onidempotencyHeaderValuehaving validated it first.uuid.Parsewith an error return would remove that coupling.- Your questions (a)–(f) under "For reviewers" still need a maintainer answer, especially (a) backoff and retry count and (b) 408/429.
This review was drafted by an AI-assisted tool and
confirmed by an Apache Iceberg Go maintainer. After you've
addressed the points above and pushed an update, an Apache Iceberg Go
maintainer — a real person — will take the next look
at the PR. The findings cite the project's review criteria;
if you think one of them is mis-applied, please reply on the
PR and a maintainer will weigh in.
…s resent Signed-off-by: Ayaan <[email protected]>
…y path Signed-off-by: Ayaan <[email protected]>
…anup path Signed-off-by: Ayaan <[email protected]>
|
Pushed 2c909d7, f74dd52 and 4c5175f. For commit calls, once
On plan/task POSTs: yes, intended. Without an advertised lifetime, The questions (a)–(f) under "For reviewers" are still open. |
Signed-off-by: Ayaan <[email protected]>
laskoviymishka
left a comment
There was a problem hiding this comment.
Thanks for turning the resend fixes around so quickly. As I read it, f74dd52 and the post-timer recheck cover @zeroshade's 409 blocker. One gap is left there: resent is only set from attempt 1, so a commit cancelled during the first backoff still returns a bare context.Canceled. The new thing I'm holding on: with SigV4 and a closed window, keyed POSTs never leave the client (inline on prepare).
On the questions: (a) 3 resends is fine since the lifetime bounds them, (b) and (c) agreed, (d)–(f) are fine. Dropping scan retries without an advertised lifetime is fine with me too; the release note covers it.
Let SigV4 read the request body before the first send even when the replay window is closed, keep ErrCommitStateUnknown alongside context.Canceled when a commit is cancelled during the first backoff, parse key lifetimes like java.time.Duration (ASCII case-insensitive, signs, comma fractions, overflow treated as malformed), and correct the send and idempotency-key comments. Signed-off-by: Ayaan <[email protected]>
…cy-retry Signed-off-by: Ayaan <[email protected]> # Conflicts: # website/src/releases.md
|
Pushed 9f6b9ac (review fixes) and 5d9d9e2 (merge of main to resolve the release-notes conflict); no force-push.
|
zeroshade
left a comment
There was a problem hiding this comment.
Thanks for the quick turnaround. My blocker is resolved: after a resend, a commit error is reported as ErrCommitStateUnknown, and the conflict/rejection chain is dropped so neither the retry loop nor orphan cleanup acts on it. TestCommitResendConflictAfterExpiry pins exactly the case I reproduced. The uuid.Parse change and the post-timer window recheck look good, and the observed-body approach fixes the SigV4 first send cleanly, since the signer only reads GetBody. go test -race ./catalog/rest/... passes on 5d9d9e29.
One part of @laskoviymishka's SigV4 thread is still open (inline on the redirect test), plus two nits. Please also resolve or reply on the open threads once they're addressed.
This review was drafted with an AI-assisted tool and may contain mistakes. An Apache Iceberg maintainer has reviewed and confirmed it before posting.
| if m == nil || strings.EqualFold(s[len(s)-1:], "T") { | ||
| return 0, false | ||
| } | ||
| total := new(big.Rat) |
There was a problem hiding this comment.
Nit (non-blocking): reproducing Java's overflow order exactly with big.Rat is a lot of code for a value that only decides whether to resend. Clamping anything at or above MaxInt64 ns to MaxInt64 would cover the same cases with much less. Happy to leave it if you prefer the exact match.
There was a problem hiding this comment.
Kept for now; details in the PR comment. Happy to switch to the clamp.
Signed-off-by: Ayaan <[email protected]>
|
Pushed 1d1ee60 (no force-push):
|
laskoviymishka
left a comment
There was a problem hiding this comment.
Round 1 is in, thanks, and 1d1ee60 now follows 307/308 when the window is closed: TestKeyedRedirectReplayWindow covers both under PT30M and PT0S and passes. What's left is the dial-error classification inline. Separately, net/http's own replay isn't counted as a resend, so a 409 on it keeps the ErrCommitFailed chain; main behaves the same, so could you open an issue for that?
| if ue, ok := errors.AsType[*url.Error](err); ok { | ||
| err = ue.Err | ||
| } | ||
| _, ok := errors.AsType[net.Error](err) |
There was a problem hiding this comment.
If no attempt reached the server, could this return the dial error as is rather than ErrCommitStateUnknown? With the server closed, a keyed CommitTable ends as not resent within idempotency-key-lifetime: ... connect: connection refused under both PT0S and PT30M, where main returns the raw dial error:
iceberg-go/catalog/rest/idempotency.go
Lines 166 to 181 in 1d1ee60
Keeping the resends is fine. The caller just shouldn't hear "unknown" when nothing was sent.
There was a problem hiding this comment.
Done in 030ba1a: the dial error is returned as is when no attempt reached the server (details in the PR comment).
…cy-retry Signed-off-by: Ayaan <[email protected]> # Conflicts: # website/src/releases.md
…he server Signed-off-by: Ayaan <[email protected]>
|
Pushed 030ba1a (no force-push) on top of a merge of main (d6b0624). When no attempt reached the server, a keyed commit that fails to dial now returns the dial error as is, and the same holds if the context is cancelled during the retries (both causes stay in the chain). An attempt counts as possibly delivered once a connection was acquired, or on any error other than a dial |
zeroshade
left a comment
There was a problem hiding this comment.
LGTM, thanks @AynSiddiqui. Everything from my and @laskoviymishka's rounds is resolved:
- 307/308 are followed with the window closed, with the per-request redirect flag cleared after signing so SigV4 re-signing works and transport replays stay bounded;
- the U+017F comment is in;
- dial-only failures return the raw dial error and keep the
ErrCommitFailedchain on a later 409; - the transport-replay follow-up is #2772.
Keeping the big.Rat path is fine with me. go test -race ./catalog/rest/... passes locally, and the resend/redirect/dial tests are stable over three runs.
One nit inline.
| if body := req.GetBody; body != nil { | ||
| sent := &atomic.Bool{} | ||
| redirect := &atomic.Bool{} | ||
| *req = *req.WithContext(context.WithValue(req.Context(), redirectResponseKey{}, redirect)) |
There was a problem hiding this comment.
nit: this overwrites the caller's request in place with a shallow copy, which is safe only because it runs before cl.Do. A one-line comment saying so would save the next reader a double take.
|
@laskoviymishka could you take another look? The request-copy comment is in bc03e6c. Could someone also rerun the |
laskoviymishka
left a comment
There was a problem hiding this comment.
I think this is good to merge
|
@AynSiddiqui ensure CI is grean and fix the conflicts |
|
Merged main again in 7fe3456 (no force-push). The only conflict was The go1.27.1, s390x and apidiff jobs fail on main's own build error at |
Signed-off-by: Ayaan <[email protected]>
…-retry Signed-off-by: Ayaan <[email protected]> # Conflicts: # catalog/rest/scan_planning_retry_test.go
Follows apache#2766, which moved every google/uuid import behind internal/uuid. Signed-off-by: Ayaan <[email protected]>
5e9c8cf to
ffcb639
Compare
Fixes #2443. Follows #2492, which added the key and header.
Motivation
#2492 sends an
Idempotency-Keyon REST mutations when the server advertisesidempotency-key-lifetime, but nothing resends a failed request or limits how late a resend may be.net/httpalready replays a keyed POST on a dropped reused connection, even when the lifetime isPT0S, and the scan plan and task POSTs have a separate retry loop that ignores the advertised lifetime. This implements the retry rules agreed in #2443.Changes
idempotency-key-lifetimeparses (ISO-8601PnDTnHnMnS) and is positive. The window starts at the first attempt, and a resend stops when its delay would reach the lifetime. Backoff is jittered, honorsRetry-Afterand the context, and is capped at three resends.CommitTable,UpdateTable,CommitTransaction) that cannot be resent after an ambiguous failure returnsErrCommitStateUnknown. Other calls return the last error.net/http's own replay of a keyed request with a body, including 307/308 redirects, is held to the same window throughGetBody. A keyedDELETEhas no body, so its transport replay cannot be bounded this way. This is documented and covered by a test.IdempotencyKeyis always sent; its age from the UUIDv7 timestamp counts against the lifetime (a future timestamp is clamped), and without an advertised lifetime it is sent once and not resent. Scan GET polling is unchanged.GetBodyrefuses a replay,Doreturns theGetBodyerror, not the original connection error (seen on go1.26.3 and go1.27.1).configuration.mdand the unreleased compatibility notes inreleases.mddescribe the final behavior, replacing the "lifetime is not enforced" warning from feat(catalog/rest): send Idempotency-Key on mutations when the server advertises it #2492.Differences from Java
net/http's implicit replay, which is why the window is applied there too, with the DELETE gap above.For reviewers
elapsed + wait < lifetime); it can finish after.UpdateViewreturns the last error, notErrCommitStateUnknown, as it has no unknown-state mapping today.Testing
go build ./...,go vet ./catalog/rest/...,golangci-lint run ./catalog/rest/...andgo test ./catalog/rest/... -race -count=1pass. Newhttptesttests cover matching keys and bodies on resends (5xx, connection error, DELETE), fresh keys per call and after a 409, no resend on 4xx, no resend with a missing, zero, negative, malformed or empty lifetime, expiry (Retry-Afterpast the window, slow first attempt),ErrCommitStateUnknown, cancellation, the resend budget, real-transport replay inside the window, after a slow first attempt and withPT0S, redirects, the keyed DELETE gap, the lifetime parser, and both scan POSTs including caller-key age. The tests for resends, transport replay bounds and scan POST changes fail onmain.