Fix NOOP bulk updates ()

 introduced an unreleased bug where NOOP updates were incorrectly mutating the bulk
shard request, inserting null item to be replicated, which would result in NullPointerExceptions when
serializing the request to be shipped to the replicas.

Closes 
This commit is contained in:
Yannick Welsch 2018-08-14 08:20:35 +02:00 committed by GitHub
parent 10fddb62ee
commit a8bfa466b2
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 4 additions and 3 deletions
server/src
main/java/org/elasticsearch/action/bulk
test/java/org/elasticsearch/action

@ -290,10 +290,10 @@ class BulkPrimaryExecutionContext {
/** finishes the execution of the current request, with the response that should be returned to the user */
public void markAsCompleted(BulkItemResponse translatedResponse) {
assertInvariants(ItemProcessingState.EXECUTED);
assert executionResult == null || translatedResponse.getItemId() == executionResult.getItemId();
assert executionResult != null && translatedResponse.getItemId() == executionResult.getItemId();
assert translatedResponse.getItemId() == getCurrentItem().id();
if (translatedResponse.isFailed() == false && requestToExecute != getCurrent()) {
if (translatedResponse.isFailed() == false && requestToExecute != null && requestToExecute != getCurrent()) {
request.items()[currentIndex] = new BulkItemRequest(request.items()[currentIndex].id(), requestToExecute);
}
getCurrentItem().setPrimaryResponse(translatedResponse);

@ -284,7 +284,6 @@ public class IndicesRequestIT extends ESIntegTestCase {
assertSameIndices(updateRequest, updateShardActions);
}
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/32808")
public void testBulk() {
String[] bulkShardActions = new String[]{BulkAction.NAME + "[s][p]", BulkAction.NAME + "[s][r]"};
interceptTransportActions(bulkShardActions);

@ -472,6 +472,8 @@ public class TransportShardBulkActionTests extends IndexShardTestCase {
assertThat(primaryResponse.getResponse(), equalTo(noopUpdateResponse));
assertThat(primaryResponse.getResponse().getResult(),
equalTo(DocWriteResponse.Result.NOOP));
assertThat(bulkShardRequest.items().length, equalTo(1));
assertEquals(primaryRequest, bulkShardRequest.items()[0]); // check that bulk item was not mutated
assertThat(primaryResponse.getResponse().getSeqNo(), equalTo(SequenceNumbers.UNASSIGNED_SEQ_NO));
}