frotmo opened a new issue, #11603: URL: https://github.com/apache/rocketmq/issues/11603
### Before Creating the Bug Report - [x] I found a bug, not just asking a question, which should be created in [GitHub Discussions](https://github.com/apache/rocketmq/discussions). - [x] I have searched the [GitHub Issues](https://github.com/apache/rocketmq/issues) and [GitHub Discussions](https://github.com/apache/rocketmq/discussions) of this repository and believe that this is not a duplicate. - [x] I have confirmed that this bug belongs to the current repository, not other repositories of RocketMQ. ### Runtime platform environment Any OS; controller mode (`enableControllerMode=true`) with auto-switch HA. ### RocketMQ version - branch: develop - version: 5.5.1 - The behavior exists in 5.x controller mode; the epoch matching path has not changed since it was introduced. ### JDK Version JDK 8 (any supported JDK). ### Describe the Bug In controller mode, if the controller re-elects a master whose recovered commitlog is behind a slave's confirmed offset, the slave resolves the consistent point towards the master and truncates its own log via `AutoSwitchHAClient#doTruncate` -> `DefaultMessageStore#truncateFiles`. `truncateFiles` has no `confirmOffset` guard, so the slave can drop messages that were already confirmed to producers, without any alarm. The setup has no fencing for a data-regressed master: - The controller neither receives nor compares broker commitlog offsets when electing a master. `RegisterBrokerToControllerRequestHeader` carries no offset information, and `ReplicasInfoManager#electMaster` only applies the election policy (liveness/syncStateSet), so a master that lost its tail can be re-elected and continue serving. - The slave side computes the consistent point purely from epoch entries and truncates to it, without comparing the truncate offset against its local `confirmOffset`. Concrete scenario (all offsets in bytes): 1. Two replicas, old master A and slave B, current epoch entry `(1, 0)` on both. 2. B has replicated up to 5802 and `confirmOffset = 5000`, i.e. `[0, 5000)` was already acknowledged to producers. 3. A crashes with async flush loss and recovers only to 4000. 4. A restarts; the controller re-elects A with the same epoch (with the same-epoch fix in PR #11588, A keeps `(1, 0)`; before that, A rewrote the entry to `(1, 4000)` and B got stuck instead of truncating). 5. During the handshake, A sends epoch entries `[(1, 0)]` with master end offset 4000. B's local `(1, 0)` matches and `findConsistentPoint` returns `min(5802, 4000) = 4000`. 6. B calls `truncateFiles(4000)` and drops `[4000, 5802)`, including the confirmed range `[4000, 5000)`. Since A also lost `[4000, 5802)` during recovery, the confirmed messages in `[4000, 5000)` are permanently lost. The same truncation can happen for epochs greater than 1 even without PR #11588: the matched previous epoch resolves the consistent point to the regressed master's offset. ### Steps to Reproduce 1. Start a NameServer with an embedded controller and two brokers in controller mode (auto-switch HA); wait until one broker becomes master with epoch 1. 2. Produce messages until the master's max offset is 5802, the slave has caught up, and the confirm offset has advanced to 5000. 3. Stop the master uncleanly and simulate async-flush data loss by rolling its commitlog back to 4000 (e.g. remove the tail, or reproduce a real unclean shutdown with `flushDiskType=ASYNC_FLUSH`). 4. Restart the master. The controller re-elects the same broker with the same master epoch. 5. Observe the slave's log: it resolves the consistent point to 4000, truncates `[4000, 5802)`, and continues from 4000, with no error or alarm about truncating confirmed data. ### What Did You Expect to See? - A master whose data regressed below the confirmed offset of the replica set should be fenced (not elected to serve, or required to catch up first), or - at minimum, the slave should refuse to truncate below its local `confirmOffset` and raise a clear alarm/error instead of silently dropping acknowledged messages. ### What Did You See Instead? The slave silently truncates its log below the confirmed offset. Confirmed messages are lost with no alarm, and the master continues serving from the regressed offset. ### Additional Context Related PR: https://github.com/apache/rocketmq/pull/11588 fixes the same-epoch master restart case where the slave could never rejoin the sync state set. The fencing/truncation protection discussed here is intentionally out of scope of that bugfix and is tracked separately. Possible directions (for discussion): 1. Fencing on election: report broker `maxPhyOffset`/`confirmOffset` in registration or heartbeat, and let the election policy reject or fence a candidate whose data is behind the replica set's confirmed offset. 2. Guard on truncation: in `AutoSwitchHAClient#doTruncate`, refuse (or require explicit override for) truncating below the local `confirmOffset`, and log an alarm. 3. Observability: emit a metric/alarm whenever a slave truncation would drop confirmed data, so operators can react even if the truncation is allowed. -- 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]
