GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — [fix] Fix ByteBuf release/retain in PerChannelBookClient by poorbarcode · Pull Request #4289 · apache/bookkeeper

Conversation

@poorbarcode

@poorbarcode poorbarcode commented Apr 16, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Thanks

This root cause was found by @codelipenghui and I just tried to reproduce and write this PR.

Motivation

PerChannelBookieClient.addEntry duplicates the binary data (@param toSend) and sends the binary data new to the IO out. Manually release the binary data new if can not be sent out due to the channel switching. See the explanation below.

Issue: it released the original data (@param toSend), it is wrong. Leading a memory leak and the bellow error log

"Apr 10, 2024 @ 16:06:49.893","2024-04-10T16:06:49,892+0000 [BookKeeperClientWorker-OrderedExecutor-0-0] ERROR org.apache.bookkeeper.common.util.SingleThreadExecutor - Error while running task: refCnt: 0, increment: 1"
"Apr 10, 2024 @ 16:06:49.893","io.netty.util.IllegalReferenceCountException: refCnt: 0, increment: 1"
"Apr 10, 2024 @ 16:06:49.893"," at io.netty.util.internal.ReferenceCountUpdater.retain(ReferenceCountUpdater.java:120) ~[io.netty-netty-common-4.1.100.Final.jar:4.1.100.Final]"
"Apr 10, 2024 @ 16:06:49.893"," at io.netty.util.AbstractReferenceCounted.retain(AbstractReferenceCounted.java:61) ~[io.netty-netty-common-4.1.100.Final.jar:4.1.100.Final]"
"Apr 10, 2024 @ 16:06:49.893"," at io.netty.util.internal.ReferenceCountUpdater.retain0(ReferenceCountUpdater.java:133) ~[io.netty-netty-common-4.1.100.Final.jar:4.1.100.Final]"
"Apr 10, 2024 @ 16:06:49.893"," at org.apache.bookkeeper.util.ByteBufList.retain(ByteBufList.java:61) ~[org.apache.bookkeeper-bookkeeper-server-4.16.3.jar:4.16.3]"
"Apr 10, 2024 @ 16:06:49.893"," at org.apache.bookkeeper.util.ByteBufList.retain(ByteBufList.java:281) ~[org.apache.bookkeeper-bookkeeper-server-4.16.3.jar:4.16.3]"
"Apr 10, 2024 @ 16:06:49.893"," at org.apache.bookkeeper.proto.BookieClientImpl.addEntry(BookieClientImpl.java:307) ~[org.apache.bookkeeper-bookkeeper-server-4.16.3.jar:4.16.3]"
"Apr 10, 2024 @ 16:06:49.893"," at org.apache.bookkeeper.client.PendingAddOp.sendWriteRequest(PendingAddOp.java:150) ~[org.apache.bookkeeper-bookkeeper-server-4.16.3.jar:4.16.3]"
"Apr 10, 2024 @ 16:06:49.893"," at org.apache.bookkeeper.client.PendingAddOp.initiate(PendingAddOp.java:258) ~[org.apache.bookkeeper-bookkeeper-server-4.16.3.jar:4.16.3]"
"Apr 10, 2024 @ 16:06:49.893"," at org.apache.bookkeeper.client.LedgerHandle.doAsyncAddEntry(LedgerHandle.java:1358) ~[org.apache.bookkeeper-bookkeeper-server-4.16.3.jar:4.16.3]"
"Apr 10, 2024 @ 16:06:49.893"," at org.apache.bookkeeper.client.LedgerHandle.asyncAddEntry(LedgerHandle.java:1056) ~[org.apache.bookkeeper-bookkeeper-server-4.16.3.jar:4.16.3]"
"Apr 10, 2024 @ 16:06:49.893"," at org.apache.bookkeeper.mledger.impl.OpAddEntry.initiate(OpAddEntry.java:144) ~[io.streamnative-managed-ledger-3.0.2.1.jar:3.0.2.1]"
"Apr 10, 2024 @ 16:06:49.893"," at org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.internalAsyncAddEntry(ManagedLedgerImpl.java:863) ~[io.streamnative-managed-ledger-3.0.2.1.jar:3.0.2.1]"
"Apr 10, 2024 @ 16:06:49.893"," at org.apache.bookkeeper.mledger.impl.ManagedLedgerImpl.lambda$asyncAddEntry$2(ManagedLedgerImpl.java:779) ~[io.streamnative-managed-ledger-3.0.2.1.jar:3.0.2.1]"
"Apr 10, 2024 @ 16:06:49.893"," at org.apache.bookkeeper.common.util.SingleThreadExecutor.safeRunTask(SingleThreadExecutor.java:137) ~[org.apache.bookkeeper-bookkeeper-common-4.16.3.jar:4.16.3]"
"Apr 10, 2024 @ 16:06:49.893"," at org.apache.bookkeeper.common.util.SingleThreadExecutor.run(SingleThreadExecutor.java:113) ~[org.apache.bookkeeper-bookkeeper-common-4.16.3.jar:4.16.3]"
"Apr 10, 2024 @ 16:06:49.893"," at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[io.netty-netty-common-4.1.100.Final.jar:4.1.100.Final]"
"Apr 10, 2024 @ 16:06:49.893"," at java.lang.Thread.run(Thread.java:840) ~[?:?]"

Explanation

Background: stacks of add entry

  1. BookieClientImpl.addEntry.
    a. Retain the ByteBuf before get PerChannelBookieClient. We call this ByteBuf as toSend in the following sections. toSend.recCnf is 2 now.
  2. Get PerChannelBookieClient
  3. ChannelReadyForAddEntryCallback.operationComplete
    a. PerChannelBookieClient.addEntry
    a-1. Build a new ByteBuf for request command. We call this ByteBuf new as request in the following sections.
    a-2. channle.writeAndFlush(request) or release the ByteBuf when channel is switching.
    b. Release the ByteBuf since it has been retained at step 1. toSend.recCnf should be 1 now.

(Highlight) the difference of V2 and V3 is only in the step "3-a-1. Build a new ByteBuf for request command"

1. The Step 3-a-1: V2 & Small payload

  • 3-a-1: Build a new ByteBuf for request command
    • request = toSend.retainedDuplicate().
  • 3-a-2: Release the ByteBuf
    • toSend.release()

Explanation: regarding this case, request and toSend share the same refCnf, it is fine to release a random one.

2. The Step 3-a-1: V2 & Large payload

  • 3-a-1: Build a new ByteBuf for request command
    • request = ByteBufList.clone(toSend).
  • 3-a-2: Release the ByteBuf
    • toSend.release()

Explanation: regarding this case, request and toSend are using different refCnf. Since the request can not be send out due to the channel switching, BK client should release request. It would cause a refCnf incorrect error if release an incorrect one. Highlight: since the internal ByteBufs of request and toSend are the same, it will not leading a memory leak even if it releases an incorrect one.

3. The Step 3-a-1: V3

  • 3-a-1: Build a new ByteBuf for request command
    • request: build a absolutely one new ByteBuf.
  • 3-a-2: Release the ByteBuf
    • toSend.release()

Explanation: regarding this case, request and toSend are using different refCnf. Since the request can not be send out due to the channel switching, BK client should release request. It would cause an refCnf incorrect error if releasing a incorrect one. Highlight: since the exactly ByteBuf of request and toSend are different, it will leading a memory leak if it releases an incorrect one.

Changes

Correct the code

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

horizonzy, hezhangjian, hangc0276, jiazhai, and ethqunzhong reacted with thumbs up emoji
All reactions
  • 👍 5 reactions
@poorbarcode
[fix] ByteBuf release/retain incorrect
7e82461
lhotari
lhotari reviewed Apr 16, 2024
View reviewed changes
Comment thread bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java Outdated
@@ -845,7 +845,7 @@ void addEntry(final long ledgerId, byte[] masterKey, final long entryId, Referen
// usually checked in writeAndFlush, but we have extra check
// because we need to release toSend.

@lhotari lhotari Apr 16, 2024

Copy link
Copy Markdown
Member

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.

update also the comment

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@poorbarcode poorbarcode Apr 16, 2024

Copy link
Copy Markdown
Contributor Author

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.

Done

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@lhotari

lhotari commented Apr 16, 2024

Copy link
Copy Markdown
Member

Please make the title more specific. for example "Fix ByteBuf release/retain in PerChannelBookClient" etc.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lhotari
lhotari reviewed Apr 16, 2024
View reviewed changes
Comment thread bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java
// because we need to release toSend.
errorOut(completionKey);
ReferenceCountUtil.release(toSend);
ReferenceCountUtil.release(request);

@lhotari lhotari Apr 16, 2024

Copy link
Copy Markdown
Member

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.

Does this also result in the correct behavior when useV2WireProtocol == false?

It doesn't look consistent how the V3 protocol is currently handled since there's no retained duplicate and the backing Netty ByteBuf isn't released.
In the case of V3 protocol, the body might consist of com.google.protobuf.NioByteString instances that wrap the Nio ByteBuffer instances backed by Netty ByteBuf instances which also control the lifecycle of the Nio ByteBuffer instances.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@lhotari lhotari Apr 16, 2024

Copy link
Copy Markdown
Member

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.

It looks like the concern about the NioBuffer lifecycle was raised by @sijie already in the original PR review: #791 (comment) .

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

poorbarcode reacted with thumbs up emoji
All reactions
  • 👍 1 reaction

@poorbarcode poorbarcode Apr 16, 2024

Copy link
Copy Markdown
Contributor Author

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.

Added release at these locations

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@poorbarcode poorbarcode Apr 16, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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.

Does this also result in the correct behavior when useV2WireProtocol == false?

No memory leak when useV2WireProtocol is false, but the error io.netty.util.IllegalReferenceCountException: refCnt: 0, increment: 1 described in the Motivation will also occur.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
horizonzy
horizonzy approved these changes Apr 16, 2024
View reviewed changes

@horizonzy horizonzy left a comment

Copy link
Copy Markdown
Member

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.

Nice catch. LGTM

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
hezhangjian
hezhangjian previously approved these changes Apr 16, 2024
View reviewed changes
@hezhangjian
hezhangjian dismissed their stale review April 16, 2024 06:17

may not retain in v3

@poorbarcode poorbarcode changed the title [fix] ByteBuf release/retain incorrect [fix] Fix ByteBuf release/retain in PerChannelBookClient Apr 16, 2024
@poorbarcode
improve the code comment
37deb38
@poorbarcode

poorbarcode commented Apr 16, 2024

Copy link
Copy Markdown
Contributor Author

Please make the title more specific. for example "Fix ByteBuf release/retain in PerChannelBookClient" etc.

Done

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@poorbarcode
fix other cases
64fc771
codelipenghui
codelipenghui approved these changes Apr 16, 2024
View reviewed changes
@poorbarcode
modify the code comment
7a06a97
zymap
zymap approved these changes Apr 16, 2024
View reviewed changes
zymap
zymap reviewed Apr 16, 2024
View reviewed changes
Comment thread bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java Outdated
} catch (Throwable e) {
LOG.warn("Operation {} failed", StringUtils.requestToString(request), e);
errorOut(key);
if (!calledWrite) {

@zymap zymap Apr 16, 2024

Copy link
Copy Markdown
Member

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.

This is a little weird. I think this catch wants to catch the channel is null for some reason. That means we may forget to release if the channel is null at line 1218. As I understand, if the request goes into the writeAndFlush, it should be handled well by Netty. So all the exceptions we get here, we can release the request.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@poorbarcode poorbarcode Apr 16, 2024

Copy link
Copy Markdown
Contributor Author

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.

Improved

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@zymap zymap assigned poorbarcode Apr 16, 2024
@zymap zymap added the type/bug label Apr 16, 2024
@zymap zymap added this to the 4.18.0 milestone Apr 16, 2024
@poorbarcode
improve the code
30c92df
hangc0276
hangc0276 approved these changes Apr 16, 2024
View reviewed changes

@hangc0276 hangc0276 left a comment

Copy link
Copy Markdown
Contributor

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.

Good job!

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
lhotari
lhotari reviewed Apr 16, 2024
View reviewed changes
Comment thread bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java
if (channel == null) {
LOG.warn("Operation {} failed: channel == null", StringUtils.requestToString(request));
errorOut(key);
ReferenceCountUtil.release(request);

@lhotari lhotari Apr 16, 2024

Copy link
Copy Markdown
Member

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 think it's the wrong thing to do generally in this method. I'll share a new PR where I explain an alternative approach that handles both the V3 protocol and the UnsafeByteOperations issue and the issue that was found.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

poorbarcode reacted with heart emoji
All reactions
  • ❤️ 1 reaction

@poorbarcode poorbarcode Apr 16, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

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.

To trace the context easier, I move the second comment here.

I think it's the wrong thing to do generally in this method. I'll share a new PR where I explain an alternative approach that handles both the V3 protocol and the UnsafeByteOperations issue and the issue that was found.

I don't think that the current changes in this PR are ok. I created #4293 to show what I think that should be done.

I added a section named Explanation in the Motivation, it explains that the current change is correct. Thanks for mentioning me and great suggestions ❤️

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lhotari reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
@lhotari lhotari mentioned this pull request Apr 16, 2024
fix: reference counting (retain/release) in PerChannelBookieClient #4293
Merged
lhotari
lhotari requested changes Apr 16, 2024
View reviewed changes

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

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 don't think that the current changes in this PR are ok. I created #4293 to show what I think that should be done.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

poorbarcode reacted with eyes emoji
All reactions
  • 👀 1 reaction
poorbarcode added 2 commits April 16, 2024 20:14
@poorbarcode
improve the test
02422ac
@poorbarcode
add description
475f259
@poorbarcode
poorbarcode requested a review from lhotari April 16, 2024 20:01
@poorbarcode

poorbarcode commented Apr 16, 2024 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor Author

I don't think that the current changes in this PR are ok. I created #4293 to show what I think that should be done.

Replied this comment here

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lhotari

lhotari commented Apr 17, 2024

Copy link
Copy Markdown
Member

Replied this comment here

Thanks @poorbarcode . Let's merge this PR first. I'll then rebase #4293 to fix the invalid handling of the wrapped nio ByteBuffer lifecycle. That's a remaining problem in this area. It seems that it's not only a problem with V3 protocol.

poorbarcode reacted with heart emoji
All reactions
  • ❤️ 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

lhotari
lhotari approved these changes Apr 17, 2024
View reviewed changes
@merlimat merlimat added the release/4.16.6 label Apr 17, 2024
@merlimat merlimat added the release/4.17.1 label Apr 17, 2024
@merlimat
merlimat merged commit 1694d67 into apache:master Apr 17, 2024
merlimat pushed a commit that referenced this pull request Apr 17, 2024
@poorbarcode @merlimat
[fix] Fix ByteBuf release/retain in PerChannelBookClient (#4289)
02a06c4
* [fix] ByteBuf release/retain incorrect

* improve the code comment

* fix other cases

* modify the code comment

* improve the code

* improve the test

* add description
merlimat pushed a commit that referenced this pull request Apr 17, 2024
@poorbarcode @merlimat
[fix] Fix ByteBuf release/retain in PerChannelBookClient (#4289)
a77458d
* [fix] ByteBuf release/retain incorrect

* improve the code comment

* fix other cases

* modify the code comment

* improve the code

* improve the test

* add description
@hangc0276 hangc0276 added cherry-picked/branch-4.16 cherry-picked/branch-4.17 labels Apr 22, 2024
@lhotari

lhotari commented Apr 22, 2024

Copy link
Copy Markdown
Member

Please review #4293. It addresses the remaining gaps in ByteBuf release/retain in PerChannelBookieClient that this PR
#4289 doesn't cover.

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

@lhotari lhotari mentioned this pull request Apr 26, 2024
[Bug] parseMessageMetadata error when broker entry metadata enable with high loading apache/pulsar#22601
Closed
2 of 3 tasks
hezhangjian pushed a commit that referenced this pull request May 24, 2024
@lhotari
fix: reference counting (retain/release) in PerChannelBookieClient (#…
0ef2f99
…4293)

### Motivation

This addresses the remaining gaps of #4289 in handling ByteBuf retain/release.
This PR will also address the concern about NioBuffer lifecycle brought up in the review of the original PR review: #791 (comment) .

This PR fixes several problems:
* ByteString buffer lifecycle in client, follows ByteBufList lifecycle
* ByteBufList lifecycle, moved to write promise
* Calling of write promises in AuthHandler which buffers messages while authentication is in progress. It was ignoring the promises.

### Changes

- add 2 callback parameters to writeAndFlush: cleanupActionFailedBeforeWrite and cleanupActionAfterWrite
  - use these callback actions for proper cleanup
- extract a utility class ByteStringUtil for wrapping ByteBufList or ByteBuf as concatenated zero copy ByteString
- properly handle releasing of ByteBufList in the write promise
- properly handle calling promises that are buffered while authentication is in progress
@lhotari lhotari mentioned this pull request May 24, 2024
[improve][misc][WIP] Detect "double release" and "use after release" bugs with recycled objects apache/pulsar#22110
Closed
1 of 4 tasks
hezhangjian pushed a commit that referenced this pull request May 25, 2024
@lhotari @hezhangjian
fix: reference counting (retain/release) in PerChannelBookieClient (#…
110d653
…4293)

### Motivation

This addresses the remaining gaps of #4289 in handling ByteBuf retain/release.
This PR will also address the concern about NioBuffer lifecycle brought up in the review of the original PR review: #791 (comment) .

This PR fixes several problems:
* ByteString buffer lifecycle in client, follows ByteBufList lifecycle
* ByteBufList lifecycle, moved to write promise
* Calling of write promises in AuthHandler which buffers messages while authentication is in progress. It was ignoring the promises.

### Changes

- add 2 callback parameters to writeAndFlush: cleanupActionFailedBeforeWrite and cleanupActionAfterWrite
  - use these callback actions for proper cleanup
- extract a utility class ByteStringUtil for wrapping ByteBufList or ByteBuf as concatenated zero copy ByteString
- properly handle releasing of ByteBufList in the write promise
- properly handle calling promises that are buffered while authentication is in progress

(cherry picked from commit 0ef2f99)
zhiheng123 pushed a commit to zhiheng123/bookkeeper that referenced this pull request May 26, 2024
@lhotari @zhiheng123
fix: reference counting (retain/release) in PerChannelBookieClient (a…
9183007
…pache#4293)

This addresses the remaining gaps of apache#4289 in handling ByteBuf retain/release.
This PR will also address the concern about NioBuffer lifecycle brought up in the review of the original PR review: apache#791 (comment) .

This PR fixes several problems:
* ByteString buffer lifecycle in client, follows ByteBufList lifecycle
* ByteBufList lifecycle, moved to write promise
* Calling of write promises in AuthHandler which buffers messages while authentication is in progress. It was ignoring the promises.

- add 2 callback parameters to writeAndFlush: cleanupActionFailedBeforeWrite and cleanupActionAfterWrite
  - use these callback actions for proper cleanup
- extract a utility class ByteStringUtil for wrapping ByteBufList or ByteBuf as concatenated zero copy ByteString
- properly handle releasing of ByteBufList in the write promise
- properly handle calling promises that are buffered while authentication is in progress
@zhiheng123 zhiheng123 mentioned this pull request May 26, 2024
[branch-4.16] fix: reference counting (retain/release) in PerChannelBookieClient #4392
Closed
@lhotari lhotari mentioned this pull request May 27, 2024
[fix][broker] Fix multiple transfer corruption issues when TLS is enabled apache/pulsar#22760
Closed
1 of 4 tasks
lhotari added a commit to lhotari/bookkeeper that referenced this pull request May 27, 2024
@lhotari
fix: reference counting (retain/release) in PerChannelBookieClient (a…
9000a3f
…pache#4293)

### Motivation

This addresses the remaining gaps of apache#4289 in handling ByteBuf retain/release.
This PR will also address the concern about NioBuffer lifecycle brought up in the review of the original PR review: apache#791 (comment) .

This PR fixes several problems:
* ByteString buffer lifecycle in client, follows ByteBufList lifecycle
* ByteBufList lifecycle, moved to write promise
* Calling of write promises in AuthHandler which buffers messages while authentication is in progress. It was ignoring the promises.

### Changes

- add 2 callback parameters to writeAndFlush: cleanupActionFailedBeforeWrite and cleanupActionAfterWrite
  - use these callback actions for proper cleanup
- extract a utility class ByteStringUtil for wrapping ByteBufList or ByteBuf as concatenated zero copy ByteString
- properly handle releasing of ByteBufList in the write promise
- properly handle calling promises that are buffered while authentication is in progress

(cherry picked from commit 0ef2f99)

# Conflicts:
#	bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java
hezhangjian pushed a commit that referenced this pull request May 27, 2024
@lhotari
fix: reference counting (retain/release) in PerChannelBookieClient (#…
29a74ac
…4293) (#4396)

### Motivation

This addresses the remaining gaps of #4289 in handling ByteBuf retain/release.
This PR will also address the concern about NioBuffer lifecycle brought up in the review of the original PR review: #791 (comment) .

This PR fixes several problems:
* ByteString buffer lifecycle in client, follows ByteBufList lifecycle
* ByteBufList lifecycle, moved to write promise
* Calling of write promises in AuthHandler which buffers messages while authentication is in progress. It was ignoring the promises.

### Changes

- add 2 callback parameters to writeAndFlush: cleanupActionFailedBeforeWrite and cleanupActionAfterWrite
  - use these callback actions for proper cleanup
- extract a utility class ByteStringUtil for wrapping ByteBufList or ByteBuf as concatenated zero copy ByteString
- properly handle releasing of ByteBufList in the write promise
- properly handle calling promises that are buffered while authentication is in progress

(cherry picked from commit 0ef2f99)

# Conflicts:
#	bookkeeper-server/src/main/java/org/apache/bookkeeper/proto/PerChannelBookieClient.java
@lhotari lhotari mentioned this pull request Jun 14, 2024
[Bug] Ledger can not recover with Digest Mismatch Error apache/pulsar#22906
Closed
2 of 3 tasks
Ghatage pushed a commit to sijie/bookkeeper that referenced this pull request Jul 12, 2024
@poorbarcode Anup Ghatage
[fix] Fix ByteBuf release/retain in PerChannelBookClient (apache#4289)
736eed6
* [fix] ByteBuf release/retain incorrect

* improve the code comment

* fix other cases

* modify the code comment

* improve the code

* improve the test

* add description
Ghatage pushed a commit to sijie/bookkeeper that referenced this pull request Jul 12, 2024
@lhotari Anup Ghatage
fix: reference counting (retain/release) in PerChannelBookieClient (a…
a28837b
…pache#4293)

### Motivation

This addresses the remaining gaps of apache#4289 in handling ByteBuf retain/release.
This PR will also address the concern about NioBuffer lifecycle brought up in the review of the original PR review: apache#791 (comment) .

This PR fixes several problems:
* ByteString buffer lifecycle in client, follows ByteBufList lifecycle
* ByteBufList lifecycle, moved to write promise
* Calling of write promises in AuthHandler which buffers messages while authentication is in progress. It was ignoring the promises.

### Changes

- add 2 callback parameters to writeAndFlush: cleanupActionFailedBeforeWrite and cleanupActionAfterWrite
  - use these callback actions for proper cleanup
- extract a utility class ByteStringUtil for wrapping ByteBufList or ByteBuf as concatenated zero copy ByteString
- properly handle releasing of ByteBufList in the write promise
- properly handle calling promises that are buffered while authentication is in progress
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@zymap zymap zymap approved these changes
@lhotari lhotari lhotari approved these changes
@hangc0276 hangc0276 hangc0276 approved these changes
@hezhangjian hezhangjian hezhangjian left review comments
+2 more reviewers
@codelipenghui codelipenghui codelipenghui approved these changes
@horizonzy horizonzy horizonzy approved these changes
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

@poorbarcode poorbarcode

Labels

cherry-picked/branch-4.16 cherry-picked/branch-4.17 release/4.16.6 release/4.17.1 type/bug

Projects

None yet

Milestone

4.18.0

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

8 participants

@poorbarcode @lhotari @hangc0276 @codelipenghui @hezhangjian @horizonzy @zymap @merlimat
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.