[CELEBORN-1866][Flink] Fix CelebornChannelBufferReader request more buffers than needed #3102
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
What changes were proposed in this pull request?
I found a case where a Flink job is hanging which utilize Celeborn hybrid integration strategy.
The issue seems to be that the CelebornChannelBufferReader is requesting more buffers than needed, which prevents other readers from getting enough buffers to continue reading data. This problem usually happens when memory competition is high.
When other readers recycle buffers back to the LocalBufferPool, the LocalBufferPool calls CelebornChannelBufferManager#notifyBufferAvailable to notify about the available buffer, and then CelebornChannelBufferManager requests buffers from the LocalBufferPool.
For instance, if CelebornBufferManager#numRequiredBuffers is set to 5 and it only gets 4 buffers from the LocalBufferPool, it won't immediately decrease numRequiredBuffers to 1. Instead, it will keep trying to request more buffers from the LocalBufferPool until it exits the synchronized block, at which point it will reduce numRequiredBuffers.
I think the bug occurs when the CelebornBufferManager exits the synchronized block. If a reader requests a buffer from this CelebornBufferManager, the number of buffers in BufferManager#bufferQueue _drops from 4 to 3. When the _LocalBufferPool has buffers again and tries to offer them to the CelebornBufferManager, the CelebornBufferManager mistakenly thinks it should request 2 buffers instead of just 1.
Why are the changes needed?
It may cause flink job hang.
Does this PR introduce any user-facing change?
no.
How was this patch tested?
We have a job that can reproduce this case. After the fix, it can be completed stably.