@@ -227,26 +227,25 @@ public void shutdown() {
227
227
}
228
228
229
229
public synchronized void changeBrokerRole (final Long newMasterBrokerId , final String newMasterAddress , final Integer newMasterEpoch ,
230
- final Integer syncStateSetEpoch ) {
230
+ final Integer syncStateSetEpoch , final Set < Long > syncStateSet ) {
231
231
if (newMasterBrokerId != null && newMasterEpoch > this .masterEpoch ) {
232
232
if (newMasterBrokerId .equals (this .brokerControllerId )) {
233
- changeToMaster (newMasterEpoch , syncStateSetEpoch );
233
+ changeToMaster (newMasterEpoch , syncStateSetEpoch , syncStateSet );
234
234
} else {
235
235
changeToSlave (newMasterAddress , newMasterEpoch , newMasterBrokerId );
236
236
}
237
237
}
238
238
}
239
239
240
- public void changeToMaster (final int newMasterEpoch , final int syncStateSetEpoch ) {
240
+ public void changeToMaster (final int newMasterEpoch , final int syncStateSetEpoch , final Set < Long > syncStateSet ) {
241
241
synchronized (this ) {
242
242
if (newMasterEpoch > this .masterEpoch ) {
243
243
LOGGER .info ("Begin to change to master, brokerName:{}, replicas:{}, new Epoch:{}" , this .brokerConfig .getBrokerName (), this .brokerAddress , newMasterEpoch );
244
244
245
245
this .masterEpoch = newMasterEpoch ;
246
246
247
247
// Change SyncStateSet
248
- final HashSet <Long > newSyncStateSet = new HashSet <>();
249
- newSyncStateSet .add (this .brokerControllerId );
248
+ final HashSet <Long > newSyncStateSet = new HashSet <>(syncStateSet );
250
249
changeSyncStateSet (newSyncStateSet , syncStateSetEpoch );
251
250
252
251
// Change record
@@ -365,8 +364,10 @@ private void handleSlaveSynchronize(final BrokerRole role) {
365
364
private boolean brokerElect () {
366
365
// Broker try to elect itself as a master in broker set.
367
366
try {
368
- ElectMasterResponseHeader tryElectResponse = this .brokerOuterAPI .brokerElect (this .controllerLeaderAddress , this .brokerConfig .getBrokerClusterName (),
367
+ Pair < ElectMasterResponseHeader , Set < Long >> tryElectResponsePair = this .brokerOuterAPI .brokerElect (this .controllerLeaderAddress , this .brokerConfig .getBrokerClusterName (),
369
368
this .brokerConfig .getBrokerName (), this .brokerControllerId );
369
+ ElectMasterResponseHeader tryElectResponse = tryElectResponsePair .getObject1 ();
370
+ Set <Long > syncStateSet = tryElectResponsePair .getObject2 ();
370
371
final String masterAddress = tryElectResponse .getMasterAddress ();
371
372
final Long masterBrokerId = tryElectResponse .getMasterBrokerId ();
372
373
if (StringUtils .isEmpty (masterAddress ) || masterBrokerId == null ) {
@@ -375,7 +376,7 @@ private boolean brokerElect() {
375
376
}
376
377
377
378
if (masterBrokerId .equals (this .brokerControllerId )) {
378
- changeToMaster (tryElectResponse .getMasterEpoch (), tryElectResponse .getSyncStateSetEpoch ());
379
+ changeToMaster (tryElectResponse .getMasterEpoch (), tryElectResponse .getSyncStateSetEpoch (), syncStateSet );
379
380
} else {
380
381
changeToSlave (masterAddress , tryElectResponse .getMasterEpoch (), tryElectResponse .getMasterBrokerId ());
381
382
}
@@ -544,15 +545,17 @@ private boolean createMetadataFileAndDeleteTemp() {
544
545
*/
545
546
private boolean registerBrokerToController () {
546
547
try {
547
- RegisterBrokerToControllerResponseHeader response = this .brokerOuterAPI .registerBrokerToController (brokerConfig .getBrokerClusterName (), brokerConfig .getBrokerName (), brokerControllerId , brokerAddress , controllerLeaderAddress );
548
- if (response == null ) return false ;
548
+ Pair <RegisterBrokerToControllerResponseHeader , Set <Long >> responsePair = this .brokerOuterAPI .registerBrokerToController (brokerConfig .getBrokerClusterName (), brokerConfig .getBrokerName (), brokerControllerId , brokerAddress , controllerLeaderAddress );
549
+ if (responsePair == null ) return false ;
550
+ RegisterBrokerToControllerResponseHeader response = responsePair .getObject1 ();
551
+ Set <Long > syncStateSet = responsePair .getObject2 ();
549
552
final Long masterBrokerId = response .getMasterBrokerId ();
550
553
final String masterAddress = response .getMasterAddress ();
551
554
if (masterBrokerId == null ) {
552
555
return true ;
553
556
}
554
557
if (this .brokerControllerId .equals (masterBrokerId )) {
555
- changeToMaster (response .getMasterEpoch (), response .getSyncStateSetEpoch ());
558
+ changeToMaster (response .getMasterEpoch (), response .getSyncStateSetEpoch (), syncStateSet );
556
559
} else {
557
560
changeToSlave (masterAddress , response .getMasterEpoch (), masterBrokerId );
558
561
}
@@ -635,7 +638,7 @@ private void schedulingSyncBrokerMetadata() {
635
638
if (StringUtils .isNoneEmpty (newMasterAddress ) && masterBrokerId != null ) {
636
639
if (masterBrokerId .equals (this .brokerControllerId )) {
637
640
// If this broker is now the master
638
- changeToMaster (newMasterEpoch , syncStateSet .getSyncStateSetEpoch ());
641
+ changeToMaster (newMasterEpoch , syncStateSet .getSyncStateSetEpoch (), syncStateSet . getSyncStateSet () );
639
642
} else {
640
643
// If this broker is now the slave, and master has been changed
641
644
changeToSlave (newMasterAddress , newMasterEpoch , masterBrokerId );
0 commit comments