Search in sources :

Example 1 with OperatorSubtaskDescriptionText

use of org.apache.flink.runtime.util.OperatorSubtaskDescriptionText in project flink by apache.

the class StreamTaskStateInitializerImpl method streamOperatorStateContext.

// -----------------------------------------------------------------------------------------------------------------
@Override
public StreamOperatorStateContext streamOperatorStateContext(@Nonnull OperatorID operatorID, @Nonnull String operatorClassName, @Nonnull ProcessingTimeService processingTimeService, @Nonnull KeyContext keyContext, @Nullable TypeSerializer<?> keySerializer, @Nonnull CloseableRegistry streamTaskCloseableRegistry, @Nonnull MetricGroup metricGroup, double managedMemoryFraction, boolean isUsingCustomRawKeyedState) throws Exception {
    TaskInfo taskInfo = environment.getTaskInfo();
    OperatorSubtaskDescriptionText operatorSubtaskDescription = new OperatorSubtaskDescriptionText(operatorID, operatorClassName, taskInfo.getIndexOfThisSubtask(), taskInfo.getNumberOfParallelSubtasks());
    final String operatorIdentifierText = operatorSubtaskDescription.toString();
    final PrioritizedOperatorSubtaskState prioritizedOperatorSubtaskStates = taskStateManager.prioritizedOperatorState(operatorID);
    CheckpointableKeyedStateBackend<?> keyedStatedBackend = null;
    OperatorStateBackend operatorStateBackend = null;
    CloseableIterable<KeyGroupStatePartitionStreamProvider> rawKeyedStateInputs = null;
    CloseableIterable<StatePartitionStreamProvider> rawOperatorStateInputs = null;
    InternalTimeServiceManager<?> timeServiceManager;
    try {
        // -------------- Keyed State Backend --------------
        keyedStatedBackend = keyedStatedBackend(keySerializer, operatorIdentifierText, prioritizedOperatorSubtaskStates, streamTaskCloseableRegistry, metricGroup, managedMemoryFraction);
        // -------------- Operator State Backend --------------
        operatorStateBackend = operatorStateBackend(operatorIdentifierText, prioritizedOperatorSubtaskStates, streamTaskCloseableRegistry);
        // -------------- Raw State Streams --------------
        rawKeyedStateInputs = rawKeyedStateInputs(prioritizedOperatorSubtaskStates.getPrioritizedRawKeyedState().iterator());
        streamTaskCloseableRegistry.registerCloseable(rawKeyedStateInputs);
        rawOperatorStateInputs = rawOperatorStateInputs(prioritizedOperatorSubtaskStates.getPrioritizedRawOperatorState().iterator());
        streamTaskCloseableRegistry.registerCloseable(rawOperatorStateInputs);
        // -------------- Internal Timer Service Manager --------------
        if (keyedStatedBackend != null) {
            // if the operator indicates that it is using custom raw keyed state,
            // then whatever was written in the raw keyed state snapshot was NOT written
            // by the internal timer services (because there is only ever one user of raw keyed
            // state);
            // in this case, timers should not attempt to restore timers from the raw keyed
            // state.
            final Iterable<KeyGroupStatePartitionStreamProvider> restoredRawKeyedStateTimers = (prioritizedOperatorSubtaskStates.isRestored() && !isUsingCustomRawKeyedState) ? rawKeyedStateInputs : Collections.emptyList();
            timeServiceManager = timeServiceManagerProvider.create(keyedStatedBackend, environment.getUserCodeClassLoader().asClassLoader(), keyContext, processingTimeService, restoredRawKeyedStateTimers);
        } else {
            timeServiceManager = null;
        }
        return new StreamOperatorStateContextImpl(prioritizedOperatorSubtaskStates.getRestoredCheckpointId(), operatorStateBackend, keyedStatedBackend, timeServiceManager, rawOperatorStateInputs, rawKeyedStateInputs);
    } catch (Exception ex) {
        // cleanup if something went wrong before results got published.
        if (keyedStatedBackend != null) {
            if (streamTaskCloseableRegistry.unregisterCloseable(keyedStatedBackend)) {
                IOUtils.closeQuietly(keyedStatedBackend);
            }
            // release resource (e.g native resource)
            keyedStatedBackend.dispose();
        }
        if (operatorStateBackend != null) {
            if (streamTaskCloseableRegistry.unregisterCloseable(operatorStateBackend)) {
                IOUtils.closeQuietly(operatorStateBackend);
            }
            operatorStateBackend.dispose();
        }
        if (streamTaskCloseableRegistry.unregisterCloseable(rawKeyedStateInputs)) {
            IOUtils.closeQuietly(rawKeyedStateInputs);
        }
        if (streamTaskCloseableRegistry.unregisterCloseable(rawOperatorStateInputs)) {
            IOUtils.closeQuietly(rawOperatorStateInputs);
        }
        throw new Exception("Exception while creating StreamOperatorStateContext.", ex);
    }
}
Also used : PrioritizedOperatorSubtaskState(org.apache.flink.runtime.checkpoint.PrioritizedOperatorSubtaskState) StateUtil.unexpectedStateHandleException(org.apache.flink.runtime.state.StateUtil.unexpectedStateHandleException) NoSuchElementException(java.util.NoSuchElementException) IOException(java.io.IOException) KeyGroupStatePartitionStreamProvider(org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider) TaskInfo(org.apache.flink.api.common.TaskInfo) StatePartitionStreamProvider(org.apache.flink.runtime.state.StatePartitionStreamProvider) KeyGroupStatePartitionStreamProvider(org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider) OperatorSubtaskDescriptionText(org.apache.flink.runtime.util.OperatorSubtaskDescriptionText) OperatorStateBackend(org.apache.flink.runtime.state.OperatorStateBackend) DefaultOperatorStateBackend(org.apache.flink.runtime.state.DefaultOperatorStateBackend)

Aggregations

IOException (java.io.IOException)1 NoSuchElementException (java.util.NoSuchElementException)1 TaskInfo (org.apache.flink.api.common.TaskInfo)1 PrioritizedOperatorSubtaskState (org.apache.flink.runtime.checkpoint.PrioritizedOperatorSubtaskState)1 DefaultOperatorStateBackend (org.apache.flink.runtime.state.DefaultOperatorStateBackend)1 KeyGroupStatePartitionStreamProvider (org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider)1 OperatorStateBackend (org.apache.flink.runtime.state.OperatorStateBackend)1 StatePartitionStreamProvider (org.apache.flink.runtime.state.StatePartitionStreamProvider)1 StateUtil.unexpectedStateHandleException (org.apache.flink.runtime.state.StateUtil.unexpectedStateHandleException)1 OperatorSubtaskDescriptionText (org.apache.flink.runtime.util.OperatorSubtaskDescriptionText)1