use of org.apache.flink.streaming.api.operators.StreamCheckpointedOperator in project flink by apache.
the class KeyedOneInputStreamOperatorTestHarness method restore.
/**
*
*/
@Override
public void restore(StreamStateHandle snapshot) throws Exception {
try (FSDataInputStream inStream = snapshot.openInputStream()) {
if (operator instanceof StreamCheckpointedOperator) {
((StreamCheckpointedOperator) operator).restoreState(inStream);
}
byte keyedStatePresent = (byte) inStream.read();
if (keyedStatePresent == 1) {
ObjectInputStream ois = new ObjectInputStream(inStream);
this.restoredKeyedState = Collections.singletonList((KeyGroupsStateHandle) ois.readObject());
}
}
}
use of org.apache.flink.streaming.api.operators.StreamCheckpointedOperator in project flink by apache.
the class KeyedOneInputStreamOperatorTestHarness method snapshotLegacy.
/**
*
*/
@Override
public StreamStateHandle snapshotLegacy(long checkpointId, long timestamp) throws Exception {
// simply use an in-memory handle
MemoryStateBackend backend = new MemoryStateBackend();
CheckpointStreamFactory streamFactory = backend.createStreamFactory(new JobID(), "test_op");
CheckpointStreamFactory.CheckpointStateOutputStream outStream = streamFactory.createCheckpointStateOutputStream(checkpointId, timestamp);
if (operator instanceof StreamCheckpointedOperator) {
((StreamCheckpointedOperator) operator).snapshotState(outStream, checkpointId, timestamp);
}
if (keyedStateBackend != null) {
RunnableFuture<KeyGroupsStateHandle> keyedSnapshotRunnable = keyedStateBackend.snapshot(checkpointId, timestamp, streamFactory, CheckpointOptions.forFullCheckpoint());
if (!keyedSnapshotRunnable.isDone()) {
Thread runner = new Thread(keyedSnapshotRunnable);
runner.start();
}
outStream.write(1);
ObjectOutputStream oos = new ObjectOutputStream(outStream);
oos.writeObject(keyedSnapshotRunnable.get());
oos.flush();
} else {
outStream.write(0);
}
return outStream.closeAndGetHandle();
}
Aggregations