Skip to content

KAFKA-10899: Producer's BufferPool closing check#9817

Closed
unlizhao wants to merge 1 commit intoapache:trunkfrom
unlizhao:fix_producer-bufferpool-support-closeing
Closed

KAFKA-10899: Producer's BufferPool closing check#9817
unlizhao wants to merge 1 commit intoapache:trunkfrom
unlizhao:fix_producer-bufferpool-support-closeing

Conversation

@unlizhao
Copy link
Copy Markdown
Contributor

@unlizhao unlizhao commented Jan 3, 2021

According to the idea of #7967, it made BufferPool support closing.
Now, there are two places in the BufferPool#allocate() method to judge the 'closed' flag. One is when 'lock' is acquired, and the other is when 'condition' is awakened.

However, if the memory is allocated outside the 'lock' code block after 'freeup',
Therefore, it is possible for another thread to modify the 'closed' flag, causing this part of memory to be allocated in vain.

So two modifications have been made,
One is to add the 'volatile' modifier before 'closed',
One is to determine whether to 'closed' before allocating memory.

According to the idea of #7967, it made BufferPool support closing
Now, there are two places in the BufferPool#allocate() method to judge the 'closed' flag. One is when 'lock' is acquired, and the other is when 'condition' is awakened

However, if the memory is allocated outside the lock code block after freeup,
Therefore, it is possible for another thread to modify the 'closed' flag, causing this part of memory to be allocated in vain

So two modifications have been made,
One is to add the 'volatile' modifier before 'closed',
One is to determine whether to 'closed' before allocating memory
@unlizhao unlizhao changed the title MINOR: Producer's BufferPool closing check KAFKA-10899: Producer's BufferPool closing check Jan 4, 2021
@unlizhao
Copy link
Copy Markdown
Contributor Author

unlizhao commented Jan 6, 2021

hi,@chia7712 @rajinisivaram PTAL,thanks

Copy link
Copy Markdown
Member

@chia7712 chia7712 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@unlizhao Thanks for your patch. one comment is left. Please take a look.

private ByteBuffer safeAllocateByteBuffer(int size) {
boolean error = true;
try {
if (this.closed) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not holding the lock so this pool can be closed anytime. How we know the "best" place to check the close flag?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@chia7712 thanks for your reviewed. This is what I thought when I wrote this code

In the PR of #3053, for efficiency, the operation of allocating memory is moved out of the locked code block.
Subsequent modifications should be based on this consensus, and do some time-consuming operations without locking.

So what we can do is to try our best to check whether the memory can be allocated before allocating, and reduce the operation of allocating memory, just like the 'fail-fast' mechanism.

In this scenario, both BufferPool#allocate() and BufferPool#close() compete for locks.
Here we can think that lock blocking is more likely to occur in concurrent cases.

Finally, even if the memory is allocated in the close state, there is a plan to release the memory. Therefore, this COMMIT is like an optimization rather than bug-fix

@unlizhao unlizhao requested a review from chia7712 January 10, 2021 01:14
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Dec 1, 2024

This PR is being marked as stale since it has not had any activity in 90 days. If you
would like to keep this PR alive, please leave a comment asking for a review. If the PR has
merge conflicts, update it with the latest from the base branch.

If you are having difficulty finding a reviewer, please reach out on the [mailing list](https://kafka.apache.org/contact).

If this PR is no longer valid or desired, please feel free to close it. If no activity occurs in the next 30 days, it will be automatically closed.

@github-actions github-actions Bot added the stale Stale PRs label Dec 1, 2024
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 1, 2025

This PR has been closed since it has not had any activity in 120 days. If you feel like this
was a mistake, or you would like to continue working on it, please feel free to re-open the
PR and ask for a review.

@github-actions github-actions Bot added the closed-stale PRs that were closed due to inactivity label Jan 1, 2025
@github-actions github-actions Bot closed this Jan 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

closed-stale PRs that were closed due to inactivity stale Stale PRs

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants