Repository navigation
fix(consensus): park queued submissions on entry liveness, not a fixed clock - #1792
Conversation
EmbeddedRaftConfig::with_submit_wait(timeout, max_retries) overrides the QueuedTransactor's 8 s × 3 default. That default is sized for leader transitions on a cluster; a single-node host whose per-branch queue runs tens of seconds deep (bulk publishes, sequential upsert chunks) reported a still-queued submission as stranded and then committed it anyway.
…d clock The queued transactor gave a submission a fixed per-attempt wait (8 s) and a fixed number of attempts (3), then reported it stranded with a 504. That budget was sized for leader transitions, but it was spent on healthy slow commits too: a single node running sequential bulk chunks whose stage plus publish exceeded 24 s had every submission reported stranded while the worker committed it anyway. A wait timeout is now a probe. When it fires the transactor checks whether the entry is still in the replicated per-branch queue and the cluster has a leader; if so the submission is alive and it parks again without spending an attempt. Only a probe that finds the entry gone (or the node leaderless — what a partitioned former leader sees) spends an attempt on the existing re-propose path. The former-leader case needs nothing more: ApplyHead replicates to every node, so a waiter bound on a former leader resolves when the new leader's worker finishes the entry. A ceiling on total parked time (default 10 minutes, `with_max_wait` / `EmbeddedRaftConfig::with_submit_max_wait`) backstops a worker that never finishes; hitting it reports the outcome as unknown rather than failed, since the commit may still land. Two embedded-node tests pin the behaviour with a 1 ms probe and a single attempt: a 2,000-node insert completes with a receipt, and a 1 ms ceiling turns the same insert into a 504 that names the outcome unknown while the commit lands regardless. Both fail under the previous fixed budget with the production message.
aaj3f
left a comment
There was a problem hiding this comment.
@bplatz the problem makes sense and seems well-identified. No contention with the solution either. Claude review below:
Praise — turning the waiter timeout from a verdict into a probe of the replicated queue and the leader, and keeping the retry path for exactly the condition it was built for. I verified it rather than read it: cargo test -p fluree-db-consensus --all-features is 332 lib + 14 integration green with all six new tests present by name, fmt and clippy are clean, and forcing every probe timeout back to SpendAttempt makes the 2,000-node embedded-node test fail with the production message verbatim (submission stranded by leader transition; retry with an idempotency key). The ceiling reporting the outcome as unknown rather than failed is the honest shape, the waiter.rs scope doc now states the ApplyHead-replicates-everywhere fact that makes dropping the drain sound, and the host knobs are additive.
Two small fold-ins and one note, none blocking: a gone-entry probe can race a terminal apply that landed between the timeout and the probe (ticket.wait leaves the outcome in the receiver on TimedOut), which for an anonymous submission returns stranded while the ticket holds the receipt — one non-blocking re-check before spending the attempt closes it; the ceiling message tells anonymous callers to poll with a key they don't have; and a live entry can now hold a request for ten minutes, which the standalone server's HTTP timeouts and any load balancer should know about.
Nothing ran in CI for this head (stacked two deep), so the gates above are local; the four files here don't overlap #1789 or #1791, so this could be retargeted straight to main and get CI on its own rather than waiting on the stats stack.
Adherence to repo commitments:
- Patterns/abstractions: ✔ extends
QueuedTransactorandEmbeddedRaftConfigin place; reusesSharedStateand the existing re-propose path; no parallel construct. - Performance (speed first, memory second): ✔ no product hot path; one read lock and an O(queue) scan per probe interval.
- Testing: ✔ verdict matrix and
entry_queuedunit tests plus two embedded-node tests with a 1 ms probe that pin both outcomes; mutation-verified;⚠️ not run in CI on this head (stacked). - Conventions: ✔ two focused multi-line commits with the mechanism; docs updated in the waiter module; clippy/fmt clean under
--all-features.
Verified locally at branch HEAD d183a0d4d: cargo test -p fluree-db-consensus --all-features → 332 + 2 + 3 + 3 + 6 passed; mutation (probe_verdict → always SpendAttempt) → embedded test FAILED as expected, restored clean; cargo fmt --all -- --check and cargo clippy -p fluree-db-consensus --all-features --all-targets -- -D warnings clean.
Approving so you can land it, particularly once underlying PRs are merged and this is retargeted to main so CI sees it, and consider the two small fold-ins first.
| match ticket.wait(self.wait_timeout).await { | ||
| Ok(outcome) => return Ok(SubmissionOutcome::Waiter(outcome)), | ||
| Err(WaitError::Displaced) => break, | ||
| Err(WaitError::TimedOut) => { |
There was a problem hiding this comment.
Optional (fold in now). This is more of a question than a suggestion. A gone-entry probe can race a terminal apply that landed between the timeout and the probe: ticket.wait returns TimedOut without consuming the oneshot (waiter.rs:146-158), so an ApplyHead that lands a moment later leaves the outcome sitting in the receiver while entry_alive finds the entry already popped → SpendAttempt.
For an idempotency-keyed submission the re-propose hits the cache and returns the receipt, so no harm. For an anonymous one it returns stranded_error while the ticket is holding the receipt. One non-blocking re-check of the ticket (ticket.wait(Duration::ZERO)) before spending the attempt closes the window. Minor, but if you agree it's right I'd rather see it here than in the backlog.
There was a problem hiding this comment.
Agreed, and it turned out wider than a zero-length re-check: the entry is popped under the state lock, but the waiter resolves in the observer's effects after the lock drops, so a probe can see the entry gone before the outcome has even been sent. At the 1 ms probe the embedded-node test uses, the original test hit it on 11 of 60 runs.
Fixed in d139736: a gone-entry probe waits GONE_ENTRY_GRACE (250 ms) on the ticket before spending the attempt, paid only on the stranded path. New test a_probe_that_finds_the_entry_just_popped_still_returns_the_receipt drives twenty sequential submissions at a 1 ms probe: 10/10 failures without the grace, 40/40 passes with it.
| entry_queued(&state, ref_key, queue_id) | ||
| } | ||
|
|
||
| fn ceiling_error(&self) -> SubmissionError { |
There was a problem hiding this comment.
Optional. The ceiling message tells every caller to "poll with the idempotency key", but an anonymous submission has none. stranded_error already distinguishes retry_eligible; the ceiling message should say the same two things: keyed → poll with the key; anonymous → the outcome is unknown and may have committed, check the ledger head.
There was a problem hiding this comment.
Done in bd0bd35. ceiling_error now takes retry_eligible like stranded_error: keyed → poll with the key; anonymous → outcome unknown, check the ledger head before retrying.
| /// probe that finds the entry still queued keeps waiting without | ||
| /// spending an attempt, so these bound leader-transition recovery, | ||
| /// not commit latency — see `QueuedTransactor`. | ||
| pub submit_wait: Option<(Duration, usize)>, |
There was a problem hiding this comment.
Note (operational, docs). A live entry can now hold the request for up to ten minutes where it used to give up at ~24 s — which is the point — but the standalone server's HTTP layer and any load balancer in front have their own idle timeouts (60 s is typical), so a client can be severed while the server task keeps waiting, and the parked tasks are bounded only by concurrent callers. Worth a line in the standalone docs next to with_submit_max_wait, and a look at whether the server's request timeout should be at least the probe interval times a few.
There was a problem hiding this comment.
Documented rather than changed here: docs/design/raft-command-queue.md has a new "Waiting for the outcome" section covering the probe, the ceiling, and the timeout mismatch. The concrete internal case is the follower → leader forward middleware, which gives up at 60 s (FORWARD_REQUEST_TIMEOUT), so on a cluster a forwarded write still 504s at the follower well below the ceiling. That, the missing server request timeout, and the server not exposing the new knobs are now listed on #1382, which already covers the ingress/processing timeout split.
| /// never applied the enqueue) and a leaderless view — which is also | ||
| /// what a partitioned former leader sees — both read as not alive, | ||
| /// so the retry path gets to surface the real condition. | ||
| async fn entry_alive(&self, ref_key: &RefKey, queue_id: Option<u64>) -> bool { |
There was a problem hiding this comment.
Praise. entry_alive reads the state the cluster actually has — the replicated per-branch queue and the current leader — instead of a clock, an unbound ticket and a leaderless view both read as not alive so the existing retry path still surfaces the real condition, and entry_queued scanning by queue_id on its own branch is O(queue) once per probe interval. Reverting the verdict to the fixed budget reproduces the production message in the new embedded-node test verbatim, so the pin has teeth.
| @@ -30,10 +30,15 @@ | |||
| //! | |||
There was a problem hiding this comment.
Praise. Rewriting the scope doc to say ApplyHead replicates to every node — so a waiter bound on a former leader resolves when the new leader's worker finishes the entry — is the fact that makes dropping the leadership-loss drain sound. Good to have it stated where the next reader will look.
EmbeddedRaftConfig grew submit_wait and submit_max_wait, and the server builds it as a struct literal, so the raft feature stopped compiling (E0063). The server keeps the transactor's defaults; operator tuning of the write path's timeouts belongs to #1382.
…ling fires The ceiling message told every caller to poll with the idempotency key, which an anonymous submission does not have. It now branches on retry_eligible the way stranded_error does: keyed submissions poll with the key; anonymous ones are told the outcome is unknown and to check the ledger head before retrying.
…ding an attempt The entry leaves the replicated queue under the state lock, but its terminal apply resolves the waiter in the observer's effects, after that lock drops. A probe that reads the queue in between sees the entry gone while the receipt is moments from landing, spends its attempt, and an anonymous submission comes back as the stranded 504 with the receipt sitting in the ticket. At the 1 ms probe the embedded-node test uses, that happened on eleven of sixty runs. A gone-entry probe now waits GONE_ENTRY_GRACE (250 ms) on the ticket before spending the attempt. A genuinely stranded entry times out again and pays only that. A new embedded-node test drives twenty sequential submissions at a 1 ms probe; it failed ten of ten runs before this change and passes forty of forty after.
The command-queue design doc now covers the probe interval, the ceiling, the grace a gone-entry probe waits, and the mismatch between the 10-minute ceiling and the 60 s follower → leader forward timeout, which #1382 tracks.
|
Review items folded in (bd0bd35, d139736, 31ad6e3), plus one the local gates did not reach: the server builds #1791 has merged, so this PR now targets |
Problem
QueuedTransactorused a fixed 8-second per-attempt wait and up to three attempts, treating expiry as a stranded submission even when execution was still progressing.The reported incident was a single
where/deleteretracting 26,839 stale edges over a roughly 4.6-million-triple ledger on a release build. Staging exceeded the synchronous wait budget: the caller received a 504 while processing continued and the write completed. This was a large-statement staging cost plus a misleading timeout response. The reporter's chunked publish/canonicalize paths used an identity commit barrier and did not hit this budget. Novelty-at-maximum refusals after restore were a separate backpressure/reindexing issue.EmbeddedRaftConfigalso gave a host no way to tune the queued submission wait.Change
EmbeddedRaftConfig; wire defaults at the server attach site. Document the wait and surrounding timeouts.ApplyHeadreplicates to every node, allowing a waiter on a former leader to resolve when another worker completes its entry.Validation
cargo test -p fluree-db-consensus --features raft: 332 library tests and 14 integration tests (including 5 embedded-node tests) pass.cargo fmt --all -- --checkandcargo clippy -p fluree-db-consensus --features raft --all-targets -- -D warningspass.Follow-up
whereexecution and retraction staging separately. This PR changes waiting/reporting, not staging performance.