From ff980ed1ee095c805546b11c6370a76242a87d93 Mon Sep 17 00:00:00 2001 From: Andrei Dan Date: Wed, 8 Jan 2020 10:38:11 +0100 Subject: [PATCH] Make the UpdateRolloverLifecycleDateStep retryable (#50702) This makes the "update-rollover-lifecycle-date" step, which is part of the rollover action, retryable. It also adds an integration test to check the step is retried and it eventually succeeds. (cherry picked from commit 5bf068522deb2b6cd2563bcf80f34fdbf459c9f2) Signed-off-by: Andrei Dan --- .../ilm/UpdateRolloverLifecycleDateStep.java | 5 ++ .../ilm/TimeSeriesLifecycleActionsIT.java | 63 ++++++++++++++++++- 2 files changed, 67 insertions(+), 1 deletion(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UpdateRolloverLifecycleDateStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UpdateRolloverLifecycleDateStep.java index d0271633d4994..3c0acc371d26a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UpdateRolloverLifecycleDateStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UpdateRolloverLifecycleDateStep.java @@ -33,6 +33,11 @@ public UpdateRolloverLifecycleDateStep(StepKey key, StepKey nextStepKey, LongSup this.fallbackTimeSupplier = fallbackTimeSupplier; } + @Override + public boolean isRetryable() { + return true; + } + @Override public ClusterState performAction(Index index, ClusterState currentState) { IndexMetaData indexMetaData = currentState.metaData().getIndexSafe(index); 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 f1398a376ba39..6cec21823568a 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 @@ -42,6 +42,7 @@ import org.elasticsearch.xpack.core.ilm.Step; import org.elasticsearch.xpack.core.ilm.Step.StepKey; import org.elasticsearch.xpack.core.ilm.TerminalPolicyStep; +import org.elasticsearch.xpack.core.ilm.UpdateRolloverLifecycleDateStep; import org.elasticsearch.xpack.core.ilm.WaitForRolloverReadyStep; import org.hamcrest.Matchers; import org.junit.Before; @@ -1087,6 +1088,67 @@ public void testRolloverStepRetriesUntilRolledOverIndexIsDeleted() throws Except assertBusy(() -> assertThat(getStepKeyForIndex(index), equalTo(TerminalPolicyStep.KEY))); } + public void testUpdateRolloverLifecycleDateStepRetriesWhenRolloverInfoIsMissing() throws Exception { + String index = this.index + "-000001"; + + createNewSingletonPolicy("hot", new RolloverAction(null, null, 1L)); + + createIndexWithSettings( + index, + 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(index).getName(), is(WaitForRolloverReadyStep.NAME))); + + // moving ILM to the "update-rollover-lifecycle-date" without having gone through the actual rollover step + // the "update-rollover-lifecycle-date" step will fail as the index has no rollover information + Request moveToStepRequest = new Request("POST", "_ilm/move/" + index); + 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\": \"update-rollover-lifecycle-date\"\n" + + " }\n" + + "}"); + client().performRequest(moveToStepRequest); + + waitUntil(() -> { + try { + Map explainIndexResponse = explainIndex(index); + String step = (String) explainIndexResponse.get("step"); + Integer retryCount = (Integer) explainIndexResponse.get(FAILED_STEP_RETRY_COUNT_FIELD); + return step != null && step.equals(UpdateRolloverLifecycleDateStep.NAME) && retryCount != null && retryCount >= 1; + } catch (IOException e) { + return false; + } + }); + + index(client(), index, "1", "foo", "bar"); + Request refreshIndex = new Request("POST", "/" + index + "/_refresh"); + client().performRequest(refreshIndex); + + // manual rollover the index so the "update-rollover-lifecycle-date" ILM step can continue and finish successfully as the index + // will have rollover information now + Request rolloverRequest = new Request("POST", "/alias/_rollover"); + rolloverRequest.setJsonEntity("{\n" + + " \"conditions\": {\n" + + " \"max_docs\": \"1\"\n" + + " }\n" + + "}" + ); + client().performRequest(rolloverRequest); + assertBusy(() -> assertThat(getStepKeyForIndex(index), equalTo(TerminalPolicyStep.KEY))); + } + public void testHistoryIsWrittenWithSuccess() throws Exception { String index = "success-index"; @@ -1131,7 +1193,6 @@ public void testHistoryIsWrittenWithSuccess() throws Exception { assertBusy(() -> assertHistoryIsPresent(policy, index + "-000002", true, "check-rollover-ready"), 30, TimeUnit.SECONDS); } - public void testHistoryIsWrittenWithFailure() throws Exception { String index = "failure-index";