leizhiyuan opened a new issue, #11659:
URL: https://github.com/apache/rocketmq/issues/11659
### Before Creating the Enhancement Request
- [x] I have confirmed that this should be classified as an enhancement
rather than a bug/feature.
### Summary
Umbrella issue to track correctness problems in the controller (master
election, master/slave switch, metadata replication) found by modelling the
controller metadata state machine in TLA+ and checking it with TLC.
### Motivation
The controller state machine (`ReplicasInfoManager` /
`RaftReplicasInfoManager`) and the broker side (`ReplicasManager`) together
implement an implicit protocol whose correctness depends on a few invariants:
- `masterBrokerId == null || masterBrokerId ∈ syncStateSet ⊆ brokerIdTable`
- `masterEpoch` of a broker-set never goes backwards (brokers only accept a
strictly larger epoch)
- a brokerId is owned by at most one broker
- no two brokers are master at the same epoch
- a broker whose heartbeat has expired (on the leader's clock) is never
elected
These invariants are not written down anywhere and are not checked by the
tests, so I wrote them down and model checked them.
### Describe the Solution You'd Like
Model: the three controller replicas are modelled as one serialized state
machine (all commands go through the raft log, so they are totally ordered and
applied deterministically; raft itself is assumed correct). The brokers, the
leader-local heartbeat table, response delivery, and per-broker clock skew are
the environment. Command guards are transcribed literally from
`ReplicasInfoManager`, `RaftReplicasInfoManager`, `DefaultElectPolicy`,
`ControllerManager` and `ReplicasManager`.
Results (2 brokers, bounded time and epochs):
| Invariant | Result |
| --- | --- |
| master ∈ syncStateSet, master ∈ replicas | violated with
`CLEAN_BROKER_DATA` (partial clean) → #11656 |
| never elect a broker whose heartbeat expired | holds with no clock skew,
violated with skew → #11657 |
| masterEpoch never decreases / stale master fenceable | violated with
`CLEAN_BROKER_DATA` (full clean) → #11658 |
| brokerId owned by one broker / no same-epoch split brain | violated with
`CLEAN_BROKER_DATA` (full clean) → #11658 |
| all of the above **without** admin commands | hold (18.9M distinct states)
|
Sub-tasks:
- [ ] #11656 Controller keeps a removed broker as master after
cleanBrokerData
- [ ] #11657 JRaft controller judges broker liveness with the requester's
clock
- [ ] #11658 Cleaning a whole broker-set resets masterEpoch and reissues
brokerIds (needs a design decision, see the issue)
Smaller code-level findings, to be confirmed and filed separately:
- `replicaInfoTable` / `syncStateSetInfoTable` are keyed by `brokerName`
only, so two clusters with the same brokerName share controller metadata.
- `applyBrokerId` (`registerCheckCode.split(";")`) and other paths can throw
unchecked exceptions inside `JRaftControllerStateMachine#processEvent`, which
only catches `RemotingCommandException`; such a log entry fails identically on
every replica.
### Describe Alternatives You've Considered
Not applicable.
--
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]