Skip to content

Commit 5bf0685

Browse files
authored
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.
1 parent 84af7c4 commit 5bf0685

File tree

2 files changed

+67
-1
lines changed

2 files changed

+67
-1
lines changed

x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/UpdateRolloverLifecycleDateStep.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,11 @@ public UpdateRolloverLifecycleDateStep(StepKey key, StepKey nextStepKey, LongSup
3333
this.fallbackTimeSupplier = fallbackTimeSupplier;
3434
}
3535

36+
@Override
37+
public boolean isRetryable() {
38+
return true;
39+
}
40+
3641
@Override
3742
public ClusterState performAction(Index index, ClusterState currentState) {
3843
IndexMetaData indexMetaData = currentState.metaData().getIndexSafe(index);

x-pack/plugin/ilm/qa/multi-node/src/test/java/org/elasticsearch/xpack/ilm/TimeSeriesLifecycleActionsIT.java

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
import org.elasticsearch.xpack.core.ilm.Step;
4343
import org.elasticsearch.xpack.core.ilm.Step.StepKey;
4444
import org.elasticsearch.xpack.core.ilm.TerminalPolicyStep;
45+
import org.elasticsearch.xpack.core.ilm.UpdateRolloverLifecycleDateStep;
4546
import org.elasticsearch.xpack.core.ilm.WaitForRolloverReadyStep;
4647
import org.hamcrest.Matchers;
4748
import org.junit.Before;
@@ -1078,6 +1079,67 @@ public void testRolloverStepRetriesUntilRolledOverIndexIsDeleted() throws Except
10781079
assertBusy(() -> assertThat(getStepKeyForIndex(index), equalTo(TerminalPolicyStep.KEY)));
10791080
}
10801081

1082+
public void testUpdateRolloverLifecycleDateStepRetriesWhenRolloverInfoIsMissing() throws Exception {
1083+
String index = this.index + "-000001";
1084+
1085+
createNewSingletonPolicy("hot", new RolloverAction(null, null, 1L));
1086+
1087+
createIndexWithSettings(
1088+
index,
1089+
Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
1090+
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
1091+
.put(LifecycleSettings.LIFECYCLE_NAME, policy)
1092+
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"),
1093+
true
1094+
);
1095+
1096+
assertBusy(() -> assertThat(getStepKeyForIndex(index).getName(), is(WaitForRolloverReadyStep.NAME)));
1097+
1098+
// moving ILM to the "update-rollover-lifecycle-date" without having gone through the actual rollover step
1099+
// the "update-rollover-lifecycle-date" step will fail as the index has no rollover information
1100+
Request moveToStepRequest = new Request("POST", "_ilm/move/" + index);
1101+
moveToStepRequest.setJsonEntity("{\n" +
1102+
" \"current_step\": {\n" +
1103+
" \"phase\": \"hot\",\n" +
1104+
" \"action\": \"rollover\",\n" +
1105+
" \"name\": \"check-rollover-ready\"\n" +
1106+
" },\n" +
1107+
" \"next_step\": {\n" +
1108+
" \"phase\": \"hot\",\n" +
1109+
" \"action\": \"rollover\",\n" +
1110+
" \"name\": \"update-rollover-lifecycle-date\"\n" +
1111+
" }\n" +
1112+
"}");
1113+
client().performRequest(moveToStepRequest);
1114+
1115+
waitUntil(() -> {
1116+
try {
1117+
Map<String, Object> explainIndexResponse = explainIndex(index);
1118+
String step = (String) explainIndexResponse.get("step");
1119+
Integer retryCount = (Integer) explainIndexResponse.get(FAILED_STEP_RETRY_COUNT_FIELD);
1120+
return step != null && step.equals(UpdateRolloverLifecycleDateStep.NAME) && retryCount != null && retryCount >= 1;
1121+
} catch (IOException e) {
1122+
return false;
1123+
}
1124+
});
1125+
1126+
index(client(), index, "1", "foo", "bar");
1127+
Request refreshIndex = new Request("POST", "/" + index + "/_refresh");
1128+
client().performRequest(refreshIndex);
1129+
1130+
// manual rollover the index so the "update-rollover-lifecycle-date" ILM step can continue and finish successfully as the index
1131+
// will have rollover information now
1132+
Request rolloverRequest = new Request("POST", "/alias/_rollover");
1133+
rolloverRequest.setJsonEntity("{\n" +
1134+
" \"conditions\": {\n" +
1135+
" \"max_docs\": \"1\"\n" +
1136+
" }\n" +
1137+
"}"
1138+
);
1139+
client().performRequest(rolloverRequest);
1140+
assertBusy(() -> assertThat(getStepKeyForIndex(index), equalTo(TerminalPolicyStep.KEY)));
1141+
}
1142+
10811143
public void testHistoryIsWrittenWithSuccess() throws Exception {
10821144
String index = "success-index";
10831145

@@ -1122,7 +1184,6 @@ public void testHistoryIsWrittenWithSuccess() throws Exception {
11221184
assertBusy(() -> assertHistoryIsPresent(policy, index + "-000002", true, "check-rollover-ready"), 30, TimeUnit.SECONDS);
11231185
}
11241186

1125-
11261187
public void testHistoryIsWrittenWithFailure() throws Exception {
11271188
String index = "failure-index";
11281189

0 commit comments

Comments
 (0)