Repository navigation
[ISSUE #11603]Reject AutoSwitch HA truncation below the confirmed offset - #11610
wozhenbang2004 wants to merge 4 commits into
Conversation
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## develop #11610 +/- ##
=============================================
+ Coverage 50.68% 51.45% +0.76%
- Complexity 14782 15091 +309
=============================================
Files 1391 1394 +3
Lines 103571 104176 +605
Branches 13575 13690 +115
=============================================
+ Hits 52494 53601 +1107
+ Misses 44819 44225 -594
- Partials 6258 6350 +92 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
ShannonDing
left a comment
There was a problem hiding this comment.
Thanks for picking up #11603. Refusing to truncate confirmed data is the right direction, but with the current check I found two problems, both reproduced end to end at the store level (two DefaultMessageStores driven through AutoSwitchHAService, no controller, on this PR merged with the latest develop, which includes #11588), and compared against develop without this change.
1. The guard is evaluated per handshake, so it only delays the problem and then ends in a silent divergence
Scenario A (the #11603 scenario):
- Master (epoch 1) and slave reach
maxPhyOffset = 3280; slaveconfirmOffset = 3280. - The master drops its last commitlog file and restarts:
maxPhyOffset = 1580,changeToMaster(1)keeps the epoch entry(1, 0)(#11588). - The slave reconnects: the consistent point is
1580 < 3280, so the handshake is refused, as intended. - The master keeps serving writes (15 messages,
maxPhyOffset = 4190). - The next handshake resolves
min(3280, 4190) = 3280, which is no longer belowconfirmOffset, so it is accepted and the slave continues appending from 3280.
develop (no guard) |
this PR | |
|---|---|---|
| While the master is behind | slave truncates to 1580, confirmOffset becomes 1580 |
Refusing to truncate slave log below confirmOffset: ... truncateOffset=1580, confirmOffset=3280 (twice) |
| After the master passes 3280 | caught up (4190 / 4190), same message at offset 1700 | caught up (4190 / 4190), but the message at offset 1700 differs: master store timestamp ...324770 vs slave ...303546 |
So the slave ends up keeping the old [1580, 3280) while the master has written different messages at the same offsets in the same epoch, and nothing reports it after the first few seconds. Before this change the outcome was "confirmed data lost, but replicas consistent"; with it the outcome is "replicas silently forked", which is harder to detect and recover from (consume queue offsets on the slave point to different messages, and the slave may later be elected). The window is short: the master only needs to write as much as it lost.
The root cause is that once an epoch is reused after a tail loss, offsets alone cannot tell the two logs apart, so a per-handshake offset comparison cannot stay correct. Some possible directions:
- Make the refusal sticky: once refused for a given master epoch / epoch start offset, keep refusing while the master stays on that epoch, and persist this so it survives a slave restart (on restart the slave's
confirmOffsetis still 3280 and the same race applies). - Or address it at the source (#11603): do not re-elect a regressed master with the same epoch, or bump the epoch when a master recovers with data loss. Then the epoch entries themselves differ, and the consistent point stays below the slave's
confirmOffset, so the refusal becomes stable.
Either way, please add a test along the lines of scenario A that asserts the handshake is still refused after the master has written past the slave's confirmOffset; the current tests only exercise a single truncateSlaveLog call with mocks.
2. With enableElectUncleanMaster=true, the old master can never rejoin
Scenario B:
- Master and slave at epoch 1 replicate 10 messages (
1580). - The slave goes away; the master writes 5 more messages and the syncStateSet shrinks to
{master}.setSyncStateSetsets the master'sconfirmOffsetto itsmaxPhyOffset(2370), which is persisted in the checkpoint. - The master crashes; the lagging broker is elected with epoch 2 (unclean election, starting at
1580) and writes 10 messages. - The old master restarts as a slave of the new master: it loads
confirmOffset = 2370, the consistent point is1580.
develop (no guard) |
this PR | |
|---|---|---|
| Old master rejoining | truncates its unreplicated tail, catches up (3160 / 3160) |
Refusing ... truncateOffset=1580, confirmOffset=2370 every 5-7 seconds; never catches up |
Unclean election accepts data loss by design, so the replica is now stuck until an operator wipes its store. Clean elections are not affected (the master's confirmOffset is the minimum ack of the syncStateSet, so it never exceeds what the newly elected in-sync replica holds). Please decide how this case should behave, e.g. a switch, or letting the controller tell the slave the election was unclean. At minimum, please document the behavior change and the manual recovery procedure in the PR description.
ShannonDing
left a comment
There was a problem hiding this comment.
Follow-up to my existing change request, with a correction to the test assessment and additional validation requirements. I am not adding a new production finding or repeating the two existing blockers and their reproduction scenarios.
Integration baseline: this PR applied to develop@1f083ebea, including #11588. The production behavior under review is the integrated result, not the older PR branch in isolation. The links below are pinned to PR head 5910be5 for navigation. This follow-up is based on code inspection; it does not claim any additional end-to-end test runs.
Correction: the equality-boundary test does exercise handshake parsing
My earlier statement that the new tests only exercise a single truncateSlaveLog call with mocks was too broad. In AutoSwitchHAStateValidationTest.java, lines 100-151, the rejection test calls the helper directly, but the equality-boundary test explicitly enters HANDSHAKE, feeds a handshake frame through the reader, and checks the transition to TRANSFER. That is useful coverage and should be retained.
Additional validation needed for the rejection path
The remaining test gap is that rejection is not exercised through that same handshake entry point. The production check is in AutoSwitchHAClient.java, lines 481-492.
Please add a reader-level rejection test: start the client in HANDSHAKE, provide epoch entries that resolve to an offset below the local confirmOffset, and process the frame through the reader. Assert that the handshake fails without calling truncateFiles, entering TRANSFER, or reporting a new replication start offset. Keep the existing successful equality-boundary test as the control.
For the unclean-election recovery mechanism selected to address the existing second blocker, please also add an automated recovery-path test. It should verify the default refusal, then verify that the explicitly authorized recovery path updates both the maximum and confirmed offsets and completes replication with matching message contents. Verifying only that truncation was invoked is not sufficient to establish successful recovery.
These are test/validation requirements, not separate demonstrated production defects. The production blockers and their required behavioral changes remain in the linked review.
|
Thanks for the review, @ShannonDing. I pushed I ran a planned DLedger replica replacement and then restarted the new replica. It kept its new ID, the message contents and offsets still matched the source, and it picked up the next write. The retired store stayed unchanged. This was a planned replacement, not recovery after an unclean election. Would rebuilding under a new identity and keeping the original store offline satisfy the recovery requirement, or do you want the original replica to rejoin in place? |
Related to #11603.
A replica now remembers a refused truncation across reconnects and restarts. A restarting broker also waits for the Controller’s election result before opening for writes; registration alone no longer makes it writable.
For recovery, the runbook keeps the original store offline and rebuilds a replica under a new identity from a source the operator has verified. The replacement copies the selected history. It does not merge messages from the offline store.
I built the Broker and Controller modules with JDK 8 and ran local checks for planned failover, a graceful DLedger Controller restart, and planned failover with a single-member JRaft Controller. I also ran a planned replica replacement with DLedger: the replacement matched the source’s maximum and confirmed offsets and message contents, and the retired store stayed unchanged. That run did not exercise recovery after an unclean election.
This change requires all Controllers to be upgraded before any upgraded Broker starts. Is rebuilding under a new identity an acceptable recovery path here, or should the original replica be able to rejoin in place?