use of org.apache.zookeeper_voltpatches.KeeperException in project voltdb by VoltDB.
the class InvocationDispatcher method takeShutdownSaveSnapshot.
private final ClientResponseImpl takeShutdownSaveSnapshot(final StoredProcedureInvocation task, final InvocationClientHandler handler, final Connection ccxn, final AuthUser user, OverrideCheck bypass) {
// shutdown save snapshot is available for Pro edition only
if (!MiscUtils.isPro()) {
task.setParams();
return dispatch(task, handler, ccxn, user, bypass, false);
}
Object p0 = task.getParams().getParam(0);
final long zkTxnId;
if (p0 instanceof Long) {
zkTxnId = ((Long) p0).longValue();
} else if (p0 instanceof String) {
try {
zkTxnId = Long.parseLong((String) p0);
} catch (NumberFormatException e) {
return gracefulFailureResponse("Incorrect argument type", task.clientHandle);
}
} else {
return gracefulFailureResponse("Incorrect argument type", task.clientHandle);
}
VoltDBInterface voltdb = VoltDB.instance();
if (!voltdb.isPreparingShuttingdown()) {
log.warn("Ignoring shutdown save snapshot request as VoltDB is not shutting down");
return unexpectedFailureResponse("Ignoring shutdown save snapshot request as VoltDB is not shutting down", task.clientHandle);
}
final ZooKeeper zk = voltdb.getHostMessenger().getZK();
// network threads are blocked from making zookeeper calls
Future<Long> fut = voltdb.getSES(true).submit(new Callable<Long>() {
@Override
public Long call() {
try {
Stat stat = zk.exists(VoltZK.operationMode, false);
if (stat == null) {
VoltDB.crashLocalVoltDB("cluster operation mode zookeeper node does not exist");
return Long.MIN_VALUE;
}
return stat.getMzxid();
} catch (KeeperException | InterruptedException e) {
VoltDB.crashLocalVoltDB("Failed to stat the cluster operation zookeeper node", true, e);
return Long.MIN_VALUE;
}
}
});
try {
if (fut.get().longValue() != zkTxnId) {
return unexpectedFailureResponse("Internal error: cannot write a startup snapshot because the " + "current system state is not consistent with an orderly shutdown. " + "Please try \"voltadmin shutdown --save\" again.", task.clientHandle);
}
} catch (InterruptedException | ExecutionException e1) {
VoltDB.crashLocalVoltDB("Failed to stat the cluster operation zookeeper node", true, e1);
return null;
}
NodeSettings paths = m_catalogContext.get().getNodeSettings();
String data;
try {
data = new JSONStringer().object().keySymbolValuePair(SnapshotUtil.JSON_TERMINUS, zkTxnId).endObject().toString();
} catch (JSONException e) {
VoltDB.crashLocalVoltDB("Failed to create startup snapshot save command", true, e);
return null;
}
log.info("Saving startup snapshot");
consoleLog.info("Taking snapshot to save database contents");
final SimpleClientResponseAdapter alternateAdapter = new SimpleClientResponseAdapter(ClientInterface.SHUTDONW_SAVE_CID, "Blocking Startup Snapshot Save");
final InvocationClientHandler alternateHandler = new InvocationClientHandler() {
@Override
public boolean isAdmin() {
return handler.isAdmin();
}
@Override
public long connectionId() {
return ClientInterface.SHUTDONW_SAVE_CID;
}
};
final long sourceHandle = task.clientHandle;
task.setClientHandle(alternateAdapter.registerCallback(SimpleClientResponseAdapter.NULL_CALLBACK));
SnapshotUtil.SnapshotResponseHandler savCallback = new SnapshotUtil.SnapshotResponseHandler() {
@Override
public void handleResponse(ClientResponse r) {
if (r == null) {
String msg = "Snapshot save failed. The database is paused and the shutdown has been cancelled";
transmitResponseMessage(gracefulFailureResponse(msg, sourceHandle), ccxn, sourceHandle);
}
if (r.getStatus() != ClientResponse.SUCCESS) {
String msg = "Snapshot save failed: " + r.getStatusString() + ". The database is paused and the shutdown has been cancelled";
ClientResponseImpl resp = new ClientResponseImpl(ClientResponse.GRACEFUL_FAILURE, r.getResults(), msg, sourceHandle);
transmitResponseMessage(resp, ccxn, sourceHandle);
}
consoleLog.info("Snapshot taken successfully");
task.setParams();
dispatch(task, alternateHandler, alternateAdapter, user, bypass, false);
}
};
// network threads are blocked from making zookeeper calls
final byte[] guardContent = data.getBytes(StandardCharsets.UTF_8);
Future<Boolean> guardFuture = voltdb.getSES(true).submit(new Callable<Boolean>() {
@Override
public Boolean call() throws Exception {
try {
ZKUtil.asyncMkdirs(zk, VoltZK.shutdown_save_guard, guardContent).get();
} catch (NodeExistsException itIsOk) {
return false;
} catch (InterruptedException | KeeperException e) {
VoltDB.crashLocalVoltDB("Failed to create shutdown save guard zookeeper node", true, e);
return false;
}
return true;
}
});
boolean created;
try {
created = guardFuture.get().booleanValue();
} catch (InterruptedException | ExecutionException e) {
VoltDB.crashLocalVoltDB("Failed to create shutdown save guard zookeeper node", true, e);
return null;
}
if (!created) {
return unexpectedFailureResponse("Internal error: detected concurrent invocations of \"voltadmin shutdown --save\"", task.clientHandle);
}
voltdb.getClientInterface().bindAdapter(alternateAdapter, null);
SnapshotUtil.requestSnapshot(sourceHandle, paths.resolve(paths.getSnapshoth()).toPath().toUri().toString(), SnapshotUtil.getShutdownSaveNonce(zkTxnId), true, SnapshotFormat.NATIVE, SnapshotPathType.SNAP_AUTO, data, savCallback, true);
return null;
}
use of org.apache.zookeeper_voltpatches.KeeperException in project voltdb by VoltDB.
the class UpdateSettings method run.
public VoltTable[] run(SystemProcedureExecutionContext ctx, byte[] settingsBytes) {
ZooKeeper zk = getHostMessenger().getZK();
Stat stat = null;
try {
stat = zk.exists(VoltZK.cluster_settings, false);
} catch (KeeperException | InterruptedException e) {
String msg = "Failed to stat cluster settings zookeeper node";
log.error(msg, e);
throw new VoltAbortException(msg);
}
final int version = stat.getVersion();
executeSysProcPlanFragments(createBarrierFragment(settingsBytes, version), DEP_updateSettingsBarrierAggregate);
return executeSysProcPlanFragments(createUpdateFragment(settingsBytes, version), DEP_updateSettingsAggregate);
}
use of org.apache.zookeeper_voltpatches.KeeperException in project voltdb by VoltDB.
the class CoreZK method removeRejoinNodeIndicatorForHost.
/**
* Removes the rejoin blocker if the current rejoin blocker contains the given host ID.
* @return true if the blocker is removed successfully, false otherwise.
*/
public static boolean removeRejoinNodeIndicatorForHost(ZooKeeper zk, int hostId) {
try {
Stat stat = new Stat();
final int rejoiningHost = ByteBuffer.wrap(zk.getData(rejoin_node_blocker, false, stat)).getInt();
if (hostId == rejoiningHost) {
zk.delete(rejoin_node_blocker, stat.getVersion());
return true;
}
} catch (KeeperException e) {
if (e.code() == KeeperException.Code.NONODE || e.code() == KeeperException.Code.BADVERSION) {
// Okay if the rejoin blocker for the given hostId is already gone.
return true;
}
} catch (InterruptedException e) {
return false;
}
return false;
}
use of org.apache.zookeeper_voltpatches.KeeperException in project voltdb by VoltDB.
the class CoreZK method removeJoinNodeIndicatorForHost.
/**
* Removes the join indicator for the given host ID.
* @return true if the indicator is removed successfully, false otherwise.
*/
public static boolean removeJoinNodeIndicatorForHost(ZooKeeper zk, int hostId) {
try {
Stat stat = new Stat();
String path = ZKUtil.joinZKPath(readyjoininghosts, Integer.toString(hostId));
zk.getData(path, false, stat);
zk.delete(path, stat.getVersion());
return true;
} catch (KeeperException e) {
if (e.code() == KeeperException.Code.NONODE || e.code() == KeeperException.Code.BADVERSION) {
// Okay if the join indicator for the given hostId is already gone.
return true;
}
} catch (InterruptedException e) {
return false;
}
return false;
}
use of org.apache.zookeeper_voltpatches.KeeperException in project voltdb by VoltDB.
the class RestoreAgent method fetchSnapshotTxnId.
/**
* Get the txnId of the snapshot the cluster is restoring from from ZK.
* NOTE that the barrier for this is now completely contained
* in run() in the restorePlanner thread; nobody gets out of there until
* someone wins the leader election and successfully writes the VoltZK.restore_snapshot_id
* node, so we just need to read it here.
*/
private void fetchSnapshotTxnId() {
try {
byte[] data = m_zk.getData(VoltZK.restore_snapshot_id, false, null);
String jsonData = new String(data, Constants.UTF8ENCODING);
if (!jsonData.equals("{}")) {
m_hasRestored = true;
JSONObject jo = new JSONObject(jsonData);
SnapshotInfo info = new SnapshotInfo(jo);
m_replayAgent.setSnapshotTxnId(info);
} else {
m_hasRestored = false;
m_replayAgent.setSnapshotTxnId(null);
}
} catch (KeeperException e2) {
VoltDB.crashGlobalVoltDB(e2.getMessage(), false, e2);
} catch (InterruptedException e2) {
} catch (JSONException je) {
VoltDB.crashLocalVoltDB(je.getMessage(), true, je);
}
}
Aggregations