frotmo opened a new pull request, #11617:
URL: https://github.com/apache/rocketmq/pull/11617

   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 `confirmOffset` and 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 when `truncateOffset < confirmOffset` by 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
   
   - Default: refuse to truncate below the local `confirmOffset`; the handshake 
fails with a clear ERROR (including epoch entries and offsets) and retries.
   - `enableTruncateBelowConfirmOffset` (default `false`): explicit 
disaster-recovery override for operators who accept the data loss.
   - Truncation to exactly `confirmOffset` is still allowed (only `<` is 
refused).
   
   ## Tests
   
   - New `AutoSwitchHAClientTest`:
     - refuses when `truncateOffset < confirmOffset` and never calls 
`truncateFiles`;
     - allows truncation at exactly `confirmOffset`;
     - allows truncation below `confirmOffset` when the override is enabled.
   - Red/green: without the guard the refusal test fails with 
`NeverWantedButInvoked: truncateFiles`.
   - Related store suite (`AutoSwitchHAClientTest`, `EpochFileCacheTest`, 
`AutoSwitchHAStateValidationTest`): 14/14 pass.
   - End-to-end check (two stores in auto-switch mode, master restarted with 
its last commitlog file removed): the slave keeps max/confirm at 3280 and logs
     `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 #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 #11588 and also protects the 
pre-existing truncation path for older epochs.
   
   ## Relation to other work
   
   - The root cause (controller re-electing a data-regressed master without 
offset fencing) is tracked in #11603. This PR is the store-side safety net; 
metrics/alarms for the recovery-time regression can follow separately.
   - Does not depend on #11588; after #11588 merges, this guard also covers the 
first-epoch same-epoch restart case.
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to