Skip to content

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

Merged
merged 9 commits into from
May 8, 2025

Conversation

jordan-powers
Copy link
Contributor

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 java-native ByteBuffer instead of the elasticsearch BytesReference.
  3. Add the XContentString interface, with the Text class implement that interface.

@jordan-powers jordan-powers added >non-issue :Core/Infra/Core Core issues without another label v9.1.0 labels May 2, 2025
@jordan-powers jordan-powers requested a review from ldematte May 2, 2025 21:13
@jordan-powers jordan-powers self-assigned this May 2, 2025
@jordan-powers jordan-powers requested a review from a team as a code owner May 2, 2025 21:13
@elasticsearchmachine elasticsearchmachine added the Team:Core/Infra Meta label for core/infra team label May 2, 2025
@elasticsearchmachine
Copy link
Collaborator

Pinging @elastic/es-core-infra (Team:Core/Infra)

Copy link
Contributor

@ldematte ldematte left a 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

Copy link
Member

@rjernst rjernst left a 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.

@@ -419,7 +419,7 @@ public void writeText(Text text) throws IOException {
writeInt(spare.length());
write(spare.bytes(), 0, spare.length());
} else {
BytesReference bytes = text.bytes();
BytesReference bytes = BytesReference.fromByteBuffer(text.bytes());
Copy link
Member

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.

Copy link
Contributor Author

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!

Copy link
Contributor Author

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.

Copy link
Contributor

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

@jordan-powers jordan-powers added auto-backport Automatically create backport pull requests when merged v8.19.0 labels May 6, 2025
Copy link
Contributor

@ldematte ldematte left a comment

Choose a reason for hiding this comment

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

LGTM

@jordan-powers jordan-powers merged commit db0c3c7 into elastic:main May 8, 2025
17 checks passed
@jordan-powers jordan-powers deleted the move-text-class branch May 8, 2025 15:19
@elasticsearchmachine
Copy link
Collaborator

💔 Backport failed

Status Branch Result
8.19 Commit could not be cherrypicked due to conflicts

You can use sqren/backport to manually backport by running backport --upstream elastic/elasticsearch --pr 127666

@jordan-powers
Copy link
Contributor Author

💚 All backports created successfully

Status Branch Result
8.19

Questions ?

Please refer to the Backport tool documentation

elasticsearchmachine pushed a commit that referenced this pull request May 8, 2025
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
ywangd pushed a commit to ywangd/elasticsearch that referenced this pull request May 9, 2025
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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
auto-backport Automatically create backport pull requests when merged :Core/Infra/Core Core issues without another label >non-issue Team:Core/Infra Meta label for core/infra team v8.19.0 v9.1.0
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants