Skip to content

Commit c4acd96

Browse files
authored
Remove auto_expand_replicas setting during index clone in searchable_snapshot (#137111) (#137120)
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.
1 parent 50d34f4 commit c4acd96

File tree

3 files changed

+17
-2
lines changed

3 files changed

+17
-2
lines changed

docs/changelog/137111.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 137111
2+
summary: Remove `auto_expand_replicas` setting during index clone in `searchable_snapshot`
3+
area: ILM+SLM
4+
type: bug
5+
issues: []

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/SearchableSnapshotAction.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,11 @@ public class SearchableSnapshotAction implements LifecycleAction {
7878
indexName,
7979
state) -> state.forceMergeCloneIndexName() != null ? state.forceMergeCloneIndexName() : indexName;
8080

81-
private static final Settings CLONE_SETTINGS = Settings.builder().put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0).build();
81+
/** The cloned index should have 0 replicas, so we also need to remove the auto_expand_replicas setting if present. */
82+
private static final Settings CLONE_SETTINGS = Settings.builder()
83+
.put(IndexMetadata.SETTING_NUMBER_OF_REPLICAS, 0)
84+
.put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, (String) null)
85+
.build();
8286
private static final Function<IndexMetadata, Settings> CLONE_SETTINGS_SUPPLIER = indexMetadata -> CLONE_SETTINGS;
8387

8488
private static final ConstructingObjectParser<SearchableSnapshotAction, Void> PARSER = new ConstructingObjectParser<>(

x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/SearchableSnapshotActionIT.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1033,11 +1033,17 @@ private String prepareDataStreamWithDocs(String phase, int numberOfPrimaries, in
10331033
createSnapshotRepo(client(), snapshotRepo, randomBoolean());
10341034
createNewSingletonPolicy(client(), policy, phase, new SearchableSnapshotAction(snapshotRepo, true));
10351035

1036+
final var indexSettings = indexSettings(numberOfPrimaries, numberOfReplicas);
1037+
// Randomly enable auto-expand replicas to test that we remove the setting for the clone with 0 replicas.
1038+
if (numberOfReplicas > 0 && randomBoolean()) {
1039+
logger.info("--> enabling auto-expand replicas on backing index");
1040+
indexSettings.put(IndexMetadata.SETTING_AUTO_EXPAND_REPLICAS, "1-all");
1041+
}
10361042
createComposableTemplate(
10371043
client(),
10381044
randomAlphaOfLengthBetween(5, 10).toLowerCase(Locale.ROOT),
10391045
dataStream,
1040-
new Template(indexSettings(numberOfPrimaries, numberOfReplicas).build(), null, null)
1046+
new Template(indexSettings.build(), null, null)
10411047
);
10421048
for (int i = 0; i < randomIntBetween(5, 10); i++) {
10431049
indexDocument(client(), dataStream, true);

0 commit comments

Comments
 (0)