Repository navigation
Conversation
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #11619 +/- ##
=============================================
+ Coverage 50.65% 50.68% +0.02%
+ Complexity 14779 14778 -1
=============================================
Files 1391 1391
Lines 103559 103564 +5
Branches 13575 13576 +1
=============================================
+ Hits 52461 52487 +26
+ Misses 44845 44813 -32
- Partials 6253 6264 +11 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ShannonDing
left a comment
There was a problem hiding this comment.
The placement of the guard and the strict < confirmOffset boundary are correct for an individual truncation attempt. I am requesting changes because the check does not remain safe across reconnects and introduces a recovery regression after an unclean election.
Integration baseline: this PR applied to develop@1f083ebea, including #11588. All behavioral findings below refer to that integrated result. Code links are pinned to PR head a7d6ed4. This is a code-path review; I have not rerun Maven or the two-store end-to-end scenarios for this PR.
1. [P1, production blocker] A later handshake can accept a rewritten same-epoch history after an earlier refusal
Location: AutoSwitchHAClient.java, lines 462-469, the new guard in doTruncate.
Minimal triggering sequence:
- Master and slave have epoch entry
(1, 0); the slave hasmaxOffset = confirmOffset = 3280. - The master loses its tail, recovers to
1580, and resumes accepting writes in the same epoch. With #11588, the epoch start remains0. - The first handshake resolves a consistent point of
1580, so the slave correctly refuses truncation. - The master writes different new messages in the same epoch and grows to
4190. - The next handshake resolves
min(3280, 4190) = 3280. This equals the slave's confirmed offset, so the guard passes and replication resumes from3280.
The slave retains the old [1580, 3280) while the master has new contents at those offsets. Equal maximum offsets can therefore conceal different message histories. Epoch matching does not compare payloads, and the refusal leaves no persistent record that this history was already found inconsistent. The new reject-then-accept path preserves the old tail and later accepts the rewritten history as if it were consistent.
Required changes:
- Do not clear a detected inconsistency merely because the master's offset has increased.
- If using persistent refusal on the slave, retain it across slave restarts and define a safe clearance condition based on validated history or explicit recovery authorization.
- Alternatively, prevent the incompatible history through effective fencing or correct epoch handling before the regressed master accepts replacement writes. Incrementing the epoch only after the fork has formed is not by itself a repair.
- Add regression tests covering the initial refusal, same-epoch writes past the original confirmed offset, and the next handshake, including a slave restart between attempts. Check that incompatible message history is not accepted, rather than only checking final offsets.
2. [P2, production blocker] A former master cannot rejoin after an unclean election, with no controlled recovery mechanism
Location: the same guard linked above, specifically the unconditional rejection of truncateOffset < confirmOffset.
Minimal triggering sequence:
- Master and slave replicate to
1580in epoch 1. - The slave goes offline; the master writes to
2370, the SyncStateSet shrinks to{master}, and the master's confirmed offset advances to2370and is persisted. - The master fails. With unclean election enabled, the lagging replica becomes the new master in epoch 2, whose start offset is
1580. - The old master rejoins as a slave with local
confirmOffset=2370, but the consistent point with the new master is1580.
The new master's epoch 1 ends at 1580, so further writes in epoch 2 do not raise that consistent point. The old master repeatedly rejects 1580 < 2370 and cannot complete the previously supported truncate-and-rejoin path. The controller's enableElectUncleanMaster setting does not bypass this store-side guard.
Preserving confirmed data by default is appropriate. The compatibility problem is that a deployment explicitly using unclean election has no controlled way in this change to accept the selected history and recover this replica without further manual rebuilding.
Required changes:
- Keep the default protection, but provide an explicit, controlled recovery mechanism for operators who accept the data loss, such as a default-off truncation override or equivalent authorization.
- Document which replica must be operated on, which data will be discarded, and how recovery authorization is withdrawn afterward. Do not automatically bypass protection solely because the epoch increased.
- Test both default refusal and explicitly authorized recovery, including the resulting offsets, successful handshake, and message-content consistency.
Test insufficiency, separate from the production defects
Location: AutoSwitchHAClientTest.java, lines 40-88.
The tests invoke doTruncate directly through reflection. The rejected case remains in READY because that is the test object's initial state; this does not exercise rejection from a real HANDSHAKE, followed by connection closure and reconnection. This is a coverage limitation, not evidence of a separate production state-transition bug.
Please retain the equality-boundary test and add rejection through the handshake reader, followed by the multi-attempt and recovery scenarios above. Successful verification should include message history, not just truncateFiles invocation or equal final offsets. The request is to make the store-side protection reliable across its actual lifecycle, not to require the entire controller fencing design in this PR.
|
I inspected the current code path. The rejection is local to a single To keep this PR store-side, I propose the following scope:
Would this store-side scope be acceptable for this PR, or would you prefer |
|
Thanks @JiangSOBD — really appreciate you putting this together. It looks like we started on the same fix for #11603 at almost the same time (#11617), and the store-side guard is nearly identical in both patches. The same P1 applies to both: the refusal only lasts for a single Would you be open to consolidating into a single PR, so the reviewer doesn't have to iterate on two nearly identical patches? My suggestion would be to use this PR (#11619) as the base, but you're much closer to the design here, so please treat that purely as one option among several:
Beyond that, I'd also be happy to contribute wherever it's useful — for example the override, the operator documentation (which replica to operate on, what data is relinquished, how the authorization is withdrawn), and a re-run of the two-store end-to-end scenario on the consolidated branch including the original 3280 -> 1580 reproduction. But these are only offers, not a proposed split: please decide the shape and division of the remaining work however you think is best, and I'll gladly fit in. If you'd rather keep the whole scope yourself, that's completely fine too — I can contribute review and the e2e evidence instead. Of course, if you see the consolidation differently, I'm happy to adjust — the main thing I'd like to avoid is two parallel patches for the same issue. Thanks also to @ShannonDing — the finding is common to the approach rather than specific to either implementation, which is what made the consolidation obvious. Just a heads-up so you don't need to review two iterations of essentially the same patch; if we consolidate, we'll come back with a single branch and the test results. |
|
One more thing I just spotted: #11610 is an earlier attempt at the same issue — a very small guard plus a reader-level handshake test added to the existing @wozhenbang2004 — would you be open to joining the consolidation too? If you're comfortable with it, your test approach could be folded into the surviving PR rather than keeping a third parallel patch; the follow-up review on #11610 also asks for the rejection path to go through the reader, which fits naturally alongside the latch tests. The two two-store scenarios reproduced on #11610 (the same-epoch rewrite and the unclean-election rejoin) would also be useful evidence to cite, so they don't have to be redone from scratch. Of course, if you'd rather keep #11610 as its own PR, that's entirely your call — I just wanted to make the option visible. No fixed plan or split in mind from my side — happy to follow @JiangSOBD's and your lead on where this work should live. I'd just like to avoid three parallel patches and keep everyone's contribution in one place. |
|
Thanks for suggesting this. I’ve updated #11610 in response to the review. I’d keep the PRs separate for now while that’s being reviewed, but I’m happy to compare notes. |
|
Thanks for the update — completely understandable to keep the PRs separate while the review runs, and I appreciate you writing back. I had a quick look at the new revision: the persisted guard plus the startup-registration fencing looks like a much more complete answer than a per-handshake check, and the recovery runbook is a valuable addition — nice work. If anything from #11617 turns out useful — the two-store reproduction, or the idea of an explicit in-place recovery option if reviewers prefer that over rebuild-under-new-identity — take it, reshape it, or ignore it entirely, whichever is best for the design. I'll close #11617 once the direction is clear, and I'm glad to contribute review or e2e evidence wherever it helps. Happy to compare notes anytime. |
Which Issue(s) This PR Fixes
Fixes #11603
Brief Description
Persist confirmed-history isolation after a rejected AutoSwitch HA handshake so later same-epoch writes, reconnects, and replica restarts cannot silently accept a previously rejected history.
Add explicit one-shot recovery authorization bound to the recorded incident, selected HA endpoint, epoch history, and truncation offset. Consume authorization before repair, durably discard the divergent suffix, and retain isolation when recovery is interrupted. Refused promotion preserves the existing slave client and membership. Operator instructions describe the affected replica, accepted data loss, authorization, revocation, and retry procedure.
How Did You Test This Change?