From ab7e6961083fcaa97df77f71eab3d892515910e8 Mon Sep 17 00:00:00 2001 From: Nhat Nguyen Date: Fri, 7 Sep 2018 12:58:00 -0400 Subject: [PATCH] TEST: Ensure merge triggered in _source retention test (#33487) We invoke force merge twice in the test to verify that recovery sources are pruned when the global checkpoint advanced. However, if the global checkpoint equals to the local checkpoint in the first force-merge, the second force-merge will be a noop because all deleted docs are expunged in the first merge already. We need to flush a new segment to make merge happen so we can verify that all recovery sources are pruned. --- .../index/engine/InternalEngineTests.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java index 6d9cdd0f225..a26fd72468b 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/InternalEngineTests.java @@ -1521,6 +1521,16 @@ public class InternalEngineTests extends EngineTestCase { settings.put(IndexSettings.INDEX_SOFT_DELETES_RETENTION_OPERATIONS_SETTING.getKey(), 0); indexSettings.updateIndexMetaData(IndexMetaData.builder(defaultSettings.getIndexMetaData()).settings(settings).build()); engine.onSettingsChanged(); + // If the global checkpoint equals to the local checkpoint, the next force-merge will be a noop + // because all deleted documents are expunged in the previous force-merge already. We need to flush + // a new segment to make merge happen so that we can verify that all _recovery_source are pruned. + if (globalCheckpoint.get() == engine.getLocalCheckpoint() && liveDocs.isEmpty() == false) { + String deleteId = randomFrom(liveDocs); + engine.delete(new Engine.Delete("test", deleteId, newUid(deleteId), primaryTerm.get())); + liveDocsWithSource.remove(deleteId); + liveDocs.remove(deleteId); + engine.flush(); + } globalCheckpoint.set(engine.getLocalCheckpoint()); engine.syncTranslog(); engine.forceMerge(true, 1, false, false, false);