org.apache.flink.streaming.api.operators.StreamOperatorStateContext Java Examples
The following examples show how to use
org.apache.flink.streaming.api.operators.StreamOperatorStateContext.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: KeyedStateInputFormat.java From flink with Apache License 2.0 | 6 votes |
private StreamOperatorStateContext getStreamOperatorStateContext(Environment environment) throws IOException { StreamTaskStateInitializer initializer = new StreamTaskStateInitializerImpl( environment, stateBackend, new NeverFireProcessingTimeService()); try { return initializer.streamOperatorStateContext( operatorState.getOperatorID(), operatorState.getOperatorID().toString(), this, keySerializer, registry, getRuntimeContext().getMetricGroup()); } catch (Exception e) { throw new IOException("Failed to restore state backend", e); } }
Example #2
Source File: KeyedStateInputFormat.java From flink with Apache License 2.0 | 6 votes |
private StreamOperatorStateContext getStreamOperatorStateContext(Environment environment) throws IOException { StreamTaskStateInitializer initializer = new StreamTaskStateInitializerImpl( environment, stateBackend); try { return initializer.streamOperatorStateContext( operatorState.getOperatorID(), operatorState.getOperatorID().toString(), new NeverFireProcessingTimeService(), operator, operator.getKeyType().createSerializer(environment.getExecutionConfig()), registry, getRuntimeContext().getMetricGroup()); } catch (Exception e) { throw new IOException("Failed to restore state backend", e); } }
Example #3
Source File: KeyedStateInputFormat.java From flink with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public void open(KeyGroupRangeInputSplit split) throws IOException { registry = new CloseableRegistry(); final Environment environment = new SavepointEnvironment .Builder(getRuntimeContext(), split.getNumKeyGroups()) .setSubtaskIndex(split.getSplitNumber()) .setPrioritizedOperatorSubtaskState(split.getPrioritizedOperatorSubtaskState()) .build(); final StreamOperatorStateContext context = getStreamOperatorStateContext(environment); keyedStateBackend = (AbstractKeyedStateBackend<K>) context.keyedStateBackend(); final DefaultKeyedStateStore keyedStateStore = new DefaultKeyedStateStore(keyedStateBackend, getRuntimeContext().getExecutionConfig()); SavepointRuntimeContext ctx = new SavepointRuntimeContext(getRuntimeContext(), keyedStateStore); FunctionUtils.setFunctionRuntimeContext(userFunction, ctx); keys = getKeyIterator(ctx); final InternalTimerService<VoidNamespace> timerService = restoreTimerService(context); try { this.ctx = new Context(keyedStateBackend, timerService); } catch (Exception e) { throw new IOException("Failed to restore timer state", e); } }
Example #4
Source File: KeyedStateInputFormat.java From flink with Apache License 2.0 | 5 votes |
@Override @SuppressWarnings("unchecked") public void open(KeyGroupRangeInputSplit split) throws IOException { registry = new CloseableRegistry(); final Environment environment = new SavepointEnvironment .Builder(getRuntimeContext(), split.getNumKeyGroups()) .setConfiguration(configuration) .setSubtaskIndex(split.getSplitNumber()) .setPrioritizedOperatorSubtaskState(split.getPrioritizedOperatorSubtaskState()) .build(); final StreamOperatorStateContext context = getStreamOperatorStateContext(environment); AbstractKeyedStateBackend<K> keyedStateBackend = (AbstractKeyedStateBackend<K>) context.keyedStateBackend(); final DefaultKeyedStateStore keyedStateStore = new DefaultKeyedStateStore(keyedStateBackend, getRuntimeContext().getExecutionConfig()); SavepointRuntimeContext ctx = new SavepointRuntimeContext(getRuntimeContext(), keyedStateStore); InternalTimeServiceManager<K> timeServiceManager = (InternalTimeServiceManager<K>) context.internalTimerServiceManager(); try { operator.setup(getRuntimeContext().getExecutionConfig(), keyedStateBackend, timeServiceManager, ctx); operator.open(); keysAndNamespaces = operator.getKeysAndNamespaces(ctx); } catch (Exception e) { throw new IOException("Failed to restore timer state", e); } }
Example #5
Source File: StreamTaskTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Override public StreamTaskStateInitializer createStreamTaskStateInitializer() { final StreamTaskStateInitializer streamTaskStateManager = super.createStreamTaskStateInitializer(); return (operatorID, operatorClassName, keyContext, keySerializer, closeableRegistry, metricGroup) -> { final StreamOperatorStateContext context = streamTaskStateManager.streamOperatorStateContext( operatorID, operatorClassName, keyContext, keySerializer, closeableRegistry, metricGroup); return new StreamOperatorStateContext() { @Override public boolean isRestored() { return context.isRestored(); } @Override public OperatorStateBackend operatorStateBackend() { return context.operatorStateBackend(); } @Override public AbstractKeyedStateBackend<?> keyedStateBackend() { return context.keyedStateBackend(); } @Override public InternalTimeServiceManager<?> internalTimerServiceManager() { InternalTimeServiceManager<?> timeServiceManager = context.internalTimerServiceManager(); return timeServiceManager != null ? spy(timeServiceManager) : null; } @Override public CloseableIterable<StatePartitionStreamProvider> rawOperatorStateInputs() { return replaceWithSpy(context.rawOperatorStateInputs()); } @Override public CloseableIterable<KeyGroupStatePartitionStreamProvider> rawKeyedStateInputs() { return replaceWithSpy(context.rawKeyedStateInputs()); } public <T extends Closeable> T replaceWithSpy(T closeable) { T spyCloseable = spy(closeable); if (closeableRegistry.unregisterCloseable(closeable)) { try { closeableRegistry.registerCloseable(spyCloseable); } catch (IOException e) { throw new RuntimeException(e); } } return spyCloseable; } }; }; }
Example #6
Source File: KeyedStateInputFormat.java From flink with Apache License 2.0 | 4 votes |
@SuppressWarnings("unchecked") private InternalTimerService<VoidNamespace> restoreTimerService(StreamOperatorStateContext context) { InternalTimeServiceManager<K> timeServiceManager = (InternalTimeServiceManager<K>) context.internalTimerServiceManager(); TimerSerializer<K, VoidNamespace> timerSerializer = new TimerSerializer<>(keySerializer, VoidNamespaceSerializer.INSTANCE); return timeServiceManager.getInternalTimerService(USER_TIMERS_NAME, timerSerializer, VoidTriggerable.instance()); }
Example #7
Source File: StreamTaskTest.java From flink with Apache License 2.0 | 4 votes |
@Override public StreamTaskStateInitializer createStreamTaskStateInitializer() { final StreamTaskStateInitializer streamTaskStateManager = super.createStreamTaskStateInitializer(); return (operatorID, operatorClassName, keyContext, keySerializer, closeableRegistry, metricGroup) -> { final StreamOperatorStateContext context = streamTaskStateManager.streamOperatorStateContext( operatorID, operatorClassName, keyContext, keySerializer, closeableRegistry, metricGroup); return new StreamOperatorStateContext() { @Override public boolean isRestored() { return context.isRestored(); } @Override public OperatorStateBackend operatorStateBackend() { return context.operatorStateBackend(); } @Override public AbstractKeyedStateBackend<?> keyedStateBackend() { return context.keyedStateBackend(); } @Override public InternalTimeServiceManager<?> internalTimerServiceManager() { InternalTimeServiceManager<?> timeServiceManager = context.internalTimerServiceManager(); return timeServiceManager != null ? spy(timeServiceManager) : null; } @Override public CloseableIterable<StatePartitionStreamProvider> rawOperatorStateInputs() { return replaceWithSpy(context.rawOperatorStateInputs()); } @Override public CloseableIterable<KeyGroupStatePartitionStreamProvider> rawKeyedStateInputs() { return replaceWithSpy(context.rawKeyedStateInputs()); } public <T extends Closeable> T replaceWithSpy(T closeable) { T spyCloseable = spy(closeable); if (closeableRegistry.unregisterCloseable(closeable)) { try { closeableRegistry.registerCloseable(spyCloseable); } catch (IOException e) { throw new RuntimeException(e); } } return spyCloseable; } }; }; }
Example #8
Source File: StreamTaskTest.java From flink with Apache License 2.0 | 4 votes |
@Override public StreamTaskStateInitializer createStreamTaskStateInitializer() { final StreamTaskStateInitializer streamTaskStateManager = super.createStreamTaskStateInitializer(); return (operatorID, operatorClassName, processingTimeService, keyContext, keySerializer, closeableRegistry, metricGroup) -> { final StreamOperatorStateContext controller = streamTaskStateManager.streamOperatorStateContext( operatorID, operatorClassName, processingTimeService, keyContext, keySerializer, closeableRegistry, metricGroup); return new StreamOperatorStateContext() { @Override public boolean isRestored() { return controller.isRestored(); } @Override public OperatorStateBackend operatorStateBackend() { return controller.operatorStateBackend(); } @Override public AbstractKeyedStateBackend<?> keyedStateBackend() { return controller.keyedStateBackend(); } @Override public InternalTimeServiceManager<?> internalTimerServiceManager() { InternalTimeServiceManager<?> timeServiceManager = controller.internalTimerServiceManager(); return timeServiceManager != null ? spy(timeServiceManager) : null; } @Override public CloseableIterable<StatePartitionStreamProvider> rawOperatorStateInputs() { return replaceWithSpy(controller.rawOperatorStateInputs()); } @Override public CloseableIterable<KeyGroupStatePartitionStreamProvider> rawKeyedStateInputs() { return replaceWithSpy(controller.rawKeyedStateInputs()); } public <T extends Closeable> T replaceWithSpy(T closeable) { T spyCloseable = spy(closeable); if (closeableRegistry.unregisterCloseable(closeable)) { try { closeableRegistry.registerCloseable(spyCloseable); } catch (IOException e) { throw new RuntimeException(e); } } return spyCloseable; } }; }; }