Search in sources :

Example 1 with CloseableIterable

use of org.apache.flink.util.CloseableIterable in project flink by apache.

the class StreamTaskStateInitializerImpl method rawOperatorStateInputs.

protected CloseableIterable<StatePartitionStreamProvider> rawOperatorStateInputs(Iterator<StateObjectCollection<OperatorStateHandle>> restoreStateAlternatives) {
    if (restoreStateAlternatives.hasNext()) {
        Collection<OperatorStateHandle> rawOperatorState = restoreStateAlternatives.next();
        // TODO currently this does not support local state recovery, so we expect there is only
        // one handle.
        Preconditions.checkState(!restoreStateAlternatives.hasNext(), "Local recovery is currently not implemented for raw operator state, but found state alternative.");
        if (rawOperatorState != null) {
            return new CloseableIterable<StatePartitionStreamProvider>() {

                final CloseableRegistry closeableRegistry = new CloseableRegistry();

                @Override
                public void close() throws IOException {
                    closeableRegistry.close();
                }

                @Nonnull
                @Override
                public Iterator<StatePartitionStreamProvider> iterator() {
                    return new OperatorStateStreamIterator(DefaultOperatorStateBackend.DEFAULT_OPERATOR_STATE_NAME, rawOperatorState.iterator(), closeableRegistry);
                }
            };
        }
    }
    return CloseableIterable.empty();
}
Also used : StatePartitionStreamProvider(org.apache.flink.runtime.state.StatePartitionStreamProvider) KeyGroupStatePartitionStreamProvider(org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider) CloseableIterable(org.apache.flink.util.CloseableIterable) OperatorStateHandle(org.apache.flink.runtime.state.OperatorStateHandle) CloseableRegistry(org.apache.flink.core.fs.CloseableRegistry)

Example 2 with CloseableIterable

use of org.apache.flink.util.CloseableIterable in project flink by apache.

the class StreamTaskStateInitializerImpl method rawKeyedStateInputs.

protected CloseableIterable<KeyGroupStatePartitionStreamProvider> rawKeyedStateInputs(Iterator<StateObjectCollection<KeyedStateHandle>> restoreStateAlternatives) {
    if (restoreStateAlternatives.hasNext()) {
        Collection<KeyedStateHandle> rawKeyedState = restoreStateAlternatives.next();
        // TODO currently this does not support local state recovery, so we expect there is only
        // one handle.
        Preconditions.checkState(!restoreStateAlternatives.hasNext(), "Local recovery is currently not implemented for raw keyed state, but found state alternative.");
        if (rawKeyedState != null) {
            Collection<KeyGroupsStateHandle> keyGroupsStateHandles = transform(rawKeyedState);
            final CloseableRegistry closeableRegistry = new CloseableRegistry();
            return new CloseableIterable<KeyGroupStatePartitionStreamProvider>() {

                @Override
                public void close() throws IOException {
                    closeableRegistry.close();
                }

                @Override
                public Iterator<KeyGroupStatePartitionStreamProvider> iterator() {
                    return new KeyGroupStreamIterator(keyGroupsStateHandles.iterator(), closeableRegistry);
                }
            };
        }
    }
    return CloseableIterable.empty();
}
Also used : CloseableIterable(org.apache.flink.util.CloseableIterable) KeyedStateHandle(org.apache.flink.runtime.state.KeyedStateHandle) CloseableRegistry(org.apache.flink.core.fs.CloseableRegistry) KeyGroupsStateHandle(org.apache.flink.runtime.state.KeyGroupsStateHandle) KeyGroupStatePartitionStreamProvider(org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider)

Aggregations

CloseableRegistry (org.apache.flink.core.fs.CloseableRegistry)2 KeyGroupStatePartitionStreamProvider (org.apache.flink.runtime.state.KeyGroupStatePartitionStreamProvider)2 CloseableIterable (org.apache.flink.util.CloseableIterable)2 KeyGroupsStateHandle (org.apache.flink.runtime.state.KeyGroupsStateHandle)1 KeyedStateHandle (org.apache.flink.runtime.state.KeyedStateHandle)1 OperatorStateHandle (org.apache.flink.runtime.state.OperatorStateHandle)1 StatePartitionStreamProvider (org.apache.flink.runtime.state.StatePartitionStreamProvider)1