|
42 | 42 | import org.elasticsearch.xpack.core.ilm.Step;
|
43 | 43 | import org.elasticsearch.xpack.core.ilm.Step.StepKey;
|
44 | 44 | import org.elasticsearch.xpack.core.ilm.TerminalPolicyStep;
|
| 45 | +import org.elasticsearch.xpack.core.ilm.UpdateRolloverLifecycleDateStep; |
45 | 46 | import org.elasticsearch.xpack.core.ilm.WaitForRolloverReadyStep;
|
46 | 47 | import org.hamcrest.Matchers;
|
47 | 48 | import org.junit.Before;
|
@@ -1078,6 +1079,67 @@ public void testRolloverStepRetriesUntilRolledOverIndexIsDeleted() throws Except
|
1078 | 1079 | assertBusy(() -> assertThat(getStepKeyForIndex(index), equalTo(TerminalPolicyStep.KEY)));
|
1079 | 1080 | }
|
1080 | 1081 |
|
| 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 | + |
1081 | 1143 | public void testHistoryIsWrittenWithSuccess() throws Exception {
|
1082 | 1144 | String index = "success-index";
|
1083 | 1145 |
|
@@ -1122,7 +1184,6 @@ public void testHistoryIsWrittenWithSuccess() throws Exception {
|
1122 | 1184 | assertBusy(() -> assertHistoryIsPresent(policy, index + "-000002", true, "check-rollover-ready"), 30, TimeUnit.SECONDS);
|
1123 | 1185 | }
|
1124 | 1186 |
|
1125 |
| - |
1126 | 1187 | public void testHistoryIsWrittenWithFailure() throws Exception {
|
1127 | 1188 | String index = "failure-index";
|
1128 | 1189 |
|
|
0 commit comments