From 66413e4065e1e90b590e643b7cd38d189171a54a Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Tue, 31 Jul 2018 12:21:49 -0600 Subject: [PATCH 1/2] Make index.lifecycle.name setting internal This commit makes the `index.lifecycle.name` setting internal an index, this means that the policy can only be set on the index creation, or with the specialized `RestSetIndexLifecyclePolicy` action. Relates to #29823 --- .../indexlifecycle/LifecycleSettings.java | 2 +- .../TimeSeriesLifecycleActionsIT.java | 17 ++++++---- .../test/index_lifecycle/10_basic.yml | 33 +++++++++++++++++-- 3 files changed, 42 insertions(+), 10 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/LifecycleSettings.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/LifecycleSettings.java index d2f386eafeb8f..5cc7d8c9da67b 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/LifecycleSettings.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/LifecycleSettings.java @@ -30,7 +30,7 @@ public class LifecycleSettings { public static final Setting LIFECYCLE_POLL_INTERVAL_SETTING = Setting.positiveTimeSetting(LIFECYCLE_POLL_INTERVAL, TimeValue.timeValueSeconds(3), Setting.Property.Dynamic, Setting.Property.NodeScope); public static final Setting LIFECYCLE_NAME_SETTING = Setting.simpleString(LIFECYCLE_NAME, - Setting.Property.Dynamic, Setting.Property.IndexScope); + Setting.Property.Dynamic, Setting.Property.IndexScope, Setting.Property.InternalIndex); public static final Setting LIFECYCLE_PHASE_SETTING = Setting.simpleString(LIFECYCLE_PHASE, Setting.Property.Dynamic, Setting.Property.IndexScope, Setting.Property.InternalIndex); public static final Setting LIFECYCLE_ACTION_SETTING = Setting.simpleString(LIFECYCLE_ACTION, diff --git a/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/TimeSeriesLifecycleActionsIT.java b/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/TimeSeriesLifecycleActionsIT.java index 593949c050e92..a4ad7a820da21 100644 --- a/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/TimeSeriesLifecycleActionsIT.java +++ b/x-pack/plugin/index-lifecycle/src/test/java/org/elasticsearch/xpack/indexlifecycle/TimeSeriesLifecycleActionsIT.java @@ -51,13 +51,18 @@ public void refreshIndex() { policy = randomAlphaOfLength(5); } + public static void updatePolicy(String indexName, String policy) throws IOException { + Request request = new Request("PUT", "/" + indexName + "/_lifecycle/" + policy); + client().performRequest(request); + } + public void testAllocate() throws Exception { createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 2) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)); String allocateNodeName = "node-" + randomFrom(0, 1); AllocateAction allocateAction = new AllocateAction(null, null, singletonMap("_name", allocateNodeName)); createNewSingletonPolicy(randomFrom("warm", "cold"), allocateAction); - updateIndexSettings(index, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy)); + updatePolicy(index, policy); assertBusy(() -> { Map settings = getOnlyIndexSettings(index); assertThat(getStepKey(settings), equalTo(TerminalPolicyStep.KEY)); @@ -69,7 +74,7 @@ public void testDelete() throws Exception { createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)); createNewSingletonPolicy("delete", new DeleteAction()); - updateIndexSettings(index, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy)); + updatePolicy(index, policy); assertBusy(() -> assertFalse(indexExists(index))); } @@ -77,7 +82,7 @@ public void testReadOnly() throws Exception { createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)); createNewSingletonPolicy("warm", new ReadOnlyAction()); - updateIndexSettings(index, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy)); + updatePolicy(index, policy); assertBusy(() -> { Map settings = getOnlyIndexSettings(index); assertThat(getStepKey(settings), equalTo(TerminalPolicyStep.KEY)); @@ -111,7 +116,7 @@ public void testForceMergeAction() throws Exception { assertThat(numSegments.get(), greaterThan(1)); createNewSingletonPolicy("warm", new ForceMergeAction(1)); - updateIndexSettings(index, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy)); + updatePolicy(index, policy); assertBusy(() -> { assertThat(getStepKey(getOnlyIndexSettings(index)), equalTo(TerminalPolicyStep.KEY)); @@ -126,7 +131,7 @@ public void testReplicasAction() throws Exception { createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, numShards) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, numReplicas)); createNewSingletonPolicy(randomFrom("warm", "cold"), new ReplicasAction(finalNumReplicas)); - updateIndexSettings(index, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy)); + updatePolicy(index, policy); assertBusy(() -> { Map settings = getOnlyIndexSettings(index); @@ -143,7 +148,7 @@ public void testShrinkAction() throws Exception { createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, numShards) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)); createNewSingletonPolicy("warm", new ShrinkAction(expectedFinalShards)); - updateIndexSettings(index, Settings.builder().put(LifecycleSettings.LIFECYCLE_NAME, policy)); + updatePolicy(index, policy); assertBusy(() -> { assertTrue(indexExists(shrunkenIndex)); assertTrue(aliasExists(shrunkenIndex, index)); diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/10_basic.yml index c12c2ff6bc704..7bca6b338cba1 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/10_basic.yml @@ -204,6 +204,34 @@ setup: - match: { my_timeseries_lifecycle.phases.warm.after: "10s" } - match: { my_timeseries_lifecycle.phases.delete.after: "30s" } + - do: + acknowlege: true + xpack.index_lifecycle.put_lifecycle: + lifecycle: "blah_lifecycle" + body: | + { + "policy": { + "type": "timeseries", + "phases": { + "warm": { + "after": "1s", + "actions": { + "forcemerge": { + "max_num_segments": 1 + } + } + }, + "delete": { + "after": "3s", + "actions": { + "delete": {} + } + } + } + } + } + + - do: indices.create: index: my_timeseries_index @@ -219,10 +247,9 @@ setup: - match: { error.root_cause.0.reason: "Cannot delete policy [my_timeseries_lifecycle]. It is being used by at least one index [my_timeseries_index]" } - do: - indices.put_settings: + xpack.index_lifecycle.set_policy: index: my_timeseries_index - body: - index.lifecycle.name: "" + new_policy: "blah_lifecycle" - do: acknowledge: true From 8ceb69ca8b038839c1b62687ef1f5b00e88c1461 Mon Sep 17 00:00:00 2001 From: Lee Hinman Date: Wed, 1 Aug 2018 08:54:58 -0600 Subject: [PATCH 2/2] Use remove_policy instead of setting it to null --- .../test/index_lifecycle/10_basic.yml | 31 +------------------ 1 file changed, 1 insertion(+), 30 deletions(-) diff --git a/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/10_basic.yml b/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/10_basic.yml index 7bca6b338cba1..8527501713fbb 100644 --- a/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/10_basic.yml +++ b/x-pack/plugin/src/test/resources/rest-api-spec/test/index_lifecycle/10_basic.yml @@ -204,34 +204,6 @@ setup: - match: { my_timeseries_lifecycle.phases.warm.after: "10s" } - match: { my_timeseries_lifecycle.phases.delete.after: "30s" } - - do: - acknowlege: true - xpack.index_lifecycle.put_lifecycle: - lifecycle: "blah_lifecycle" - body: | - { - "policy": { - "type": "timeseries", - "phases": { - "warm": { - "after": "1s", - "actions": { - "forcemerge": { - "max_num_segments": 1 - } - } - }, - "delete": { - "after": "3s", - "actions": { - "delete": {} - } - } - } - } - } - - - do: indices.create: index: my_timeseries_index @@ -247,9 +219,8 @@ setup: - match: { error.root_cause.0.reason: "Cannot delete policy [my_timeseries_lifecycle]. It is being used by at least one index [my_timeseries_index]" } - do: - xpack.index_lifecycle.set_policy: + xpack.index_lifecycle.remove_policy: index: my_timeseries_index - new_policy: "blah_lifecycle" - do: acknowledge: true