-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Introduce chunked version of ToXContentObject #92549
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
Introduce chunked version of ToXContentObject #92549
Conversation
Aligning how chunked and normal `ToXContent` work here and simplifying spots where it matters whether or not something is a fragment or not.
|
|
||
| @Override | ||
| public String toString() { | ||
| return "InternalScriptedMetric{" + reduceScript + "}"; |
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.
Had to do something here since the parent class's toString would call back to toXContent here which would throw if the instance hasn't yet been reduced.
| Map<String, DiskUsage> builder = new HashMap<>(numEntries); | ||
| for (int i = 0; i < numEntries; i++) { | ||
| String key = randomAlphaOfLength(32); | ||
| final int totalBytes = randomIntBetween(0, Integer.MAX_VALUE); |
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.
Had to fix this to use plausible values, otherwise toString would run into negative byte values which would throw illegal argument ex.
| }"""), xContent.utf8ToString()); | ||
| } | ||
|
|
||
| public void testToString() { |
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.
Moved to the parent now to deal with this for all the things we serialize
| @Override | ||
| public String toString() { | ||
| if (indexResponses.size() > 0) { | ||
| return "FieldCapabilitiesResponse{unmerged}"; |
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.
Not great but we shouldn't throw on toString ever so we have to have some breakout here for the un-merged case that doesn't allow toXContent.
|
Jenkins run elasticsearch-ci/part-3 |
|
@DaveCTurner I think this is the direction I'd like to go before we add more stuff around fragments. Seems easiest to just align with |
|
Pinging @elastic/es-core-infra (Team:Core/Infra) |
DaveCTurner
left a comment
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.
Makes sense, yes.
Why not replace org.elasticsearch.common.xcontent.ChunkedToXContent#wrapAsXContentObject with something that returns a ToXContent with the appropriate isFragment value?
|
@DaveCTurner ++ good point, that alley for even more simplifications. See f64ad95 :) |
DaveCTurner
left a comment
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 (one naming nit)
server/src/main/java/org/elasticsearch/common/xcontent/ChunkedToXContent.java
Outdated
Show resolved
Hide resolved
|
Thanks David! |
Aligning how chunked and normal
ToXContentwork here and simplifying spots where it matters whether or not something is a fragment or not.This fixes broken
toStringfor all kinds of classes and adds a test that makes sure the implementation at least produces a result and doesn't throw.