Search in sources :

Example 6 with Checkpoint

use of com.twitter.heron.spi.statefulstorage.Checkpoint 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 7 with Checkpoint

use of com.twitter.heron.spi.statefulstorage.Checkpoint 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 8 with Checkpoint

use of com.twitter.heron.spi.statefulstorage.Checkpoint in project incubator-heron by apache.

the class DlogStorageTest method testRestore.

@Test
public void testRestore() throws Exception {
    Checkpoint restoreCheckpoint = new Checkpoint(StatefulStorageTestContext.TOPOLOGY_NAME, instance, instanceStateCheckpoint);
    InputStream mockInputStream = mock(InputStream.class);
    doReturn(mockInputStream).when(dlogStorage).openInputStream(anyString());
    PowerMockito.spy(CheckpointManager.InstanceStateCheckpoint.class);
    PowerMockito.doReturn(instanceStateCheckpoint).when(CheckpointManager.InstanceStateCheckpoint.class, "parseFrom", mockInputStream);
    dlogStorage.restore(StatefulStorageTestContext.TOPOLOGY_NAME, StatefulStorageTestContext.CHECKPOINT_ID, instance);
    assertEquals(restoreCheckpoint.getCheckpoint(), instanceStateCheckpoint);
}
Also used : Checkpoint(com.twitter.heron.spi.statefulstorage.Checkpoint) InputStream(java.io.InputStream) CheckpointManager(com.twitter.heron.proto.ckptmgr.CheckpointManager) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 9 with Checkpoint

use of com.twitter.heron.spi.statefulstorage.Checkpoint in project incubator-heron by apache.

the class DlogStorageTest method testStore.

@Test
public void testStore() throws Exception {
    PowerMockito.mockStatic(CheckpointManager.InstanceStateCheckpoint.class);
    CheckpointManager.InstanceStateCheckpoint mockCheckpointState = mock(CheckpointManager.InstanceStateCheckpoint.class);
    Checkpoint checkpoint = new Checkpoint(StatefulStorageTestContext.TOPOLOGY_NAME, instance, mockCheckpointState);
    DistributedLogManager mockDLM = mock(DistributedLogManager.class);
    when(mockNamespace.openLog(anyString())).thenReturn(mockDLM);
    AppendOnlyStreamWriter mockWriter = mock(AppendOnlyStreamWriter.class);
    when(mockDLM.getAppendOnlyStreamWriter()).thenReturn(mockWriter);
    dlogStorage.store(checkpoint);
    verify(mockWriter).markEndOfStream();
    verify(mockWriter).close();
}
Also used : Checkpoint(com.twitter.heron.spi.statefulstorage.Checkpoint) CheckpointManager(com.twitter.heron.proto.ckptmgr.CheckpointManager) DistributedLogManager(org.apache.distributedlog.api.DistributedLogManager) AppendOnlyStreamWriter(org.apache.distributedlog.AppendOnlyStreamWriter) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 10 with Checkpoint

use of com.twitter.heron.spi.statefulstorage.Checkpoint in project incubator-heron by apache.

the class LocalFileSystemStorageTest method testRestore.

@Test
public void testRestore() throws Exception {
    PowerMockito.spy(FileUtils.class);
    PowerMockito.doReturn(checkpoint.toByteArray()).when(FileUtils.class, "readFromFile", anyString());
    Checkpoint ckpt = new Checkpoint(StatefulStorageTestContext.TOPOLOGY_NAME, instance, checkpoint);
    localFileSystemStorage.restore(StatefulStorageTestContext.TOPOLOGY_NAME, StatefulStorageTestContext.CHECKPOINT_ID, instance);
    assertEquals(checkpoint, ckpt.getCheckpoint());
}
Also used : InstanceStateCheckpoint(com.twitter.heron.proto.ckptmgr.CheckpointManager.InstanceStateCheckpoint) Checkpoint(com.twitter.heron.spi.statefulstorage.Checkpoint) Test(org.junit.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

Checkpoint (com.twitter.heron.spi.statefulstorage.Checkpoint)13 CheckpointManager (com.twitter.heron.proto.ckptmgr.CheckpointManager)9 Test (org.junit.Test)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 StatefulStorageException (com.twitter.heron.spi.statefulstorage.StatefulStorageException)5 ByteString (com.google.protobuf.ByteString)3 Path (org.apache.hadoop.fs.Path)3 InstanceStateCheckpoint (com.twitter.heron.proto.ckptmgr.CheckpointManager.InstanceStateCheckpoint)2 Common (com.twitter.heron.proto.system.Common)2 IOException (java.io.IOException)2 InputStream (java.io.InputStream)2 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Message (com.google.protobuf.Message)1 HeronClient (com.twitter.heron.common.network.HeronClient)1 StatusCode (com.twitter.heron.common.network.StatusCode)1 HeronServerTester (com.twitter.heron.common.testhelpers.HeronServerTester)1 DLInputStream (com.twitter.heron.dlog.DLInputStream)1 PhysicalPlans (com.twitter.heron.proto.system.PhysicalPlans)1 AppendOnlyStreamWriter (org.apache.distributedlog.AppendOnlyStreamWriter)1