Fix ASTERIXDB-1089
This fixes a case where an NPE is thrown when a substitute node joins but
no substitute nodes are specified in the cluster config
Change-Id: I8977d91ea82cd3a0538a84dc6d727d94fe2ece1d
Reviewed-on: https://asterix-gerrit.ics.uci.edu/508
Reviewed-by: Till Westmann <tillw@apache.org>
Tested-by: Jenkins <jenkins@fulliautomatix.ics.uci.edu>
Reviewed-by: Murtadha Hubail <hubailmor@gmail.com>
Reviewed-by: Keren-Audrey Ouaknine <kereno@gmail.com>
diff --git a/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java b/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java
index 490f42b..2cd6a1a 100644
--- a/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java
+++ b/asterix-app/src/main/java/org/apache/asterix/hyracks/bootstrap/NCApplicationEntryPoint.java
@@ -22,6 +22,7 @@
import java.io.IOException;
import java.rmi.server.UnicastRemoteObject;
import java.util.HashMap;
+import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
@@ -38,6 +39,7 @@
import org.apache.asterix.common.transactions.IRecoveryManager.SystemState;
import org.apache.asterix.event.schema.cluster.Cluster;
import org.apache.asterix.event.schema.cluster.Node;
+import org.apache.asterix.event.schema.cluster.SubstituteNodes;
import org.apache.asterix.metadata.MetadataManager;
import org.apache.asterix.metadata.MetadataNode;
import org.apache.asterix.metadata.api.IAsterixStateProxy;
@@ -295,11 +297,20 @@
if (!metadataProperties.getNodeNames().contains(nodeId)) {
metadataProperties.getNodeNames().add(nodeId);
Cluster cluster = AsterixClusterProperties.INSTANCE.getCluster();
+ if (cluster == null) {
+ throw new IllegalStateException("No cluster configuration found for this instance");
+ }
String asterixInstanceName = cluster.getInstanceName();
AsterixTransactionProperties txnProperties = ((IAsterixPropertiesProvider) runtimeContext)
.getTransactionProperties();
Node self = null;
- for (Node node : cluster.getSubstituteNodes().getNode()) {
+ List<Node> nodes;
+ if (cluster.getSubstituteNodes() != null) {
+ nodes = cluster.getSubstituteNodes().getNode();
+ } else {
+ throw new IllegalStateException("Unknown node joining the cluster");
+ }
+ for (Node node : nodes) {
String ncId = asterixInstanceName + "_" + node.getId();
if (ncId.equalsIgnoreCase(nodeId)) {
String storeDir = node.getStore() == null ? cluster.getStore() : node.getStore();