Skip to content

Commit

Permalink
Throw exception if requirements match multiple nodes or v.v.
Browse files Browse the repository at this point in the history
  • Loading branch information
DaveCTurner committed Jan 15, 2019
1 parent 61af11d commit 7d70a29
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,20 @@ public static boolean discoveryIsConfigured(Settings settings) {
void onFoundPeersUpdated() {
final Set<DiscoveryNode> nodes = getDiscoveredNodes();
if (transportService.getLocalNode().isMasterNode() && initialMasterNodes.isEmpty() == false
&& nodes.stream().noneMatch(Coordinator::isZen1Node) && checkWaitRequirements(nodes)) {
&& nodes.stream().noneMatch(Coordinator::isZen1Node)) {

startBootstrap(nodes);
final boolean waitRequirementsPassed;
try {
waitRequirementsPassed = checkWaitRequirements(nodes);
} catch (IllegalStateException e) {
logger.warn("bootstrapping cancelled", e);
bootstrappingPermitted.set(false);
return;
}

if (waitRequirementsPassed) {
startBootstrap(nodes);
}
}
}

Expand Down Expand Up @@ -172,17 +183,13 @@ private boolean checkWaitRequirements(Set<DiscoveryNode> nodes) {
return false;
}
if (matchingNodes.size() > 1) {
bootstrappingPermitted.set(false);
logger.warn("bootstrapping cancelled: requirement [{}] matches multiple nodes: {}", requirement, matchingNodes);
return false;
throw new IllegalStateException("requirement [" + requirement + "] matches multiple nodes: " + matchingNodes);
}

for (final DiscoveryNode matchingNode : matchingNodes) {
if (selectedNodes.add(matchingNode) == false) {
bootstrappingPermitted.set(false);
logger.warn("bootstrapping cancelled: node [{}] matches multiple requirements: {}", matchingNode,
throw new IllegalStateException("node [" + matchingNode + "] matches multiple requirements: " +
initialMasterNodes.stream().filter(r -> matchesRequirement(matchingNode, r)).collect(Collectors.toList()));
return false;
}
}
}
Expand Down

0 comments on commit 7d70a29

Please sign in to comment.