use of org.apache.zookeeper_voltpatches.data.Stat 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.data.Stat 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.data.Stat in project voltdb by VoltDB.
the class UpdateSettings method executePlanFragment.
@Override
public DependencyPair executePlanFragment(Map<Integer, List<VoltTable>> dependencies, long fragmentId, ParameterSet params, SystemProcedureExecutionContext context) {
if (fragmentId == SysProcFragmentId.PF_updateSettingsBarrier) {
DependencyPair success = new DependencyPair.TableDependencyPair(DEP_updateSettingsBarrier, new VoltTable(new ColumnInfo[] { new ColumnInfo("UNUSED", VoltType.BIGINT) }));
if (log.isInfoEnabled()) {
log.info("Site " + CoreUtils.hsIdToString(m_site.getCorrespondingSiteId()) + " reached settings update barrier.");
}
return success;
} else if (fragmentId == SysProcFragmentId.PF_updateSettingsBarrierAggregate) {
Object[] paramarr = params.toArray();
byte[] settingsBytes = (byte[]) paramarr[0];
int version = ((Integer) paramarr[1]).intValue();
ZooKeeper zk = getHostMessenger().getZK();
Stat stat = null;
try {
stat = zk.setData(VoltZK.cluster_settings, settingsBytes, version);
} catch (KeeperException | InterruptedException e) {
String msg = "Failed to update cluster settings";
log.error(msg, e);
throw new SettingsException(msg, e);
}
log.info("Saved new cluster settings state");
return new DependencyPair.TableDependencyPair(DEP_updateSettingsBarrierAggregate, getVersionResponse(stat.getVersion()));
} else if (fragmentId == SysProcFragmentId.PF_updateSettings) {
Object[] paramarr = params.toArray();
byte[] settingsBytes = (byte[]) paramarr[0];
int version = ((Integer) paramarr[1]).intValue();
ClusterSettings settings = ClusterSettings.create(settingsBytes);
Pair<CatalogContext, CatalogSpecificPlanner> ctgdef = getVoltDB().settingsUpdate(settings, version);
context.updateSettings(ctgdef.getFirst(), ctgdef.getSecond());
VoltTable result = new VoltTable(VoltSystemProcedure.STATUS_SCHEMA);
result.addRow(VoltSystemProcedure.STATUS_OK);
return new DependencyPair.TableDependencyPair(DEP_updateSettings, result);
} else if (fragmentId == SysProcFragmentId.PF_updateSettingsAggregate) {
VoltTable result = VoltTableUtil.unionTables(dependencies.get(DEP_updateSettings));
return new DependencyPair.TableDependencyPair(DEP_updateSettingsAggregate, result);
} else {
VoltDB.crashLocalVoltDB("Received unrecognized plan fragment id " + fragmentId + " in UpdateSettings", false, null);
}
throw new RuntimeException("Should not reach this code");
}
use of org.apache.zookeeper_voltpatches.data.Stat 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.data.Stat 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;
}
Aggregations