-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Stop Redundantly Serializing ShardId in BulkShardResponse #56094
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
Changes from all commits
3f7b8e6
c70fb36
9b083a7
478595f
8e2e096
328e078
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -40,6 +40,7 @@ | |
| import org.elasticsearch.common.xcontent.XContentParser; | ||
| import org.elasticsearch.index.mapper.MapperService; | ||
| import org.elasticsearch.index.seqno.SequenceNumbers; | ||
| import org.elasticsearch.index.shard.ShardId; | ||
| import org.elasticsearch.rest.RestStatus; | ||
|
|
||
| import java.io.IOException; | ||
|
|
@@ -359,6 +360,26 @@ public String toString() { | |
|
|
||
| BulkItemResponse() {} | ||
|
|
||
| BulkItemResponse(ShardId shardId, StreamInput in) throws IOException { | ||
| id = in.readVInt(); | ||
| opType = OpType.fromId(in.readByte()); | ||
|
|
||
| byte type = in.readByte(); | ||
| if (type == 0) { | ||
| response = new IndexResponse(shardId, in); | ||
| } else if (type == 1) { | ||
| response = new DeleteResponse(shardId, in); | ||
| } else if (type == 3) { // make 3 instead of 2, because 2 is already in use for 'no responses' | ||
| response = new UpdateResponse(shardId, in); | ||
| } else if (type != 2) { | ||
| throw new IllegalArgumentException("Unexpected type [" + type + "]"); | ||
| } | ||
DaveCTurner marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| if (in.readBoolean()) { | ||
| failure = new Failure(in); | ||
| } | ||
| } | ||
|
|
||
| BulkItemResponse(StreamInput in) throws IOException { | ||
| id = in.readVInt(); | ||
| opType = OpType.fromId(in.readByte()); | ||
|
|
@@ -370,6 +391,8 @@ public String toString() { | |
| response = new DeleteResponse(in); | ||
| } else if (type == 3) { // make 3 instead of 2, because 2 is already in use for 'no responses' | ||
| response = new UpdateResponse(in); | ||
| } else if (type != 2) { | ||
| throw new IllegalArgumentException("Unexpected type [" + type + "]"); | ||
| } | ||
|
|
||
| if (in.readBoolean()) { | ||
|
|
@@ -473,13 +496,7 @@ public void writeTo(StreamOutput out) throws IOException { | |
| if (response == null) { | ||
| out.writeByte((byte) 2); | ||
| } else { | ||
| if (response instanceof IndexResponse) { | ||
| out.writeByte((byte) 0); | ||
| } else if (response instanceof DeleteResponse) { | ||
| out.writeByte((byte) 1); | ||
| } else if (response instanceof UpdateResponse) { | ||
| out.writeByte((byte) 3); // make 3 instead of 2, because 2 is already in use for 'no responses' | ||
| } | ||
| writeResponseType(out); | ||
| response.writeTo(out); | ||
| } | ||
| if (failure == null) { | ||
|
|
@@ -489,4 +506,34 @@ public void writeTo(StreamOutput out) throws IOException { | |
| failure.writeTo(out); | ||
| } | ||
| } | ||
|
|
||
| public void writeThin(StreamOutput out) throws IOException { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems to leave
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We're still using it in
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ok |
||
| out.writeVInt(id); | ||
| out.writeByte(opType.getId()); | ||
|
|
||
| if (response == null) { | ||
| out.writeByte((byte) 2); | ||
| } else { | ||
| writeResponseType(out); | ||
| response.writeThin(out); | ||
| } | ||
| if (failure == null) { | ||
| out.writeBoolean(false); | ||
| } else { | ||
| out.writeBoolean(true); | ||
| failure.writeTo(out); | ||
| } | ||
| } | ||
|
|
||
| private void writeResponseType(StreamOutput out) throws IOException { | ||
| if (response instanceof IndexResponse) { | ||
| out.writeByte((byte) 0); | ||
| } else if (response instanceof DeleteResponse) { | ||
| out.writeByte((byte) 1); | ||
| } else if (response instanceof UpdateResponse) { | ||
| out.writeByte((byte) 3); // make 3 instead of 2, because 2 is already in use for 'no responses' | ||
| } else { | ||
| throw new IllegalStateException("Unexpected response type found [" + response.getClass() + "]"); | ||
| } | ||
| } | ||
| } | ||
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.
Can we assert anything about
in.getVersion()here? Not looked in detail, but I hope that this constructor will become obsolete after this change is complete.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 quite I think. We still have
TransportIndexActionwhich still uses and logically needs the full deserialization on anIndexResponseas far as I can tell and won't go away in8right?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.
Can't we get rid of that yet? It was deprecated over 3 years ago.
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.
Right in 8 we can ... opening a PR for that sec
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.
Urgh nevermind, technically we can remove this now but it's a far from trivial change to do so (we're still using that action all over the place in tests). I don't think I can do that in the short-term.
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, can we mention
IndexActionin this method's Javadoc so we keep track of the dependency.