|
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; |
@@ -1087,6 +1088,67 @@ public void testRolloverStepRetriesUntilRolledOverIndexIsDeleted() throws Except |
1087 | 1088 | assertBusy(() -> assertThat(getStepKeyForIndex(index), equalTo(TerminalPolicyStep.KEY))); |
1088 | 1089 | } |
1089 | 1090 |
|
| 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 | + |
1090 | 1152 | public void testHistoryIsWrittenWithSuccess() throws Exception { |
1091 | 1153 | String index = "success-index"; |
1092 | 1154 |
|
@@ -1131,7 +1193,6 @@ public void testHistoryIsWrittenWithSuccess() throws Exception { |
1131 | 1193 | assertBusy(() -> assertHistoryIsPresent(policy, index + "-000002", true, "check-rollover-ready"), 30, TimeUnit.SECONDS); |
1132 | 1194 | } |
1133 | 1195 |
|
1134 | | - |
1135 | 1196 | public void testHistoryIsWrittenWithFailure() throws Exception { |
1136 | 1197 | String index = "failure-index"; |
1137 | 1198 |
|
|
0 commit comments