ARTEMIS-3755 mitigate NPE related to fail-back

This commit is contained in:
Justin Bertram 2022-04-01 13:15:21 -05:00 committed by clebertsuconic
parent 84e68c76e9
commit 650952ba67
2 changed files with 25 additions and 4 deletions

View File

@ -1773,6 +1773,11 @@ public interface ActiveMQServerLogger extends BasicLogger {
@Message(id = 222307, value = "The queues element is deprecated and replaced by the addresses element")
void queuesElementDeprecated();
@LogMessage(level = Logger.Level.WARN)
@Message(id = 222308, value = "Unable to listen for incoming fail-back request because {0} is null. Ensure the broker has the proper cluster-connection configuration.",
format = Message.Format.MESSAGE_FORMAT)
void failBackCheckerFailure(String component);
@LogMessage(level = Logger.Level.ERROR)

View File

@ -35,6 +35,8 @@ import org.apache.activemq.artemis.core.server.NodeManager;
import org.apache.activemq.artemis.core.server.NodeManager.LockListener;
import org.apache.activemq.artemis.core.server.NodeManager.NodeManagerException;
import org.apache.activemq.artemis.core.server.QueueFactory;
import org.apache.activemq.artemis.core.server.cluster.ClusterConnection;
import org.apache.activemq.artemis.core.server.cluster.ClusterManager;
import org.apache.activemq.artemis.core.server.cluster.ha.ScaleDownPolicy;
import org.apache.activemq.artemis.core.server.cluster.ha.SharedStoreSlavePolicy;
import org.apache.activemq.artemis.core.server.group.GroupingHandler;
@ -253,15 +255,29 @@ public final class SharedStoreBackupActivation extends Activation {
BackupTopologyListener backupListener;
FailbackChecker() {
TransportConfiguration connector = activeMQServer.getClusterManager().getDefaultConnection(null).getConnector();
backupListener = new BackupTopologyListener(activeMQServer.getNodeID().toString(), connector);
activeMQServer.getClusterManager().getDefaultConnection(null).addClusterTopologyListener(backupListener);
ClusterManager clusterManager = activeMQServer.getClusterManager();
if (clusterManager != null) {
ClusterConnection clusterConnection = clusterManager.getDefaultConnection(null);
if (clusterConnection != null) {
TransportConfiguration connector = clusterConnection.getConnector();
if (connector != null) {
backupListener = new BackupTopologyListener(activeMQServer.getNodeID().toString(), connector);
clusterConnection.addClusterTopologyListener(backupListener);
} else {
ActiveMQServerLogger.LOGGER.failBackCheckerFailure("connector");
}
} else {
ActiveMQServerLogger.LOGGER.failBackCheckerFailure("cluster connection");
}
} else {
ActiveMQServerLogger.LOGGER.failBackCheckerFailure("cluster manager");
}
}
@Override
public void run() {
try {
if (!restarting.get() && activeMQServer.getNodeManager().isAwaitingFailback() && backupListener.waitForBackup()) {
if (!restarting.get() && activeMQServer.getNodeManager().isAwaitingFailback() && backupListener != null && backupListener.waitForBackup()) {
if (!restarting.compareAndSet(false, true)) {
return;
}