Skip to content

Commit 1326199

Browse files
authored
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 5632e31 commit 1326199

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
@@ -844,7 +844,7 @@ public IndexResult index(Index index) throws IOException {
844844
if (indexResult.getResultType() == Result.Type.SUCCESS) {
845845
location = translog.add(new Translog.Index(index, indexResult));
846846
} else if (indexResult.getSeqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO) {
847-
// if we have document failure, record it as a no-op in the translog with the generated seq_no
847+
// if we have document failure, record it as a no-op in the translog and Lucene with the generated seq_no
848848
final NoOp noOp = new NoOp(indexResult.getSeqNo(), index.primaryTerm(), index.origin(),
849849
index.startTime(), indexResult.getFailure().toString());
850850
location = innerNoOp(noOp).getTranslogLocation();
@@ -1182,8 +1182,10 @@ public DeleteResult delete(Delete delete) throws IOException {
11821182
if (deleteResult.getResultType() == Result.Type.SUCCESS) {
11831183
location = translog.add(new Translog.Delete(delete, deleteResult));
11841184
} else if (deleteResult.getSeqNo() != SequenceNumbers.UNASSIGNED_SEQ_NO) {
1185-
location = translog.add(new Translog.NoOp(deleteResult.getSeqNo(),
1186-
delete.primaryTerm(), deleteResult.getFailure().toString()));
1185+
// if we have document failure, record it as a no-op in the translog and Lucene with the generated seq_no
1186+
final NoOp noOp = new NoOp(deleteResult.getSeqNo(), delete.primaryTerm(), delete.origin(),
1187+
delete.startTime(), deleteResult.getFailure().toString());
1188+
location = innerNoOp(noOp).getTranslogLocation();
11871189
} else {
11881190
location = null;
11891191
}

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

+6
Original file line numberDiff line numberDiff line change
@@ -404,6 +404,9 @@ public long softUpdateDocument(Term term, Iterable<? extends IndexableField> doc
404404
try (Translog.Snapshot snapshot = getTranslog(shard).newSnapshot()) {
405405
assertThat(snapshot, SnapshotMatchers.containsOperationsInAnyOrder(expectedTranslogOps));
406406
}
407+
try (Translog.Snapshot snapshot = shard.getHistoryOperations("test", 0)) {
408+
assertThat(snapshot, SnapshotMatchers.containsOperationsInAnyOrder(expectedTranslogOps));
409+
}
407410
}
408411
// unlike previous failures, these two failures replicated directly from the replication channel.
409412
indexResp = shards.index(new IndexRequest(index.getName(), "type", "any").source("{}", XContentType.JSON));
@@ -418,6 +421,9 @@ public long softUpdateDocument(Term term, Iterable<? extends IndexableField> doc
418421
try (Translog.Snapshot snapshot = getTranslog(shard).newSnapshot()) {
419422
assertThat(snapshot, SnapshotMatchers.containsOperationsInAnyOrder(expectedTranslogOps));
420423
}
424+
try (Translog.Snapshot snapshot = shard.getHistoryOperations("test", 0)) {
425+
assertThat(snapshot, SnapshotMatchers.containsOperationsInAnyOrder(expectedTranslogOps));
426+
}
421427
}
422428
shards.assertAllEqual(1);
423429
}

0 commit comments

Comments
 (0)