Skip to content

Commit 0887cbc

Browse files
committed
Fix testForceMergeWithSoftDeletesRetentionAndRecoverySource (#48766)
This test failure manifests the limitation of the recovery source merge policy explained in #41628. If we already merge down to a single segment then subsequent force merges will be noop although they can prune recovery source. We need to adjust this test until we have a fix for the merge policy. Relates #41628 Closes #48735
1 parent 3c20541 commit 0887cbc

File tree

1 file changed

+19
-11
lines changed

1 file changed

+19
-11
lines changed

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

+19-11
Original file line numberDiff line numberDiff line change
@@ -1720,18 +1720,26 @@ public void testForceMergeWithSoftDeletesRetentionAndRecoverySource() throws Exc
17201720
settings.put(IndexSettings.INDEX_SOFT_DELETES_RETENTION_OPERATIONS_SETTING.getKey(), 0);
17211721
indexSettings.updateIndexMetaData(IndexMetaData.builder(defaultSettings.getIndexMetaData()).settings(settings).build());
17221722
engine.onSettingsChanged();
1723-
// If the global checkpoint equals to the local checkpoint, the next force-merge will be a noop
1724-
// because all deleted documents are expunged in the previous force-merge already. We need to flush
1725-
// a new segment to make merge happen so that we can verify that all _recovery_source are pruned.
1726-
if (globalCheckpoint.get() == engine.getPersistedLocalCheckpoint() && liveDocs.isEmpty() == false) {
1727-
String deleteId = randomFrom(liveDocs);
1728-
engine.delete(new Engine.Delete("test", deleteId, newUid(deleteId), primaryTerm.get()));
1729-
liveDocsWithSource.remove(deleteId);
1730-
liveDocs.remove(deleteId);
1731-
engine.flush();
1723+
// If we already merged down to 1 segment, then the next force-merge will be a noop. We need to add an extra segment to make
1724+
// merges happen so we can verify that _recovery_source are pruned. See: https://github.com/elastic/elasticsearch/issues/41628.
1725+
final int numSegments;
1726+
try (Engine.Searcher searcher = engine.acquireSearcher("test", Engine.SearcherScope.INTERNAL)) {
1727+
numSegments = searcher.getDirectoryReader().leaves().size();
1728+
}
1729+
if (numSegments == 1) {
1730+
boolean useRecoverySource = randomBoolean() || omitSourceAllTheTime;
1731+
ParsedDocument doc = testParsedDocument("dummy", null, testDocument(), B_1, null, useRecoverySource);
1732+
engine.index(indexForDoc(doc));
1733+
if (useRecoverySource == false) {
1734+
liveDocsWithSource.add(doc.id());
1735+
}
1736+
engine.syncTranslog();
1737+
globalCheckpoint.set(engine.getPersistedLocalCheckpoint());
1738+
engine.flush(randomBoolean(), true);
1739+
} else {
1740+
globalCheckpoint.set(engine.getPersistedLocalCheckpoint());
1741+
engine.syncTranslog();
17321742
}
1733-
globalCheckpoint.set(engine.getPersistedLocalCheckpoint());
1734-
engine.syncTranslog();
17351743
engine.forceMerge(true, 1, false, false, false);
17361744
assertConsistentHistoryBetweenTranslogAndLuceneIndex(engine, mapperService);
17371745
assertThat(readAllOperationsInLucene(engine, mapperService), hasSize(liveDocsWithSource.size()));

0 commit comments

Comments
 (0)