Skip to content

[FLINK-24035][network] Notify the buffer listeners when the local buffer pool receives available notification from the global pool#17030

Closed
wsry wants to merge 4 commits intoapache:masterfrom
wsry:FLINK-24035
Closed

[FLINK-24035][network] Notify the buffer listeners when the local buffer pool receives available notification from the global pool#17030
wsry wants to merge 4 commits intoapache:masterfrom
wsry:FLINK-24035

Conversation

@wsry
Copy link
Contributor

@wsry wsry commented Aug 28, 2021

What is the purpose of the change

Previously, The buffer listeners are not notified when the the local buffer pool receives available notification from the global pool. This may cause potential deadlock issue:

1. A LocalBufferPool is created but there is no available buffers in the global NetworkBufferPool.
2. The LocalBufferPool registers an available buffer listener to the global NetworkBufferPool.
3. The BufferManager requests buffers from the LocalBufferPool but no buffer is available. As a result, it registers an available buffer listener to the LocalBufferPool.
4. A buffer is recycled to the global NetworkBufferPool and the LocalBufferPool is notified about the available buffer.
5. The LocalBufferPool requests the available buffer from the global NetworkBufferPool but the registered available buffer listener of BufferManager is not notified and it can never get a chance to be notified so deadlock occurs.

This patch fixes this issue by notifying the buffer listeners when the local buffer pool receives available notification from the global pool.

Brief change log

  • Notify the buffer listeners when the local buffer pool receives available notification from the global pool.

Verifying this change

This change added tests.

Does this pull request potentially affect one of the following parts:

  • Dependencies (does it add or upgrade a dependency): (yes / no)
  • The public API, i.e., is any changed class annotated with @Public(Evolving): (yes / no)
  • The serializers: (yes / no / don't know)
  • The runtime per-record code paths (performance sensitive): (yes / no / don't know)
  • Anything that affects deployment or recovery: JobManager (and its components), Checkpointing, Kubernetes/Yarn, ZooKeeper: (yes / no / don't know)
  • The S3 file system connector: (yes / no / don't know)

Documentation

  • Does this pull request introduce a new feature? (yes / no)
  • If yes, how is the feature documented? (not applicable / docs / JavaDocs / not documented)

kevin.cyj added 3 commits August 27, 2021 19:42
… help debugging when the case is stuck

This closes apache#17009.
…otified when recycling buffers

Previously, the buffer listener will be removed from the listener queue when notified and then it will be added to the listener queue again if it needs more buffers. However, if some buffers are recycled meanwhile, the buffer listener will not be notified of the available buffers. For example:

1. Thread 1 calls LocalBufferPool#recycle().
2. Thread 1 reaches LocalBufferPool#fireBufferAvailableNotification() and listener.notifyBufferAvailable() is invoked, but Thread 1 sleeps before acquiring the lock to registeredListeners.add(listener).
3. Thread 2 is being woken up as a result of notifyBufferAvailable() call. It takes the buffer, but it needs more buffers.
4. Other threads, return all buffers, including this one that has been recycled. None are taken. Are all in the LocalBufferPool.
5. Thread 1 wakes up, and continues fireBufferAvailableNotification() invocation.
6. Thread 1 re-adds listener that's waiting for more buffer registeredListeners.add(listener).
7. Thread 1 exits loop LocalBufferPool#recycle(MemorySegment, int) inside, as the original memory segment has been used.

At the end we have a state where all buffers are in the LocalBufferPool, so no new recycle() calls will happen, but there is still one listener waiting for a buffer (despite buffers being available).

This change fixes the issue by letting the buffer listener request multiple buffers one after another without having to enqueue BufferListener to the registeredListener queue.

This closes apache#17009.
@flinkbot
Copy link
Collaborator

flinkbot commented Aug 28, 2021

Thanks a lot for your contribution to the Apache Flink project. I'm the @flinkbot. I help the community
to review your pull request. We will use this comment to track the progress of the review.

Automated Checks

Last check on commit f096231 (Sat Aug 28 13:11:25 UTC 2021)

Warnings:

  • No documentation files were touched! Remember to keep the Flink docs up to date!
  • This pull request references an unassigned Jira ticket. According to the code contribution guide, tickets need to be assigned before starting with the implementation work.

Mention the bot in a comment to re-run the automated checks.

Review Progress

  • ❓ 1. The [description] looks good.
  • ❓ 2. There is [consensus] that the contribution should go into to Flink.
  • ❓ 3. Needs [attention] from.
  • ❓ 4. The change fits into the overall [architecture].
  • ❓ 5. Overall code [quality] is good.

Please see the Pull Request Review Guide for a full explanation of the review process.

Details
The Bot is tracking the review progress through labels. Labels are applied according to the order of the review items. For consensus, approval by a Flink committer of PMC member is required Bot commands
The @flinkbot bot supports the following commands:

  • @flinkbot approve description to approve one or more aspects (aspects: description, consensus, architecture and quality)
  • @flinkbot approve all to approve all aspects
  • @flinkbot approve-until architecture to approve everything until architecture
  • @flinkbot attention @username1 [@username2 ..] to require somebody's attention
  • @flinkbot disapprove architecture to remove an approval you gave earlier

@flinkbot
Copy link
Collaborator

flinkbot commented Aug 28, 2021

CI report:

Bot commands The @flinkbot bot supports the following commands:
  • @flinkbot run travis re-run the last Travis build
  • @flinkbot run azure re-run the last Azure build

@wsry
Copy link
Contributor Author

wsry commented Aug 28, 2021

This fix is still under testing.

…fer pool receives available notification from the global pool

Previously, The buffer listeners are not notified when the the local buffer pool receives available notification from the global pool. This may cause potential deadlock issue:

1. A LocalBufferPool is created but there is no available buffers in the global NetworkBufferPool.
2. The LocalBufferPool registers an available buffer listener to the global NetworkBufferPool.
3. The BufferManager requests buffers from the LocalBufferPool but no buffer is available. As a result, it registers an available buffer listener to the LocalBufferPool.
4. A buffer is recycled to the global NetworkBufferPool and the LocalBufferPool is notified about the available buffer.
5. The LocalBufferPool requests the available buffer from the global NetworkBufferPool but the registered available buffer listener of BufferManager is not notified and it can never get a chance to be notified so deadlock occurs.

This patch fixes this issue by notifying the buffer listeners when the local buffer pool receives available notification from the global pool.
@wsry
Copy link
Contributor Author

wsry commented Aug 29, 2021

@flinkbot run azure

1 similar comment
@wsry
Copy link
Contributor Author

wsry commented Aug 30, 2021

@flinkbot run azure

@wsry wsry closed this Aug 30, 2021
@wsry
Copy link
Contributor Author

wsry commented Aug 30, 2021

Abandoned.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants