leizhiyuan opened a new issue, #11656:
URL: https://github.com/apache/rocketmq/issues/11656

   ### 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
   
   Linux (any)
   
   ### RocketMQ version
   
   develop, commit 19352a246
   
   ### JDK Version
   
   1.8
   
   ### Describe the Bug
   
   `CLEAN_BROKER_DATA` with `brokerControllerIdsToClean` removes the given 
brokerIds from a broker-set. `ReplicasInfoManager#handleCleanBrokerDataEvent` 
removes them from the `BrokerReplicaInfo` and from the syncStateSet, but never 
touches `SyncStateInfo#masterBrokerId`:
   
   ```java
   for (Long brokerId : brokerIdSetToClean) {
       brokerReplicaInfo.removeBrokerId(brokerId);
       syncStateInfo.removeFromSyncState(brokerId);
   }
   ```
   
   If one of the removed ids is the current master, the broker-set ends up with 
a master that is neither a replica nor in the syncStateSet, and the master 
epoch does not move:
   
   - `getReplicaInfo` / `registerBroker` / `getSyncStateData` keep returning 
the removed id as master, with `masterAddress = null` and the old 
`masterEpoch`. Because the epoch did not change, slaves are not told that the 
master is gone (the broker only reacts to a larger epoch).
   - With `cleanLivingBroker = true` and the removed master still running, 
nothing triggers a re-election (the master is alive), and every 
`alterSyncStateSet` it sends is rejected: a set containing itself fails with 
`the replicas {id} don't exist`, a set without itself is either equal to the 
current set or fails with `don't contains origin leader`. The syncStateSet of 
the broker-set is frozen.
   - With the default `cleanLivingBroker = false` the removed master must 
already be inactive, so the inconsistency lasts until the next 
controller-triggered re-election.
   
   The invariant that is broken is `masterBrokerId == null || masterBrokerId ∈ 
syncStateSet ⊆ brokerIdTable`, which every other `ReplicasInfoManager` path 
preserves.
   
   ### Steps to Reproduce
   
   Directly against `ReplicasInfoManager` (same code path for DLedger and JRaft 
controllers):
   
   ```java
   ReplicasInfoManager m = new ReplicasInfoManager(new ControllerConfig());
   m.applyEvent(new ApplyBrokerIdEvent("c", "broker-a", "addr1", 1L, 
"addr1;1"));
   m.applyEvent(new ApplyBrokerIdEvent("c", "broker-a", "addr2", 2L, 
"addr2;2"));
   // elect 1, then alterSyncStateSet({1,2})
   ...
   // broker 1 (the master) is gone, the operator removes it
   m.cleanBrokerData(new CleanControllerBrokerDataRequestHeader("c", 
"broker-a", "1", false), (c, b, id) -> false)
       .getEvents().forEach(m::applyEvent);
   m.getReplicaInfo(new GetReplicaInfoRequestHeader("broker-a"));
   ```
   
   Output:
   
   ```
   elect(id=1)                        master=1 mEpoch=1 sEpoch=1
   alterSyncStateSet({1,2})           code=0 newSstEpoch=2
   cleanBrokerData(ids={1})           code=0
   getReplicaInfo                     masterId=1 masterAddr=null mEpoch=1 
sst=[2]
   alterSyncStateSet({1,2}) again     code=2003 Rejecting alter syncStateSet 
request because the replicas {1} don't exist
   alterSyncStateSet({2})             code=2013 The newSyncStateSet is equal 
with oldSyncStateSet
   ```
   
   ### What Did You Expect to See?
   
   Removing the master from the broker-set clears `masterBrokerId` and 
increases `masterEpoch`, exactly like an election that finds no new master 
(`ElectMasterEvent` with `newMasterElected = false`). The remaining in-sync 
replicas can then elect a new master, and the removed broker is fenced by the 
larger epoch.
   
   ### What Did You See Instead?
   
   The removed broker stays as master with an unchanged epoch, see above.
   
   ### Additional Context
   
   Found while model checking the controller metadata state machine with 
TLA+/TLC (tracked in the umbrella issue). The existing 
`ReplicasInfoManagerTest#testCleanBrokerData` cleans the master id but only 
asserts the response code and never applies the events, so this was not covered.
   


-- 
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