diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverAction.java index f5dd88e34b36e..ce17efc1e31fc 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/RolloverAction.java @@ -6,6 +6,7 @@ package org.elasticsearch.xpack.core.ilm; import org.elasticsearch.client.Client; +import org.elasticsearch.common.Nullable; import org.elasticsearch.common.ParseField; import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; @@ -56,7 +57,7 @@ public static RolloverAction parse(XContentParser parser) { return PARSER.apply(parser, null); } - public RolloverAction(ByteSizeValue maxSize, TimeValue maxAge, Long maxDocs) { + public RolloverAction(@Nullable ByteSizeValue maxSize, @Nullable TimeValue maxAge, @Nullable Long maxDocs) { if (maxSize == null && maxAge == null && maxDocs == null) { throw new IllegalArgumentException("At least one rollover condition must be set."); } diff --git a/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java b/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java index 14ce149e468e1..b16da84940da9 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java @@ -808,6 +808,42 @@ public void testMoveToInjectedStep() throws Exception { }); } + public void testMoveToStepRereadsPolicy() throws Exception { + createNewSingletonPolicy("hot", new RolloverAction(null, TimeValue.timeValueHours(1), null), TimeValue.ZERO); + + createIndexWithSettings("test-1", Settings.builder() + .put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) + .put(LifecycleSettings.LIFECYCLE_NAME, policy) + .put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"), + true); + + assertBusy(() -> assertThat(getStepKeyForIndex("test-1"), equalTo(new StepKey("hot", "rollover", "check-rollover-ready")))); + + createNewSingletonPolicy("hot", new RolloverAction(null, TimeValue.timeValueSeconds(1), null), TimeValue.ZERO); + + // Move to the same step, which should re-read the policy + Request moveToStepRequest = new Request("POST", "_ilm/move/test-1"); + moveToStepRequest.setJsonEntity("{\n" + + " \"current_step\": { \n" + + " \"phase\": \"hot\",\n" + + " \"action\": \"rollover\",\n" + + " \"name\": \"check-rollover-ready\"\n" + + " },\n" + + " \"next_step\": { \n" + + " \"phase\": \"hot\",\n" + + " \"action\": \"rollover\",\n" + + " \"name\": \"check-rollover-ready\"\n" + + " }\n" + + "}"); + assertOK(client().performRequest(moveToStepRequest)); + + // Make sure we actually rolled over + assertBusy(() -> { + indexExists("test-000002"); + }); + } + public void testCanStopILMWithPolicyUsingNonexistentPolicy() throws Exception { createIndexWithSettings(index, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java index ce89cd71e25a4..d24447accf686 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java @@ -317,13 +317,11 @@ static Step getCurrentStep(PolicyStepsRegistry stepRegistry, String policy, Inde * @param nextStepKey The next step to move the index into * @param nowSupplier The current-time supplier for updating when steps changed * @param stepRegistry The steps registry to check a step-key's existence in the index's current policy - * @param forcePhaseDefinitionRefresh When true, step information will be recompiled from the latest version of the - * policy. Otherwise, existing phase definition is used. * @return The updated cluster state where the index moved to nextStepKey */ static ClusterState moveClusterStateToStep(String indexName, ClusterState currentState, StepKey currentStepKey, StepKey nextStepKey, LongSupplier nowSupplier, - PolicyStepsRegistry stepRegistry, boolean forcePhaseDefinitionRefresh) { + PolicyStepsRegistry stepRegistry) { IndexMetaData idxMeta = currentState.getMetaData().index(indexName); validateTransition(idxMeta, currentStepKey, nextStepKey, stepRegistry); @@ -333,7 +331,7 @@ static ClusterState moveClusterStateToStep(String indexName, ClusterState curren indexName, currentStepKey, nextStepKey, policy); return IndexLifecycleRunner.moveClusterStateToNextStep(idxMeta.getIndex(), currentState, currentStepKey, - nextStepKey, nowSupplier, forcePhaseDefinitionRefresh); + nextStepKey, nowSupplier, true); } static void validateTransition(IndexMetaData idxMeta, StepKey currentStepKey, StepKey nextStepKey, PolicyStepsRegistry stepRegistry) { diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java index 04b476053a85a..ac3968b30600c 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleService.java @@ -88,7 +88,7 @@ public void maybeRunAsyncAction(ClusterState clusterState, IndexMetaData indexMe public ClusterState moveClusterStateToStep(ClusterState currentState, String indexName, StepKey currentStepKey, StepKey nextStepKey) { return IndexLifecycleRunner.moveClusterStateToStep(indexName, currentState, currentStepKey, nextStepKey, - nowSupplier, policyRegistry, false); + nowSupplier, policyRegistry); } public ClusterState moveClusterStateToPreviouslyFailedStep(ClusterState currentState, String[] indices) { diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java index 26adcb65a773a..3239fe23e176b 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java @@ -839,7 +839,7 @@ public void testSuccessfulValidatedMoveClusterStateToNextStep() { ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), policyMetadatas); Index index = clusterState.metaData().index(indexName).getIndex(); ClusterState newClusterState = IndexLifecycleRunner.moveClusterStateToStep(indexName, clusterState, currentStepKey, - nextStepKey, () -> now, stepRegistry, false); + nextStepKey, () -> now, stepRegistry); assertClusterStateOnNextStep(clusterState, index, currentStepKey, nextStepKey, newClusterState, now); } @@ -861,7 +861,7 @@ public void testValidatedMoveClusterStateToNextStepWithoutPolicy() { ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), Collections.emptyList()); IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> IndexLifecycleRunner.moveClusterStateToStep(indexName, clusterState, currentStepKey, - nextStepKey, () -> now, stepRegistry, false)); + nextStepKey, () -> now, stepRegistry)); assertThat(exception.getMessage(), equalTo("index [my_index] is not associated with an Index Lifecycle Policy")); } @@ -884,7 +884,7 @@ public void testValidatedMoveClusterStateToNextStepInvalidCurrentStep() { ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), Collections.emptyList()); IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> IndexLifecycleRunner.moveClusterStateToStep(indexName, clusterState, notCurrentStepKey, - nextStepKey, () -> now, stepRegistry, false)); + nextStepKey, () -> now, stepRegistry)); assertThat(exception.getMessage(), equalTo("index [my_index] is not on current step " + "[{\"phase\":\"not_current_phase\",\"action\":\"not_current_action\",\"name\":\"not_current_step\"}]")); } @@ -907,7 +907,7 @@ public void testValidatedMoveClusterStateToNextStepInvalidNextStep() { ClusterState clusterState = buildClusterState(indexName, indexSettingsBuilder, lifecycleState.build(), Collections.emptyList()); IllegalArgumentException exception = expectThrows(IllegalArgumentException.class, () -> IndexLifecycleRunner.moveClusterStateToStep(indexName, clusterState, currentStepKey, - nextStepKey, () -> now, stepRegistry, false)); + nextStepKey, () -> now, stepRegistry)); assertThat(exception.getMessage(), equalTo("step [{\"phase\":\"next_phase\",\"action\":\"next_action\",\"name\":\"next_step\"}] " + "for index [my_index] with policy [my_policy] does not exist"));