Skip to content

Commit 04d443b

Browse files
committed
Add NoOps to Lucene for failed delete ops (#33217)
Today we add a NoOp to Lucene and translog if we fail to process an indexing operation. However, we are only adding NoOps to translog for delete operations. In order to have a complete history in Lucene, we should add NoOps of failed delete operations to both Lucene and translog. Relates #29530
1 parent fd4397e commit 04d443b

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

server/src/main/java/org/elasticsearch/index/engine/InternalEngine.java

+5-3
Original file line numberDiff line numberDiff line change
@@ -898,7 +898,7 @@ public IndexResult index(Index index) throws IOException {
898898
if (indexResult.getResultType() == Result.Type.SUCCESS) {
899899
location = translog.add(new Translog.Index(index, indexResult));
900900
} else if (indexResult.getSeqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO) {
901-
// if we have document failure, record it as a no-op in the translog with the generated seq_no
901+
// if we have document failure, record it as a no-op in the translog and Lucene with the generated seq_no
902902
final NoOp noOp = new NoOp(indexResult.getSeqNo(), index.primaryTerm(), index.origin(),
903903
index.startTime(), indexResult.getFailure().toString());
904904
location = innerNoOp(noOp).getTranslogLocation();
@@ -1249,8 +1249,10 @@ public DeleteResult delete(Delete delete) throws IOException {
12491249
if (deleteResult.getResultType() == Result.Type.SUCCESS) {
12501250
location = translog.add(new Translog.Delete(delete, deleteResult));
12511251
} else if (deleteResult.getSeqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO) {
1252-
location = translog.add(new Translog.NoOp(deleteResult.getSeqNo(),
1253-
delete.primaryTerm(), deleteResult.getFailure().toString()));
1252+
// if we have document failure, record it as a no-op in the translog and Lucene with the generated seq_no
1253+
final NoOp noOp = new NoOp(deleteResult.getSeqNo(), delete.primaryTerm(), delete.origin(),
1254+
delete.startTime(), deleteResult.getFailure().toString());
1255+
location = innerNoOp(noOp).getTranslogLocation();
12541256
} else {
12551257
location = null;
12561258
}

server/src/test/java/org/elasticsearch/index/replication/IndexLevelReplicationTests.java

+6
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ public long softUpdateDocument(Term term, Iterable<? extends IndexableField> doc
407407
try (Translog.Snapshot snapshot = getTranslog(shard).newSnapshot()) {
408408
assertThat(snapshot, SnapshotMatchers.containsOperationsInAnyOrder(expectedTranslogOps));
409409
}
410+
try (Translog.Snapshot snapshot = shard.getHistoryOperations("test", 0)) {
411+
assertThat(snapshot, SnapshotMatchers.containsOperationsInAnyOrder(expectedTranslogOps));
412+
}
410413
}
411414
// unlike previous failures, these two failures replicated directly from the replication channel.
412415
indexResp = shards.index(new IndexRequest(index.getName(), "type", "any").source("{}", XContentType.JSON));
@@ -421,6 +424,9 @@ public long softUpdateDocument(Term term, Iterable<? extends IndexableField> doc
421424
try (Translog.Snapshot snapshot = getTranslog(shard).newSnapshot()) {
422425
assertThat(snapshot, SnapshotMatchers.containsOperationsInAnyOrder(expectedTranslogOps));
423426
}
427+
try (Translog.Snapshot snapshot = shard.getHistoryOperations("test", 0)) {
428+
assertThat(snapshot, SnapshotMatchers.containsOperationsInAnyOrder(expectedTranslogOps));
429+
}
424430
}
425431
shards.assertAllEqual(1);
426432
}

0 commit comments

Comments
 (0)