Skip to content

Commit d396c7e

Browse files
author
Ali Beyad
committed
Adds sequence number and checkpoint testing for document deletion
intertwined with document indexing.
1 parent 1d63334 commit d396c7e

File tree

1 file changed

+33
-12
lines changed

1 file changed

+33
-12
lines changed

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

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@
124124
import java.util.List;
125125
import java.util.Locale;
126126
import java.util.Map;
127+
import java.util.Set;
127128
import java.util.concurrent.BrokenBarrierException;
128129
import java.util.concurrent.CountDownLatch;
129130
import java.util.concurrent.CyclicBarrier;
@@ -1625,10 +1626,10 @@ public void testIndexWriterInfoStream() throws IllegalAccessException {
16251626
}
16261627

16271628
public void testSeqNoAndCheckpoints() throws IOException {
1628-
// nocommit: does not test deletes
16291629
final int opCount = randomIntBetween(1, 256);
16301630
long primarySeqNo = SequenceNumbersService.NO_OPS_PERFORMED;
16311631
final String[] ids = new String[]{"1", "2", "3"};
1632+
final Set<String> indexedIds = new HashSet<>();
16321633
long localCheckpoint = SequenceNumbersService.NO_OPS_PERFORMED;
16331634
long replicaLocalCheckpoint = SequenceNumbersService.NO_OPS_PERFORMED;
16341635
long globalCheckpoint = SequenceNumbersService.UNASSIGNED_SEQ_NO;
@@ -1641,18 +1642,38 @@ public void testSeqNoAndCheckpoints() throws IOException {
16411642
.seqNoService()
16421643
.updateAllocationIdsFromMaster(new HashSet<>(Arrays.asList("primary", "replica")), Collections.emptySet());
16431644
for (int op = 0; op < opCount; op++) {
1644-
final String id = randomFrom(ids);
1645-
ParsedDocument doc = testParsedDocument("test#" + id, id, "test", null, -1, -1, testDocumentWithTextField(), SOURCE, null);
1646-
final Engine.Index index = new Engine.Index(newUid("test#" + id), doc,
1647-
SequenceNumbersService.UNASSIGNED_SEQ_NO,
1648-
rarely() ? 100 : Versions.MATCH_ANY, VersionType.INTERNAL,
1649-
PRIMARY, 0, -1, false);
1645+
final String id;
16501646
boolean versionConflict = false;
1651-
try {
1652-
initialEngine.index(index);
1647+
// mostly index, sometimes delete
1648+
if (rarely() && indexedIds.isEmpty() == false) {
1649+
// we have some docs indexed, so delete one of them
1650+
id = randomFrom(indexedIds);
1651+
final Engine.Delete delete = new Engine.Delete(
1652+
"test", id, newUid("test#" + id), SequenceNumbersService.UNASSIGNED_SEQ_NO,
1653+
rarely() ? 100 : Versions.MATCH_ANY, VersionType.INTERNAL, PRIMARY, 0, false);
1654+
try {
1655+
initialEngine.delete(delete);
1656+
indexedIds.remove(id);
1657+
} catch (VersionConflictEngineException e) {
1658+
versionConflict = true;
1659+
}
1660+
} else {
1661+
// index a document
1662+
id = randomFrom(ids);
1663+
ParsedDocument doc = testParsedDocument("test#" + id, id, "test", null, -1, -1, testDocumentWithTextField(), SOURCE, null);
1664+
final Engine.Index index = new Engine.Index(newUid("test#" + id), doc,
1665+
SequenceNumbersService.UNASSIGNED_SEQ_NO,
1666+
rarely() ? 100 : Versions.MATCH_ANY, VersionType.INTERNAL,
1667+
PRIMARY, 0, -1, false);
1668+
try {
1669+
initialEngine.index(index);
1670+
indexedIds.add(id);
1671+
} catch (VersionConflictEngineException e) {
1672+
versionConflict = true;
1673+
}
1674+
}
1675+
if (versionConflict == false) {
16531676
primarySeqNo++;
1654-
} catch (VersionConflictEngineException e) {
1655-
versionConflict = true;
16561677
}
16571678

16581679
replicaLocalCheckpoint =
@@ -1662,7 +1683,7 @@ public void testSeqNoAndCheckpoints() throws IOException {
16621683

16631684
// make sure the max seq no in the latest commit hasn't advanced due to more documents having been added;
16641685
// the first time the commit data iterable gets an iterator, the max seq no from that point in time should
1665-
// remain from any subsequent call to IndexWriter#getLiveCommitData unless the commit data is overridden by a
1686+
// remain from any subsequent call to IndexWriter#getLiveCommitData unless the commit data is overwritten by a
16661687
// subsequent call to IndexWriter#setLiveCommitData.
16671688
if (initialEngine.seqNoService().getMaxSeqNo() != SequenceNumbersService.NO_OPS_PERFORMED) {
16681689
assertThat(

0 commit comments

Comments
 (0)