Repository navigation
Conversation
- also improve data release to cover both entries
| } | ||
|
|
||
| synchronized OpAddEntry pollPendingAddEntry() { | ||
| return pendingAddEntries.poll(); |
There was a problem hiding this comment.
should we make pendingAddEntries 'private' ?
There was a problem hiding this comment.
I was thinking of doing that but there is some test code that accesses the field directly.
There was a problem hiding this comment.
You could mark it with @VisibleForTesting
| firstInQueue.failed(managedLedgerException); | ||
| } | ||
| } finally { | ||
| failed(managedLedgerException); |
There was a problem hiding this comment.
Seems the OpAddEntry get failed but does not remove from the pending entries.
There was a problem hiding this comment.
that's true, but I guess that this PR is doing the right thing by calling .failed on the entries to discard them if the execution gets to this point? The previous behavior of using checkArgument(this == firstInQueue) would throw an IllegalArgumentException and leak ByteBufs on the discarded OpAddEntrys. Isn't this PR an improvement to that since it blocks the memory leak?
The repro case in #10738 was able to reproduce these errors in the original code amoung others.
@codelipenghui do you expect that some changes would be made to this PR?
There was a problem hiding this comment.
@lhotari The checkArgument(..) call is used in a lot of places in Pulsar. Could it be an issue in other places as well?
There was a problem hiding this comment.
@devinbost if the arguments get rejected and one of the argument is a Netty reference counted object, it would cause a memory leak if the called method is responsible for releasing the object.
There was a problem hiding this comment.
Regarding the comment from @codelipenghui , I don't remember seeing any logic to handle that case (of removing from pending entries upon failure), so should we just add that logic, or would we want to investigate the cause of why the get failed?
There was a problem hiding this comment.
@devinbost there is some logic for that.
It's a bit hard to understand why the
addOperation gets added to the pendingAddEntries initially. Why doesn't this happen after the state is checked? However I consider handling this a separate issue.
In Netty, the contract of reference counted objects is that "The general rule of thumb is that the party that accesses a reference-counted object last is also responsible for the destruction of that reference-counted object.". This PR attempts to follow this rule. Therefore I'd suggest that we first process this PR and file separate issues to fix other problems.
There was a problem hiding this comment.
Looks like it's only removed according to the state, but if the sanity check fails, it's not handled right.
eolivelli
left a comment
There was a problem hiding this comment.
Overall LGTM
I wonder if you could add some unit test cases (even with Mockito is fine)
|
I discussed this PR with @merlimat . I'll split the PR into individual changes since this PR now contains multiple independent changes bundled in a single PR. I'll close this PR and open new PRs. |
| public void safeRun() { | ||
| // Remove this entry from the head of the pending queue | ||
| OpAddEntry firstInQueue = ml.pendingAddEntries.poll(); | ||
| checkArgument(this == firstInQueue); |
There was a problem hiding this comment.
I'd leave this change out of this PR. This is a "logic" check. If this fails it means we really have a code bug issue and we cannot make many assumptions on how to recover from it.
| existsOp.close(); | ||
| existsOp = OpAddEntry.create(existsOp.ml, existsOp.data, existsOp.getNumberOfMessages(), existsOp.callback, existsOp.ctx); | ||
| // release the extra retain | ||
| ReferenceCountUtil.release(existsOp.data); |
| this.recycle(); | ||
| } else { | ||
| ByteBuf data = this.data; | ||
| try { |
There was a problem hiding this comment.
The change here LGTM, although I'd prefer to get it in a separate PR. Also, do you have a stack trace on why the exception would have been triggered here?
| } | ||
| ByteBuf data = this.data; | ||
| try { | ||
| checkArgument(ledger.getId() == lh.getId(), "ledgerId %s doesn't match with acked ledgerId %s", |
There was a problem hiding this comment.
Same comment for the other assertion above. This is really a code-sanity check. If this fails, it means things are very broken.
Fixes #10738 ### Motivation There's a ByteBuf leak that happens in ledger rollover. The repro case in #10738 reproduces some Netty ByteBuf leaks that are detected by the Netty Leak detector. ### Modifications Release `OpAddEntry.data` when the original entry is copied and discarded ### Additional Context This PR was split out of PR #10755 which was closed without merging.
) Fixes apache#10738 ### Motivation There's a ByteBuf leak that happens in ledger rollover. The repro case in apache#10738 reproduces some Netty ByteBuf leaks that are detected by the Netty Leak detector. ### Modifications Release `OpAddEntry.data` when the original entry is copied and discarded ### Additional Context This PR was split out of PR apache#10755 which was closed without merging.
Fixes #10738 There's a ByteBuf leak that happens in ledger rollover. The repro case in #10738 reproduces some Netty ByteBuf leaks that are detected by the Netty Leak detector. Release `OpAddEntry.data` when the original entry is copied and discarded This PR was split out of PR #10755 which was closed without merging.
Fixes #10738 There's a ByteBuf leak that happens in ledger rollover. The repro case in #10738 reproduces some Netty ByteBuf leaks that are detected by the Netty Leak detector. Release `OpAddEntry.data` when the original entry is copied and discarded This PR was split out of PR #10755 which was closed without merging.
) Fixes apache#10738 There's a ByteBuf leak that happens in ledger rollover. The repro case in apache#10738 reproduces some Netty ByteBuf leaks that are detected by the Netty Leak detector. Release `OpAddEntry.data` when the original entry is copied and discarded This PR was split out of PR apache#10755 which was closed without merging. (cherry picked from commit 121305f)
) Fixes apache#10738 ### Motivation There's a ByteBuf leak that happens in ledger rollover. The repro case in apache#10738 reproduces some Netty ByteBuf leaks that are detected by the Netty Leak detector. ### Modifications Release `OpAddEntry.data` when the original entry is copied and discarded ### Additional Context This PR was split out of PR apache#10755 which was closed without merging.
) Fixes apache#10738 ### Motivation There's a ByteBuf leak that happens in ledger rollover. The repro case in apache#10738 reproduces some Netty ByteBuf leaks that are detected by the Netty Leak detector. ### Modifications Release `OpAddEntry.data` when the original entry is copied and discarded ### Additional Context This PR was split out of PR apache#10755 which was closed without merging.
Motivation
The repro case in #10738 reproduces some Netty ByteBuf leaks that are detected by the Netty Leak detector. There are a few exceptional execution paths where the data ByteBuf of OpAddEntry isn't released.
Modifications
This seems to stop the detected leaks in #10738 case.