Skip to content

Commit 952c859

Browse files
committed
Test out of order delivery of append only index and retry with an intermediate delete
1 parent 27e157f commit 952c859

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

core/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2983,6 +2983,50 @@ public void testDoubleDeliveryPrimary() throws IOException {
29832983
}
29842984
}
29852985

2986+
public void testDoubleDeliveryReplicaAppendingAndDeleteOnly() throws IOException {
2987+
final ParsedDocument doc = testParsedDocument("1", null, testDocumentWithTextField(),
2988+
new BytesArray("{}".getBytes(Charset.defaultCharset())), null);
2989+
Engine.Index operation = appendOnlyReplica(doc, false, 1, randomIntBetween(0, 5));
2990+
Engine.Index retry = appendOnlyReplica(doc, true, 1, randomIntBetween(0, 5));
2991+
Engine.Delete delete = new Engine.Delete(operation.type(), operation.id(), operation.uid(),
2992+
Math.max(retry.seqNo(), operation.seqNo())+1, operation.primaryTerm(), operation.version()+1, operation.versionType(),
2993+
REPLICA, operation.startTime()+1);
2994+
// operations with a seq# equal or lower to the local checkpoint are not indexed to lucene
2995+
// and the version lookup is skipped
2996+
final boolean belowLckp = operation.seqNo() == 0 && retry.seqNo() == 0;
2997+
if (randomBoolean()) {
2998+
Engine.IndexResult indexResult = engine.index(operation);
2999+
assertFalse(engine.indexWriterHasDeletions());
3000+
assertEquals(0, engine.getNumVersionLookups());
3001+
assertNotNull(indexResult.getTranslogLocation());
3002+
engine.delete(delete);
3003+
assertEquals(1, engine.getNumVersionLookups());
3004+
assertTrue(engine.indexWriterHasDeletions());
3005+
Engine.IndexResult retryResult = engine.index(retry);
3006+
assertEquals(belowLckp ? 1 : 2, engine.getNumVersionLookups());
3007+
assertNotNull(retryResult.getTranslogLocation());
3008+
assertTrue(retryResult.getTranslogLocation().compareTo(indexResult.getTranslogLocation()) > 0);
3009+
} else {
3010+
Engine.IndexResult retryResult = engine.index(retry);
3011+
assertFalse(engine.indexWriterHasDeletions());
3012+
assertEquals(1, engine.getNumVersionLookups());
3013+
assertNotNull(retryResult.getTranslogLocation());
3014+
engine.delete(delete);
3015+
assertTrue(engine.indexWriterHasDeletions());
3016+
assertEquals(2, engine.getNumVersionLookups());
3017+
Engine.IndexResult indexResult = engine.index(operation);
3018+
assertEquals(belowLckp ? 2 : 3, engine.getNumVersionLookups());
3019+
assertNotNull(retryResult.getTranslogLocation());
3020+
assertTrue(retryResult.getTranslogLocation().compareTo(indexResult.getTranslogLocation()) < 0);
3021+
}
3022+
3023+
engine.refresh("test");
3024+
try (Engine.Searcher searcher = engine.acquireSearcher("test")) {
3025+
TopDocs topDocs = searcher.searcher().search(new MatchAllDocsQuery(), 10);
3026+
assertEquals(0, topDocs.totalHits);
3027+
}
3028+
}
3029+
29863030
public void testDoubleDeliveryReplicaAppendingOnly() throws IOException {
29873031
final ParsedDocument doc = testParsedDocument("1", null, testDocumentWithTextField(),
29883032
new BytesArray("{}".getBytes(Charset.defaultCharset())), null);

0 commit comments

Comments
 (0)