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

fix memory leak #9194

Merged
merged 2 commits into from
Jan 13, 2021
Merged

fix memory leak #9194

merged 2 commits into from
Jan 13, 2021

Conversation

aloyszhang
Copy link
Contributor

Motivation

This pr fix memory leak by release bytebuf.

@aloyszhang
Copy link
Contributor Author

/pulsarbot run-failure-checks

@codelipenghui codelipenghui added the type/bug The PR fixed a bug or issue reported a bug label Jan 13, 2021
@codelipenghui codelipenghui added this to the 2.8.0 milestone Jan 13, 2021
@@ -99,6 +100,12 @@ public void onManagedLedgerLastLedgerInitialize(String name, LedgerHandle lh) {
}
} catch (org.apache.bookkeeper.client.api.BKException | InterruptedException e) {
log.error("[{}] Read last entry error.", name, e);
} finally {
if (ledgerEntries != null) {
Copy link
Member

Choose a reason for hiding this comment

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

LedgerEntries has a close() interface.

@aloyszhang
Copy link
Contributor Author

/pulsarbot run-failure-checks

try {
for (BrokerEntryMetadataInterceptor interceptor : brokerEntryMetadataInterceptors) {
if (interceptor instanceof AppendIndexMetadataInterceptor && lh.getLastAddConfirmed() >= 0) {
LedgerEntries ledgerEntries =
ledgerEntries =
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if we get to here multiple times?
There is no invariant that enforces the presence of only one AppendIndexMetadataInterceptor

Copy link
Contributor

Choose a reason for hiding this comment

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

You can use a try-with-resources block and close the object as soon as we do not it anymore

Copy link
Contributor Author

@aloyszhang aloyszhang Jan 13, 2021

Choose a reason for hiding this comment

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

There will be only one AppendIndexMetadataInterceptor for each ManagedLedger, it was set before open a new ManagedLedger

Copy link
Contributor

Choose a reason for hiding this comment

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

what about

try (LedgerEntries ledgerEntries = lh.read....) {
...
}

Copy link
Contributor Author

Choose a reason for hiding this comment

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

try-with-resources is alternative way and makes code more tidy.
I think it's better to raise an individual issue for refactor code like try-with-resources

@aloyszhang
Copy link
Contributor Author

/pulsarbot run-failure-checks

@sijie sijie merged commit 49d3e86 into apache:master Jan 13, 2021
@aloyszhang aloyszhang deleted the mem-leak branch January 22, 2021 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants