Skip to content

Commit 5f656d7

Browse files
committed
Fix NOOP bulk updates (#32819)
#31821 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 #32808
1 parent 28309b1 commit 5f656d7

File tree

3 files changed

+4
-3
lines changed

3 files changed

+4
-3
lines changed

server/src/main/java/org/elasticsearch/action/bulk/BulkPrimaryExecutionContext.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,10 +290,10 @@ public void markOperationAsExecuted(Engine.Result result) {
290290
/** finishes the execution of the current request, with the response that should be returned to the user */
291291
public void markAsCompleted(BulkItemResponse translatedResponse) {
292292
assertInvariants(ItemProcessingState.EXECUTED);
293-
assert executionResult == null || translatedResponse.getItemId() == executionResult.getItemId();
293+
assert executionResult != null && translatedResponse.getItemId() == executionResult.getItemId();
294294
assert translatedResponse.getItemId() == getCurrentItem().id();
295295

296-
if (translatedResponse.isFailed() == false && requestToExecute != getCurrent()) {
296+
if (translatedResponse.isFailed() == false && requestToExecute != null && requestToExecute != getCurrent()) {
297297
request.items()[currentIndex] = new BulkItemRequest(request.items()[currentIndex].id(), requestToExecute);
298298
}
299299
getCurrentItem().setPrimaryResponse(translatedResponse);

server/src/test/java/org/elasticsearch/action/IndicesRequestIT.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,6 @@ public void testUpdateDelete() {
284284
assertSameIndices(updateRequest, updateShardActions);
285285
}
286286

287-
@AwaitsFix(bugUrl = "https://github.com/elastic/elasticsearch/issues/32808")
288287
public void testBulk() {
289288
String[] bulkShardActions = new String[]{BulkAction.NAME + "[s][p]", BulkAction.NAME + "[s][r]"};
290289
interceptTransportActions(bulkShardActions);

server/src/test/java/org/elasticsearch/action/bulk/TransportShardBulkActionTests.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -472,6 +472,8 @@ public void testNoopUpdateRequest() throws Exception {
472472
assertThat(primaryResponse.getResponse(), equalTo(noopUpdateResponse));
473473
assertThat(primaryResponse.getResponse().getResult(),
474474
equalTo(DocWriteResponse.Result.NOOP));
475+
assertThat(bulkShardRequest.items().length, equalTo(1));
476+
assertEquals(primaryRequest, bulkShardRequest.items()[0]); // check that bulk item was not mutated
475477
assertThat(primaryResponse.getResponse().getSeqNo(), equalTo(SequenceNumbers.UNASSIGNED_SEQ_NO));
476478
}
477479

0 commit comments

Comments
 (0)