Search in sources :

Example 1 with TaskEvent

use of org.apache.flink.runtime.event.TaskEvent in project flink by apache.

the class SingleInputGate method updateInputChannel.

public void updateInputChannel(InputChannelDeploymentDescriptor icdd) throws IOException, InterruptedException {
    synchronized (requestLock) {
        if (isReleased) {
            // There was a race with a task failure/cancel
            return;
        }
        final IntermediateResultPartitionID partitionId = icdd.getConsumedPartitionId().getPartitionId();
        InputChannel current = inputChannels.get(partitionId);
        if (current.getClass() == UnknownInputChannel.class) {
            UnknownInputChannel unknownChannel = (UnknownInputChannel) current;
            InputChannel newChannel;
            ResultPartitionLocation partitionLocation = icdd.getConsumedPartitionLocation();
            if (partitionLocation.isLocal()) {
                newChannel = unknownChannel.toLocalInputChannel();
            } else if (partitionLocation.isRemote()) {
                newChannel = unknownChannel.toRemoteInputChannel(partitionLocation.getConnectionId());
            } else {
                throw new IllegalStateException("Tried to update unknown channel with unknown channel.");
            }
            LOG.debug("Updated unknown input channel to {}.", newChannel);
            inputChannels.put(partitionId, newChannel);
            if (requestedPartitionsFlag) {
                newChannel.requestSubpartition(consumedSubpartitionIndex);
            }
            for (TaskEvent event : pendingEvents) {
                newChannel.sendTaskEvent(event);
            }
            if (--numberOfUninitializedChannels == 0) {
                pendingEvents.clear();
            }
        }
    }
}
Also used : ResultPartitionLocation(org.apache.flink.runtime.deployment.ResultPartitionLocation) TaskEvent(org.apache.flink.runtime.event.TaskEvent) IntermediateResultPartitionID(org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID)

Example 2 with TaskEvent

use of org.apache.flink.runtime.event.TaskEvent in project flink by apache.

the class SingleInputGateTest method testBackwardsEventWithUninitializedChannel.

@Test
public void testBackwardsEventWithUninitializedChannel() throws Exception {
    // Setup environment
    TestingTaskEventPublisher taskEventPublisher = new TestingTaskEventPublisher();
    TestingResultPartitionManager partitionManager = new TestingResultPartitionManager(new NoOpResultSubpartitionView());
    // Setup reader with one local and one unknown input channel
    NettyShuffleEnvironment environment = createNettyShuffleEnvironment();
    final SingleInputGate inputGate = createInputGate(environment, 2, ResultPartitionType.PIPELINED);
    final InputChannel[] inputChannels = new InputChannel[2];
    try (Closer closer = Closer.create()) {
        closer.register(environment::close);
        closer.register(inputGate::close);
        // Local
        ResultPartitionID localPartitionId = new ResultPartitionID();
        inputChannels[0] = InputChannelBuilder.newBuilder().setPartitionId(localPartitionId).setPartitionManager(partitionManager).setTaskEventPublisher(taskEventPublisher).buildLocalChannel(inputGate);
        // Unknown
        ResultPartitionID unknownPartitionId = new ResultPartitionID();
        inputChannels[1] = InputChannelBuilder.newBuilder().setChannelIndex(1).setPartitionId(unknownPartitionId).setPartitionManager(partitionManager).setTaskEventPublisher(taskEventPublisher).buildUnknownChannel(inputGate);
        setupInputGate(inputGate, inputChannels);
        // Only the local channel can request
        assertEquals(1, partitionManager.counter);
        // Send event backwards and initialize unknown channel afterwards
        final TaskEvent event = new TestTaskEvent();
        inputGate.sendTaskEvent(event);
        // Only the local channel can send out the event
        assertEquals(1, taskEventPublisher.counter);
        // After the update, the pending event should be send to local channel
        ResourceID location = ResourceID.generate();
        inputGate.updateInputChannel(location, createRemoteWithIdAndLocation(unknownPartitionId.getPartitionId(), location));
        assertEquals(2, partitionManager.counter);
        assertEquals(2, taskEventPublisher.counter);
    }
}
Also used : Closer(org.apache.flink.shaded.guava30.com.google.common.io.Closer) TestTaskEvent(org.apache.flink.runtime.io.network.util.TestTaskEvent) NettyShuffleEnvironment(org.apache.flink.runtime.io.network.NettyShuffleEnvironment) NoOpResultSubpartitionView(org.apache.flink.runtime.io.network.partition.NoOpResultSubpartitionView) ResourceID(org.apache.flink.runtime.clusterframework.types.ResourceID) InputChannelTestUtils.createRemoteInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createRemoteInputChannel) InputChannelTestUtils.createLocalInputChannel(org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel) TaskEvent(org.apache.flink.runtime.event.TaskEvent) TestTaskEvent(org.apache.flink.runtime.io.network.util.TestTaskEvent) ResultPartitionID(org.apache.flink.runtime.io.network.partition.ResultPartitionID) IntermediateResultPartitionID(org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID) Test(org.junit.Test)

Example 3 with TaskEvent

use of org.apache.flink.runtime.event.TaskEvent in project flink by apache.

the class SingleInputGate method updateInputChannel.

public void updateInputChannel(ResourceID localLocation, NettyShuffleDescriptor shuffleDescriptor) throws IOException, InterruptedException {
    synchronized (requestLock) {
        if (closeFuture.isDone()) {
            // There was a race with a task failure/cancel
            return;
        }
        IntermediateResultPartitionID partitionId = shuffleDescriptor.getResultPartitionID().getPartitionId();
        for (int subpartitionIndex = subpartitionIndexRange.getStartIndex(); subpartitionIndex <= subpartitionIndexRange.getEndIndex(); ++subpartitionIndex) {
            SubpartitionInfo subpartitionInfo = new SubpartitionInfo(partitionId, subpartitionIndex);
            InputChannel current = inputChannels.get(subpartitionInfo);
            if (current instanceof UnknownInputChannel) {
                UnknownInputChannel unknownChannel = (UnknownInputChannel) current;
                boolean isLocal = shuffleDescriptor.isLocalTo(localLocation);
                InputChannel newChannel;
                if (isLocal) {
                    newChannel = unknownChannel.toLocalInputChannel();
                } else {
                    RemoteInputChannel remoteInputChannel = unknownChannel.toRemoteInputChannel(shuffleDescriptor.getConnectionId());
                    remoteInputChannel.setup();
                    newChannel = remoteInputChannel;
                }
                LOG.debug("{}: Updated unknown input channel to {}.", owningTaskName, newChannel);
                inputChannels.put(subpartitionInfo, newChannel);
                channels[current.getChannelIndex()] = newChannel;
                if (requestedPartitionsFlag) {
                    newChannel.requestSubpartition();
                }
                for (TaskEvent event : pendingEvents) {
                    newChannel.sendTaskEvent(event);
                }
                if (--numberOfUninitializedChannels == 0) {
                    pendingEvents.clear();
                }
            }
        }
    }
}
Also used : TaskEvent(org.apache.flink.runtime.event.TaskEvent) IntermediateResultPartitionID(org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID)

Aggregations

TaskEvent (org.apache.flink.runtime.event.TaskEvent)3 IntermediateResultPartitionID (org.apache.flink.runtime.jobgraph.IntermediateResultPartitionID)3 ResourceID (org.apache.flink.runtime.clusterframework.types.ResourceID)1 ResultPartitionLocation (org.apache.flink.runtime.deployment.ResultPartitionLocation)1 NettyShuffleEnvironment (org.apache.flink.runtime.io.network.NettyShuffleEnvironment)1 InputChannelTestUtils.createLocalInputChannel (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createLocalInputChannel)1 InputChannelTestUtils.createRemoteInputChannel (org.apache.flink.runtime.io.network.partition.InputChannelTestUtils.createRemoteInputChannel)1 NoOpResultSubpartitionView (org.apache.flink.runtime.io.network.partition.NoOpResultSubpartitionView)1 ResultPartitionID (org.apache.flink.runtime.io.network.partition.ResultPartitionID)1 TestTaskEvent (org.apache.flink.runtime.io.network.util.TestTaskEvent)1 Closer (org.apache.flink.shaded.guava30.com.google.common.io.Closer)1 Test (org.junit.Test)1