Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -67,4 +67,9 @@ public ClusterState performAction(Index index, ClusterState clusterState) {
);
return newClusterStateBuilder.build();
}

@Override
public boolean isRetryable() {
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.elasticsearch.xpack.core.ilm.DeleteAction;
import org.elasticsearch.xpack.core.ilm.ForceMergeAction;
import org.elasticsearch.xpack.core.ilm.FreezeAction;
import org.elasticsearch.xpack.core.ilm.InitializePolicyContextStep;
import org.elasticsearch.xpack.core.ilm.LifecycleAction;
import org.elasticsearch.xpack.core.ilm.LifecyclePolicy;
import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
Expand Down Expand Up @@ -1179,6 +1180,52 @@ public void testHistoryIsWrittenWithDeletion() throws Exception {
}, 30, TimeUnit.SECONDS);
}

public void testRetryableInitializationStep() throws Exception {
String index = "retryinit-20xx-01-10";
Request stopReq = new Request("POST", "/_ilm/stop");
Request startReq = new Request("POST", "/_ilm/start");

createNewSingletonPolicy("hot", new SetPriorityAction(1));

// Stop ILM so that the initialize step doesn't run
assertOK(client().performRequest(stopReq));

// Create the index with the origination parsing turn *off* so it doesn't prevent creation
createIndexWithSettings(
index,
Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(LifecycleSettings.LIFECYCLE_NAME, policy)
.put(LifecycleSettings.LIFECYCLE_PARSE_ORIGINATION_DATE, false));

updateIndexSettings(index, Settings.builder()
.put(LifecycleSettings.LIFECYCLE_PARSE_ORIGINATION_DATE, true));

assertOK(client().performRequest(startReq));

// Wait until an error has occurred.
waitUntil(() -> {
try {
Map<String, Object> explainIndexResponse = explainIndex(index);
String step = (String) explainIndexResponse.get("step");
Integer retryCount = (Integer) explainIndexResponse.get(FAILED_STEP_RETRY_COUNT_FIELD);
return step != null && step.equals(InitializePolicyContextStep.KEY.getAction()) && retryCount != null && retryCount >= 1;
} catch (IOException e) {
return false;
}
}, 30, TimeUnit.SECONDS);

// Turn origination date parsing back off
updateIndexSettings(index, Settings.builder()
.put(LifecycleSettings.LIFECYCLE_PARSE_ORIGINATION_DATE, false));

assertBusy(() -> {
Map<String, Object> explainResp = explainIndex(index);
String phase = (String) explainResp.get("phase");
assertThat(phase, equalTo(TerminalPolicyStep.COMPLETED_PHASE));
});
}

// This method should be called inside an assertBusy, it has no retry logic of its own
private void assertHistoryIsPresent(String policyName, String indexName, boolean success, String stepName) throws IOException {
assertHistoryIsPresent(policyName, indexName, success, null, null, stepName);
Expand Down