Skip to content

Commit ff980ed

Browse files
committed
Make the UpdateRolloverLifecycleDateStep retryable (elastic#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 5bf0685) Signed-off-by: Andrei Dan <[email protected]>
1 parent d8c907d commit ff980ed

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;
@@ -1087,6 +1088,67 @@ public void testRolloverStepRetriesUntilRolledOverIndexIsDeleted() throws Except
10871088
assertBusy(() -> assertThat(getStepKeyForIndex(index), equalTo(TerminalPolicyStep.KEY)));
10881089
}
10891090

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

@@ -1131,7 +1193,6 @@ public void testHistoryIsWrittenWithSuccess() throws Exception {
11311193
assertBusy(() -> assertHistoryIsPresent(policy, index + "-000002", true, "check-rollover-ready"), 30, TimeUnit.SECONDS);
11321194
}
11331195

1134-
11351196
public void testHistoryIsWrittenWithFailure() throws Exception {
11361197
String index = "failure-index";
11371198

0 commit comments

Comments
 (0)