use of org.apache.flink.runtime.io.network.PartitionRequestClient in project flink by apache.
the class NettyPartitionRequestClientTest method testAcknowledgeAllRecordsProcessed.
@Test
public void testAcknowledgeAllRecordsProcessed() throws Exception {
CreditBasedPartitionRequestClientHandler handler = new CreditBasedPartitionRequestClientHandler();
EmbeddedChannel channel = new EmbeddedChannel(handler);
PartitionRequestClient client = createPartitionRequestClient(channel, handler, connectionReuseEnabled);
NetworkBufferPool networkBufferPool = new NetworkBufferPool(10, 32);
SingleInputGate inputGate = createSingleInputGate(1, networkBufferPool);
RemoteInputChannel inputChannel = createRemoteInputChannel(inputGate, client);
try {
BufferPool bufferPool = networkBufferPool.createBufferPool(6, 6);
inputGate.setBufferPool(bufferPool);
inputGate.setupChannels();
inputChannel.requestSubpartition();
inputChannel.acknowledgeAllRecordsProcessed();
channel.runPendingTasks();
Object readFromOutbound = channel.readOutbound();
assertThat(readFromOutbound, instanceOf(PartitionRequest.class));
readFromOutbound = channel.readOutbound();
assertThat(readFromOutbound, instanceOf(NettyMessage.AckAllUserRecordsProcessed.class));
assertEquals(inputChannel.getInputChannelId(), ((NettyMessage.AckAllUserRecordsProcessed) readFromOutbound).receiverId);
assertNull(channel.readOutbound());
} finally {
// Release all the buffer resources
inputGate.close();
networkBufferPool.destroyAllBufferPools();
networkBufferPool.destroy();
}
}
use of org.apache.flink.runtime.io.network.PartitionRequestClient in project flink by apache.
the class NettyPartitionRequestClientTest method testDoublePartitionRequest.
@Test
public void testDoublePartitionRequest() throws Exception {
final CreditBasedPartitionRequestClientHandler handler = new CreditBasedPartitionRequestClientHandler();
final EmbeddedChannel channel = new EmbeddedChannel(handler);
final PartitionRequestClient client = createPartitionRequestClient(channel, handler, connectionReuseEnabled);
final int numExclusiveBuffers = 2;
final NetworkBufferPool networkBufferPool = new NetworkBufferPool(10, 32);
final SingleInputGate inputGate = createSingleInputGate(1, networkBufferPool);
final RemoteInputChannel inputChannel = createRemoteInputChannel(inputGate, client);
try {
inputGate.setInputChannels(inputChannel);
final BufferPool bufferPool = networkBufferPool.createBufferPool(6, 6);
inputGate.setBufferPool(bufferPool);
inputGate.setupChannels();
inputChannel.requestSubpartition();
// The input channel should only send one partition request
assertTrue(channel.isWritable());
Object readFromOutbound = channel.readOutbound();
assertThat(readFromOutbound, instanceOf(PartitionRequest.class));
assertEquals(inputChannel.getInputChannelId(), ((PartitionRequest) readFromOutbound).receiverId);
assertEquals(numExclusiveBuffers, ((PartitionRequest) readFromOutbound).credit);
assertNull(channel.readOutbound());
} finally {
// Release all the buffer resources
inputGate.close();
networkBufferPool.destroyAllBufferPools();
networkBufferPool.destroy();
}
}
use of org.apache.flink.runtime.io.network.PartitionRequestClient in project flink by apache.
the class NettyPartitionRequestClientTest method testRetriggerPartitionRequest.
@Test
public void testRetriggerPartitionRequest() throws Exception {
// 30 secs
final long deadline = System.currentTimeMillis() + 30_000L;
final CreditBasedPartitionRequestClientHandler handler = new CreditBasedPartitionRequestClientHandler();
final EmbeddedChannel channel = new EmbeddedChannel(handler);
final PartitionRequestClient client = createPartitionRequestClient(channel, handler, connectionReuseEnabled);
final int numExclusiveBuffers = 2;
final NetworkBufferPool networkBufferPool = new NetworkBufferPool(10, 32);
final SingleInputGate inputGate = createSingleInputGate(1, networkBufferPool);
final RemoteInputChannel inputChannel = InputChannelBuilder.newBuilder().setConnectionManager(mockConnectionManagerWithPartitionRequestClient(client)).setInitialBackoff(1).setMaxBackoff(2).buildRemoteChannel(inputGate);
try {
inputGate.setInputChannels(inputChannel);
final BufferPool bufferPool = networkBufferPool.createBufferPool(6, 6);
inputGate.setBufferPool(bufferPool);
inputGate.setupChannels();
// first subpartition request
inputChannel.requestSubpartition();
assertTrue(channel.isWritable());
Object readFromOutbound = channel.readOutbound();
assertThat(readFromOutbound, instanceOf(PartitionRequest.class));
assertEquals(inputChannel.getInputChannelId(), ((PartitionRequest) readFromOutbound).receiverId);
assertEquals(numExclusiveBuffers, ((PartitionRequest) readFromOutbound).credit);
// retrigger subpartition request, e.g. due to failures
inputGate.retriggerPartitionRequest(inputChannel.getPartitionId().getPartitionId(), inputChannel.getConsumedSubpartitionIndex());
runAllScheduledPendingTasks(channel, deadline);
readFromOutbound = channel.readOutbound();
assertThat(readFromOutbound, instanceOf(PartitionRequest.class));
assertEquals(inputChannel.getInputChannelId(), ((PartitionRequest) readFromOutbound).receiverId);
assertEquals(numExclusiveBuffers, ((PartitionRequest) readFromOutbound).credit);
// retrigger subpartition request once again, e.g. due to failures
inputGate.retriggerPartitionRequest(inputChannel.getPartitionId().getPartitionId(), inputChannel.getConsumedSubpartitionIndex());
runAllScheduledPendingTasks(channel, deadline);
readFromOutbound = channel.readOutbound();
assertThat(readFromOutbound, instanceOf(PartitionRequest.class));
assertEquals(inputChannel.getInputChannelId(), ((PartitionRequest) readFromOutbound).receiverId);
assertEquals(numExclusiveBuffers, ((PartitionRequest) readFromOutbound).credit);
assertNull(channel.readOutbound());
} finally {
// Release all the buffer resources
inputGate.close();
networkBufferPool.destroyAllBufferPools();
networkBufferPool.destroy();
}
}
use of org.apache.flink.runtime.io.network.PartitionRequestClient in project flink by apache.
the class RemoteInputChannelTest method testOnFailedPartitionRequestDoesNotBlockNetworkThreads.
/**
* Test to guard against FLINK-13249.
*/
@Test
public void testOnFailedPartitionRequestDoesNotBlockNetworkThreads() throws Exception {
final long testBlockedWaitTimeoutMillis = 30_000L;
final PartitionProducerStateChecker partitionProducerStateChecker = (jobId, intermediateDataSetId, resultPartitionId) -> CompletableFuture.completedFuture(ExecutionState.RUNNING);
final NettyShuffleEnvironment shuffleEnvironment = new NettyShuffleEnvironmentBuilder().build();
final Task task = new TestTaskBuilder(shuffleEnvironment).setPartitionProducerStateChecker(partitionProducerStateChecker).build();
final SingleInputGate inputGate = new SingleInputGateBuilder().setPartitionProducerStateProvider(task).build();
TestTaskBuilder.setTaskState(task, ExecutionState.RUNNING);
final OneShotLatch ready = new OneShotLatch();
final OneShotLatch blocker = new OneShotLatch();
final AtomicBoolean timedOutOrInterrupted = new AtomicBoolean(false);
final ConnectionManager blockingConnectionManager = new TestingConnectionManager() {
@Override
public PartitionRequestClient createPartitionRequestClient(ConnectionID connectionId) {
ready.trigger();
try {
// We block here, in a section that holds the
// SingleInputGate#requestLock
blocker.await(testBlockedWaitTimeoutMillis, TimeUnit.MILLISECONDS);
} catch (InterruptedException | TimeoutException e) {
timedOutOrInterrupted.set(true);
}
return new TestingPartitionRequestClient();
}
};
final RemoteInputChannel remoteInputChannel = InputChannelBuilder.newBuilder().setConnectionManager(blockingConnectionManager).buildRemoteChannel(inputGate);
inputGate.setInputChannels(remoteInputChannel);
final Thread simulatedNetworkThread = new Thread(() -> {
try {
ready.await();
// We want to make sure that our simulated network thread does not
// block on
// SingleInputGate#requestLock as well through this call.
remoteInputChannel.onFailedPartitionRequest();
// Will only give free the blocker if we did not block ourselves.
blocker.trigger();
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
}
});
simulatedNetworkThread.start();
// The entry point to that will lead us into
// blockingConnectionManager#createPartitionRequestClient(...).
inputGate.requestPartitions();
simulatedNetworkThread.join();
Assert.assertFalse("Test ended by timeout or interruption - this indicates that the network thread was blocked.", timedOutOrInterrupted.get());
}
use of org.apache.flink.runtime.io.network.PartitionRequestClient in project flink by apache.
the class NettyPartitionRequestClientTest method testResumeConsumption.
@Test
public void testResumeConsumption() throws Exception {
final CreditBasedPartitionRequestClientHandler handler = new CreditBasedPartitionRequestClientHandler();
final EmbeddedChannel channel = new EmbeddedChannel(handler);
final PartitionRequestClient client = createPartitionRequestClient(channel, handler, connectionReuseEnabled);
final NetworkBufferPool networkBufferPool = new NetworkBufferPool(10, 32);
final SingleInputGate inputGate = createSingleInputGate(1, networkBufferPool);
final RemoteInputChannel inputChannel = createRemoteInputChannel(inputGate, client);
try {
final BufferPool bufferPool = networkBufferPool.createBufferPool(6, 6);
inputGate.setBufferPool(bufferPool);
inputGate.setupChannels();
inputChannel.requestSubpartition();
inputChannel.resumeConsumption();
channel.runPendingTasks();
Object readFromOutbound = channel.readOutbound();
assertThat(readFromOutbound, instanceOf(PartitionRequest.class));
readFromOutbound = channel.readOutbound();
assertThat(readFromOutbound, instanceOf(ResumeConsumption.class));
assertEquals(inputChannel.getInputChannelId(), ((ResumeConsumption) readFromOutbound).receiverId);
assertNull(channel.readOutbound());
} finally {
// Release all the buffer resources
inputGate.close();
networkBufferPool.destroyAllBufferPools();
networkBufferPool.destroy();
}
}
Aggregations