use of org.apache.zookeeper_voltpatches.KeeperException in project voltdb by VoltDB.
the class LeaderCache method processChildEvent.
/**
* Update a modified child and republish a new snapshot. This may indicate
* a deleted child or a child with modified data.
*/
private void processChildEvent(WatchedEvent event) throws Exception {
HashMap<Integer, Long> cacheCopy = new HashMap<Integer, Long>(m_publicCache);
ByteArrayCallback cb = new ByteArrayCallback();
m_zk.getData(event.getPath(), m_childWatch, cb, null);
try {
// cb.getData() and cb.getPath() throw KeeperException
byte[] payload = cb.getData();
long HSId = Long.valueOf(new String(payload, "UTF-8"));
cacheCopy.put(getPartitionIdFromZKPath(cb.getPath()), HSId);
} catch (KeeperException.NoNodeException e) {
// rtb: I think result's path is the same as cb.getPath()?
cacheCopy.remove(getPartitionIdFromZKPath(event.getPath()));
}
m_publicCache = ImmutableMap.copyOf(cacheCopy);
if (m_cb != null) {
m_cb.run(m_publicCache);
}
}
use of org.apache.zookeeper_voltpatches.KeeperException in project voltdb by VoltDB.
the class ClusterSettingsRef method store.
public int store(ZooKeeper zk) {
Stat stat = null;
int[] stamp = new int[] { 0 };
ClusterSettings settings = get(stamp);
try {
// at this stage zookeeper is one version behind
stat = zk.setData(VoltZK.cluster_settings, settings.asBytes(), stamp[0] - 1);
} catch (KeeperException | InterruptedException e) {
throw new SettingsException("Failed to store to ZooKeeper", e);
}
return stat.getVersion();
}
use of org.apache.zookeeper_voltpatches.KeeperException in project voltdb by VoltDB.
the class TopologyZKUtils method updateTopologyToZK.
public static void updateTopologyToZK(ZooKeeper zk, AbstractTopology topology) {
Stat stat = new Stat();
try {
zk.getData(VoltZK.topology, false, stat);
byte[] payload = topology.topologyToJSON().toString().getBytes(Charsets.UTF_8);
zk.setData(VoltZK.topology, payload, stat.getVersion());
} catch (KeeperException | InterruptedException | JSONException e) {
VoltDB.crashLocalVoltDB("Unable to update topology to ZK, dying", true, e);
}
}
use of org.apache.zookeeper_voltpatches.KeeperException 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);
}
use of org.apache.zookeeper_voltpatches.KeeperException in project voltdb by VoltDB.
the class DataTree method processTxn.
public ProcessTxnResult processTxn(TxnHeader header, Record txn) {
ProcessTxnResult rc = new ProcessTxnResult();
String debug = "";
try {
rc.clientId = header.getClientId();
rc.cxid = header.getCxid();
rc.zxid = header.getZxid();
rc.type = header.getType();
rc.err = 0;
if (rc.zxid > lastProcessedZxid) {
lastProcessedZxid = rc.zxid;
}
switch(header.getType()) {
case OpCode.create:
CreateTxn createTxn = (CreateTxn) txn;
debug = "Create transaction for " + createTxn.getPath();
createNode(createTxn.getPath(), createTxn.getData(), createTxn.getAcl(), createTxn.getEphemeral() ? header.getClientId() : 0, header.getZxid(), header.getTime());
rc.path = createTxn.getPath();
break;
case OpCode.delete:
DeleteTxn deleteTxn = (DeleteTxn) txn;
debug = "Delete transaction for " + deleteTxn.getPath();
deleteNode(deleteTxn.getPath(), header.getZxid());
break;
case OpCode.setData:
SetDataTxn setDataTxn = (SetDataTxn) txn;
debug = "Set data for transaction for " + setDataTxn.getPath();
rc.stat = setData(setDataTxn.getPath(), setDataTxn.getData(), setDataTxn.getVersion(), header.getZxid(), header.getTime());
break;
case OpCode.setACL:
SetACLTxn setACLTxn = (SetACLTxn) txn;
debug = "Set ACL for transaction for " + setACLTxn.getPath();
rc.stat = setACL(setACLTxn.getPath(), setACLTxn.getAcl(), setACLTxn.getVersion());
break;
case OpCode.closeSession:
killSession(header.getClientId(), header.getZxid());
break;
case OpCode.error:
ErrorTxn errTxn = (ErrorTxn) txn;
rc.err = errTxn.getErr();
break;
}
} catch (KeeperException e) {
// These are expected errors since we take a lazy snapshot
if (initialized || (e.code() != Code.NONODE && e.code() != Code.NODEEXISTS)) {
LOG.warn("Failed:" + debug, e);
}
}
return rc;
}
Aggregations