use of com.twitter.heron.spi.statefulstorage.StatefulStorageException in project incubator-heron by apache.
the class CheckpointManagerServer method handleSaveInstanceStateRequest.
protected void handleSaveInstanceStateRequest(REQID rid, SocketChannel channel, CheckpointManager.SaveInstanceStateRequest request) {
Checkpoint checkpoint = new Checkpoint(topologyName, request.getInstance(), request.getCheckpoint());
LOG.info(String.format("Got a save checkpoint request for checkpointId %s " + " component %s instance %s on connection %s", checkpoint.getCheckpointId(), checkpoint.getComponent(), checkpoint.getInstance(), channel.socket().getRemoteSocketAddress()));
Common.StatusCode statusCode = Common.StatusCode.OK;
String errorMessage = "";
try {
statefulStorage.store(checkpoint);
LOG.info(String.format("Saved checkpoint for checkpointId %s compnent %s instance %s", checkpoint.getCheckpointId(), checkpoint.getComponent(), checkpoint.getInstance()));
} catch (StatefulStorageException e) {
errorMessage = String.format("Save checkpoint not successful for checkpointId " + "%s component %s instance %s", checkpoint.getCheckpointId(), checkpoint.getComponent(), checkpoint.getInstance());
statusCode = Common.StatusCode.NOTOK;
LOG.log(Level.WARNING, errorMessage, e);
}
CheckpointManager.SaveInstanceStateResponse.Builder responseBuilder = CheckpointManager.SaveInstanceStateResponse.newBuilder();
responseBuilder.setStatus(Common.Status.newBuilder().setStatus(statusCode).setMessage(errorMessage));
responseBuilder.setCheckpointId(request.getCheckpoint().getCheckpointId());
responseBuilder.setInstance(request.getInstance());
sendResponse(rid, channel, responseBuilder.build());
}
use of com.twitter.heron.spi.statefulstorage.StatefulStorageException in project incubator-heron by apache.
the class CheckpointManagerServer method handleCleanStatefulCheckpointRequest.
protected void handleCleanStatefulCheckpointRequest(REQID rid, SocketChannel channel, CheckpointManager.CleanStatefulCheckpointRequest request) {
LOG.info(String.format("Got a clean request from %s running at host:port %s", request.toString(), channel.socket().getRemoteSocketAddress()));
boolean deleteAll = request.hasCleanAllCheckpoints() && request.getCleanAllCheckpoints();
Common.StatusCode statusCode = Common.StatusCode.OK;
String errorMessage = "";
try {
statefulStorage.dispose(topologyName, request.getOldestCheckpointPreserved(), deleteAll);
LOG.info("Dispose checkpoint successful");
} catch (StatefulStorageException e) {
errorMessage = String.format("Request to dispose checkpoint failed for oldest Checkpoint " + "%s and deleteAll? %b", request.getOldestCheckpointPreserved(), deleteAll);
statusCode = Common.StatusCode.NOTOK;
LOG.log(Level.WARNING, errorMessage, e);
}
CheckpointManager.CleanStatefulCheckpointResponse.Builder responseBuilder = CheckpointManager.CleanStatefulCheckpointResponse.newBuilder();
responseBuilder.setStatus(Common.Status.newBuilder().setStatus(statusCode).setMessage(errorMessage));
sendResponse(rid, channel, responseBuilder.build());
}
use of com.twitter.heron.spi.statefulstorage.StatefulStorageException in project incubator-heron by apache.
the class CheckpointManagerServer method handleGetInstanceStateRequest.
protected void handleGetInstanceStateRequest(REQID rid, SocketChannel channel, CheckpointManager.GetInstanceStateRequest request) {
LOG.info(String.format("Got a get checkpoint request for checkpointId %s " + " component %s taskId %d on connection %s", request.getCheckpointId(), request.getInstance().getInfo().getComponentName(), request.getInstance().getInfo().getTaskId(), channel.socket().getRemoteSocketAddress()));
CheckpointManager.GetInstanceStateResponse.Builder responseBuilder = CheckpointManager.GetInstanceStateResponse.newBuilder();
responseBuilder.setInstance(request.getInstance());
responseBuilder.setCheckpointId(request.getCheckpointId());
String errorMessage = "";
Common.StatusCode statusCode = Common.StatusCode.OK;
if (!request.hasCheckpointId() || request.getCheckpointId().isEmpty()) {
LOG.info("The checkpoint id was empty, this sending empty state");
CheckpointManager.InstanceStateCheckpoint dummyState = CheckpointManager.InstanceStateCheckpoint.newBuilder().setCheckpointId(request.getCheckpointId()).setState(ByteString.EMPTY).build();
responseBuilder.setCheckpoint(dummyState);
} else {
try {
Checkpoint checkpoint = statefulStorage.restore(topologyName, request.getCheckpointId(), request.getInstance());
LOG.info(String.format("Get checkpoint successful for checkpointId %s " + "component %s taskId %d", checkpoint.getCheckpointId(), checkpoint.getComponent(), checkpoint.getTaskId()));
// Set the checkpoint-state in response
responseBuilder.setCheckpoint(checkpoint.getCheckpoint());
} catch (StatefulStorageException e) {
errorMessage = String.format("Get checkpoint not successful for checkpointId %s " + "component %s taskId %d", request.getCheckpointId(), request.getInstance().getInfo().getComponentName(), request.getInstance().getInfo().getTaskId());
LOG.log(Level.WARNING, errorMessage, e);
statusCode = Common.StatusCode.NOTOK;
}
}
responseBuilder.setStatus(Common.Status.newBuilder().setStatus(statusCode).setMessage(errorMessage));
sendResponse(rid, channel, responseBuilder.build());
}
use of com.twitter.heron.spi.statefulstorage.StatefulStorageException in project incubator-heron by apache.
the class DlogStorage method restore.
@Override
public Checkpoint restore(String topologyName, String checkpointId, PhysicalPlans.Instance instanceInfo) throws StatefulStorageException {
String checkpointPath = getCheckpointPath(topologyName, checkpointId, instanceInfo.getInfo().getComponentName(), instanceInfo.getInfo().getTaskId());
InputStream in = null;
CheckpointManager.InstanceStateCheckpoint state;
try {
in = openInputStream(checkpointPath);
state = CheckpointManager.InstanceStateCheckpoint.parseFrom(in);
} catch (IOException ioe) {
throw new StatefulStorageException("Failed to read checkpoint from " + checkpointPath, ioe);
} finally {
SysUtils.closeIgnoringExceptions(in);
}
return new Checkpoint(topologyName, instanceInfo, state);
}
use of com.twitter.heron.spi.statefulstorage.StatefulStorageException in project incubator-heron by apache.
the class DlogStorage method store.
@Override
public void store(Checkpoint checkpoint) throws StatefulStorageException {
String checkpointPath = getCheckpointPath(checkpoint.getTopologyName(), checkpoint.getCheckpointId(), checkpoint.getComponent(), checkpoint.getTaskId());
OutputStream out = null;
try {
out = openOutputStream(checkpointPath);
checkpoint.getCheckpoint().writeTo(out);
} catch (IOException e) {
throw new StatefulStorageException("Failed to persist checkpoint @ " + checkpointPath, e);
} finally {
SysUtils.closeIgnoringExceptions(out);
}
}
Aggregations