From f2e7e7f5b2a25f2c5ea543c035d85a8aece91ad9 Mon Sep 17 00:00:00 2001 From: Niels Bauman Date: Fri, 24 Oct 2025 16:49:04 +0200 Subject: [PATCH 1/2] Remove `auto_expand_replicas` setting during index clone in `searchable_snapshot` In #133954, we modified the `searchable_snapshot` ILM action to clone the index with 0 replicas before performing the force-merge. We didn't take the `index.auto_expand_replicas` setting into account, which could result in the clone having indices after all. That's harmless, as it merely nullifies the optimization of that PR, but we should remove the setting to ensure we achieve the intended optimizations. --- .../xpack/core/ilm/SearchableSnapshotAction.java | 6 +++++- .../xpack/ilm/actions/SearchableSnapshotActionIT.java | 8 +++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SearchableSnapshotAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SearchableSnapshotAction.java index d3c7b0cb52730..61d26dfa4af09 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SearchableSnapshotAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SearchableSnapshotAction.java @@ -78,7 +78,11 @@ public class SearchableSnapshotAction implements LifecycleAction { indexName, state) -> state.forceMergeCloneIndexName() != null ? state.forceMergeCloneIndexName() : indexName; - private static final Settings CLONE_SETTINGS = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).build(); + /** The cloned index should have 0 replicas, so we also need to remove the auto_expand_replicas setting if present. */ + private static final Settings CLONE_SETTINGS = Settings.builder() + .put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0) + .put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, (String) null) + .build(); private static final Function CLONE_SETTINGS_SUPPLIER = indexMetadata -> CLONE_SETTINGS; private static final ConstructingObjectParser PARSER = new ConstructingObjectParser<>( diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/SearchableSnapshotActionIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/SearchableSnapshotActionIT.java index 63108dd3cbcf6..df04dbc6a8a6c 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/SearchableSnapshotActionIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/SearchableSnapshotActionIT.java @@ -1033,11 +1033,17 @@ private String prepareDataStreamWithDocs(String phase, int numberOfPrimaries, in createSnapshotRepo(client(), snapshotRepo, randomBoolean()); createNewSingletonPolicy(client(), policy, phase, new SearchableSnapshotAction(snapshotRepo, true)); + final var indexSettings = indexSettings(numberOfPrimaries, numberOfReplicas); + // Randomly enable auto-expand replicas to test that we remove the setting for the clone with 0 replicas. + if (numberOfReplicas > 0 && randomBoolean()) { + logger.info("--> enabling auto-expand replicas on backing index"); + indexSettings.put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "1-all"); + } createComposableTemplate( client(), randomAlphaOfLengthBetween(5, 10).toLowerCase(Locale.ROOT), dataStream, - new Template(indexSettings(numberOfPrimaries, numberOfReplicas).build(), null, null) + new Template(indexSettings.build(), null, null) ); for (int i = 0; i < randomIntBetween(5, 10); i++) { indexDocument(client(), dataStream, true); From dc1e9d88f328e355162817d6204a1e14e4d90c7f Mon Sep 17 00:00:00 2001 From: Niels Bauman <33722607+nielsbauman@users.noreply.github.com> Date: Fri, 24 Oct 2025 16:51:55 +0200 Subject: [PATCH 2/2] Update docs/changelog/137111.yaml --- docs/changelog/137111.yaml | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 docs/changelog/137111.yaml diff --git a/docs/changelog/137111.yaml b/docs/changelog/137111.yaml new file mode 100644 index 0000000000000..3122a54e673ed --- /dev/null +++ b/docs/changelog/137111.yaml @@ -0,0 +1,5 @@ +pr: 137111 +summary: Remove `auto_expand_replicas` setting during index clone in `searchable_snapshot` +area: ILM+SLM +type: bug +issues: []