@Override @SuppressWarnings("unchecked") public StreamTaskState snapshotOperatorState(long checkpointId, long timestamp) throws Exception { if (mergingWindowsByKey != null) { TupleSerializer<Tuple2<W, W>> tupleSerializer = new TupleSerializer<>( (Class) Tuple2.class, new TypeSerializer[] {windowSerializer, windowSerializer}); ListStateDescriptor<Tuple2<W, W>> mergeStateDescriptor = new ListStateDescriptor<>("merging-window-set", tupleSerializer); for (Map.Entry<K, MergingWindowSet<W>> key : mergingWindowsByKey.entrySet()) { setKeyContext(key.getKey()); ListState<Tuple2<W, W>> mergeState = getStateBackend() .getPartitionedState(null, VoidSerializer.INSTANCE, mergeStateDescriptor); mergeState.clear(); key.getValue().persist(mergeState); } } StreamTaskState taskState = super.snapshotOperatorState(checkpointId, timestamp); AbstractStateBackend.CheckpointStateOutputView out = getStateBackend().createCheckpointStateOutputView(checkpointId, timestamp); snapshotTimers(out); taskState.setOperatorState(out.closeAndGetHandle()); return taskState; }
@Override public StreamTaskState snapshotOperatorState(long checkpointId, long timestamp) throws Exception { StreamTaskState taskState = super.snapshotOperatorState(checkpointId, timestamp); // we write the panes with the key/value maps into the stream StateBackend.CheckpointStateOutputView out = getStateBackend().createCheckpointStateOutputView(checkpointId, timestamp); int numKeys = windows.size(); out.writeInt(numKeys); for (Map.Entry<K, Map<W, Context>> keyWindows : windows.entrySet()) { int numWindows = keyWindows.getValue().size(); out.writeInt(numWindows); for (Context context : keyWindows.getValue().values()) { context.writeToState(out); } } taskState.setOperatorState(out.closeAndGetHandle()); return taskState; }