-
Notifications
You must be signed in to change notification settings - Fork 24.9k
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
Name BulkItemResponse
ctors
#76439
Merged
Merged
Name BulkItemResponse
ctors
#76439
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -147,9 +147,9 @@ public static BulkItemResponse fromXContent(XContentParser parser, int id) throw | |
BulkItemResponse bulkItemResponse; | ||
if (exception != null) { | ||
Failure failure = new Failure(builder.getShardId().getIndexName(), builder.getId(), exception, status); | ||
bulkItemResponse = new BulkItemResponse(id, opType, failure); | ||
bulkItemResponse = BulkItemResponse.failure(id, opType, failure); | ||
} else { | ||
bulkItemResponse = new BulkItemResponse(id, opType, builder.build()); | ||
bulkItemResponse = BulkItemResponse.success(id, opType, builder.build()); | ||
} | ||
return bulkItemResponse; | ||
} | ||
|
@@ -341,66 +341,48 @@ public String toString() { | |
} | ||
} | ||
|
||
private int id; | ||
private final int id; | ||
|
||
private OpType opType; | ||
private final OpType opType; | ||
|
||
private DocWriteResponse response; | ||
private final DocWriteResponse response; | ||
|
||
private Failure failure; | ||
|
||
BulkItemResponse() {} | ||
private final Failure failure; | ||
|
||
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 + "]"); | ||
} | ||
|
||
if (in.readBoolean()) { | ||
failure = new Failure(in); | ||
} | ||
response = readResponse(shardId, in); | ||
failure = in.readBoolean() ? new Failure(in) : null; | ||
assertConsistent(); | ||
} | ||
|
||
BulkItemResponse(StreamInput in) throws IOException { | ||
id = in.readVInt(); | ||
opType = OpType.fromId(in.readByte()); | ||
|
||
byte type = in.readByte(); | ||
if (type == 0) { | ||
response = new IndexResponse(in); | ||
} else if (type == 1) { | ||
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()) { | ||
failure = new Failure(in); | ||
} | ||
response = readResponse(in); | ||
failure = in.readBoolean() ? new Failure(in) : null; | ||
assertConsistent(); | ||
} | ||
|
||
public BulkItemResponse(int id, OpType opType, DocWriteResponse response) { | ||
private BulkItemResponse(int id, OpType opType, DocWriteResponse response, Failure failure) { | ||
this.id = id; | ||
this.response = response; | ||
this.opType = opType; | ||
this.failure = failure; | ||
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. I think it makes sense to add an assertion here that either 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. 👍 |
||
assertConsistent(); | ||
} | ||
|
||
public BulkItemResponse(int id, OpType opType, Failure failure) { | ||
this.id = id; | ||
this.opType = opType; | ||
this.failure = failure; | ||
private void assertConsistent() { | ||
assert (response == null) ^ (failure == null) : "only one of response or failure may be set"; | ||
} | ||
|
||
public static BulkItemResponse success(int id, OpType opType, DocWriteResponse response) { | ||
return new BulkItemResponse(id, opType, response, null); | ||
} | ||
|
||
public static BulkItemResponse failure(int id, OpType opType, Failure failure) { | ||
return new BulkItemResponse(id, opType, null, failure); | ||
} | ||
|
||
/** | ||
|
@@ -528,4 +510,36 @@ private void writeResponseType(StreamOutput out) throws IOException { | |
throw new IllegalStateException("Unexpected response type found [" + response.getClass() + "]"); | ||
} | ||
} | ||
|
||
private static DocWriteResponse readResponse(ShardId shardId, StreamInput in) throws IOException { | ||
int type = in.readByte(); | ||
switch (type) { | ||
case 0: | ||
return new IndexResponse(shardId, in); | ||
case 1: | ||
return new DeleteResponse(shardId, in); | ||
case 2: | ||
return null; | ||
case 3: | ||
return new UpdateResponse(shardId, in); | ||
default: | ||
throw new IllegalArgumentException("Unexpected type [" + type + "]"); | ||
} | ||
} | ||
|
||
private static DocWriteResponse readResponse(StreamInput in) throws IOException { | ||
int type = in.readByte(); | ||
switch (type) { | ||
case 0: | ||
return new IndexResponse(in); | ||
case 1: | ||
return new DeleteResponse(in); | ||
case 2: | ||
return null; | ||
case 3: | ||
return new UpdateResponse(in); | ||
default: | ||
throw new IllegalArgumentException("Unexpected type [" + type + "]"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
This all started with me wanting to make these final to make them easier to reason about.