use of com.google_voltpatches.common.base.Joiner in project voltdb by VoltDB.
the class MeshProber method considerMeshPlea.
@Override
public JoinAcceptor.PleaDecision considerMeshPlea(ZooKeeper zk, int hostId, JSONObject jo) {
checkArgument(zk != null, "zookeeper is null");
checkArgument(jo != null, "json object is null");
if (!HostCriteria.hasCriteria(jo)) {
return new JoinAcceptor.PleaDecision(String.format("Joining node version %s is incompatible with this node verion %s", jo.optString(SocketJoiner.VERSION_STRING, "(unknown)"), m_versionChecker.getVersionString()), false, false);
}
HostCriteria hc = new HostCriteria(jo);
Map<Integer, HostCriteria> hostCriteria = m_hostCriteria.get();
// when the cluster is forming anew)
if (!getNodeState().operational() && !hostCriteria.values().stream().anyMatch(c -> c.getNodeState().operational())) {
List<String> incompatibilities = asHostCriteria().listIncompatibilities(hc);
if (!incompatibilities.isEmpty()) {
Joiner joiner = Joiner.on("\n ").skipNulls();
String error = "Incompatible joining criteria:\n " + joiner.join(incompatibilities);
return new JoinAcceptor.PleaDecision(error, false, false);
}
return new JoinAcceptor.PleaDecision(null, true, false);
} else {
StartAction operationalStartAction = hostCriteria.values().stream().filter(c -> c.getNodeState().operational()).map(c -> c.getStartAction()).findFirst().orElse(getStartAction());
if (operationalStartAction == StartAction.PROBE && hc.getStartAction() != StartAction.PROBE) {
String msg = "Invalid VoltDB command. Please use init and start to join this cluster";
return new JoinAcceptor.PleaDecision(msg, false, false);
}
}
// how many hosts are already in the mesh?
Stat stat = new Stat();
try {
zk.getChildren(CoreZK.hosts, false, stat);
} catch (InterruptedException e) {
String msg = "Interrupted while considering mesh plea";
m_networkLog.error(msg, e);
return new JoinAcceptor.PleaDecision(msg, false, false);
} catch (KeeperException e) {
EnumSet<KeeperException.Code> closing = EnumSet.of(KeeperException.Code.SESSIONEXPIRED, KeeperException.Code.CONNECTIONLOSS);
if (closing.contains(e.code())) {
return new JoinAcceptor.PleaDecision("Shutting down", false, false);
} else {
String msg = "Failed to list hosts while considering a mesh plea";
m_networkLog.error(msg, e);
return new JoinAcceptor.PleaDecision(msg, false, false);
}
}
// connecting to already wholly formed cluster
if (stat.getNumChildren() >= getHostCount()) {
return new JoinAcceptor.PleaDecision(hc.isAddAllowed() ? null : "Cluster is already complete", hc.isAddAllowed(), false);
} else if (stat.getNumChildren() < getHostCount()) {
// check for concurrent rejoins
final int rejoiningHost = CoreZK.createRejoinNodeIndicator(zk, hostId);
if (rejoiningHost == -1) {
return new JoinAcceptor.PleaDecision(null, true, false);
} else {
String msg = "Only one host can rejoin at a time. Host " + rejoiningHost + " is still rejoining.";
return new JoinAcceptor.PleaDecision(msg, false, true);
}
}
return new JoinAcceptor.PleaDecision(null, true, false);
}
Aggregations