-
Notifications
You must be signed in to change notification settings - Fork 907
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Release readBuffer when close BufferedReadChannel
& BufferedChannel
#4030
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would you please provide more context about this change?
bookkeeper-server/src/main/java/org/apache/bookkeeper/bookie/BufferedChannel.java
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I support this change. Would you please add a test to cover this change? Especially cover the readBuffer
leak case.
} | ||
|
||
readBufferStartPosition = Long.MIN_VALUE; | ||
readBuffer.release(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We'd better use ReferenceCountUtil.release(readBuffer);
instead of readBuffer.release();
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for review, fixed.
super.close(); | ||
writeBufferStartPosition.set(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we close and reset the position after setting the closed to true?
@@ -899,6 +899,7 @@ private BufferedReadChannel getChannelForLogId(long entryLogId) throws IOExcepti | |||
// We set the position of the write buffer of this buffered channel to Long.MAX_VALUE | |||
// so that there are no overlaps with the write buffer while reading | |||
fc = new BufferedReadChannel(newFc, conf.getReadBufferBytes()); | |||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
|
||
// BufferedReadChannel is not response for fileChannel close. | ||
|
||
closed = true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move the closed to the first step?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
In general LGTM, but needs a test and more context on scenarios when this is a problem
Motivation
Release readBuffer when close
BufferedReadChannel
&BufferedChannel
BufferedChannel is subclass of BufferedReadChannel, which will create a readBuffer to cache read content.
When close BufferedChannel, the readBuffer should be released to avoid memory leak.