From b1f4f3213792e4da3834ec49f168d9da40163764 Mon Sep 17 00:00:00 2001 From: Luca Cavanna Date: Mon, 23 Mar 2020 13:42:35 +0100 Subject: [PATCH] Async Search: replicas to auto expand from 0 to 1 (#53964) This way single node clusters that are green don't go yellow once async search is used, while all the others still have one replica. --- .../xpack/search/AsyncSearchIndexService.java | 6 +++--- .../search/AsyncSearchIndexServiceTests.java | 16 ++++++++++++++++ 2 files changed, 19 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/async-search/src/main/java/org/elasticsearch/xpack/search/AsyncSearchIndexService.java b/x-pack/plugin/async-search/src/main/java/org/elasticsearch/xpack/search/AsyncSearchIndexService.java index d1ec9fac7c06f..94d5e7797cad1 100644 --- a/x-pack/plugin/async-search/src/main/java/org/elasticsearch/xpack/search/AsyncSearchIndexService.java +++ b/x-pack/plugin/async-search/src/main/java/org/elasticsearch/xpack/search/AsyncSearchIndexService.java @@ -66,14 +66,14 @@ class AsyncSearchIndexService { public static final String EXPIRATION_TIME_FIELD = "expiration_time"; public static final String RESULT_FIELD = "result"; - public static Settings settings() { + private static Settings settings() { return Settings.builder() .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) - .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 1) + .put(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS, "0-1") .build(); } - public static XContentBuilder mappings() throws IOException { + private static XContentBuilder mappings() throws IOException { XContentBuilder builder = jsonBuilder() .startObject() .startObject(SINGLE_MAPPING_NAME) diff --git a/x-pack/plugin/async-search/src/test/java/org/elasticsearch/xpack/search/AsyncSearchIndexServiceTests.java b/x-pack/plugin/async-search/src/test/java/org/elasticsearch/xpack/search/AsyncSearchIndexServiceTests.java index afc7627b2e4df..c66c61f93439b 100644 --- a/x-pack/plugin/async-search/src/test/java/org/elasticsearch/xpack/search/AsyncSearchIndexServiceTests.java +++ b/x-pack/plugin/async-search/src/test/java/org/elasticsearch/xpack/search/AsyncSearchIndexServiceTests.java @@ -5,6 +5,10 @@ */ package org.elasticsearch.xpack.search; +import org.elasticsearch.action.admin.indices.get.GetIndexRequest; +import org.elasticsearch.action.admin.indices.get.GetIndexResponse; +import org.elasticsearch.action.support.PlainActionFuture; +import org.elasticsearch.cluster.metadata.IndexMetaData; import org.elasticsearch.cluster.service.ClusterService; import org.elasticsearch.common.settings.Settings; import org.elasticsearch.common.util.concurrent.ThreadContext; @@ -17,6 +21,7 @@ import java.io.IOException; import java.util.Collections; +import java.util.concurrent.ExecutionException; import static org.elasticsearch.xpack.search.AsyncSearchResponseTests.assertEqualResponses; import static org.elasticsearch.xpack.search.AsyncSearchResponseTests.randomAsyncSearchResponse; @@ -100,4 +105,15 @@ public void testEnsuredAuthenticatedUserIsSame() throws IOException { assertFalse(indexService.ensureAuthenticatedUserIsSame(original, runAsDiffType)); assertFalse(indexService.ensureAuthenticatedUserIsSame(threadContext.getHeaders(), runAsDiffType)); } + + public void testSettings() throws ExecutionException, InterruptedException { + PlainActionFuture future = PlainActionFuture.newFuture(); + indexService.createIndexIfNecessary(future); + future.get(); + GetIndexResponse getIndexResponse = client().admin().indices().getIndex( + new GetIndexRequest().indices(AsyncSearchIndexService.INDEX)).actionGet(); + Settings settings = getIndexResponse.getSettings().get(AsyncSearchIndexService.INDEX); + assertEquals("1", settings.get(IndexMetaData.SETTING_NUMBER_OF_SHARDS)); + assertEquals("0-1", settings.get(IndexMetaData.SETTING_AUTO_EXPAND_REPLICAS)); + } }