-
Notifications
You must be signed in to change notification settings - Fork 3.5k
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
fix memory leak #9194
Conversation
/pulsarbot run-failure-checks |
@@ -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) { |
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.
LedgerEntries has a close()
interface.
/pulsarbot run-failure-checks |
try { | ||
for (BrokerEntryMetadataInterceptor interceptor : brokerEntryMetadataInterceptors) { | ||
if (interceptor instanceof AppendIndexMetadataInterceptor && lh.getLastAddConfirmed() >= 0) { | ||
LedgerEntries ledgerEntries = | ||
ledgerEntries = |
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.
What happens if we get to here multiple times?
There is no invariant that enforces the presence of only one AppendIndexMetadataInterceptor
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.
You can use a try-with-resources block and close the object as soon as we do not it anymore
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.
There will be only one AppendIndexMetadataInterceptor
for each ManagedLedger
, it was set before open a new ManagedLedger
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.
what about
try (LedgerEntries ledgerEntries = lh.read....) {
...
}
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.
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
/pulsarbot run-failure-checks |
Motivation
This pr fix memory leak by release bytebuf.