use of org.apache.zookeeper_voltpatches.KeeperException in project voltdb by VoltDB.
the class ExportGeneration method createAndRegisterAckMailboxes.
private void createAndRegisterAckMailboxes(final Set<Integer> localPartitions, HostMessenger messenger) {
m_mailboxesZKPath = VoltZK.exportGenerations + "/" + m_timestamp + "/" + "mailboxes";
m_mbox = new LocalMailbox(messenger) {
@Override
public void deliver(VoltMessage message) {
if (message instanceof BinaryPayloadMessage) {
BinaryPayloadMessage bpm = (BinaryPayloadMessage) message;
ByteBuffer buf = ByteBuffer.wrap(bpm.m_payload);
final int partition = buf.getInt();
final int length = buf.getInt();
byte[] stringBytes = new byte[length];
buf.get(stringBytes);
String signature = new String(stringBytes, Constants.UTF8ENCODING);
final long ackUSO = buf.getLong();
final boolean runEveryWhere = (buf.getShort() == (short) 1);
final Map<String, ExportDataSource> partitionSources = m_dataSourcesByPartition.get(partition);
if (partitionSources == null) {
exportLog.error("Received an export ack for partition " + partition + " which does not exist on this node, partitions = " + m_dataSourcesByPartition);
return;
}
final ExportDataSource eds = partitionSources.get(signature);
if (eds == null) {
exportLog.warn("Received an export ack for partition " + partition + " source signature " + signature + " which does not exist on this node, sources = " + partitionSources);
return;
}
try {
eds.ack(ackUSO, runEveryWhere);
} catch (RejectedExecutionException ignoreIt) {
// ignore it: as it is already shutdown
}
} else {
exportLog.error("Receive unexpected message " + message + " in export subsystem");
}
}
};
messenger.createMailbox(null, m_mbox);
for (Integer partition : localPartitions) {
final String partitionDN = m_mailboxesZKPath + "/" + partition;
ZKUtil.asyncMkdirs(messenger.getZK(), partitionDN);
ZKUtil.StringCallback cb = new ZKUtil.StringCallback();
messenger.getZK().create(partitionDN + "/" + m_mbox.getHSId(), null, Ids.OPEN_ACL_UNSAFE, CreateMode.EPHEMERAL, cb, null);
}
ListenableFuture<?> fut = m_childUpdatingThread.submit(new Runnable() {
@Override
public void run() {
List<Pair<Integer, ZKUtil.ChildrenCallback>> callbacks = new ArrayList<Pair<Integer, ZKUtil.ChildrenCallback>>();
for (Integer partition : localPartitions) {
ZKUtil.ChildrenCallback callback = new ZKUtil.ChildrenCallback();
messenger.getZK().getChildren(m_mailboxesZKPath + "/" + partition, constructMailboxChildWatcher(messenger), callback, null);
callbacks.add(Pair.of(partition, callback));
}
for (Pair<Integer, ZKUtil.ChildrenCallback> p : callbacks) {
final Integer partition = p.getFirst();
List<String> children = null;
try {
children = p.getSecond().getChildren();
} catch (InterruptedException e) {
Throwables.propagate(e);
} catch (KeeperException e) {
Throwables.propagate(e);
}
ImmutableList.Builder<Long> mailboxes = ImmutableList.builder();
for (String child : children) {
if (child.equals(Long.toString(m_mbox.getHSId())))
continue;
mailboxes.add(Long.valueOf(child));
}
ImmutableList<Long> mailboxHsids = mailboxes.build();
for (ExportDataSource eds : m_dataSourcesByPartition.get(partition).values()) {
eds.updateAckMailboxes(Pair.of(m_mbox, mailboxHsids));
}
}
}
});
try {
fut.get();
} catch (Throwable t) {
Throwables.propagate(t);
}
}
use of org.apache.zookeeper_voltpatches.KeeperException in project voltdb by VoltDB.
the class RealVoltDB method validateStartAction.
private void validateStartAction() {
ZooKeeper zk = m_messenger.getZK();
boolean initCompleted = false;
List<String> children = null;
try {
initCompleted = zk.exists(VoltZK.init_completed, false) != null;
children = zk.getChildren(VoltZK.start_action, new StartActionWatcher(), null);
} catch (KeeperException e) {
hostLog.error("Failed to validate the start actions", e);
return;
} catch (InterruptedException e) {
VoltDB.crashLocalVoltDB("Interrupted during start action validation:" + e.getMessage(), true, e);
}
if (children != null && !children.isEmpty()) {
for (String child : children) {
byte[] data = null;
try {
data = zk.getData(VoltZK.start_action + "/" + child, false, null);
} catch (KeeperException excp) {
if (excp.code() == Code.NONODE) {
hostLog.debug("Failed to validate the start action as node " + VoltZK.start_action + "/" + child + " got disconnected", excp);
} else {
hostLog.error("Failed to validate the start actions ", excp);
}
return;
} catch (InterruptedException e) {
VoltDB.crashLocalVoltDB("Interrupted during start action validation:" + e.getMessage(), true, e);
}
if (data == null) {
VoltDB.crashLocalVoltDB("Couldn't find " + VoltZK.start_action + "/" + child);
}
String startAction = new String(data);
if ((startAction.equals(StartAction.JOIN.toString()) || startAction.equals(StartAction.REJOIN.toString()) || startAction.equals(StartAction.LIVE_REJOIN.toString())) && !initCompleted) {
int nodeId = VoltZK.getHostIDFromChildName(child);
if (nodeId == m_messenger.getHostId()) {
VoltDB.crashLocalVoltDB("This node was started with start action " + startAction + " during cluster creation. " + "All nodes should be started with matching create or recover actions when bring up a cluster. " + "Join and rejoin are for adding nodes to an already running cluster.");
} else {
hostLog.warn("Node " + nodeId + " tried to " + startAction + " cluster but it is not allowed during cluster creation. " + "All nodes should be started with matching create or recover actions when bring up a cluster. " + "Join and rejoin are for adding nodes to an already running cluster.");
}
}
}
}
}
use of org.apache.zookeeper_voltpatches.KeeperException in project voltdb by VoltDB.
the class SnapshotSaveAPI method logParticipatingHostCount.
/**
* Once participating host count is set, SnapshotCompletionMonitor can check this ZK node to
* determine whether the snapshot has finished or not.
*
* This should only be called when all participants have responded. It is possible that some
* hosts finish taking snapshot before the coordinator logs the participating host count. In
* this case, the host count would have been decremented multiple times already. To make sure
* finished hosts are logged correctly, this method adds participating host count + 1 to the
* current host count.
*
* @param txnId The snapshot txnId
* @param participantCount The number of hosts participating in this snapshot
*/
public static void logParticipatingHostCount(long txnId, int participantCount) {
ZooKeeper zk = VoltDB.instance().getHostMessenger().getZK();
final String snapshotPath = VoltZK.completed_snapshots + "/" + txnId;
boolean success = false;
while (!success) {
Stat stat = new Stat();
byte[] data = null;
try {
data = zk.getData(snapshotPath, false, stat);
} catch (KeeperException e) {
if (e.code() == KeeperException.Code.NONODE) {
// If snapshot creation failed for some reason, the node won't exist. ignore
return;
}
VoltDB.crashLocalVoltDB("Failed to get snapshot completion node", true, e);
} catch (InterruptedException e) {
VoltDB.crashLocalVoltDB("Interrupted getting snapshot completion node", true, e);
}
if (data == null) {
VoltDB.crashLocalVoltDB("Data should not be null if the node exists", false, null);
}
try {
JSONObject jsonObj = new JSONObject(new String(data, Charsets.UTF_8));
if (jsonObj.getLong("txnId") != txnId) {
VoltDB.crashLocalVoltDB("TxnId should match", false, null);
}
int hostCount = jsonObj.getInt("hostCount");
// +1 because hostCount was initialized to -1
jsonObj.put("hostCount", hostCount + participantCount + 1);
zk.setData(snapshotPath, jsonObj.toString(4).getBytes(Charsets.UTF_8), stat.getVersion());
} catch (KeeperException.BadVersionException e) {
continue;
} catch (Exception e) {
VoltDB.crashLocalVoltDB("This ZK call should never fail", true, e);
}
success = true;
}
}
use of org.apache.zookeeper_voltpatches.KeeperException in project voltdb by VoltDB.
the class SnapshotDaemon method init.
public void init(DaemonInitiator initiator, HostMessenger messenger, Runnable threadLocalInit, GlobalServiceElector gse) {
m_initiator = initiator;
m_zk = messenger.getZK();
m_mb = new SiteMailbox(messenger, messenger.getHSIdForLocalSite(HostMessenger.SNAPSHOT_DAEMON_ID));
messenger.createMailbox(m_mb.getHSId(), m_mb);
try {
m_zk.create(VoltZK.nodes_currently_snapshotting, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
} catch (Exception e) {
}
try {
m_zk.create(VoltZK.completed_snapshots, null, Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
} catch (Exception e) {
}
if (threadLocalInit != null) {
m_es.execute(threadLocalInit);
}
/*
* Really shouldn't leak this from a constructor, and twice to boot
* If IV2 is enabled leader election for the snapshot daemon is always tied to
* leader election for the MP coordinator so that they can't be partitioned
* from each other.
*/
if (gse == null) {
m_es.execute(new Runnable() {
@Override
public void run() {
leaderElection();
}
});
} else {
gse.registerService(new Promotable() {
@Override
public void acceptPromotion() throws InterruptedException, ExecutionException, KeeperException {
m_es.submit(new Runnable() {
@Override
public void run() {
try {
m_isAutoSnapshotLeader = true;
if (m_lastKnownSchedule != null) {
makeActivePrivate(m_lastKnownSchedule);
}
electedTruncationLeader();
} catch (Exception e) {
VoltDB.crashLocalVoltDB("Exception in snapshot daemon electing master via ZK", true, e);
}
}
});
}
});
}
}
use of org.apache.zookeeper_voltpatches.KeeperException in project voltdb by VoltDB.
the class MockVoltDB method validateStartAction.
public void validateStartAction() {
try {
ZooKeeper zk = m_hostMessenger.getZK();
boolean initCompleted = zk.exists(VoltZK.init_completed, false) != null;
List<String> children = zk.getChildren(VoltZK.start_action, new StartActionWatcher(), null);
if (!children.isEmpty()) {
for (String child : children) {
byte[] data = zk.getData(VoltZK.start_action + "/" + child, false, null);
if (data == null) {
VoltDB.crashLocalVoltDB("Couldn't find " + VoltZK.start_action + "/" + child);
}
String startAction = new String(data);
if ((startAction.equals(StartAction.JOIN.toString()) || startAction.equals(StartAction.REJOIN.toString()) || startAction.equals(StartAction.LIVE_REJOIN.toString())) && !initCompleted) {
int nodeId = VoltZK.getHostIDFromChildName(child);
if (nodeId == m_hostMessenger.getHostId()) {
VoltDB.crashLocalVoltDB("This node was started with start action " + startAction + " during cluster creation. All nodes should be started with matching " + "create or recover actions when bring up a cluster. Join and Rejoin " + "are for adding nodes to an already running cluster.");
} else {
logger.warn("Node " + nodeId + " tried to " + startAction + " cluster but it is not allowed during cluster creation. " + "All nodes should be started with matching create or recover actions when bring up a cluster. " + "Join and rejoin are for adding nodes to an already running cluster.");
}
}
}
}
} catch (KeeperException e) {
logger.error("Failed to validate the start actions:" + e.getMessage());
} catch (InterruptedException e) {
VoltDB.crashLocalVoltDB("Interrupted during start action validation:" + e.getMessage(), true, e);
}
}
Aggregations