From fd88ab8c75e580f76e5671cd89251e1147177656 Mon Sep 17 00:00:00 2001 From: Colin Goodheart-Smithe Date: Thu, 23 Aug 2018 16:36:57 +0100 Subject: [PATCH] Fixes shrink action to remove single ndoe allocation (#33091) This change fixes the shrink action so when the shrink is performed we remove the single node allocation fromt eh shard allocation filtering settings. Without this fix replicas cannot be allocated after we have performed the shrink and we cannot make progress with the rest of the shink aciton. This change also fixes a bug in the explain API where the maste node timeout was being set to null if it wasn't provided instead of using its default value causing a NPE --- .../elasticsearch/xpack/core/indexlifecycle/ShrinkStep.java | 2 ++ .../xpack/core/indexlifecycle/ShrinkStepTests.java | 1 + .../indexlifecycle/action/RestExplainLifecycleAction.java | 5 ++++- 3 files changed, 7 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkStep.java index 6f14c35c48a..16fbf7dbc31 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkStep.java @@ -56,6 +56,8 @@ public class ShrinkStep extends AsyncActionStep { .put(LifecycleSettings.LIFECYCLE_PHASE, phase) .put(LifecycleSettings.LIFECYCLE_ACTION, action) .put(LifecycleSettings.LIFECYCLE_STEP, ShrunkenIndexCheckStep.NAME) // skip source-index steps + .put(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "_name", (String) null) // need to remove the single shard + // allocation so replicas can be allocated .build(); String shrunkenIndexName = shrunkIndexPrefix + indexMetaData.getIndex().getName(); ResizeRequest resizeRequest = new ResizeRequest(shrunkenIndexName, indexMetaData.getIndex().getName()); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkStepTests.java index 51ef2ea8d9e..c66a29cb8b3 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/ShrinkStepTests.java @@ -119,6 +119,7 @@ public class ShrinkStepTests extends AbstractStepTestCase { .put(LifecycleSettings.LIFECYCLE_PHASE, step.getKey().getPhase()) .put(LifecycleSettings.LIFECYCLE_ACTION, step.getKey().getAction()) .put(LifecycleSettings.LIFECYCLE_STEP, ShrunkenIndexCheckStep.NAME) + .put(IndexMetaData.INDEX_ROUTING_REQUIRE_GROUP_SETTING.getKey() + "_name", (String) null) .build())); assertThat(request.getTargetIndexRequest().settings() .getAsInt(IndexMetaData.SETTING_NUMBER_OF_SHARDS, -1), equalTo(step.getNumberOfShards())); diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestExplainLifecycleAction.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestExplainLifecycleAction.java index 3b3981fc38b..044a9f16d29 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestExplainLifecycleAction.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/indexlifecycle/action/RestExplainLifecycleAction.java @@ -37,7 +37,10 @@ public class RestExplainLifecycleAction extends BaseRestHandler { ExplainLifecycleRequest explainLifecycleRequest = new ExplainLifecycleRequest(); explainLifecycleRequest.indices(indexes); explainLifecycleRequest.indicesOptions(IndicesOptions.fromRequest(restRequest, IndicesOptions.strictExpandOpen())); - explainLifecycleRequest.masterNodeTimeout(restRequest.param("master_timeout")); + String masterNodeTimeout = restRequest.param("master_timeout"); + if (masterNodeTimeout != null) { + explainLifecycleRequest.masterNodeTimeout(masterNodeTimeout); + } return channel -> client.execute(ExplainLifecycleAction.INSTANCE, explainLifecycleRequest, new RestToXContentListener<>(channel)); }