Search in sources :

Example 6 with TaggedOperatorSubtaskState

use of org.apache.flink.state.api.output.TaggedOperatorSubtaskState in project flink by apache.

the class BootstrapTransformationTest method testBroadcastStateTransformationParallelism.

@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));
}
Also used : Path(org.apache.flink.core.fs.Path) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) TaggedOperatorSubtaskState(org.apache.flink.state.api.output.TaggedOperatorSubtaskState) Test(org.junit.Test)

Example 7 with TaggedOperatorSubtaskState

use of org.apache.flink.state.api.output.TaggedOperatorSubtaskState in project flink by apache.

the class BootstrapTransformationTest method testDefaultParallelismRespectedWhenLessThanMaxParallelism.

@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));
}
Also used : Path(org.apache.flink.core.fs.Path) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) TaggedOperatorSubtaskState(org.apache.flink.state.api.output.TaggedOperatorSubtaskState) Test(org.junit.Test)

Example 8 with TaggedOperatorSubtaskState

use of org.apache.flink.state.api.output.TaggedOperatorSubtaskState in project flink by apache.

the class BootstrapTransformationTest method testMaxParallelismRespected.

@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));
}
Also used : Path(org.apache.flink.core.fs.Path) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) TaggedOperatorSubtaskState(org.apache.flink.state.api.output.TaggedOperatorSubtaskState) Test(org.junit.Test)

Example 9 with TaggedOperatorSubtaskState

use of org.apache.flink.state.api.output.TaggedOperatorSubtaskState in project flink by apache.

the class BootstrapTransformationTest method testOperatorSpecificMaxParallelismRespected.

@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));
}
Also used : Path(org.apache.flink.core.fs.Path) ExecutionEnvironment(org.apache.flink.api.java.ExecutionEnvironment) MemoryStateBackend(org.apache.flink.runtime.state.memory.MemoryStateBackend) TaggedOperatorSubtaskState(org.apache.flink.state.api.output.TaggedOperatorSubtaskState) Test(org.junit.Test)

Example 10 with TaggedOperatorSubtaskState

use of org.apache.flink.state.api.output.TaggedOperatorSubtaskState in project flink by apache.

the class BootstrapTransformation method writeOperatorSubtaskStates.

private MapPartitionOperator<T, TaggedOperatorSubtaskState> writeOperatorSubtaskStates(OperatorID operatorID, @Nullable StateBackend stateBackend, Configuration additionalConfig, 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, additionalConfig, operator);
    BoundedOneInputStreamTaskRunner<T> operatorRunner = new BoundedOneInputStreamTaskRunner<>(config, localMaxParallelism, timestamper);
    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;
}
Also used : BroadcastStateBootstrapOperator(org.apache.flink.state.api.output.operators.BroadcastStateBootstrapOperator) StreamConfig(org.apache.flink.streaming.api.graph.StreamConfig) KeyGroupRangePartitioner(org.apache.flink.state.api.output.partitioner.KeyGroupRangePartitioner) TaggedOperatorSubtaskState(org.apache.flink.state.api.output.TaggedOperatorSubtaskState) BoundedOneInputStreamTaskRunner(org.apache.flink.state.api.output.BoundedOneInputStreamTaskRunner)

Aggregations

TaggedOperatorSubtaskState (org.apache.flink.state.api.output.TaggedOperatorSubtaskState)14 Path (org.apache.flink.core.fs.Path)8 Test (org.junit.Test)8 ExecutionEnvironment (org.apache.flink.api.java.ExecutionEnvironment)4 HashMapStateBackend (org.apache.flink.runtime.state.hashmap.HashMapStateBackend)4 MemoryStateBackend (org.apache.flink.runtime.state.memory.MemoryStateBackend)4 StreamExecutionEnvironment (org.apache.flink.streaming.api.environment.StreamExecutionEnvironment)4 BroadcastStateBootstrapOperator (org.apache.flink.state.api.output.operators.BroadcastStateBootstrapOperator)2 StreamConfig (org.apache.flink.streaming.api.graph.StreamConfig)2 BootstrapStreamTaskRunner (org.apache.flink.state.api.output.BootstrapStreamTaskRunner)1 BoundedOneInputStreamTaskRunner (org.apache.flink.state.api.output.BoundedOneInputStreamTaskRunner)1 KeyGroupRangePartitioner (org.apache.flink.state.api.output.partitioner.KeyGroupRangePartitioner)1