|
30 | 30 | import org.elasticsearch.xpack.core.ilm.ErrorStep;
|
31 | 31 | import org.elasticsearch.xpack.core.ilm.ForceMergeAction;
|
32 | 32 | import org.elasticsearch.xpack.core.ilm.FreezeAction;
|
| 33 | +import org.elasticsearch.xpack.core.ilm.InitializePolicyContextStep; |
33 | 34 | import org.elasticsearch.xpack.core.ilm.LifecycleAction;
|
34 | 35 | import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
|
35 | 36 | import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
|
@@ -1257,6 +1258,52 @@ public void testHistoryIsWrittenWithDeletion() throws Exception {
|
1257 | 1258 | }, 30, TimeUnit.SECONDS);
|
1258 | 1259 | }
|
1259 | 1260 |
|
| 1261 | + public void testRetryableInitializationStep() throws Exception { |
| 1262 | + String index = "retryinit-20xx-01-10"; |
| 1263 | + Request stopReq = new Request("POST", "/_ilm/stop"); |
| 1264 | + Request startReq = new Request("POST", "/_ilm/start"); |
| 1265 | + |
| 1266 | + createNewSingletonPolicy("hot", new SetPriorityAction(1)); |
| 1267 | + |
| 1268 | + // Stop ILM so that the initialize step doesn't run |
| 1269 | + assertOK(client().performRequest(stopReq)); |
| 1270 | + |
| 1271 | + // Create the index with the origination parsing turn *off* so it doesn't prevent creation |
| 1272 | + createIndexWithSettings( |
| 1273 | + index, |
| 1274 | + Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1) |
| 1275 | + .put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0) |
| 1276 | + .put(LifecycleSettings.LIFECYCLE_NAME, policy) |
| 1277 | + .put(LifecycleSettings.LIFECYCLE_PARSE_ORIGINATION_DATE, false)); |
| 1278 | + |
| 1279 | + updateIndexSettings(index, Settings.builder() |
| 1280 | + .put(LifecycleSettings.LIFECYCLE_PARSE_ORIGINATION_DATE, true)); |
| 1281 | + |
| 1282 | + assertOK(client().performRequest(startReq)); |
| 1283 | + |
| 1284 | + // Wait until an error has occurred. |
| 1285 | + waitUntil(() -> { |
| 1286 | + try { |
| 1287 | + Map<String, Object> explainIndexResponse = explainIndex(index); |
| 1288 | + String step = (String) explainIndexResponse.get("step"); |
| 1289 | + Integer retryCount = (Integer) explainIndexResponse.get(FAILED_STEP_RETRY_COUNT_FIELD); |
| 1290 | + return step != null && step.equals(InitializePolicyContextStep.KEY.getAction()) && retryCount != null && retryCount >= 1; |
| 1291 | + } catch (IOException e) { |
| 1292 | + return false; |
| 1293 | + } |
| 1294 | + }, 30, TimeUnit.SECONDS); |
| 1295 | + |
| 1296 | + // Turn origination date parsing back off |
| 1297 | + updateIndexSettings(index, Settings.builder() |
| 1298 | + .put(LifecycleSettings.LIFECYCLE_PARSE_ORIGINATION_DATE, false)); |
| 1299 | + |
| 1300 | + assertBusy(() -> { |
| 1301 | + Map<String, Object> explainResp = explainIndex(index); |
| 1302 | + String phase = (String) explainResp.get("phase"); |
| 1303 | + assertThat(phase, equalTo(TerminalPolicyStep.COMPLETED_PHASE)); |
| 1304 | + }); |
| 1305 | + } |
| 1306 | + |
1260 | 1307 | // This method should be called inside an assertBusy, it has no retry logic of its own
|
1261 | 1308 | private void assertHistoryIsPresent(String policyName, String indexName, boolean success, String stepName) throws IOException {
|
1262 | 1309 | assertHistoryIsPresent(policyName, indexName, success, null, null, stepName);
|
|
0 commit comments