pnowojski commented on code in PR #27861:
URL: https://github.com/apache/flink/pull/27861#discussion_r3032833140


##########
flink-runtime/src/main/java/org/apache/flink/runtime/io/network/partition/consumer/SingleInputGate.java:
##########
@@ -384,19 +388,40 @@ public void convertRecoveredInputChannels() {
                     new HashSet<>(inputChannelsForCurrentPartition.keySet());
             for (InputChannelInfo inputChannelInfo : oldInputChannelInfos) {
                 InputChannel inputChannel = 
inputChannelsForCurrentPartition.get(inputChannelInfo);
-                if (inputChannel instanceof RecoveredInputChannel) {
-                    try {
-                        InputChannel realInputChannel =
-                                ((RecoveredInputChannel) 
inputChannel).toInputChannel();
-                        inputChannel.releaseAllResources();
+                if (!(inputChannel instanceof RecoveredInputChannel)) {
+                    continue;
+                }
+                try {
+                    // Phase 1: Convert channel and release resources outside 
the lock.
+                    // These calls may acquire the receivedBuffers lock 
internally, so they
+                    // run outside inputChannelsWithData lock to maintain a 
consistent lock
+                    // order with onRecoveredStateBuffer() which acquires 
receivedBuffers
+                    // first and then inputChannelsWithData.
+                    InputChannel realInputChannel =
+                            ((RecoveredInputChannel) 
inputChannel).toInputChannel();
+                    inputChannel.releaseAllResources();
+                    int buffersInUseCount = 
realInputChannel.getBuffersInUseCount();
+
+                    // Phase 2: Atomically update data structures under the 
lock.
+                    synchronized (inputChannelsWithData) {

Review Comment:
   Why the previous code didn't need the lock in the first place? What has 
changed or what did I miss?



##########
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:
   never mind, I got confused



-- 
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]

Reply via email to