org.apache.flink.state.api.output.TaggedOperatorSubtaskState Java Examples

The following examples show how to use org.apache.flink.state.api.output.TaggedOperatorSubtaskState. 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: BootstrapTransformationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testOperatorSpecificMaxParallelismRespected() {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	env.setParallelism(4);

	DataSource<Integer> input = env.fromElements(0);

	BootstrapTransformation<Integer> transformation = OperatorTransformation
		.bootstrapWith(input)
		.setMaxParallelism(1)
		.transform(new ExampleStateBootstrapFunction());

	int maxParallelism = transformation.getMaxParallelism(4);
	DataSet<TaggedOperatorSubtaskState> result = transformation.writeOperatorSubtaskStates(
		OperatorIDGenerator.fromUid("uid"),
		new MemoryStateBackend(),
		new Path(),
		maxParallelism
	);

	Assert.assertEquals("The parallelism of a data set should be constrained my the savepoint max parallelism", 1, getParallelism(result));
}
 
Example #2
Source File: BootstrapTransformationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testMaxParallelismRespected() {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	env.setParallelism(10);

	DataSource<Integer> input = env.fromElements(0);

	BootstrapTransformation<Integer> transformation = OperatorTransformation
		.bootstrapWith(input)
		.transform(new ExampleStateBootstrapFunction());

	int maxParallelism = transformation.getMaxParallelism(4);
	DataSet<TaggedOperatorSubtaskState> result = transformation.writeOperatorSubtaskStates(
		OperatorIDGenerator.fromUid("uid"),
		new MemoryStateBackend(),
		new Path(),
		maxParallelism
	);

	Assert.assertEquals(
		"The parallelism of a data set should be constrained my the savepoint max parallelism",
		4,
		getParallelism(result));
}
 
Example #3
Source File: BootstrapTransformationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultParallelismRespectedWhenLessThanMaxParallelism() {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	env.setParallelism(4);

	DataSource<Integer> input = env.fromElements(0);

	BootstrapTransformation<Integer> transformation = OperatorTransformation
		.bootstrapWith(input)
		.transform(new ExampleStateBootstrapFunction());

	int maxParallelism = transformation.getMaxParallelism(10);
	DataSet<TaggedOperatorSubtaskState> result = transformation.writeOperatorSubtaskStates(
		OperatorIDGenerator.fromUid("uid"),
		new MemoryStateBackend(),
		new Path(),
		maxParallelism
	);

	Assert.assertEquals(
		"The parallelism of a data set should not change when less than the max parallelism of the savepoint",
		ExecutionConfig.PARALLELISM_DEFAULT,
		getParallelism(result));
}
 
Example #4
Source File: BootstrapTransformationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testBroadcastStateTransformationParallelism() {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	env.setParallelism(10);

	DataSet<Integer> input = env.fromElements(0);

	BootstrapTransformation<Integer> transformation = OperatorTransformation
		.bootstrapWith(input)
		.transform(new ExampleBroadcastStateBootstrapFunction());

	int maxParallelism = transformation.getMaxParallelism(4);
	DataSet<TaggedOperatorSubtaskState> result = transformation.writeOperatorSubtaskStates(
		OperatorIDGenerator.fromUid("uid"),
		new MemoryStateBackend(),
		new Path(),
		maxParallelism
	);

	Assert.assertEquals("Broadcast transformations should always be run at parallelism 1",
		1,
		getParallelism(result));
}
 
Example #5
Source File: BootstrapTransformation.java    From flink with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
StreamConfig getConfig(OperatorID operatorID, StateBackend stateBackend, StreamOperator<TaggedOperatorSubtaskState> operator) {
	final StreamConfig config;
	if (keyType == null) {
		config = new BoundedStreamConfig();
	} else {
		TypeSerializer<?> keySerializer = keyType.createSerializer(dataSet.getExecutionEnvironment().getConfig());
		config = new BoundedStreamConfig(keySerializer, originalKeySelector);
	}

	config.setStreamOperator(operator);
	config.setOperatorName(operatorID.toHexString());
	config.setOperatorID(operatorID);
	config.setStateBackend(stateBackend);
	return config;
}
 
Example #6
Source File: BootstrapTransformationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testBroadcastStateTransformationParallelism() {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	env.setParallelism(10);

	DataSet<Integer> input = env.fromElements(0);

	BootstrapTransformation<Integer> transformation = OperatorTransformation
		.bootstrapWith(input)
		.transform(new ExampleBroadcastStateBootstrapFunction());

	int maxParallelism = transformation.getMaxParallelism(4);
	DataSet<TaggedOperatorSubtaskState> result = transformation.writeOperatorSubtaskStates(
		OperatorIDGenerator.fromUid("uid"),
		new MemoryStateBackend(),
		new Path(),
		maxParallelism
	);

	Assert.assertEquals("Broadcast transformations should always be run at parallelism 1",
		1,
		getParallelism(result));
}
 
Example #7
Source File: BootstrapTransformationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testDefaultParallelismRespectedWhenLessThanMaxParallelism() {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	env.setParallelism(4);

	DataSource<Integer> input = env.fromElements(0);

	BootstrapTransformation<Integer> transformation = OperatorTransformation
		.bootstrapWith(input)
		.transform(new ExampleStateBootstrapFunction());

	int maxParallelism = transformation.getMaxParallelism(10);
	DataSet<TaggedOperatorSubtaskState> result = transformation.writeOperatorSubtaskStates(
		OperatorIDGenerator.fromUid("uid"),
		new MemoryStateBackend(),
		new Path(),
		maxParallelism
	);

	Assert.assertEquals(
		"The parallelism of a data set should not change when less than the max parallelism of the savepoint",
		ExecutionConfig.PARALLELISM_DEFAULT,
		getParallelism(result));
}
 
Example #8
Source File: BootstrapTransformationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testMaxParallelismRespected() {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	env.setParallelism(10);

	DataSource<Integer> input = env.fromElements(0);

	BootstrapTransformation<Integer> transformation = OperatorTransformation
		.bootstrapWith(input)
		.transform(new ExampleStateBootstrapFunction());

	int maxParallelism = transformation.getMaxParallelism(4);
	DataSet<TaggedOperatorSubtaskState> result = transformation.writeOperatorSubtaskStates(
		OperatorIDGenerator.fromUid("uid"),
		new MemoryStateBackend(),
		new Path(),
		maxParallelism
	);

	Assert.assertEquals(
		"The parallelism of a data set should be constrained my the savepoint max parallelism",
		4,
		getParallelism(result));
}
 
Example #9
Source File: BootstrapTransformationTest.java    From flink with Apache License 2.0 6 votes vote down vote up
@Test
public void testOperatorSpecificMaxParallelismRespected() {
	ExecutionEnvironment env = ExecutionEnvironment.getExecutionEnvironment();
	env.setParallelism(4);

	DataSource<Integer> input = env.fromElements(0);

	BootstrapTransformation<Integer> transformation = OperatorTransformation
		.bootstrapWith(input)
		.setMaxParallelism(1)
		.transform(new ExampleStateBootstrapFunction());

	int maxParallelism = transformation.getMaxParallelism(4);
	DataSet<TaggedOperatorSubtaskState> result = transformation.writeOperatorSubtaskStates(
		OperatorIDGenerator.fromUid("uid"),
		new MemoryStateBackend(),
		new Path(),
		maxParallelism
	);

	Assert.assertEquals("The parallelism of a data set should be constrained my the savepoint max parallelism", 1, getParallelism(result));
}
 
Example #10
Source File: BootstrapTransformation.java    From flink with Apache License 2.0 6 votes vote down vote up
@VisibleForTesting
StreamConfig getConfig(OperatorID operatorID, StateBackend stateBackend, StreamOperator<TaggedOperatorSubtaskState> operator) {
	// Eagerly perform a deep copy of the configuration, otherwise it will result in undefined behavior
	// when deploying with multiple bootstrap transformations.
	Configuration deepCopy = new Configuration(dataSet.getExecutionEnvironment().getConfiguration());
	final StreamConfig config = new StreamConfig(deepCopy);
	config.setChainStart();
	config.setCheckpointingEnabled(true);
	config.setCheckpointMode(CheckpointingMode.EXACTLY_ONCE);

	if (keyType != null) {
		TypeSerializer<?> keySerializer = keyType.createSerializer(dataSet.getExecutionEnvironment().getConfig());

		config.setStateKeySerializer(keySerializer);
		config.setStatePartitioner(0, originalKeySelector);
	}

	config.setStreamOperator(operator);
	config.setOperatorName(operatorID.toHexString());
	config.setOperatorID(operatorID);
	config.setStateBackend(stateBackend);
	return config;
}
 
Example #11
Source File: FunctionsStateBootstrapOperator.java    From flink-statefun with Apache License 2.0 5 votes vote down vote up
@Override
public void endInput() throws Exception {
  // bootstrap dataset is now completely processed;
  // take a snapshot of the function states
  final TaggedOperatorSubtaskState state =
      SnapshotUtils.snapshot(
          this,
          getRuntimeContext().getIndexOfThisSubtask(),
          snapshotTimestamp,
          getContainingTask().getCheckpointStorage(),
          snapshotPath);

  output.collect(new StreamRecord<>(state));
}
 
Example #12
Source File: BootstrapTransformation.java    From flink with Apache License 2.0 5 votes vote down vote up
private static <T> int getParallelism(MapPartitionOperator<T, TaggedOperatorSubtaskState> subtaskStates) {
	int parallelism = subtaskStates.getParallelism();
	if (parallelism == ExecutionConfig.PARALLELISM_DEFAULT) {
		parallelism = subtaskStates.getExecutionEnvironment().getParallelism();
	}

	return parallelism;
}
 
Example #13
Source File: BootstrapTransformation.java    From flink with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
MapPartitionOperator<T, TaggedOperatorSubtaskState> writeOperatorSubtaskStates(
	OperatorID operatorID,
	StateBackend stateBackend,
	Path savepointPath,
	int localMaxParallelism) {

	DataSet<T> input = dataSet;
	if (originalKeySelector != null) {
		input = dataSet.partitionCustom(new KeyGroupRangePartitioner(localMaxParallelism), hashKeySelector);
	}

	StreamOperator<TaggedOperatorSubtaskState> operator = factory.createOperator(
		System.currentTimeMillis(),
		savepointPath);

	operator = dataSet.clean(operator);

	final StreamConfig config = getConfig(operatorID, stateBackend, operator);

	BoundedOneInputStreamTaskRunner<T> operatorRunner = new BoundedOneInputStreamTaskRunner<>(
		config,
		localMaxParallelism);

	MapPartitionOperator<T, TaggedOperatorSubtaskState> subtaskStates = input
		.mapPartition(operatorRunner)
		.name(operatorID.toHexString());

	if (operator instanceof BroadcastStateBootstrapOperator) {
		subtaskStates = subtaskStates.setParallelism(1);
	} else {
		int currentParallelism = getParallelism(subtaskStates);
		if (currentParallelism > localMaxParallelism) {
			subtaskStates.setParallelism(localMaxParallelism);
		}
	}
	return subtaskStates;
}
 
Example #14
Source File: KeyedStateBootstrapOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void endInput() throws Exception {
	TaggedOperatorSubtaskState state = SnapshotUtils.snapshot(
		this,
		getRuntimeContext().getIndexOfThisSubtask(),
		timestamp,
		getContainingTask().getConfiguration().isExactlyOnceCheckpointMode(),
		getContainingTask().getConfiguration().isUnalignedCheckpointsEnabled(),
		getContainingTask().getCheckpointStorage(),
		savepointPath);

	output.collect(new StreamRecord<>(state));
}
 
Example #15
Source File: StateBootstrapOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void endInput() throws Exception {
	TaggedOperatorSubtaskState state = SnapshotUtils.snapshot(
		this,
		getRuntimeContext().getIndexOfThisSubtask(),
		timestamp,
		getContainingTask().getConfiguration().isExactlyOnceCheckpointMode(),
		getContainingTask().getConfiguration().isUnalignedCheckpointsEnabled(),
		getContainingTask().getCheckpointStorage(),
		savepointPath);

	output.collect(new StreamRecord<>(state));
}
 
Example #16
Source File: BroadcastStateBootstrapOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void endInput() throws Exception {
	TaggedOperatorSubtaskState state = SnapshotUtils.snapshot(
		this,
		getRuntimeContext().getIndexOfThisSubtask(),
		timestamp,
		getContainingTask().getConfiguration().isExactlyOnceCheckpointMode(),
		getContainingTask().getConfiguration().isUnalignedCheckpointsEnabled(),
		getContainingTask().getCheckpointStorage(),
		savepointPath);

	output.collect(new StreamRecord<>(state));
}
 
Example #17
Source File: FunctionsStateBootstrapOperator.java    From stateful-functions with Apache License 2.0 5 votes vote down vote up
@Override
public void endInput() throws Exception {
  // bootstrap dataset is now completely processed;
  // take a snapshot of the function states
  final TaggedOperatorSubtaskState state =
      SnapshotUtils.snapshot(
          this,
          getRuntimeContext().getIndexOfThisSubtask(),
          snapshotTimestamp,
          getContainingTask().getCheckpointStorage(),
          snapshotPath);

  output.collect(new StreamRecord<>(state));
}
 
Example #18
Source File: BootstrapTransformation.java    From flink with Apache License 2.0 5 votes vote down vote up
private static <T> int getParallelism(MapPartitionOperator<T, TaggedOperatorSubtaskState> subtaskStates) {
	int parallelism = subtaskStates.getParallelism();
	if (parallelism == ExecutionConfig.PARALLELISM_DEFAULT) {
		parallelism = subtaskStates.getExecutionEnvironment().getParallelism();
	}

	return parallelism;
}
 
Example #19
Source File: BootstrapTransformation.java    From flink with Apache License 2.0 5 votes vote down vote up
@VisibleForTesting
MapPartitionOperator<T, TaggedOperatorSubtaskState> writeOperatorSubtaskStates(
	OperatorID operatorID,
	StateBackend stateBackend,
	Path savepointPath,
	int localMaxParallelism) {

	DataSet<T> input = dataSet;
	if (originalKeySelector != null) {
		input = dataSet.partitionCustom(new KeyGroupRangePartitioner(localMaxParallelism), hashKeySelector);
	}

	StreamOperator<TaggedOperatorSubtaskState> operator = factory.createOperator(
		System.currentTimeMillis(),
		savepointPath);

	operator = dataSet.clean(operator);

	final StreamConfig config = getConfig(operatorID, stateBackend, operator);

	BoundedOneInputStreamTaskRunner<T> operatorRunner = new BoundedOneInputStreamTaskRunner<>(
		config,
		localMaxParallelism
	);

	MapPartitionOperator<T, TaggedOperatorSubtaskState> subtaskStates = input
		.mapPartition(operatorRunner)
		.name(operatorID.toHexString());

	if (operator instanceof BroadcastStateBootstrapOperator) {
		subtaskStates = subtaskStates.setParallelism(1);
	} else {
		int currentParallelism = getParallelism(subtaskStates);
		if (currentParallelism > localMaxParallelism) {
			subtaskStates.setParallelism(localMaxParallelism);
		}
	}
	return subtaskStates;
}
 
Example #20
Source File: KeyedStateBootstrapOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void endInput() throws Exception {
	TaggedOperatorSubtaskState state = SnapshotUtils.snapshot(
		this,
		getRuntimeContext().getIndexOfThisSubtask(),
		timestamp,
		getContainingTask().getCheckpointStorage(),
		savepointPath);

	output.collect(new StreamRecord<>(state));
}
 
Example #21
Source File: StateBootstrapOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void endInput() throws Exception {
	TaggedOperatorSubtaskState state = SnapshotUtils.snapshot(
		this,
		getRuntimeContext().getIndexOfThisSubtask(),
		timestamp,
		getContainingTask().getCheckpointStorage(),
		savepointPath);

	output.collect(new StreamRecord<>(state));
}
 
Example #22
Source File: BroadcastStateBootstrapOperator.java    From flink with Apache License 2.0 5 votes vote down vote up
@Override
public void endInput() throws Exception {
	TaggedOperatorSubtaskState state = SnapshotUtils.snapshot(
		this,
		getRuntimeContext().getIndexOfThisSubtask(),
		timestamp,
		getContainingTask().getCheckpointStorage(),
		savepointPath);

	output.collect(new StreamRecord<>(state));
}
 
Example #23
Source File: SavepointWriterOperatorFactory.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a {@link StreamOperator} to be used for generating and snapshotting state.
 *
 * @param savepointTimestamp the timestamp to associate with the generated savepoint.
 * @param savepointPath the path to write the savepoint to.
 *
 * @return a stream operator for writing the savepoint.
 */
StreamOperator<TaggedOperatorSubtaskState> createOperator(long savepointTimestamp, Path savepointPath);
 
Example #24
Source File: SavepointWriterOperatorFactory.java    From flink with Apache License 2.0 2 votes vote down vote up
/**
 * Creates a {@link StreamOperator} to be used for generating and snapshotting state.
 *
 * @param savepointTimestamp the timestamp to associate with the generated savepoint.
 * @param savepointPath the path to write the savepoint to.
 *
 * @return a stream operator for writing the savepoint.
 */
StreamOperator<TaggedOperatorSubtaskState> createOperator(long savepointTimestamp, Path savepointPath);