pnowojski commented on code in PR #27861:
URL: https://github.com/apache/flink/pull/27861#discussion_r3026926909
##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/SingleInputGate.java:
##########
@@ -375,6 +375,19 @@ public void requestPartitions() {
}
}
+ /**
+ * Converts all {@link RecoveredInputChannel}s to their real channel types
({@link
+ * LocalInputChannel} or {@link RemoteInputChannel}).
+ *
+ * <p><b>Lock ordering note:</b> This method acquires {@code
inputChannelsWithData} and then may
+ * indirectly acquire {@code receivedBuffers} (via {@code
toInputChannel()} and {@code
+ * releaseAllResources()}). This is the reverse order of {@link
+ * RecoveredInputChannel#onRecoveredStateBuffer}, which acquires {@code
receivedBuffers} first
+ * and then {@code inputChannelsWithData} (via {@code
notifyChannelNonEmpty()}). This is safe
+ * because {@code convertRecoveredInputChannels()} is only called from
{@link
+ * #requestPartitions()}, which happens after all state recovery is
complete (buffer filtering
+ * future is done), so {@code onRecoveredStateBuffer()} is no longer being
called concurrently.
Review Comment:
This sounds fishy and fragile 🤔
##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/LocalInputChannel.java:
##########
@@ -98,7 +98,8 @@ public LocalInputChannel(
int maxBackoff,
Counter numBytesIn,
Counter numBuffersIn,
- ChannelStateWriter stateWriter) {
+ ChannelStateWriter stateWriter,
+ @Nullable ArrayDeque<Buffer> initialRecoveredBuffers) {
Review Comment:
Why support `null` instead of an empty collection? (ditto for remote)
##########
flink-runtime/src/test/java/org/apache/flink/runtime/io/network/partition/consumer/RemoteInputChannelTest.java:
##########
@@ -2073,6 +2074,51 @@ void verifyResult(
}
}
+ @Test
+ void testGetNextBufferWithMigratedRecoveredBuffers() throws Exception {
Review Comment:
Aren't we missing the same test for `LocalInputChannel`?
##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/LocalInputChannel.java:
##########
@@ -273,63 +273,7 @@ public Optional<BufferAndAvailability> getNextBuffer()
throws IOException {
checkError();
if (!toBeConsumedBuffers.isEmpty()) {
- // If there is a pending priority event (e.g., unaligned
checkpoint barrier), fetch it
- // from subpartitionView first, skipping toBeConsumedBuffers. This
ensures priority
- // events are processed immediately even when there are pending
recovered buffers.
- if (hasPendingPriorityEvent) {
- checkState(subpartitionView != null, "No subpartition view
available");
- BufferAndBacklog next = subpartitionView.getNextBuffer();
- checkState(
- next != null &&
next.buffer().getDataType().hasPriority(),
- "Expected priority event, but got %s",
- next == null ? "null" : next.buffer().getDataType());
-
- // Check for barrier to update channel state persister.
- // Note: maybePersist is not needed for barriers as they are
not regular data
- // buffers.
- channelStatePersister.checkForBarrier(next.buffer());
-
- Buffer.DataType expectedNextDataType = next.getNextDataType();
- if (!expectedNextDataType.hasPriority()) {
- // Reset hasPendingPriorityEvent to false if no more
priority event
- hasPendingPriorityEvent = false;
- if (!toBeConsumedBuffers.isEmpty()) {
- // Correct nextDataType: if toBeConsumedBuffers is not
empty, the actual
- // next
- // element to consume is from toBeConsumedBuffers, not
from subpartitionView
- expectedNextDataType =
toBeConsumedBuffers.peek().buffer().getDataType();
- }
- }
-
- return getBufferAndAvailability(
- new BufferAndBacklog(
- next.buffer(),
- next.buffersInBacklog(),
- expectedNextDataType,
- next.getSequenceNumber()));
- }
-
- BufferAndBacklog next = toBeConsumedBuffers.removeFirst();
-
- // If this is the last recovered buffer and nextDataType is NONE,
- // dynamically check if subpartitionView has data available.
- // The last buffer's nextDataType was preset to NONE during
construction,
- // but subpartitionView may already have data available.
- if (toBeConsumedBuffers.isEmpty()
- && next.getNextDataType() == Buffer.DataType.NONE
- && subpartitionView != null) {
- ResultSubpartitionView.AvailabilityWithBacklog availability =
- subpartitionView.getAvailabilityAndBacklog(true);
- if (availability.isAvailable()) {
- next =
- new BufferAndBacklog(
- next.buffer(),
- availability.getBacklog(),
- Buffer.DataType.DATA_BUFFER,
- next.getSequenceNumber());
- }
- }
- return getBufferAndAvailability(next);
+ return getNextRecoveredBuffer();
Review Comment:
Shouldn't this be squashed with a previous commit?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]