1996fanrui commented on code in PR #27861:
URL: https://github.com/apache/flink/pull/27861#discussion_r3032936842
##########
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:
The previous(master branch) code didn't touch `inputChannelsWithData` at all
— it was a simple channel swap without any lock. FLINK-39018 changes introduced
buffer migration from `RecoveredInputChannel` to physical channels, where
`onRecoveredStateBuffer()` now enqueues the channel into
`inputChannelsWithData` via `notifyChannelNonEmpty()`. So during conversion, we
now need to dequeue the old channel and conditionally enqueue the new one,
which requires the `inputChannelsWithData` lock. I've structured it so the lock
only covers the queue/map updates (phase 2), while `toInputChannel()` and
`releaseAllResources()` run outside the lock (phase 1) to avoid reverse lock
ordering with `onRecoveredStateBuffer()`.
--
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]