From 2ab926bcc8ad2ee0fa43aa84da8861bbfe9b3048 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?danielhuang=28=E9=BB=84=E5=8D=8E=29?= Date: Mon, 9 Nov 2020 14:19:28 +0800 Subject: [PATCH 1/8] Add low level log info to indicate read only index blocking operations. --- .../java/org/elasticsearch/index/engine/ReadOnlyEngine.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java b/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java index 4bc697e018ee4..6011115541e63 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java +++ b/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java @@ -346,6 +346,7 @@ public List segments(boolean verbose) { public void refresh(String source) { // we could allow refreshes if we want down the road the reader manager will then reflect changes to a rw-engine // opened side-by-side + logger.trace("Index[{}] is read only, do not support refresh.", shardId.getIndexName()); } @Override @@ -365,11 +366,13 @@ public boolean shouldPeriodicallyFlush() { @Override public void flush(boolean force, boolean waitIfOngoing) throws EngineException { // noop + logger.trace("Index[{}] is read only, do not support flush.", shardId.getIndexName()); } @Override public void forceMerge(boolean flush, int maxNumSegments, boolean onlyExpungeDeletes, boolean upgrade, boolean upgradeOnlyAncientSegments, String forceMergeUUID) { + logger.trace("Index[{}] is read only, do not support force merge.", shardId.getIndexName()); } @Override From f66faa116428dabc861c144a157169981b4898db Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?danielhuang=28=E9=BB=84=E5=8D=8E=29?= Date: Mon, 9 Nov 2020 23:33:20 +0800 Subject: [PATCH 2/8] Support index write block for force merge. --- .../admin/indices/forcemerge/TransportForceMergeAction.java | 2 +- .../java/org/elasticsearch/index/engine/ReadOnlyEngine.java | 3 --- 2 files changed, 1 insertion(+), 4 deletions(-) diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/TransportForceMergeAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/TransportForceMergeAction.java index 3affb65ffef95..accc60b1017dc 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/TransportForceMergeAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/TransportForceMergeAction.java @@ -94,6 +94,6 @@ protected ClusterBlockException checkGlobalBlock(ClusterState state, ForceMergeR @Override protected ClusterBlockException checkRequestBlock(ClusterState state, ForceMergeRequest request, String[] concreteIndices) { - return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, concreteIndices); + return state.blocks().indicesBlockedException(ClusterBlockLevel.WRITE, concreteIndices); } } diff --git a/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java b/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java index 6011115541e63..4bc697e018ee4 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java +++ b/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java @@ -346,7 +346,6 @@ public List segments(boolean verbose) { public void refresh(String source) { // we could allow refreshes if we want down the road the reader manager will then reflect changes to a rw-engine // opened side-by-side - logger.trace("Index[{}] is read only, do not support refresh.", shardId.getIndexName()); } @Override @@ -366,13 +365,11 @@ public boolean shouldPeriodicallyFlush() { @Override public void flush(boolean force, boolean waitIfOngoing) throws EngineException { // noop - logger.trace("Index[{}] is read only, do not support flush.", shardId.getIndexName()); } @Override public void forceMerge(boolean flush, int maxNumSegments, boolean onlyExpungeDeletes, boolean upgrade, boolean upgradeOnlyAncientSegments, String forceMergeUUID) { - logger.trace("Index[{}] is read only, do not support force merge.", shardId.getIndexName()); } @Override From 8ba6b7cbab55262c26c5db29e715c0a2ee53b4ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?danielhuang=28=E9=BB=84=E5=8D=8E=29?= Date: Mon, 9 Nov 2020 23:52:22 +0800 Subject: [PATCH 3/8] add test case. --- .../admin/indices/forcemerge/ForceMergeIT.java | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeIT.java b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeIT.java index 3eadd1bbe293d..07326946dada2 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeIT.java @@ -21,6 +21,7 @@ import org.elasticsearch.action.admin.indices.flush.FlushResponse; import org.elasticsearch.cluster.ClusterState; +import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; @@ -33,6 +34,9 @@ import java.io.IOException; +import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE; +import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; +import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; @@ -81,6 +85,20 @@ public void testForceMergeUUIDConsistent() throws IOException { assertThat(primaryForceMergeUUID, is(replicaForceMergeUUID)); } + public void testForceMergeBlockedByIndexReadOnly() { + internalCluster().startNodes(1); + final String index = "test-index"; + createIndex(index, + Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).build()); + ensureGreen(index); + assertAcked(client().admin().indices().prepareUpdateSettings("test-index") + .setSettings(Settings.builder().put(SETTING_BLOCKS_WRITE, true)).get()); + ClusterBlockException exception = + expectThrows(ClusterBlockException.class, () -> client().admin().indices().prepareForceMerge("test-index").get()); + assertThat(exception.getMessage(), containsString("index [test-index] blocked by: [FORBIDDEN/8/index write (api)]")); + } + private static String getForceMergeUUID(IndexShard indexShard) throws IOException { try (Engine.IndexCommitRef indexCommitRef = indexShard.acquireLastIndexCommit(true)) { return indexCommitRef.getIndexCommit().getUserData().get(Engine.FORCE_MERGE_UUID_KEY); From 40ee1ef3a9ecd019eca53b985a10310b1c579324 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?danielhuang=28=E9=BB=84=E5=8D=8E=29?= Date: Wed, 11 Nov 2020 10:38:07 +0800 Subject: [PATCH 4/8] unsupport force merge for frozen index --- .../action/admin/indices/forcemerge/ForceMergeIT.java | 6 +++--- .../admin/indices/forcemerge/TransportForceMergeAction.java | 2 +- .../java/org/elasticsearch/index/engine/ReadOnlyEngine.java | 2 ++ 3 files changed, 6 insertions(+), 4 deletions(-) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeIT.java b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeIT.java index 07326946dada2..d8a7db7e338ff 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeIT.java @@ -85,15 +85,15 @@ public void testForceMergeUUIDConsistent() throws IOException { assertThat(primaryForceMergeUUID, is(replicaForceMergeUUID)); } - public void testForceMergeBlockedByIndexReadOnly() { + public void testForceMergeShouldRejectedByFrozenIndex() { internalCluster().startNodes(1); final String index = "test-index"; createIndex(index, Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).build()); ensureGreen(index); - assertAcked(client().admin().indices().prepareUpdateSettings("test-index") - .setSettings(Settings.builder().put(SETTING_BLOCKS_WRITE, true)).get()); + /* assertAcked(client().freprepareUpdateSettings("test-index") + .setSettings(Settings.builder().put(SETTING_BLOCKS_WRITE, true)).get());*/ ClusterBlockException exception = expectThrows(ClusterBlockException.class, () -> client().admin().indices().prepareForceMerge("test-index").get()); assertThat(exception.getMessage(), containsString("index [test-index] blocked by: [FORBIDDEN/8/index write (api)]")); diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/TransportForceMergeAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/TransportForceMergeAction.java index accc60b1017dc..3affb65ffef95 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/TransportForceMergeAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/forcemerge/TransportForceMergeAction.java @@ -94,6 +94,6 @@ protected ClusterBlockException checkGlobalBlock(ClusterState state, ForceMergeR @Override protected ClusterBlockException checkRequestBlock(ClusterState state, ForceMergeRequest request, String[] concreteIndices) { - return state.blocks().indicesBlockedException(ClusterBlockLevel.WRITE, concreteIndices); + return state.blocks().indicesBlockedException(ClusterBlockLevel.METADATA_WRITE, concreteIndices); } } diff --git a/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java b/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java index 4bc697e018ee4..136df9ce7d91d 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java +++ b/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java @@ -370,6 +370,8 @@ public void flush(boolean force, boolean waitIfOngoing) throws EngineException { @Override public void forceMerge(boolean flush, int maxNumSegments, boolean onlyExpungeDeletes, boolean upgrade, boolean upgradeOnlyAncientSegments, String forceMergeUUID) { + assert false : "this should not be called"; + throw new UnsupportedOperationException("force merge is not supported on a read-only engine"); } @Override From a0c3470b7184c3e23c2fd4d90cb646c67b945732 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?danielhuang=28=E9=BB=84=E5=8D=8E=29?= Date: Fri, 13 Nov 2020 16:10:58 +0800 Subject: [PATCH 5/8] Reject force merge if it's going to do real merge. --- .../indices/forcemerge/ForceMergeIT.java | 3 +- .../index/engine/ReadOnlyEngine.java | 10 ++++-- .../index/engine/ReadOnlyEngineTests.java | 36 +++++++++++++++++++ 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeIT.java b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeIT.java index d8a7db7e338ff..46aba0a3fc5dc 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeIT.java @@ -92,8 +92,7 @@ public void testForceMergeShouldRejectedByFrozenIndex() { Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).build()); ensureGreen(index); - /* assertAcked(client().freprepareUpdateSettings("test-index") - .setSettings(Settings.builder().put(SETTING_BLOCKS_WRITE, true)).get());*/ + ClusterBlockException exception = expectThrows(ClusterBlockException.class, () -> client().admin().indices().prepareForceMerge("test-index").get()); assertThat(exception.getMessage(), containsString("index [test-index] blocked by: [FORBIDDEN/8/index write (api)]")); diff --git a/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java b/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java index ef8e1db81a18f..4b98901c28130 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java +++ b/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java @@ -370,8 +370,14 @@ public void flush(boolean force, boolean waitIfOngoing) throws EngineException { @Override public void forceMerge(boolean flush, int maxNumSegments, boolean onlyExpungeDeletes, boolean upgrade, boolean upgradeOnlyAncientSegments, String forceMergeUUID) { - assert false : "this should not be called"; - throw new UnsupportedOperationException("force merge is not supported on a read-only engine"); + if (maxNumSegments < lastCommittedSegmentInfos.size()) { + throw new UnsupportedOperationException("force merge is not supported on a read-only engine, " + + "target max number of segments[" + maxNumSegments + "], " + + "current number of segments[" + lastCommittedSegmentInfos.size() + "]."); + } else { + logger.debug("current number of segments[{}] is not greater than target max number of segments[{}].", + lastCommittedSegmentInfos.size(), maxNumSegments); + } } @Override diff --git a/server/src/test/java/org/elasticsearch/index/engine/ReadOnlyEngineTests.java b/server/src/test/java/org/elasticsearch/index/engine/ReadOnlyEngineTests.java index a9731539fc446..f03e5de3b0d97 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/ReadOnlyEngineTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/ReadOnlyEngineTests.java @@ -22,6 +22,7 @@ import org.apache.lucene.index.IndexReader; import org.apache.lucene.util.LuceneTestCase; import org.elasticsearch.Version; +import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader; import org.elasticsearch.core.internal.io.IOUtils; @@ -186,6 +187,41 @@ public void testVerifyShardBeforeIndexClosingIsNoOp() throws IOException { } } + public void testForceMergeOnReadOnlyEngine() throws IOException { + IOUtils.close(engine, store); + final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED); + try (Store store = createStore()) { + EngineConfig config = config(defaultSettings, store, createTempDir(), newMergePolicy(), null, null, globalCheckpoint::get); + int numDocs = scaledRandomIntBetween(10, 100); + int numSegments; + try (InternalEngine engine = createEngine(config)) { + for (int i = 0; i < numDocs; i++) { + ParsedDocument doc = testParsedDocument(Integer.toString(i), null, testDocument(), new BytesArray("{}"), null); + engine.index(new Engine.Index(newUid(doc), doc, i, primaryTerm.get(), 1, null, Engine.Operation.Origin.REPLICA, + System.nanoTime(), -1, false, SequenceNumbers.UNASSIGNED_SEQ_NO, 0)); + engine.flush(); + globalCheckpoint.set(i); + } + engine.syncTranslog(); + engine.flushAndClose(); + numSegments = engine.getLastCommittedSegmentInfos().size(); + assertTrue( numSegments > 1); + } + + try (ReadOnlyEngine readOnlyEngine = new ReadOnlyEngine(config, null , null, true, Function.identity(), true)) { + UnsupportedOperationException exception = expectThrows(UnsupportedOperationException.class, + () -> readOnlyEngine.forceMerge( + true, numSegments-1, false, false, false, UUIDs.randomBase64UUID())); + assertThat(exception.getMessage(), equalTo("force merge is not supported on a read-only engine, " + + "target max number of segments[" + (numSegments-1) + "], current number of segments[" + numSegments + "].")); + + readOnlyEngine.forceMerge(true, numSegments, false, false, false, UUIDs.randomBase64UUID()); + readOnlyEngine.forceMerge(true, numSegments+1, false, false, false, UUIDs.randomBase64UUID()); + assertEquals(readOnlyEngine.getLastCommittedSegmentInfos().size(), numSegments); + } + } + } + public void testRecoverFromTranslogAppliesNoOperations() throws IOException { IOUtils.close(engine, store); final AtomicLong globalCheckpoint = new AtomicLong(SequenceNumbers.NO_OPS_PERFORMED); From 88674810e132a10793a172318d03411417f572a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?danielhuang=28=E9=BB=84=E5=8D=8E=29?= Date: Fri, 13 Nov 2020 16:14:02 +0800 Subject: [PATCH 6/8] revert write block --- .../admin/indices/forcemerge/ForceMergeIT.java | 17 ----------------- 1 file changed, 17 deletions(-) diff --git a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeIT.java b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeIT.java index 46aba0a3fc5dc..3eadd1bbe293d 100644 --- a/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeIT.java +++ b/server/src/internalClusterTest/java/org/elasticsearch/action/admin/indices/forcemerge/ForceMergeIT.java @@ -21,7 +21,6 @@ import org.elasticsearch.action.admin.indices.flush.FlushResponse; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.block.ClusterBlockException; import org.elasticsearch.cluster.metadata.IndexMetadata; import org.elasticsearch.cluster.routing.IndexRoutingTable; import org.elasticsearch.cluster.routing.IndexShardRoutingTable; @@ -34,9 +33,6 @@ import java.io.IOException; -import static org.elasticsearch.cluster.metadata.IndexMetadata.SETTING_BLOCKS_WRITE; -import static org.elasticsearch.test.hamcrest.ElasticsearchAssertions.assertAcked; -import static org.hamcrest.CoreMatchers.containsString; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.nullValue; @@ -85,19 +81,6 @@ public void testForceMergeUUIDConsistent() throws IOException { assertThat(primaryForceMergeUUID, is(replicaForceMergeUUID)); } - public void testForceMergeShouldRejectedByFrozenIndex() { - internalCluster().startNodes(1); - final String index = "test-index"; - createIndex(index, - Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_SHARDS, 1) - .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).build()); - ensureGreen(index); - - ClusterBlockException exception = - expectThrows(ClusterBlockException.class, () -> client().admin().indices().prepareForceMerge("test-index").get()); - assertThat(exception.getMessage(), containsString("index [test-index] blocked by: [FORBIDDEN/8/index write (api)]")); - } - private static String getForceMergeUUID(IndexShard indexShard) throws IOException { try (Engine.IndexCommitRef indexCommitRef = indexShard.acquireLastIndexCommit(true)) { return indexCommitRef.getIndexCommit().getUserData().get(Engine.FORCE_MERGE_UUID_KEY); From f41b425901d8cd6bae810c012c0ee7764181e1c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?danielhuang=28=E9=BB=84=E5=8D=8E=29?= Date: Sat, 12 Dec 2020 21:17:17 +0800 Subject: [PATCH 7/8] Remove unsued version --- .../java/org/elasticsearch/index/engine/ReadOnlyEngineTests.java | 1 - 1 file changed, 1 deletion(-) diff --git a/server/src/test/java/org/elasticsearch/index/engine/ReadOnlyEngineTests.java b/server/src/test/java/org/elasticsearch/index/engine/ReadOnlyEngineTests.java index 280f60571f1ce..f8d2c45b52ab6 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/ReadOnlyEngineTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/ReadOnlyEngineTests.java @@ -21,7 +21,6 @@ import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.util.LuceneTestCase; -import org.elasticsearch.Version; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader; From 971790f978c9ae2de685b6b4243d33d6ef7cb8ed Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?danielhuang=28=E9=BB=84=E5=8D=8E=29?= Date: Wed, 16 Dec 2020 23:06:31 +0800 Subject: [PATCH 8/8] Support default max num segments. --- .../java/org/elasticsearch/index/engine/ReadOnlyEngine.java | 5 ++++- .../org/elasticsearch/index/engine/ReadOnlyEngineTests.java | 3 +++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java b/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java index d06d76de6ca16..6fb41e5da45bf 100644 --- a/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java +++ b/server/src/main/java/org/elasticsearch/index/engine/ReadOnlyEngine.java @@ -29,6 +29,7 @@ import org.apache.lucene.store.Directory; import org.apache.lucene.store.Lock; import org.elasticsearch.Version; +import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest; import org.elasticsearch.common.lucene.Lucene; import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader; import org.elasticsearch.common.util.concurrent.ReleasableLock; @@ -375,7 +376,9 @@ public void flush(boolean force, boolean waitIfOngoing) throws EngineException { @Override public void forceMerge(boolean flush, int maxNumSegments, boolean onlyExpungeDeletes, boolean upgrade, boolean upgradeOnlyAncientSegments, String forceMergeUUID) { - if (maxNumSegments < lastCommittedSegmentInfos.size()) { + if (maxNumSegments == ForceMergeRequest.Defaults.MAX_NUM_SEGMENTS) { + // noop + } else if (maxNumSegments < lastCommittedSegmentInfos.size()) { throw new UnsupportedOperationException("force merge is not supported on a read-only engine, " + "target max number of segments[" + maxNumSegments + "], " + "current number of segments[" + lastCommittedSegmentInfos.size() + "]."); diff --git a/server/src/test/java/org/elasticsearch/index/engine/ReadOnlyEngineTests.java b/server/src/test/java/org/elasticsearch/index/engine/ReadOnlyEngineTests.java index f8d2c45b52ab6..71d46db74d0a1 100644 --- a/server/src/test/java/org/elasticsearch/index/engine/ReadOnlyEngineTests.java +++ b/server/src/test/java/org/elasticsearch/index/engine/ReadOnlyEngineTests.java @@ -21,6 +21,7 @@ import org.apache.lucene.index.DirectoryReader; import org.apache.lucene.index.IndexReader; import org.apache.lucene.util.LuceneTestCase; +import org.elasticsearch.action.admin.indices.forcemerge.ForceMergeRequest; import org.elasticsearch.common.UUIDs; import org.elasticsearch.common.bytes.BytesArray; import org.elasticsearch.common.lucene.index.ElasticsearchDirectoryReader; @@ -214,6 +215,8 @@ public void testForceMergeOnReadOnlyEngine() throws IOException { assertThat(exception.getMessage(), equalTo("force merge is not supported on a read-only engine, " + "target max number of segments[" + (numSegments-1) + "], current number of segments[" + numSegments + "].")); + readOnlyEngine.forceMerge(true, ForceMergeRequest.Defaults.MAX_NUM_SEGMENTS, + false, false, false, UUIDs.randomBase64UUID()); readOnlyEngine.forceMerge(true, numSegments, false, false, false, UUIDs.randomBase64UUID()); readOnlyEngine.forceMerge(true, numSegments+1, false, false, false, UUIDs.randomBase64UUID()); assertEquals(readOnlyEngine.getLastCommittedSegmentInfos().size(), numSegments);