Search in sources :

Example 6 with StatefulStorageException

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());
}
Also used : StatefulStorageException(com.twitter.heron.spi.statefulstorage.StatefulStorageException) Checkpoint(com.twitter.heron.spi.statefulstorage.Checkpoint) ByteString(com.google.protobuf.ByteString) Common(com.twitter.heron.proto.system.Common)

Example 7 with StatefulStorageException

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());
}
Also used : StatefulStorageException(com.twitter.heron.spi.statefulstorage.StatefulStorageException) ByteString(com.google.protobuf.ByteString) Common(com.twitter.heron.proto.system.Common)

Example 8 with StatefulStorageException

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());
}
Also used : StatefulStorageException(com.twitter.heron.spi.statefulstorage.StatefulStorageException) Checkpoint(com.twitter.heron.spi.statefulstorage.Checkpoint) CheckpointManager(com.twitter.heron.proto.ckptmgr.CheckpointManager) ByteString(com.google.protobuf.ByteString) Common(com.twitter.heron.proto.system.Common)

Example 9 with StatefulStorageException

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);
}
Also used : StatefulStorageException(com.twitter.heron.spi.statefulstorage.StatefulStorageException) Checkpoint(com.twitter.heron.spi.statefulstorage.Checkpoint) DLInputStream(com.twitter.heron.dlog.DLInputStream) InputStream(java.io.InputStream) CheckpointManager(com.twitter.heron.proto.ckptmgr.CheckpointManager) IOException(java.io.IOException)

Example 10 with StatefulStorageException

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);
    }
}
Also used : StatefulStorageException(com.twitter.heron.spi.statefulstorage.StatefulStorageException) OutputStream(java.io.OutputStream) DLOutputStream(com.twitter.heron.dlog.DLOutputStream) IOException(java.io.IOException)

Aggregations

StatefulStorageException (com.twitter.heron.spi.statefulstorage.StatefulStorageException)13 IOException (java.io.IOException)8 Checkpoint (com.twitter.heron.spi.statefulstorage.Checkpoint)5 CheckpointManager (com.twitter.heron.proto.ckptmgr.CheckpointManager)4 ByteString (com.google.protobuf.ByteString)3 Common (com.twitter.heron.proto.system.Common)3 Path (org.apache.hadoop.fs.Path)3 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 DLInputStream (com.twitter.heron.dlog.DLInputStream)1 DLOutputStream (com.twitter.heron.dlog.DLOutputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 OutputStream (java.io.OutputStream)1 URI (java.net.URI)1 Namespace (org.apache.distributedlog.api.namespace.Namespace)1 Configuration (org.apache.hadoop.conf.Configuration)1 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 FileStatus (org.apache.hadoop.fs.FileStatus)1