Skip to content

fix(shard): judge a partition transfer peer by the view this log adopted - #4439

Closed
almostintuitive wants to merge 1 commit into
apache:masterfrom
aperiodic-io:test/state-transfer-lagging-replica
Closed

almostintuitive wants to merge 1 commit into
apache:masterfrom
aperiodic-io:test/state-transfer-lagging-replica

Conversation

@almostintuitive

@almostintuitive almostintuitive commented Oct 8, 2026 •

Copy link
Copy Markdown
Contributor

Which issue does this PR address?

Closes #4438

This PR first held three failing tests, one per livelock. Now that #4311 merged, it holds the fix, as asked on the issue. Master already resolved two of the three livelocks in its own way, so this PR now covers only the remaining one:

  • Livelock 1, an install that refused every offer under load: install_state_transfer now refuses only when the journal holds an op in (commit_op, held_max].
  • Livelock 3, a floor refusal that never became final: repair chunking was redesigned, and RepairSession::requested_from pulls the next chunk while a fenced commit point cannot move.

I dropped those two tests. Their setup no longer matches the code, and the behavior they pinned is gone.

Rationale

A replica that needs partition state transfer cannot finish a view change. Its WAL cannot certify a log with holes, so the persist gate withholds every view-scoped send. Its elections time out with nobody to hear them, and each timeout raises its view by one. In the reproduction from #4438, its log was last adopted in view 11, its own view reached 58, and the group's primary was at view 20.

Two places trusted that raised view:

  • The descriptor gate. on_partition_state_transfer_target refused an offer when header.view < view(). Every offer from the real primary (view 20 < 58) was refused as "from a replica behind this one", though it held more committed state.
  • The transient-refusal retry. Under load, the primary's first answer is usually a transient refusal, because the offer is still flushing or hashing. The retry compared the refuser with primary_index(view()), which is replica 1 at view 58. The real primary (replica 2) did not match, so the retry rotated to replica 1. Replica 1 is a backup and can only refuse, but it matched the raised view's primary, so the replica asked it forever.

Either way the replica stayed behind and kept serving reads from its stale prefix.

What changed?

  • transfer_offer_is_behind compares the serving view with the local log_view, the last view whose log this replica adopted, instead of view. It still refuses a phantom view-0 primary, an offer from before the adopted view, and an offer below the local commit_max.
  • The transient-refusal branch judges the primary by the refuser's own view when that view is at least the local log_view. Otherwise it falls back to the local view, as before. Refusal descriptors already carry the sender's view. If a backup refuses, the existing ring rotation still moves on, and it now reaches the real primary.

Nothing else decides what may be installed. The install keeps its own guards: commit_op at or above commit_min, no journaled op erased through max(WAL head, commit_max), and the incarnation and history fences.

Tests

Both handler tests call the real on_partition_state_transfer_target with the reproduction's numbers (log view 11, view 58, primary at view 20):

  • given_the_primary_offer_when_this_replica_ratcheted_its_view_alone_should_accept_it: fails on master (the offer is refused), passes with the fix.
  • given_a_transient_refusal_from_the_primary_when_this_replica_ratcheted_its_view_alone_should_ask_it_again: fails on master (left: Some(1), right: Some(2): the re-arm targets backup 1), passes with the fix.
  • transfer_descriptor_gate_tests: three unit tests for the refusals the gate must keep (an offer from before the adopted view, one below the known commit point, a phantom view-0 primary).

Local Execution

  • Passed. Toolchain 1.99.1 from rust-toolchain.toml, in a Linux container, on master b15c8e1e9.
    • cargo test -p shard --lib: 274 passed.
    • cargo test -p simulator: 16 passed.
    • cargo test -p partitions --lib: 642 passed. partition_storage::tests::a_removal_cut_short_leaves_the_marker_in_place fails on unmodified master too when run as root, because root ignores the directory mode.
    • cargo fmt --all --check and cargo clippy -p shard --all-targets --all-features -- -D warnings are clean.
  • Pre-commit hooks: I ran the hooks that apply to the changed files by calling them directly: trailing whitespace, trailing newline, binary artifacts, typos 1.51.1 and cargo fmt. All pass. I did not run the workspace-wide cargo clippy pre-push hook, only clippy on the touched crate.
  • Real-process runs. I reran the Partition replica stuck after rolling crash-restarts: state transfer never completes while it keeps serving its stale prefix #4438 scenario on apache/iggy:edge (44c7dc834, no fix) once: 1 partition, 30k msg/s, persisted, each node SIGKILLed in turn 80 s apart and down for 40 s. The wedge did not occur in that run (5,994,900 acked, 0 lost, all three replicas converged after one state transfer), and in October it occurred in 1 of 2 upstream runs. Our fork evidence:
    • On the October base f6dfbdbb3, with all three original fixes: 4 of 4 runs passed, one of them with dedup on. Each had 0 lost, and all replicas ended byte-identical. The same build without the fixes lost 2,130,700 of 4,407,400 acked events, and one replica stayed wedged at view 58.
    • On this base, with the gate change but not the rotation change: 1 run, 5,826,600 acked, 0 lost.
    • The rotation change has no real-process run yet. Only the handler test covers it.

AI Usage

  1. Claude (Claude Code).
  2. The root-cause analysis of the reproduction logs, the fix, the tests and this write-up.
  3. Each handler test fails on master at its assertion and passes with the fix. A review pass using the team-review charter ran on the diff, with one combined distributed-systems and storage reviewer instead of four, because the change is small. It found no safety problem in the gate change. It found the transient-refusal rotation that the first version of this fix missed. It also proposed the plain-number signature for transfer_offer_is_behind. Both are in this PR.
  4. Yes.

🤖 Generated with Claude Code

@github-actions

github-actions Bot commented Oct 8, 2026

Copy link
Copy Markdown

Thanks for the PR. It is labeled S-waiting-on-review and queued for review.

Slash commands (own line, regular comment) move it around the queue:

  • /ready - back to S-waiting-on-review after addressing feedback
  • /author - flip to S-waiting-on-author while you finish changes
  • /request-review @user-or-team - request a reviewer
  • /pin - exempt the PR from the stale bot, /unpin to undo

See CONTRIBUTING.md for details.

@codecov

codecov Bot commented Oct 8, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 89.28571% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 74.52%. Comparing base (b15c8e1) to head (931f5e5).

Files with missing lines Patch % Lines
core/shard/src/lib.rs 89.28% 3 Missing ⚠️

❌ Your patch check has failed because the patch coverage (0.00%) is below the target coverage (50.00%). You can increase the patch coverage or adjust the target coverage.

❗ There is a different number of reports uploaded between BASE (b15c8e1) and HEAD (931f5e5). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (b15c8e1) HEAD (931f5e5)
rust 3 2
Additional details and impacted files
@@              Coverage Diff              @@
##             master    #4439       +/-   ##
=============================================
- Coverage     90.75%   74.52%   -16.24%     
  Complexity     2611     2611               
=============================================
  Files          1406     1400        -6     
  Lines        331886   228943   -102943     
  Branches     283658   180717   -102941     
=============================================
- Hits         301216   170612   -130604     
- Misses        24367    52461    +28094     
+ Partials       6303     5870      -433     
Components Coverage Δ
Rust Core 71.60% <89.28%> (-20.37%) ⬇️
Java SDK 75.95% <ø> (+0.02%) ⬆️
C# SDK 82.36% <ø> (-0.16%) ⬇️
Python SDK 90.89% <ø> (ø)
PHP SDK 86.14% <ø> (ø)
Node SDK 96.12% <ø> (ø)
Go SDK 72.75% <ø> (+0.29%) ⬆️
C++ SDK 84.21% <ø> (ø)
Files with missing lines Coverage Δ
core/shard/src/lib.rs 80.55% <89.28%> (-11.51%) ⬇️

... and 567 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

A replica that needs partition state transfer cannot finish a view change: its
WAL cannot certify a holed log, so every view-scoped send is withheld. Its
elections time out alone and ratchet its view far past the group's (58
against the primary's 20 in a reproduction). Two places trusted that view
(apache#4438):

- The descriptor gate compared the serving primary's view with it, so it
  refused every offer from the group's real primary as "from a replica behind
  this one", though the offer held more committed state.
- A transient refusal (an offer still flushing or hashing, routine under load)
  was judged against the primary of that view. The real primary did not match,
  so the retry rotated to a backup, which then matched and was asked forever.

Either way the replica stayed behind for good and kept serving reads from its
stale prefix. Compare the serving view with the local log_view, the last view
whose log this replica adopted, and judge a refusal by the refuser's own view
when it is at least that log_view. A phantom view-0 primary is still refused,
and so is an offer from before the adopted view or below the commit point this
replica knows.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@almostintuitive almostintuitive changed the title test(partitions): reproduce a lagging replica stuck in state transfer fix(shard): judge a partition transfer peer by the view this log adopted Oct 24, 2026
@almostintuitive
almostintuitive force-pushed the test/state-transfer-lagging-replica branch from 19e3519 to 931f5e5 Compare October 24, 2026 05:49
@spetz

spetz commented Oct 24, 2026

Copy link
Copy Markdown
Contributor

Closing as superseded by #4483, which closes #4438 with the same log_view gate, the gate unit tests and both handler tests. For the transient-refusal retry it uses primary_hint() instead of the refuser's view, because a second lagging replica can stamp a view it leads and pin every retry to itself (given_a_lagging_peer_refusing_at_its_inflated_view_when_the_group_primary_was_heard_should_rearm_to_the_group_primary).

@spetz spetz closed this Oct 24, 2026
@github-actions github-actions Bot removed the S-waiting-on-review PR is waiting on a reviewer label Oct 24, 2026
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.

Partition replica stuck after rolling crash-restarts: state transfer never completes while it keeps serving its stale prefix

2 participants