ReplicasInfoManager use controller config instead of enableElectUncleanMaster so that it can be modified at run time

This commit is contained in:
RongtongJin
2022-06-17 15:50:20 +08:00
parent d6e922290f
commit fd8dafd5f9
3 changed files with 11 additions and 11 deletions
@@ -58,7 +58,7 @@ public interface Controller {
boolean isLeaderState();
/**
* Alter ISR of broker replicas.
* Alter SyncStateSet of broker replicas.
*
* @param request AlterSyncStateSetRequestHeader
* @return RemotingCommand(AlterSyncStateSetResponseHeader)
@@ -90,11 +90,6 @@ public interface Controller {
*/
CompletableFuture<RemotingCommand> getReplicaInfo(final GetReplicaInfoRequestHeader request);
/**
* Get inSyncStateData for target brokers, this api is used for admin tools.
*/
CompletableFuture<RemotingCommand> getSyncStateData(final List<String> brokerNames);
/**
* Get Metadata of controller
*
@@ -102,6 +97,11 @@ public interface Controller {
*/
RemotingCommand getControllerMetadata();
/**
* Get inSyncStateData for target brokers, this api is used for admin tools.
*/
CompletableFuture<RemotingCommand> getSyncStateData(final List<String> brokerNames);
/**
* Get the remotingServer used by the controller, the upper layer will reuse this remotingServer.
*/
@@ -56,12 +56,12 @@ import org.apache.rocketmq.logging.InternalLoggerFactory;
*/
public class ReplicasInfoManager {
private static final InternalLogger log = InternalLoggerFactory.getLogger(LoggerName.CONTROLLER_LOGGER_NAME);
private final boolean enableElectUncleanMaster;
private final ControllerConfig controllerConfig;
private final Map<String/* brokerName */, BrokerInfo> replicaInfoTable;
private final Map<String/* brokerName */, SyncStateInfo> syncStateSetInfoTable;
public ReplicasInfoManager(final ControllerConfig config) {
this.enableElectUncleanMaster = config.isEnableElectUncleanMaster();
this.controllerConfig = config;
this.replicaInfoTable = new HashMap<>();
this.syncStateSetInfoTable = new HashMap<>();
}
@@ -176,7 +176,7 @@ public class ReplicasInfoManager {
}
// Try elect a master in lagging replicas if enableElectUncleanMaster = true
if (enableElectUncleanMaster) {
if (controllerConfig.isEnableElectUncleanMaster()) {
boolean electSuccess = tryElectMaster(result, brokerName, brokerInfo.getAllBroker(), (candidate) ->
!candidate.equals(syncStateInfo.getMasterAddress()) && brokerAlivePredicate.test(brokerInfo.getClusterName(), candidate));
if (electSuccess) {
@@ -267,7 +267,7 @@ public class ReplicasInfoManager {
// If the master is not alive, we should elect a new master:
// Case1: This replicas was in sync state set list
// Case2: The option {EnableElectUncleanMaster} is true
canBeElectedAsMaster = syncStateInfo.getSyncStateSet().contains(brokerAddress) || this.enableElectUncleanMaster;
canBeElectedAsMaster = syncStateInfo.getSyncStateSet().contains(brokerAddress) || this.controllerConfig.isEnableElectUncleanMaster();
}
} else {
// If the broker's metadata does not exist in the state machine, the replicas can be elected as master directly.
@@ -20,7 +20,7 @@ import java.util.HashSet;
import java.util.Set;
/**
* In sync replicas info, manages the master and syncStateSet of a broker.
* Manages the syncStateSet of broker replicas.
*/
public class SyncStateInfo {
private final String clusterName;