Search in sources :

Example 1 with OperatorInstanceID

use of org.apache.flink.runtime.jobgraph.OperatorInstanceID in project flink by apache.

the class StateAssignmentOperationTest method verifyAndCollectStateInfo.

// ------------------------------------------------------------------------
/**
 * Verify that after repartition states, state of different modes works as expected and collect
 * the information of state-name -> how many operator stat handles would be used for new
 * sub-tasks to initialize in total.
 */
private void verifyAndCollectStateInfo(OperatorState operatorState, OperatorID operatorID, int oldParallelism, int newParallelism, Map<String, Integer> stateInfoCounts) {
    final Map<OperatorInstanceID, List<OperatorStateHandle>> newManagedOperatorStates = new HashMap<>();
    StateAssignmentOperation.reDistributePartitionableStates(Collections.singletonMap(operatorID, operatorState), newParallelism, OperatorSubtaskState::getManagedOperatorState, RoundRobinOperatorStateRepartitioner.INSTANCE, newManagedOperatorStates);
    // Verify the repartitioned managed operator states per sub-task.
    for (List<OperatorStateHandle> operatorStateHandles : newManagedOperatorStates.values()) {
        final EnumMap<OperatorStateHandle.Mode, Map<String, Integer>> stateModeOffsets = new EnumMap<>(OperatorStateHandle.Mode.class);
        for (OperatorStateHandle.Mode mode : OperatorStateHandle.Mode.values()) {
            stateModeOffsets.put(mode, new HashMap<>());
        }
        for (OperatorStateHandle operatorStateHandle : operatorStateHandles) {
            for (Map.Entry<String, OperatorStateHandle.StateMetaInfo> stateNameToMetaInfo : operatorStateHandle.getStateNameToPartitionOffsets().entrySet()) {
                String stateName = stateNameToMetaInfo.getKey();
                stateInfoCounts.merge(stateName, 1, (count, inc) -> count + inc);
                OperatorStateHandle.StateMetaInfo stateMetaInfo = stateNameToMetaInfo.getValue();
                stateModeOffsets.get(stateMetaInfo.getDistributionMode()).merge(stateName, stateMetaInfo.getOffsets().length, (count, inc) -> count + inc);
            }
        }
        for (Map.Entry<OperatorStateHandle.Mode, Map<String, Integer>> modeMapEntry : stateModeOffsets.entrySet()) {
            OperatorStateHandle.Mode mode = modeMapEntry.getKey();
            Map<String, Integer> stateOffsets = modeMapEntry.getValue();
            if (OperatorStateHandle.Mode.SPLIT_DISTRIBUTE.equals(mode)) {
                if (oldParallelism < newParallelism) {
                    // SPLIT_DISTRIBUTE: when rescale up, split the state and re-distribute it
                    // -> each one will go to one task
                    stateOffsets.values().forEach(length -> Assert.assertEquals(1, (int) length));
                } else {
                    // SPLIT_DISTRIBUTE: when rescale down to 1 or not rescale, not
                    // re-distribute them.
                    stateOffsets.values().forEach(length -> Assert.assertEquals(2, (int) length));
                }
            } else if (OperatorStateHandle.Mode.UNION.equals(mode)) {
                // UNION: all to all
                stateOffsets.values().forEach(length -> Assert.assertEquals(2, (int) length));
            } else {
                // BROADCAST: so all to all
                stateOffsets.values().forEach(length -> Assert.assertEquals(3, (int) length));
            }
        }
    }
}
Also used : OperatorInstanceID(org.apache.flink.runtime.jobgraph.OperatorInstanceID) InflightDataRescalingDescriptorUtil.set(org.apache.flink.runtime.checkpoint.InflightDataRescalingDescriptorUtil.set) StateHandleDummyUtil.createNewOperatorStateHandle(org.apache.flink.runtime.checkpoint.StateHandleDummyUtil.createNewOperatorStateHandle) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Arrays(java.util.Arrays) TestingDefaultExecutionGraphBuilder(org.apache.flink.runtime.executiongraph.TestingDefaultExecutionGraphBuilder) RANGE(org.apache.flink.runtime.io.network.api.writer.SubtaskStateMapper.RANGE) JobGraph(org.apache.flink.runtime.jobgraph.JobGraph) SubtaskStateMapper(org.apache.flink.runtime.io.network.api.writer.SubtaskStateMapper) Random(java.util.Random) RESCALING(org.apache.flink.runtime.checkpoint.InflightDataRescalingDescriptor.InflightDataGateOrPartitionRescalingDescriptor.MappingType.RESCALING) Collections.singletonList(java.util.Collections.singletonList) ARBITRARY(org.apache.flink.runtime.io.network.api.writer.SubtaskStateMapper.ARBITRARY) Arrays.asList(java.util.Arrays.asList) Map(java.util.Map) TestLogger(org.apache.flink.util.TestLogger) InflightDataGateOrPartitionRescalingDescriptor(org.apache.flink.runtime.checkpoint.InflightDataRescalingDescriptor.InflightDataGateOrPartitionRescalingDescriptor) StateHandleDummyUtil.createNewResultSubpartitionStateHandle(org.apache.flink.runtime.checkpoint.StateHandleDummyUtil.createNewResultSubpartitionStateHandle) KeyGroupRange(org.apache.flink.runtime.state.KeyGroupRange) EnumMap(java.util.EnumMap) KeyedStateHandle(org.apache.flink.runtime.state.KeyedStateHandle) Set(java.util.Set) Collectors(java.util.stream.Collectors) List(java.util.List) StateHandleDummyUtil.createNewInputChannelStateHandle(org.apache.flink.runtime.checkpoint.StateHandleDummyUtil.createNewInputChannelStateHandle) Stream(java.util.stream.Stream) OperatorInstanceID(org.apache.flink.runtime.jobgraph.OperatorInstanceID) Matchers.containsInAnyOrder(org.hamcrest.Matchers.containsInAnyOrder) OperatorID(org.apache.flink.runtime.jobgraph.OperatorID) InflightDataRescalingDescriptorUtil.rescalingDescriptor(org.apache.flink.runtime.checkpoint.InflightDataRescalingDescriptorUtil.rescalingDescriptor) IntStream(java.util.stream.IntStream) JobEdge(org.apache.flink.runtime.jobgraph.JobEdge) JobVertex(org.apache.flink.runtime.jobgraph.JobVertex) ExecutionGraph(org.apache.flink.runtime.executiongraph.ExecutionGraph) ResultPartitionType(org.apache.flink.runtime.io.network.partition.ResultPartitionType) HashMap(java.util.HashMap) StateHandleDummyUtil.createNewKeyedStateHandle(org.apache.flink.runtime.checkpoint.StateHandleDummyUtil.createNewKeyedStateHandle) OperatorStreamStateHandle(org.apache.flink.runtime.state.OperatorStreamStateHandle) Function(java.util.function.Function) InflightDataRescalingDescriptorUtil.array(org.apache.flink.runtime.checkpoint.InflightDataRescalingDescriptorUtil.array) JobVertexID(org.apache.flink.runtime.jobgraph.JobVertexID) HashSet(java.util.HashSet) JobException(org.apache.flink.runtime.JobException) InflightDataRescalingDescriptorUtil.to(org.apache.flink.runtime.checkpoint.InflightDataRescalingDescriptorUtil.to) JobGraphTestUtils(org.apache.flink.runtime.jobgraph.JobGraphTestUtils) OperatorStateHandle(org.apache.flink.runtime.state.OperatorStateHandle) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) JobExecutionException(org.apache.flink.runtime.client.JobExecutionException) DistributionPattern(org.apache.flink.runtime.jobgraph.DistributionPattern) ExecutionJobVertex(org.apache.flink.runtime.executiongraph.ExecutionJobVertex) Matchers.empty(org.hamcrest.Matchers.empty) Collections.emptySet(java.util.Collections.emptySet) ExecutionGraphTestUtils(org.apache.flink.runtime.executiongraph.ExecutionGraphTestUtils) ROUND_ROBIN(org.apache.flink.runtime.io.network.api.writer.SubtaskStateMapper.ROUND_ROBIN) Test(org.junit.Test) OperatorIDPair(org.apache.flink.runtime.OperatorIDPair) InflightDataRescalingDescriptorUtil.mappings(org.apache.flink.runtime.checkpoint.InflightDataRescalingDescriptorUtil.mappings) ByteStreamStateHandle(org.apache.flink.runtime.state.memory.ByteStreamStateHandle) Assert(org.junit.Assert) ExecutionVertex(org.apache.flink.runtime.executiongraph.ExecutionVertex) Collections(java.util.Collections) Assert.assertEquals(org.junit.Assert.assertEquals) NoOpInvokable(org.apache.flink.runtime.testtasks.NoOpInvokable) HashMap(java.util.HashMap) Collections.singletonList(java.util.Collections.singletonList) Arrays.asList(java.util.Arrays.asList) List(java.util.List) StateHandleDummyUtil.createNewOperatorStateHandle(org.apache.flink.runtime.checkpoint.StateHandleDummyUtil.createNewOperatorStateHandle) OperatorStateHandle(org.apache.flink.runtime.state.OperatorStateHandle) Map(java.util.Map) EnumMap(java.util.EnumMap) HashMap(java.util.HashMap) EnumMap(java.util.EnumMap)

Example 2 with OperatorInstanceID

use of org.apache.flink.runtime.jobgraph.OperatorInstanceID in project flink by apache.

the class StateAssignmentOperation method assignNonFinishedStateToTask.

private void assignNonFinishedStateToTask(TaskStateAssignment assignment, List<OperatorIDPair> operatorIDs, int subTaskIndex, Execution currentExecutionAttempt) {
    TaskStateSnapshot taskState = new TaskStateSnapshot(operatorIDs.size(), false);
    for (OperatorIDPair operatorID : operatorIDs) {
        OperatorInstanceID instanceID = OperatorInstanceID.of(subTaskIndex, operatorID.getGeneratedOperatorID());
        OperatorSubtaskState operatorSubtaskState = assignment.getSubtaskState(instanceID);
        taskState.putSubtaskStateByOperatorID(operatorID.getGeneratedOperatorID(), operatorSubtaskState);
    }
    JobManagerTaskRestore taskRestore = new JobManagerTaskRestore(restoreCheckpointId, taskState);
    currentExecutionAttempt.setInitialState(taskRestore);
}
Also used : OperatorInstanceID(org.apache.flink.runtime.jobgraph.OperatorInstanceID) OperatorIDPair(org.apache.flink.runtime.OperatorIDPair)

Example 3 with OperatorInstanceID

use of org.apache.flink.runtime.jobgraph.OperatorInstanceID in project flink by apache.

the class StateAssignmentOperation method reDistributeKeyedStates.

private void reDistributeKeyedStates(List<KeyGroupRange> keyGroupPartitions, TaskStateAssignment stateAssignment) {
    stateAssignment.oldState.forEach((operatorID, operatorState) -> {
        for (int subTaskIndex = 0; subTaskIndex < stateAssignment.newParallelism; subTaskIndex++) {
            OperatorInstanceID instanceID = OperatorInstanceID.of(subTaskIndex, operatorID);
            Tuple2<List<KeyedStateHandle>, List<KeyedStateHandle>> subKeyedStates = reAssignSubKeyedStates(operatorState, keyGroupPartitions, subTaskIndex, stateAssignment.newParallelism, operatorState.getParallelism());
            stateAssignment.subManagedKeyedState.put(instanceID, subKeyedStates.f0);
            stateAssignment.subRawKeyedState.put(instanceID, subKeyedStates.f1);
        }
    });
}
Also used : OperatorInstanceID(org.apache.flink.runtime.jobgraph.OperatorInstanceID) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List)

Example 4 with OperatorInstanceID

use of org.apache.flink.runtime.jobgraph.OperatorInstanceID in project flink by apache.

the class StateAssignmentOperation method reDistributeInputChannelStates.

public void reDistributeInputChannelStates(TaskStateAssignment stateAssignment) {
    if (!stateAssignment.hasInputState) {
        return;
    }
    checkForUnsupportedToplogyChanges(stateAssignment.oldState, OperatorSubtaskState::getInputChannelState, stateAssignment.inputOperatorID);
    final ExecutionJobVertex executionJobVertex = stateAssignment.executionJobVertex;
    final List<IntermediateResult> inputs = executionJobVertex.getInputs();
    // check for rescaling: no rescaling = simple reassignment
    final OperatorState inputState = stateAssignment.oldState.get(stateAssignment.inputOperatorID);
    final List<List<InputChannelStateHandle>> inputOperatorState = splitBySubtasks(inputState, OperatorSubtaskState::getInputChannelState);
    if (inputState.getParallelism() == executionJobVertex.getParallelism()) {
        stateAssignment.inputChannelStates.putAll(toInstanceMap(stateAssignment.inputOperatorID, inputOperatorState));
        return;
    }
    // subtask 0 + 2
    for (int gateIndex = 0; gateIndex < inputs.size(); gateIndex++) {
        final RescaleMappings mapping = stateAssignment.getInputMapping(gateIndex).getRescaleMappings();
        final List<List<InputChannelStateHandle>> gateState = inputs.size() == 1 ? inputOperatorState : getPartitionState(inputOperatorState, InputChannelInfo::getGateIdx, gateIndex);
        final MappingBasedRepartitioner<InputChannelStateHandle> repartitioner = new MappingBasedRepartitioner(mapping);
        final Map<OperatorInstanceID, List<InputChannelStateHandle>> repartitioned = applyRepartitioner(stateAssignment.inputOperatorID, repartitioner, gateState, inputOperatorState.size(), stateAssignment.newParallelism);
        addToSubtasks(stateAssignment.inputChannelStates, repartitioned);
    }
}
Also used : OperatorInstanceID(org.apache.flink.runtime.jobgraph.OperatorInstanceID) IntermediateResult(org.apache.flink.runtime.executiongraph.IntermediateResult) ExecutionJobVertex(org.apache.flink.runtime.executiongraph.ExecutionJobVertex) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List) InputChannelStateHandle(org.apache.flink.runtime.state.InputChannelStateHandle)

Example 5 with OperatorInstanceID

use of org.apache.flink.runtime.jobgraph.OperatorInstanceID in project flink by apache.

the class StateAssignmentOperation method reDistributeResultSubpartitionStates.

public <I, T extends AbstractChannelStateHandle<I>> void reDistributeResultSubpartitionStates(TaskStateAssignment assignment) {
    if (!assignment.hasOutputState) {
        return;
    }
    checkForUnsupportedToplogyChanges(assignment.oldState, OperatorSubtaskState::getResultSubpartitionState, assignment.outputOperatorID);
    final OperatorState outputState = assignment.oldState.get(assignment.outputOperatorID);
    final List<List<ResultSubpartitionStateHandle>> outputOperatorState = splitBySubtasks(outputState, OperatorSubtaskState::getResultSubpartitionState);
    final ExecutionJobVertex executionJobVertex = assignment.executionJobVertex;
    final List<IntermediateDataSet> outputs = executionJobVertex.getJobVertex().getProducedDataSets();
    if (outputState.getParallelism() == executionJobVertex.getParallelism()) {
        assignment.resultSubpartitionStates.putAll(toInstanceMap(assignment.outputOperatorID, outputOperatorState));
        return;
    }
    // according to output mapping.
    for (int partitionIndex = 0; partitionIndex < outputs.size(); partitionIndex++) {
        final List<List<ResultSubpartitionStateHandle>> partitionState = outputs.size() == 1 ? outputOperatorState : getPartitionState(outputOperatorState, ResultSubpartitionInfo::getPartitionIdx, partitionIndex);
        final MappingBasedRepartitioner<ResultSubpartitionStateHandle> repartitioner = new MappingBasedRepartitioner<>(assignment.getOutputMapping(partitionIndex).getRescaleMappings());
        final Map<OperatorInstanceID, List<ResultSubpartitionStateHandle>> repartitioned = applyRepartitioner(assignment.outputOperatorID, repartitioner, partitionState, outputOperatorState.size(), executionJobVertex.getParallelism());
        addToSubtasks(assignment.resultSubpartitionStates, repartitioned);
    }
}
Also used : OperatorInstanceID(org.apache.flink.runtime.jobgraph.OperatorInstanceID) IntermediateDataSet(org.apache.flink.runtime.jobgraph.IntermediateDataSet) ExecutionJobVertex(org.apache.flink.runtime.executiongraph.ExecutionJobVertex) ResultSubpartitionStateHandle(org.apache.flink.runtime.state.ResultSubpartitionStateHandle) ArrayList(java.util.ArrayList) Collections.emptyList(java.util.Collections.emptyList) List(java.util.List)

Aggregations

OperatorInstanceID (org.apache.flink.runtime.jobgraph.OperatorInstanceID)5 List (java.util.List)4 ArrayList (java.util.ArrayList)3 Collections.emptyList (java.util.Collections.emptyList)3 ExecutionJobVertex (org.apache.flink.runtime.executiongraph.ExecutionJobVertex)3 OperatorIDPair (org.apache.flink.runtime.OperatorIDPair)2 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collections (java.util.Collections)1 Collections.emptySet (java.util.Collections.emptySet)1 Collections.singletonList (java.util.Collections.singletonList)1 EnumMap (java.util.EnumMap)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1 Random (java.util.Random)1 Set (java.util.Set)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 IntStream (java.util.stream.IntStream)1