Search in sources :

Example 6 with Checkpoint

use of org.apache.heron.spi.statefulstorage.Checkpoint in project heron by twitter.

the class HDFSStorage method restoreCheckpoint.

@Override
public Checkpoint restoreCheckpoint(CheckpointInfo info) throws StatefulStorageException {
    Path path = new Path(getCheckpointPath(info.getCheckpointId(), info.getComponent(), info.getInstanceId()));
    FSDataInputStream in = null;
    CheckpointManager.InstanceStateCheckpoint state = null;
    try {
        in = fileSystem.open(path);
        state = CheckpointManager.InstanceStateCheckpoint.parseFrom(in);
    } catch (IOException e) {
        throw new StatefulStorageException("Failed to read", e);
    } finally {
        SysUtils.closeIgnoringExceptions(in);
    }
    return new Checkpoint(state);
}
Also used : Path(org.apache.hadoop.fs.Path) StatefulStorageException(org.apache.heron.spi.statefulstorage.StatefulStorageException) Checkpoint(org.apache.heron.spi.statefulstorage.Checkpoint) CheckpointManager(org.apache.heron.proto.ckptmgr.CheckpointManager) FSDataInputStream(org.apache.hadoop.fs.FSDataInputStream) IOException(java.io.IOException)

Example 7 with Checkpoint

use of org.apache.heron.spi.statefulstorage.Checkpoint in project heron by twitter.

the class HDFSStorageTest method testStore.

@Test
public void testStore() throws Exception {
    PowerMockito.mockStatic(CheckpointManager.InstanceStateCheckpoint.class);
    CheckpointManager.InstanceStateCheckpoint mockCheckpointState = mock(CheckpointManager.InstanceStateCheckpoint.class);
    Checkpoint checkpoint = new Checkpoint(mockCheckpointState);
    FSDataOutputStream mockFSDateOutputStream = mock(FSDataOutputStream.class);
    when(mockFileSystem.create(any(Path.class))).thenReturn(mockFSDateOutputStream);
    doNothing().when(hdfsStorage).createDir(anyString());
    final CheckpointInfo info = new CheckpointInfo(StatefulStorageTestContext.CHECKPOINT_ID, instance);
    hdfsStorage.storeCheckpoint(info, checkpoint);
    verify(mockCheckpointState).writeTo(mockFSDateOutputStream);
}
Also used : Path(org.apache.hadoop.fs.Path) Checkpoint(org.apache.heron.spi.statefulstorage.Checkpoint) CheckpointManager(org.apache.heron.proto.ckptmgr.CheckpointManager) FSDataOutputStream(org.apache.hadoop.fs.FSDataOutputStream) CheckpointInfo(org.apache.heron.spi.statefulstorage.CheckpointInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 8 with Checkpoint

use of org.apache.heron.spi.statefulstorage.Checkpoint in project heron by twitter.

the class DlogStorage method restoreCheckpoint.

@Override
public Checkpoint restoreCheckpoint(CheckpointInfo info) throws StatefulStorageException {
    String checkpointPath = getCheckpointPath(topologyName, info.getCheckpointId(), info.getComponent(), info.getInstanceId());
    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 {
        if (in != null) {
            final long num = ((DLInputStream) in).getNumOfBytesRead();
            LOG.info(() -> num + " bytes read");
        }
        SysUtils.closeIgnoringExceptions(in);
    }
    return new Checkpoint(state);
}
Also used : StatefulStorageException(org.apache.heron.spi.statefulstorage.StatefulStorageException) Checkpoint(org.apache.heron.spi.statefulstorage.Checkpoint) DLInputStream(org.apache.heron.dlog.DLInputStream) DLInputStream(org.apache.heron.dlog.DLInputStream) InputStream(java.io.InputStream) CheckpointManager(org.apache.heron.proto.ckptmgr.CheckpointManager) IOException(java.io.IOException)

Example 9 with Checkpoint

use of org.apache.heron.spi.statefulstorage.Checkpoint in project heron by twitter.

the class DlogStorageTest method testStore.

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

Example 10 with Checkpoint

use of org.apache.heron.spi.statefulstorage.Checkpoint in project heron by twitter.

the class DlogStorageTest method testRestore.

@Test
public void testRestore() throws Exception {
    DLInputStream mockInputStream = mock(DLInputStream.class);
    doReturn(mockInputStream).when(dlogStorage).openInputStream(anyString());
    PowerMockito.spy(CheckpointManager.InstanceStateCheckpoint.class);
    PowerMockito.doReturn(checkpointPartition).when(CheckpointManager.InstanceStateCheckpoint.class, "parseFrom", mockInputStream);
    final CheckpointInfo info = new CheckpointInfo(StatefulStorageTestContext.CHECKPOINT_ID, instance);
    Checkpoint restoreCheckpoint = dlogStorage.restoreCheckpoint(info);
    assertEquals(restoreCheckpoint.getCheckpoint(), checkpointPartition);
}
Also used : Checkpoint(org.apache.heron.spi.statefulstorage.Checkpoint) DLInputStream(org.apache.heron.dlog.DLInputStream) CheckpointManager(org.apache.heron.proto.ckptmgr.CheckpointManager) CheckpointInfo(org.apache.heron.spi.statefulstorage.CheckpointInfo) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

Checkpoint (org.apache.heron.spi.statefulstorage.Checkpoint)13 CheckpointManager (org.apache.heron.proto.ckptmgr.CheckpointManager)9 CheckpointInfo (org.apache.heron.spi.statefulstorage.CheckpointInfo)9 Test (org.junit.Test)7 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)6 StatefulStorageException (org.apache.heron.spi.statefulstorage.StatefulStorageException)5 ByteString (com.google.protobuf.ByteString)3 Path (org.apache.hadoop.fs.Path)3 IOException (java.io.IOException)2 FSDataInputStream (org.apache.hadoop.fs.FSDataInputStream)2 DLInputStream (org.apache.heron.dlog.DLInputStream)2 InstanceStateCheckpoint (org.apache.heron.proto.ckptmgr.CheckpointManager.InstanceStateCheckpoint)2 Common (org.apache.heron.proto.system.Common)2 InvalidProtocolBufferException (com.google.protobuf.InvalidProtocolBufferException)1 Message (com.google.protobuf.Message)1 InputStream (java.io.InputStream)1 AppendOnlyStreamWriter (org.apache.distributedlog.AppendOnlyStreamWriter)1 DistributedLogManager (org.apache.distributedlog.api.DistributedLogManager)1 FSDataOutputStream (org.apache.hadoop.fs.FSDataOutputStream)1 TopologyAPI (org.apache.heron.api.generated.TopologyAPI)1