Skip to content

Commit 8dc6e98

Browse files
authored
[7.x] Make InitializePolicyContextStep retryable (#50685) (#50760)
This commits makes the "init" ILM step retryable. It also adds a test where an index is created with a non-parsable index name and then fails. Related to #48183
1 parent e95b0c4 commit 8dc6e98

File tree

2 files changed

+52
-0
lines changed

2 files changed

+52
-0
lines changed

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

+5
Original file line numberDiff line numberDiff line change
@@ -67,4 +67,9 @@ public ClusterState performAction(Index index, ClusterState clusterState) {
6767
);
6868
return newClusterStateBuilder.build();
6969
}
70+
71+
@Override
72+
public boolean isRetryable() {
73+
return true;
74+
}
7075
}

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

+47
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import org.elasticsearch.xpack.core.ilm.ErrorStep;
3131
import org.elasticsearch.xpack.core.ilm.ForceMergeAction;
3232
import org.elasticsearch.xpack.core.ilm.FreezeAction;
33+
import org.elasticsearch.xpack.core.ilm.InitializePolicyContextStep;
3334
import org.elasticsearch.xpack.core.ilm.LifecycleAction;
3435
import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
3536
import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
@@ -1257,6 +1258,52 @@ public void testHistoryIsWrittenWithDeletion() throws Exception {
12571258
}, 30, TimeUnit.SECONDS);
12581259
}
12591260

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+
12601307
// This method should be called inside an assertBusy, it has no retry logic of its own
12611308
private void assertHistoryIsPresent(String policyName, String indexName, boolean success, String stepName) throws IOException {
12621309
assertHistoryIsPresent(policyName, indexName, success, null, null, stepName);

0 commit comments

Comments
 (0)