Skip to content
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

[bookie] Fix memory leak when the Bookie is in read only mode #3746

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public Object decode(ByteBuf packet)
packet.markReaderIndex();
return BookieProtocol.ParsedAddRequest.create(
version, ledgerId, entryId, flags,
masterKey, packet.retain());
masterKey, packet);
}

case BookieProtocol.READENTRY:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,9 @@ public void run() {
if (request instanceof BookieProtocol.ReadRequest) {
requestProcessor.onReadRequestFinish();
}
if (request instanceof BookieProtocol.AddRequest) {
if (request instanceof BookieProtocol.ParsedAddRequest) {
((BookieProtocol.ParsedAddRequest) request).release();
request.recycle();
requestProcessor.onAddRequestFinish();
Comment on lines +178 to 181
Copy link
Member

Choose a reason for hiding this comment

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

Can the release of ParsedAddRequest be executed in the recycle method? It seems that these two methods are always used together, and there is a forced switch here, which seems a bit awkward.

You can look at org.apache.bookkeeper.proto.BookieProtocol.AddRequest#recycle method

        @Override
        public void recycle() {
            ledgerId = -1;
            entryId = -1;
            masterKey = null;
            ReferenceCountUtil.safeRelease(data);
            data = null;
            recyclerHandle.recycle(this);
        }

Copy link
Member Author

Choose a reason for hiding this comment

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

It can't, we shouldn't release the data in the recycle.
In the normal case, it will recycle the request, but the data is already free.

See:

Copy link
Member

Choose a reason for hiding this comment

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

I saw it, sorry I misread it earlier. Nice work. Thanks.

}
return;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
import io.netty.buffer.ByteBuf;
import io.netty.channel.Channel;
import io.netty.util.Recycler;
import io.netty.util.ReferenceCountUtil;
import java.io.IOException;
import java.util.concurrent.TimeUnit;
import org.apache.bookkeeper.bookie.BookieException;
Expand Down Expand Up @@ -101,8 +100,6 @@ protected void processPacket() {
request.ledgerId, request.entryId, t.getMessage(), t);
// some bad request which cause unexpected exception
rc = BookieProtocol.EBADREQ;
} finally {
ReferenceCountUtil.safeRelease(addData);
}

if (rc != BookieProtocol.EOK) {
Expand Down