Search in sources :

Example 1 with StreamCheckpointedOperator

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());
        }
    }
}
Also used : FSDataInputStream(org.apache.flink.core.fs.FSDataInputStream) StreamCheckpointedOperator(org.apache.flink.streaming.api.operators.StreamCheckpointedOperator) KeyGroupsStateHandle(org.apache.flink.runtime.state.KeyGroupsStateHandle) ObjectInputStream(java.io.ObjectInputStream)

Example 2 with StreamCheckpointedOperator

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();
}
Also used : CheckpointStreamFactory(org.apache.flink.runtime.state.CheckpointStreamFactory) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) StreamCheckpointedOperator(org.apache.flink.streaming.api.operators.StreamCheckpointedOperator) ObjectOutputStream(java.io.ObjectOutputStream) JobID(org.apache.flink.api.common.JobID) KeyGroupsStateHandle(org.apache.flink.runtime.state.KeyGroupsStateHandle)

Aggregations

KeyGroupsStateHandle (org.apache.flink.runtime.state.KeyGroupsStateHandle)2 StreamCheckpointedOperator (org.apache.flink.streaming.api.operators.StreamCheckpointedOperator)2 ObjectInputStream (java.io.ObjectInputStream)1 ObjectOutputStream (java.io.ObjectOutputStream)1 JobID (org.apache.flink.api.common.JobID)1 FSDataInputStream (org.apache.flink.core.fs.FSDataInputStream)1 CheckpointStreamFactory (org.apache.flink.runtime.state.CheckpointStreamFactory)1 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)1