-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Update Text class to use native java ByteBuffer #127666
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
Conversation
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
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.
Looks good, thanks for separating this, made it easier to focus the review.
I left a couple of comments
server/src/main/java/org/elasticsearch/common/io/stream/StreamInput.java
Outdated
Show resolved
Hide resolved
libs/x-content/src/main/java/org/elasticsearch/xcontent/Text.java
Outdated
Show resolved
Hide resolved
libs/x-content/src/main/java/org/elasticsearch/xcontent/XContentString.java
Outdated
Show resolved
Hide resolved
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 agree with Lorenzo's comments, and have one myself.
| write(spare.bytes(), 0, spare.length()); | ||
| } else { | ||
| BytesReference bytes = text.bytes(); | ||
| BytesReference bytes = BytesReference.fromByteBuffer(text.bytes()); |
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.
nit: we could support reading/writing ByteBuffer directly in StreamInput/Output so that conversions are not necessary here. That could allow optimizing in the ByteArrayStreamInput case to create a ByteBuffer that wraps the underlying byte array with appropriate offset/length, without needing to copy bytes to a new array.
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'll look into that, thanks!
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.
Ok, I'm thinking this might be a bigger change than we want to incorporate into this PR. It might be better to leave it as a follow-up, since the current implementation will still work, it'll just be less optimized.
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'm OK with leaving this in a follow-up, it will help with reviews too
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.
LGTM
💔 Backport failed
You can use sqren/backport to manually backport by running |
💚 All backports created successfully
Questions ?Please refer to the Backport tool documentation |
This PR is a precursor to #126492. It does three things: - Move org.elasticsearch.common.text.Text from :server to org.elasticsearch.xcontent.Text in :libs:x-content. - Refactor the Text class to use a java-native ByteBuffer instead of the elasticsearch BytesReference. - Add the XContentString interface, with the Text class implementing that interface. (cherry picked from commit db0c3c7) # Conflicts: # server/src/main/java/org/elasticsearch/search/fetch/subphase/highlight/DefaultHighlighter.java # server/src/test/java/org/elasticsearch/common/xcontent/BaseXContentTestCase.java # server/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlightFieldTests.java # test/framework/src/main/java/org/elasticsearch/search/SearchResponseUtils.java
This PR is a precursor to elastic#126492. It does three things: - Move org.elasticsearch.common.text.Text from :server to org.elasticsearch.xcontent.Text in :libs:x-content. - Refactor the Text class to use a java-native ByteBuffer instead of the elasticsearch BytesReference. - Add the XContentString interface, with the Text class implementing that interface.
This PR is a precursor to elastic#126492. It does three things: - Move org.elasticsearch.common.text.Text from :server to org.elasticsearch.xcontent.Text in :libs:x-content. - Refactor the Text class to use a java-native ByteBuffer instead of the elasticsearch BytesReference. - Add the XContentString interface, with the Text class implementing that interface.
After updating the Text class to use ByteBuffer in elastic#127666 we saw test failures where similar Text instances are shared between different threads and tested for equals(). The reason is that calling bytes() lazily materializes the internal ByteBuffer. That method is what the equals method calls on both instances it tests. Apparently this can leads to race conditions when instances are shared across threads. Making the internal `bytes` representation volatile fixes the problem. Closes elastic#128029
…)" This reverts commit db0c3c7.
…)" This reverts commit db0c3c7.
* Revert "Fix the Text class package change in example plugins (elastic#128316)" This reverts commit cc48648. * Revert "Update Text class to use native java ByteBuffer (elastic#127666)" This reverts commit db0c3c7.
* Revert "Fix the Text class package change in example plugins (elastic#128316)" This reverts commit cc48648. * Revert "Update Text class to use native java ByteBuffer (elastic#127666)" This reverts commit db0c3c7.
* Revert "Fix the Text class package change in example plugins (elastic#128316)" This reverts commit cc48648. * Revert "Update Text class to use native java ByteBuffer (elastic#127666)" This reverts commit db0c3c7.
* Revert changes to Text class (#128483) * Revert "Fix the Text class package change in example plugins (#128316)" This reverts commit cc48648. * Revert "Update Text class to use native java ByteBuffer (#127666)" This reverts commit db0c3c7. * [CI] Auto commit changes from spotless --------- Co-authored-by: elasticsearchmachine <[email protected]>
* Revert "Fix the Text class package change in example plugins (#128316)" This reverts commit cc48648. * Revert "Update Text class to use native java ByteBuffer (#127666)" This reverts commit db0c3c7. Co-authored-by: Lorenzo Dematté <[email protected]>
This PR is a precursor to #126492. It does three things: 1. Move org.elasticsearch.common.text.Text from :server to org.elasticsearch.xcontent.Text in :libs:x-content. 2. Refactor the Text class to use a new EncodedBytes record instead of the elasticsearch BytesReference. 3. Add the XContentString interface, with the Text class implementing that interface. These changes were originally implemented in #127666 and #128316, however they were reverted in #128484 due to problems caused by the mutable nature of java ByteBuffers. This is resolved by instead using a new immutable EncodedBytes record.
This PR is a precursor to #126492. It does three things: 1. Move org.elasticsearch.common.text.Text from :server to org.elasticsearch.xcontent.Text in :libs:x-content. 2. Refactor the Text class to use a new EncodedBytes record instead of the elasticsearch BytesReference. 3. Add the XContentString interface, with the Text class implementing that interface. These changes were originally implemented in #127666 and #128316, however they were reverted in #128484 due to problems caused by the mutable nature of java ByteBuffers. This is resolved by instead using a new immutable EncodedBytes record. (cherry picked from commit de40ac4) # Conflicts: # server/src/main/java/org/elasticsearch/search/fetch/subphase/highlight/DefaultHighlighter.java # server/src/test/java/org/elasticsearch/common/xcontent/BaseXContentTestCase.java # server/src/test/java/org/elasticsearch/search/fetch/subphase/highlight/HighlightFieldTests.java # test/framework/src/main/java/org/elasticsearch/search/SearchResponseUtils.java
This PR is a precursor to #126492.
It does three things:
org.elasticsearch.common.text.Textfrom:servertoorg.elasticsearch.xcontent.Textin:libs:x-content.Textclass to use a java-nativeByteBufferinstead of the elasticsearchBytesReference.XContentStringinterface, with theTextclass implement that interface.