frotmo commented on issue #11603:
URL: https://github.com/apache/rocketmq/issues/11603#issuecomment-7164585128
Thanks for the guidance so far, @ShannonDing. Following the store-side guard
in PR #11617 and the verification work in this issue, I would like to align on
the design of the remaining controller-side and broker-side protection before
writing more code.
## Verified so far
- Store level: a slave with `maxOffset = confirmOffset = 3280` was truncated
to 1580 after the master recovered to 1580 and was re-elected with the same
epoch (reproduced with two stores, no controller involved). PR #11617 refuses
this truncation by default and logs an error instead.
- Controller level (unit checks against the current develop code):
- `DefaultElectPolicy#tryElect` returns the old master as soon as it is a
valid candidate; `BrokerLiveInfoGetter` is not called, so a regressed
`maxOffset` never enters the decision.
- `DefaultBrokerHeartbeatManager#onBrokerHeartbeat` only updates the live
entry when the epoch increases, or when the epoch is equal and `maxOffset`
increases; a reported regression is ignored and the previous values are kept.
In addition, the first heartbeat creates the entry with the 9-argument
`BrokerLiveInfo` constructor, so the reported `confirmOffset` is dropped (stays
0) until an update with a higher `maxOffset`. This matters after a controller
leader change, when the live table is rebuilt from heartbeats.
## Proposed direction (for discussion)
1. Fix the live-info plumbing first (small, controller-only): populate
`confirmOffset` when an entry is created, and record offset regressions instead
of silently ignoring them.
2. Election invariant: do not elect a candidate whose `maxOffset` is below
the highest `confirmOffset` observed among live replicas; apply the check
before the old-master short-circuit. If the old master fails the check, elect
the replica with the highest `(epoch, maxOffset)` under a new epoch. This is
the Raft leader-completeness property adapted to the controller.
3. Broker self-fencing (defense in depth for single-replica sets and
controller restarts): during recovery, compare the persisted `confirmOffset`
(before it is clamped to `processOffset`) with the recovered `processOffset`.
If confirmed data is missing, refuse the master role (today `ReplicasManager`
ignores `changeToMaster` failures, so this also needs fixing) and report the
state to the controller.
4. Observability at both detection points: a metric/alarm for "data
regressed on recovery" and one for "truncation refused because it is below
`confirmOffset`".
## Questions where we need maintainer input
1. Failure policy: should a set with no eligible candidate fail closed (no
master), or elect the best available replica with a new epoch? What should a
single-replica set do?
2. Live info: is tracking regressions in the in-memory live table
acceptable, or should the offset history be persisted/replicated so it survives
a controller leader change? Today a new leader rebuilds the table from
heartbeats.
3. Election input: should the invariant use the maximum `confirmOffset`
among all live replicas, or only among the SyncStateSet? How should stale
heartbeats be treated?
4. Scope/split: would you prefer one controller-side PR and one broker-side
PR, or a design document first? Is it acceptable that steps 1-2 require no
protocol change (the heartbeat already carries both offsets)?
I am happy to start with step 1 and its tests if the direction looks right,
or to file a dedicated issue if you prefer tracking the controller work
separately.
--
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]