Repository navigation
Conversation
…uto-switch HA A slave whose master restarted with a regressed commitlog resolved a consistent point below its own confirmOffset and truncated messages that were already acknowledged to producers. Refuse the truncation by default and log an error; enableTruncateBelowConfirmOffset is added as an explicit disaster-recovery override. Add unit tests for the refused case, the exact-confirm boundary, and the override.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## develop #11617 +/- ##
=============================================
+ Coverage 50.04% 50.71% +0.67%
- Complexity 14515 14795 +280
=============================================
Files 1391 1391
Lines 103460 103569 +109
Branches 13558 13577 +19
=============================================
+ Hits 51777 52526 +749
+ Misses 45449 44784 -665
- Partials 6234 6259 +25 ☔ 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 default-deny check and explicit disaster-recovery override are useful, but I am requesting changes because the default protection can stop rejecting a known-inconsistent history on a later handshake. There is also a separate validation gap in the recovery tests.
Integration baseline: this PR applied to develop@1f083ebea, including #11588. All behavioral findings below refer to that integrated result, not the older PR branch in isolation. Code links are pinned to PR head dc66b3a. 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] The refusal is forgotten when the same-epoch master writes past the slave's confirmed offset
Location: AutoSwitchHAClient.java, lines 462-471, the new guard in doTruncate.
Minimal triggering sequence:
- Master and slave have epoch entry
(1, 0); the slave hasmaxOffset = confirmOffset = 3280. KeepenableTruncateBelowConfirmOffset=false. - The master loses its tail and recovers to
1580, then resumes serving in the same epoch. With #11588, its epoch start remains0. - The first handshake resolves a consistent point of
1580. The guard correctly refuses1580 < 3280. - The master writes different new messages in the same epoch and reaches
4190. - The next handshake resolves
min(3280, 4190) = 3280. The guard now passes, and the slave resumes replication from3280.
The slave retains its old [1580, 3280) while the master has rewritten that interval. The replicas can end up with equal maximum offsets but different message histories. Epoch matching checks epoch metadata and offsets, not message contents, and this guard does not retain the earlier evidence of inconsistency. The failure is therefore not merely incomplete controller fencing: the new reject-then-accept path preserves an old tail and later treats the rewritten history as consistent.
The recovery override does not address this sequence, which occurs with the override disabled throughout. Enabling it after the divergence has formed also cannot force truncation back to the originally rejected 1580: the newly computed consistent point is already 3280.
Required changes:
- Once this inconsistency is detected, do not resume replication solely because the master's offset has increased.
- If implementing a persistent refusal on the slave, preserve it across slave restarts and define an explicit, safe clearance condition based on validated history or authorized recovery. A numeric catch-up alone is not such a condition.
- Alternatively, prevent the regressed master from producing this history through effective fencing or correct epoch handling before it accepts replacement writes. A later epoch increment alone is not sufficient evidence that the earlier fork is resolved.
- Add regression coverage for refusal, same-epoch writes past the original confirmed offset, and a subsequent handshake, including a slave restart between attempts. Assert that incompatible history is not accepted; equal final offsets alone are insufficient.
This does not require implementing the entire controller-side design in this PR, but the store-side safety net must remain effective after it has detected the dangerous truncation.
2. Test insufficiency, not a separate demonstrated production defect: the allowed-truncation tests do not establish successful recovery
Location: AutoSwitchHAClientTest.java, lines 46-123.
The equality and override-enabled tests call doTruncate reflectively and verify that truncateFiles was invoked, but do not assert that doTruncate returned true. The mock maximum offset does not decrease after truncation, and successful socket writes are not configured. Consequently, a truncation invocation does not demonstrate successful offset reporting or completion of the handshake.
Required validation before merge:
- Model the post-truncation maximum and confirmed offsets, or use real stores; assert successful completion, the
TRANSFERstate, and any required offset report. - Cover an unclean-election recovery: the former master has persisted
confirmOffset=2370, while the new master's epoch 2 starts at1580. Verify that the default setting refuses truncation without changing the log; then enable the explicit recovery override on the recovering slave and verify truncation and replication complete with matching message contents. Finally, disable the override and verify the protection is active again. - Document which replica receives the override, what data is being relinquished, and that the override must be disabled after recovery.
The explicit override provides a recovery mechanism for this unclean-election case, so I am not reporting the default refusal there as a second production defect. The missing success assertions are a validation gap, separate from the P1 production blocker above.
|
Hi! I have a question about the confirmOffset guard. If the first handshake refuses truncation because 1580 < 3280, but the master later writes new messages up to 4190, the next handshake may resolve to 3280 and allow replication to resume. How does this implementation ensure that the slave's retained message history is still consistent with the master? Thanks! |
Related issue: #11603 (this PR implements the store-side guard; controller-side election/fencing remains tracked there).
Summary
In controller mode with auto-switch HA, when the master restarts with a regressed commitlog (e.g. async-flush tail loss) and is re-elected, a slave can resolve a consistent point below its own
confirmOffsetand truncate messages that were already acknowledged to producers, with no error or alarm. Reproduced at store level: a slave with max/confirm = 3280 was truncated to 1580 after the master recovered to 1580.This PR adds a guard in
AutoSwitchHAClient#doTruncate: refuse the truncation whentruncateOffset < confirmOffsetby default, log an ERROR with the epoch details, and leave the log untouched. The slave keeps retrying the handshake instead of silently dropping confirmed data.Behavior change
confirmOffset; the handshake fails with a clear ERROR (including epoch entries and offsets) and retries.enableTruncateBelowConfirmOffset(defaultfalse): explicit disaster-recovery override for operators who accept the data loss.confirmOffsetis still allowed (only<is refused).Tests
AutoSwitchHAClientTest:truncateOffset < confirmOffsetand never callstruncateFiles;confirmOffset;confirmOffsetwhen the override is enabled.NeverWantedButInvoked: truncateFiles.AutoSwitchHAClientTest,EpochFileCacheTest,AutoSwitchHAStateValidationTest): 14/14 pass.Refuse to truncate slave log to 1580, which is below the local confirmOffset 3280....Note: reaching this path after a same-epoch restart also needs the epoch-preserving fix from [ISSUE #11585] Fix AutoSwitchHA slave unable to rejoin after same-epoch master restart #11588 (applied locally for the e2e check); on the current develop baseline the slave stays in HANDSHAKE before reaching
doTruncate. The guard itself is independent of [ISSUE #11585] Fix AutoSwitchHA slave unable to rejoin after same-epoch master restart #11588 and also protects the pre-existing truncation path for older epochs.Relation to other work