org.apache.flink.streaming.api.operators.StreamTaskStateInitializer Java Examples

The following examples show how to use org.apache.flink.streaming.api.operators.StreamTaskStateInitializer. 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: MockStreamTask.java    From flink with Apache License 2.0 6 votes vote down vote up
public MockStreamTask(
	Environment environment,
	Object checkpointLock,
	StreamConfig config,
	ExecutionConfig executionConfig,
	StreamTaskStateInitializer streamTaskStateInitializer,
	StreamStatusMaintainer streamStatusMaintainer,
	CheckpointStorageWorkerView checkpointStorage,
	TimerService timerService,
	BiConsumer<String, Throwable> handleAsyncException,
	TaskMailbox taskMailbox,
	StreamTaskActionExecutor.SynchronizedStreamTaskActionExecutor taskActionExecutor,
	StreamInputProcessor inputProcessor) throws Exception {

	super(environment, timerService, FatalExitExceptionHandler.INSTANCE, taskActionExecutor, taskMailbox);
	this.checkpointLock = checkpointLock;
	this.config = config;
	this.executionConfig = executionConfig;
	this.streamTaskStateInitializer = streamTaskStateInitializer;
	this.streamStatusMaintainer = streamStatusMaintainer;
	this.checkpointStorage = checkpointStorage;
	this.processingTimeService = timerService;
	this.handleAsyncException = handleAsyncException;
	this.inputProcessor = inputProcessor;
}
 
Example #2
Source File: KeyedStateInputFormat.java    From flink with Apache License 2.0 6 votes vote down vote up
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 #3
Source File: KeyedStateInputFormat.java    From flink with Apache License 2.0 6 votes vote down vote up
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 #4
Source File: AbstractStreamOperatorTestHarness.java    From flink with Apache License 2.0 5 votes vote down vote up
protected StreamTaskStateInitializer createStreamTaskStateManager(
	Environment env,
	StateBackend stateBackend,
	TtlTimeProvider ttlTimeProvider) {
	return new StreamTaskStateInitializerImpl(
		env,
		stateBackend,
		ttlTimeProvider);
}
 
Example #5
Source File: MockStreamTask.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
public MockStreamTask(
	Environment environment,
	String name,
	Object checkpointLock,
	StreamConfig config,
	ExecutionConfig executionConfig,
	StreamTaskStateInitializer streamTaskStateInitializer,
	CloseableRegistry closableRegistry,
	StreamStatusMaintainer streamStatusMaintainer,
	CheckpointStorage checkpointStorage,
	ProcessingTimeService processingTimeService,
	BiConsumer<String, Throwable> handleAsyncException,
	Map<String, Accumulator<?, ?>> accumulatorMap
) {
	super(environment);
	this.name = name;
	this.checkpointLock = checkpointLock;
	this.config = config;
	this.executionConfig = executionConfig;
	this.streamTaskStateInitializer = streamTaskStateInitializer;
	this.closableRegistry = closableRegistry;
	this.streamStatusMaintainer = streamStatusMaintainer;
	this.checkpointStorage = checkpointStorage;
	this.processingTimeService = processingTimeService;
	this.handleAsyncException = handleAsyncException;
	this.accumulatorMap = accumulatorMap;
}
 
Example #6
Source File: AbstractStreamOperatorTestHarness.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
protected StreamTaskStateInitializer createStreamTaskStateManager(
	Environment env,
	StateBackend stateBackend,
	ProcessingTimeService processingTimeService) {
	return new StreamTaskStateInitializerImpl(
		env,
		stateBackend,
		processingTimeService);
}
 
Example #7
Source File: MockStreamTask.java    From flink with Apache License 2.0 5 votes vote down vote up
public MockStreamTask(
	Environment environment,
	String name,
	Object checkpointLock,
	StreamConfig config,
	ExecutionConfig executionConfig,
	StreamTaskStateInitializer streamTaskStateInitializer,
	CloseableRegistry closableRegistry,
	StreamStatusMaintainer streamStatusMaintainer,
	CheckpointStorageWorkerView checkpointStorage,
	ProcessingTimeService processingTimeService,
	BiConsumer<String, Throwable> handleAsyncException,
	Map<String, Accumulator<?, ?>> accumulatorMap
) {
	super(environment);
	this.name = name;
	this.checkpointLock = checkpointLock;
	this.config = config;
	this.executionConfig = executionConfig;
	this.streamTaskStateInitializer = streamTaskStateInitializer;
	this.closableRegistry = closableRegistry;
	this.streamStatusMaintainer = streamStatusMaintainer;
	this.checkpointStorage = checkpointStorage;
	this.processingTimeService = processingTimeService;
	this.handleAsyncException = handleAsyncException;
	this.accumulatorMap = accumulatorMap;
}
 
Example #8
Source File: OperatorChain.java    From flink with Apache License 2.0 5 votes vote down vote up
/**
 * Initialize state and open all operators in the chain from <b>tail to head</b>,
 * contrary to {@link StreamOperator#close()} which happens <b>head to tail</b>
 * (see {@link #closeOperators(StreamTaskActionExecutor)}).
 */
protected void initializeStateAndOpenOperators(StreamTaskStateInitializer streamTaskStateInitializer) throws Exception {
	for (StreamOperatorWrapper<?, ?> operatorWrapper : getAllOperators(true)) {
		StreamOperator<?> operator = operatorWrapper.getStreamOperator();
		operator.initializeState(streamTaskStateInitializer);
		operator.open();
	}
}
 
Example #9
Source File: AbstractStreamOperatorTestHarness.java    From flink with Apache License 2.0 5 votes vote down vote up
protected StreamTaskStateInitializer createStreamTaskStateManager(
	Environment env,
	StateBackend stateBackend,
	ProcessingTimeService processingTimeService) {
	return new StreamTaskStateInitializerImpl(
		env,
		stateBackend,
		processingTimeService);
}
 
Example #10
Source File: MockStreamTask.java    From flink with Apache License 2.0 4 votes vote down vote up
public void setStreamTaskStateInitializer(StreamTaskStateInitializer streamTaskStateInitializer) {
	this.streamTaskStateInitializer = streamTaskStateInitializer;
}
 
Example #11
Source File: MockStreamTask.java    From flink with Apache License 2.0 4 votes vote down vote up
public void setStreamTaskStateInitializer(StreamTaskStateInitializer streamTaskStateInitializer) {
	this.streamTaskStateInitializer = streamTaskStateInitializer;
}
 
Example #12
Source File: MockStreamTask.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public StreamTaskStateInitializer createStreamTaskStateInitializer() {
	return streamTaskStateInitializer;
}
 
Example #13
Source File: MockStreamTaskBuilder.java    From flink with Apache License 2.0 4 votes vote down vote up
public MockStreamTaskBuilder setStreamTaskStateInitializer(StreamTaskStateInitializer streamTaskStateInitializer) {
	this.streamTaskStateInitializer = streamTaskStateInitializer;
	return this;
}
 
Example #14
Source File: StreamTaskTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@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;
			}
		};
	};
}
 
Example #15
Source File: SubtaskCheckpointCoordinatorTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void initializeState(StreamTaskStateInitializer streamTaskStateManager) throws Exception {
}
 
Example #16
Source File: StreamTask.java    From flink with Apache License 2.0 4 votes vote down vote up
public StreamTaskStateInitializer createStreamTaskStateInitializer() {
	return new StreamTaskStateInitializerImpl(
		getEnvironment(),
		stateBackend);
}
 
Example #17
Source File: SnapshotUtilsTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public void initializeState(StreamTaskStateInitializer streamTaskStateManager) throws Exception {
	ACTUAL_ORDER_TRACKING.add("initializeState");
}
 
Example #18
Source File: StreamTask.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public StreamTaskStateInitializer createStreamTaskStateInitializer() {
	return new StreamTaskStateInitializerImpl(
		getEnvironment(),
		stateBackend,
		timerService);
}
 
Example #19
Source File: MockStreamTask.java    From flink with Apache License 2.0 4 votes vote down vote up
@Override
public StreamTaskStateInitializer createStreamTaskStateInitializer() {
	return streamTaskStateInitializer;
}
 
Example #20
Source File: MockStreamTaskBuilder.java    From flink with Apache License 2.0 4 votes vote down vote up
public MockStreamTaskBuilder setStreamTaskStateInitializer(StreamTaskStateInitializer streamTaskStateInitializer) {
	this.streamTaskStateInitializer = streamTaskStateInitializer;
	return this;
}
 
Example #21
Source File: StreamTaskTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@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 #22
Source File: StreamTask.java    From flink with Apache License 2.0 4 votes vote down vote up
public StreamTaskStateInitializer createStreamTaskStateInitializer() {
	return new StreamTaskStateInitializerImpl(
		getEnvironment(),
		stateBackend,
		timerService);
}
 
Example #23
Source File: MockStreamTask.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public void setStreamTaskStateInitializer(StreamTaskStateInitializer streamTaskStateInitializer) {
	this.streamTaskStateInitializer = streamTaskStateInitializer;
}
 
Example #24
Source File: MockStreamTask.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Override
public StreamTaskStateInitializer createStreamTaskStateInitializer() {
	return streamTaskStateInitializer;
}
 
Example #25
Source File: MockStreamTaskBuilder.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
public MockStreamTaskBuilder setStreamTaskStateInitializer(StreamTaskStateInitializer streamTaskStateInitializer) {
	this.streamTaskStateInitializer = streamTaskStateInitializer;
	return this;
}
 
Example #26
Source File: StreamTaskTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@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;
			}
		};
	};
}