private static boolean tryRestoreFunction( StateInitializationContext context, Function userFunction) throws Exception { if (userFunction instanceof CheckpointedFunction) { ((CheckpointedFunction) userFunction).initializeState(context); return true; } if (context.isRestored() && userFunction instanceof ListCheckpointed) { @SuppressWarnings("unchecked") ListCheckpointed<Serializable> listCheckpointedFun = (ListCheckpointed<Serializable>) userFunction; ListState<Serializable> listState = context.getOperatorStateStore(). getSerializableListState(DefaultOperatorStateBackend.DEFAULT_OPERATOR_STATE_NAME); List<Serializable> list = new ArrayList<>(); for (Serializable serializable : listState.get()) { list.add(serializable); } try { listCheckpointedFun.restoreState(list); } catch (Exception e) { throw new Exception("Failed to restore state to function: " + e.getMessage(), e); } return true; } return false; }
@Override public void initializeState(StateInitializationContext context) throws Exception { Assert.assertEquals(verifyRestore, context.isRestored()); .getKeyedStateStore() .getState(new ValueStateDescriptor<>("managed-keyed", Integer.class, 0)); .getOperatorStateStore() .getListState(new ListStateDescriptor<>("managed-op-state", IntSerializer.INSTANCE)); if (context.isRestored()) { for (KeyGroupStatePartitionStreamProvider streamProvider : context.getRawKeyedStateInputs()) { try (InputStream in = streamProvider.getStream()) { DataInputView div = new DataInputViewStreamWrapper(in); for (StatePartitionStreamProvider streamProvider : context.getRawOperatorStateInputs()) { try (InputStream in = streamProvider.getStream()) { DataInputView div = new DataInputViewStreamWrapper(in);
@Override public void initializeState(StateInitializationContext context) throws Exception { keyedStateBackend = (AbstractKeyedStateBackend<?>) getKeyedStateBackend(); operatorStateBackend = getOperatorStateBackend(); rawOperatorStateInputs = (CloseableIterable<StatePartitionStreamProvider>) context.getRawOperatorStateInputs(); rawKeyedStateInputs = (CloseableIterable<KeyGroupStatePartitionStreamProvider>) context.getRawKeyedStateInputs(); super.initializeState(context); } }
@Override public void initializeState(StateInitializationContext context) throws Exception { super.initializeState(context); recoveredStreamElements = context .getOperatorStateStore() .getListState(new ListStateDescriptor<>(STATE_NAME, inStreamElementSerializer)); }
@Override public void initializeState(StateInitializationContext context) throws Exception { super.initializeState(context); // initializeState through the provided context computationStates = context.getKeyedStateStore().getState( new ValueStateDescriptor<>( NFA_STATE_NAME, new NFAStateSerializer())); partialMatches = new SharedBuffer<>(context.getKeyedStateStore(), inputSerializer); elementQueueState = context.getKeyedStateStore().getMapState( new MapStateDescriptor<>( EVENT_QUEUE_STATE_NAME, LongSerializer.INSTANCE, new ListSerializer<>(inputSerializer))); migrateOldState(); }
@Override public void initializeState(StateInitializationContext context) throws Exception { if (context.isRestored()) { RESTORED_OPERATORS.add(getOperatorID()); } } }
@Override public void initializeState(StateInitializationContext context) throws Exception { if (getKeyedStateBackend() != null) { KeyGroupsList localKeyGroupRange = getKeyedStateBackend().getKeyGroupRange(); for (KeyGroupStatePartitionStreamProvider streamProvider : context.getRawKeyedStateInputs()) { DataInputViewStreamWrapper div = new DataInputViewStreamWrapper(streamProvider.getStream()); int keyGroupIdx = streamProvider.getKeyGroupId(); checkArgument(localKeyGroupRange.contains(keyGroupIdx), "Key Group " + keyGroupIdx + " does not belong to the local range."); // if (this instanceof KeyGroupRestoringOperator) restoreKeyGroupState(keyGroupIdx, div); } } }
@Override public void initializeState(FunctionInitializationContext context) throws Exception { // raw keyed state is already read by timer service, all others to initialize the context...we only need to // trigger this manually. ((StateInitializationContext) context).getRawOperatorStateInputs().iterator().next().getStream().read(); } }
@Override public void initializeState(StateInitializationContext context) throws Exception { recoveredStreamElements = context .getOperatorStateStore() .getListState(new ListStateDescriptor<>(STATE_NAME, inStreamElementSerializer)); }
@Override public void initializeState(StateInitializationContext context) throws Exception { super.initializeState(context); this.leftBuffer = context.getKeyedStateStore().getMapState(new MapStateDescriptor<>( LEFT_BUFFER, LongSerializer.INSTANCE, new ListSerializer<>(new BufferEntrySerializer<>(leftTypeSerializer)) )); this.rightBuffer = context.getKeyedStateStore().getMapState(new MapStateDescriptor<>( RIGHT_BUFFER, LongSerializer.INSTANCE, new ListSerializer<>(new BufferEntrySerializer<>(rightTypeSerializer)) )); }
/** * Stream operators with state which can be restored need to override this hook method. * * @param context context that allows to register different states. */ public void initializeState(StateInitializationContext context) throws Exception { if (getKeyedStateBackend() != null) { KeyGroupsList localKeyGroupRange = getKeyedStateBackend().getKeyGroupRange(); // and then initialize the timer services for (KeyGroupStatePartitionStreamProvider streamProvider : context.getRawKeyedStateInputs()) { int keyGroupIdx = streamProvider.getKeyGroupId(); checkArgument(localKeyGroupRange.contains(keyGroupIdx), "Key Group " + keyGroupIdx + " does not belong to the local range."); timeServiceManager.restoreStateForKeyGroup( new DataInputViewStreamWrapper(streamProvider.getStream()), keyGroupIdx, getUserCodeClassloader()); } } }
@Override public void initializeState(StateInitializationContext context) throws Exception { super.initializeState(context); checkState(checkpointedState == null, "The reader state has already been initialized."); checkpointedState = context.getOperatorStateStore().getSerializableListState("splits"); int subtaskIdx = getRuntimeContext().getIndexOfThisSubtask(); if (context.isRestored()) { LOG.info("Restoring state for the {} (taskIdx={}).", getClass().getSimpleName(), subtaskIdx); // this may not be null in case we migrate from a previous Flink version. if (restoredReaderState == null) { restoredReaderState = new ArrayList<>(); for (TimestampedFileInputSplit split : checkpointedState.get()) { restoredReaderState.add(split); } if (LOG.isDebugEnabled()) { LOG.debug("{} (taskIdx={}) restored {}.", getClass().getSimpleName(), subtaskIdx, restoredReaderState); } } } else { LOG.info("No state to restore for the {} (taskIdx={}).", getClass().getSimpleName(), subtaskIdx); } }
@Override public void initializeState(StateInitializationContext context) throws Exception { super.initializeState(context); recoveredStreamElements = context .getOperatorStateStore() .getListState(new ListStateDescriptor<>(STATE_NAME, inStreamElementSerializer)); }
@Override public void initializeState(StateInitializationContext context) throws Exception { super.initializeState(context); // initializeState through the provided context computationStates = context.getKeyedStateStore().getState( new ValueStateDescriptor<>( NFA_STATE_NAME, NFAStateSerializer.INSTANCE)); partialMatches = new SharedBuffer<>(context.getKeyedStateStore(), inputSerializer); elementQueueState = context.getKeyedStateStore().getMapState( new MapStateDescriptor<>( EVENT_QUEUE_STATE_NAME, LongSerializer.INSTANCE, new ListSerializer<>(inputSerializer))); migrateOldState(); }
@Override public void initializeState(StateInitializationContext context) throws Exception { if (getKeyedStateBackend() != null) { int totalKeyGroups = getKeyedStateBackend().getNumberOfKeyGroups(); KeyGroupsList localKeyGroupRange = getKeyedStateBackend().getKeyGroupRange(); for (KeyGroupStatePartitionStreamProvider streamProvider : context.getRawKeyedStateInputs()) { DataInputViewStreamWrapper div = new DataInputViewStreamWrapper(streamProvider.getStream()); int keyGroupIdx = streamProvider.getKeyGroupId(); checkArgument(localKeyGroupRange.contains(keyGroupIdx), "Key Group " + keyGroupIdx + " does not belong to the local range."); // if (this instanceof KeyGroupRestoringOperator) restoreKeyGroupState(keyGroupIdx, div); // We just initialize our timerService if (keyCoder != null) { if (timerService == null) { timerService = new HeapInternalTimerService<>( totalKeyGroups, localKeyGroupRange, this, getRuntimeContext().getProcessingTimeService()); } timerService.restoreTimersForKeyGroup(div, keyGroupIdx, getUserCodeClassloader()); } } } }
@Override public void initializeState(StateInitializationContext context) throws Exception { super.initializeState(context); Preconditions.checkState(this.checkpointedState == null, "The reader state has already been initialized."); checkpointedState = context.getOperatorStateStore() .getSerializableListState("pending-checkpoints"); int subtaskIdx = getRuntimeContext().getIndexOfThisSubtask(); if (context.isRestored()) { LOG.info("Restoring state for the GenericWriteAheadSink (taskIdx={}).", subtaskIdx); for (PendingCheckpoint pendingCheckpoint : checkpointedState.get()) { this.pendingCheckpoints.add(pendingCheckpoint); } if (LOG.isDebugEnabled()) { LOG.debug("GenericWriteAheadSink idx {} restored {}.", subtaskIdx, this.pendingCheckpoints); } } else { LOG.info("No state to restore for the GenericWriteAheadSink (taskIdx={}).", subtaskIdx); } }
@Override public void initializeState(StateInitializationContext context) throws Exception { super.initializeState(context); recoveredStreamElements = context .getOperatorStateStore() .getListState(new ListStateDescriptor<>(STATE_NAME, inStreamElementSerializer)); }
@Override public void initializeState(StateInitializationContext context) throws Exception { super.initializeState(context); // initializeState through the provided context computationStates = context.getKeyedStateStore().getState( new ValueStateDescriptor<>( NFA_STATE_NAME, NFAStateSerializer.INSTANCE)); partialMatches = new SharedBuffer<>(context.getKeyedStateStore(), inputSerializer); elementQueueState = context.getKeyedStateStore().getMapState( new MapStateDescriptor<>( EVENT_QUEUE_STATE_NAME, LongSerializer.INSTANCE, new ListSerializer<>(inputSerializer))); migrateOldState(); }
@Override public void initializeState(StateInitializationContext context) throws Exception { super.initializeState(context); counterState = context .getOperatorStateStore() .getListState(new ListStateDescriptor<>("counter-state", LongSerializer.INSTANCE)); if (context.isRestored()) { for (Long value : counterState.get()) { counter += value; } counterState.clear(); } }
@Override public void initializeState(StateInitializationContext context) throws Exception { super.initializeState(context); TypeInformation<Tuple2<K, V>> tupleType = new TupleTypeInfo<>(keyType, valueType); this.bufferState = context .getOperatorStateStore() .getListState(new ListStateDescriptor<>(STATE_NAME, tupleType)); }