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 java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer when enabling topic metadata compression #11594

Conversation

codelipenghui
Copy link
Contributor

Motivation

Related to #11593. This PR is copying the bytes to the DirectBuf to get around issue #11593.

Verifying this change

Make the ManagedLedgerCompressionTest running on JDK8

…/nio/ByteBuffer when enabling topic metadata compression

Related to apache#11593. This PR is copy the bytes to the DirectBuf to get around the issue apache#11593.
@codelipenghui codelipenghui self-assigned this Aug 8, 2021
@codelipenghui codelipenghui added doc-not-needed Your PR changes do not impact docs type/bug The PR fixed a bug or issue reported a bug labels Aug 8, 2021
@codelipenghui codelipenghui added this to the 2.9.0 milestone Aug 8, 2021
@codelipenghui codelipenghui added release/2.8.1 release/blocker Indicate the PR or issue that should block the release until it gets resolved labels Aug 8, 2021
Copy link
Contributor

@gaoran10 gaoran10 left a comment

Choose a reason for hiding this comment

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

LGTM


byte[] byteArray = managedLedgerInfo.toByteArray();
uncompressedByteBuf = Unpooled.directBuffer(byteArray.length);
uncompressedByteBuf.writeBytes(byteArray);
Copy link
Contributor

Choose a reason for hiding this comment

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

Why we need a copy here?

Copy link
Contributor

Choose a reason for hiding this comment

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

Please add some comments to avoid being optimized for wrappers later by other developers

Copy link
Contributor

Choose a reason for hiding this comment

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

Unpooled.wrappedBuffer will create ByteBuf on heap and the hasMemoryAddress will return false.
Unpooled.directBuffer will create ByteBuf on PooledUnsafeDirectByteBuf, and the hasMemoryAddress will return false.

Copy link
Contributor

@hangc0276 hangc0276 left a comment

Choose a reason for hiding this comment

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

nice catch!
Please add notes to explain the reason to use Unpooled.directBuffer instead of Unpooled.wrappedBuffer


byte[] byteArray = managedLedgerInfo.toByteArray();
uncompressedByteBuf = Unpooled.directBuffer(byteArray.length);
uncompressedByteBuf.writeBytes(byteArray);
Copy link
Contributor

Choose a reason for hiding this comment

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

Unpooled.wrappedBuffer will create ByteBuf on heap and the hasMemoryAddress will return false.
Unpooled.directBuffer will create ByteBuf on PooledUnsafeDirectByteBuf, and the hasMemoryAddress will return false.

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

Can we ask for another release at airlift?

It looks like they had a bad compatibility issue on the release.

We do are not in a hurry as this feature is for 2.9

@codelipenghui
Copy link
Contributor Author

@eolivelli Yes, we can ask for a new airlift release, but the code is already in branch-2.8, we need to find a way to get around first to unblock 2.8.1 release.

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

Makes sense to me

@codelipenghui
Copy link
Contributor Author

The created issue airlift/aircompressor#133 for tracking fix from aircompressor

@codelipenghui codelipenghui merged commit 53c7c13 into apache:master Aug 9, 2021
@codelipenghui codelipenghui deleted the penghui/fix-topic-metadata-compression branch August 9, 2021 09:01
LeBW pushed a commit to LeBW/pulsar that referenced this pull request Aug 9, 2021
…/nio/ByteBuffer when enabling topic metadata compression (apache#11594)

### Motivation

Related to apache#11593. This PR is copying the bytes to the DirectBuf to get around issue apache#11593.

The created issue airlift/aircompressor#133 for tracking fix from [aircompressor](https://github.com/airlift/aircompressor)

### Verifying this change

Make the `ManagedLedgerCompressionTest` running on JDK8
hangc0276 pushed a commit that referenced this pull request Aug 12, 2021
…/nio/ByteBuffer when enabling topic metadata compression (#11594)

### Motivation

Related to #11593. This PR is copying the bytes to the DirectBuf to get around issue #11593.

The created issue airlift/aircompressor#133 for tracking fix from [aircompressor](https://github.com/airlift/aircompressor)

### Verifying this change

Make the `ManagedLedgerCompressionTest` running on JDK8

(cherry picked from commit 53c7c13)
@hangc0276 hangc0276 added the cherry-picked/branch-2.8 Archived: 2.8 is end of life label Aug 12, 2021
@eolivelli
Copy link
Contributor

eolivelli commented Aug 26, 2021

AirLift has been released
we can revert this patch and upgrade AirLift the problem is present in other code points #11789

hangc0276 added a commit that referenced this pull request Aug 26, 2021
…r upgrade to 0.20 (#11792)

### Motivation
Due to aircompressor 0.19 can't work with heap buffer on JDK1.8, so #11594 use copy data to direct buffer to avoid NoSuchMethodError exception. Now aircompressor released 0.20 and #11790 has upgrade the aircompressor version to 0.20 to fix this issue, we can revert #11594 to avoid copy data to direct buffer to improve performance.

### Modification
1. revert Fix java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer when enabling topic metadata compression #11594, but keep the tests.
hangc0276 added a commit that referenced this pull request Aug 26, 2021
…r upgrade to 0.20 (#11792)

### Motivation
Due to aircompressor 0.19 can't work with heap buffer on JDK1.8, so #11594 use copy data to direct buffer to avoid NoSuchMethodError exception. Now aircompressor released 0.20 and #11790 has upgrade the aircompressor version to 0.20 to fix this issue, we can revert #11594 to avoid copy data to direct buffer to improve performance.

### Modification
1. revert Fix java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer when enabling topic metadata compression #11594, but keep the tests.

(cherry picked from commit cc1b983)
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
…/nio/ByteBuffer when enabling topic metadata compression (apache#11594)

### Motivation

Related to apache#11593. This PR is copying the bytes to the DirectBuf to get around issue apache#11593.

The created issue airlift/aircompressor#133 for tracking fix from [aircompressor](https://github.com/airlift/aircompressor)

### Verifying this change

Make the `ManagedLedgerCompressionTest` running on JDK8
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
…r upgrade to 0.20 (apache#11792)

### Motivation
Due to aircompressor 0.19 can't work with heap buffer on JDK1.8, so apache#11594 use copy data to direct buffer to avoid NoSuchMethodError exception. Now aircompressor released 0.20 and apache#11790 has upgrade the aircompressor version to 0.20 to fix this issue, we can revert apache#11594 to avoid copy data to direct buffer to improve performance.

### Modification
1. revert Fix java.lang.NoSuchMethodError: java.nio.ByteBuffer.position(I)Ljava/nio/ByteBuffer when enabling topic metadata compression apache#11594, but keep the tests.
@codelipenghui codelipenghui restored the penghui/fix-topic-metadata-compression branch May 17, 2022 01:20
@codelipenghui codelipenghui deleted the penghui/fix-topic-metadata-compression branch May 17, 2022 01:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
cherry-picked/branch-2.8 Archived: 2.8 is end of life doc-not-needed Your PR changes do not impact docs release/blocker Indicate the PR or issue that should block the release until it gets resolved release/2.8.1 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

5 participants