diff --git a/docs/changelog/129945.yaml b/docs/changelog/129945.yaml new file mode 100644 index 0000000000000..8271c77c08ab1 --- /dev/null +++ b/docs/changelog/129945.yaml @@ -0,0 +1,5 @@ +pr: 129945 +summary: "Enhancement: ILM sets `indexing_complete` to true from `ReadOnly` action" +area: ILM+SLM +type: enhancement +issues: [] diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ReadOnlyAction.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ReadOnlyAction.java index b93bf652b84b4..0ce513b782b25 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ReadOnlyAction.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ReadOnlyAction.java @@ -10,6 +10,7 @@ import org.elasticsearch.common.Strings; import org.elasticsearch.common.io.stream.StreamInput; import org.elasticsearch.common.io.stream.StreamOutput; +import org.elasticsearch.common.settings.Settings; import org.elasticsearch.xcontent.ObjectParser; import org.elasticsearch.xcontent.XContentBuilder; import org.elasticsearch.xcontent.XContentParser; @@ -27,6 +28,10 @@ public class ReadOnlyAction implements LifecycleAction { private static final ObjectParser PARSER = new ObjectParser<>(NAME, false, ReadOnlyAction::new); + public static final String INDEXING_COMPLETE_STEP_NAME = "set-indexing-complete"; + + private static final Settings INDEXING_COMPLETE = Settings.builder().put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, true).build(); + public static ReadOnlyAction parse(XContentParser parser) { return PARSER.apply(parser, null); } @@ -60,6 +65,8 @@ public List toSteps(Client client, String phase, StepKey nextStepKey) { StepKey checkNotWriteIndex = new StepKey(phase, NAME, CheckNotDataStreamWriteIndexStep.NAME); StepKey waitTimeSeriesEndTimePassesKey = new StepKey(phase, NAME, WaitUntilTimeSeriesEndTimePassesStep.NAME); StepKey readOnlyKey = new StepKey(phase, NAME, NAME); + StepKey setIndexingCompleteStepKey = new StepKey(phase, NAME, INDEXING_COMPLETE_STEP_NAME); + CheckNotDataStreamWriteIndexStep checkNotWriteIndexStep = new CheckNotDataStreamWriteIndexStep( checkNotWriteIndex, waitTimeSeriesEndTimePassesKey @@ -69,8 +76,16 @@ public List toSteps(Client client, String phase, StepKey nextStepKey) { readOnlyKey, Instant::now ); - ReadOnlyStep readOnlyStep = new ReadOnlyStep(readOnlyKey, nextStepKey, client, true); - return List.of(checkNotWriteIndexStep, waitUntilTimeSeriesEndTimeStep, readOnlyStep); + ReadOnlyStep readOnlyStep = new ReadOnlyStep(readOnlyKey, setIndexingCompleteStepKey, client, true); + + UpdateSettingsStep setIndexingCompleteStep = new UpdateSettingsStep( + setIndexingCompleteStepKey, + nextStepKey, + client, + INDEXING_COMPLETE + ); + + return List.of(checkNotWriteIndexStep, waitUntilTimeSeriesEndTimeStep, readOnlyStep, setIndexingCompleteStep); } @Override diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ReadOnlyActionTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ReadOnlyActionTests.java index 81fa437f2768d..abbdc6aca5035 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ReadOnlyActionTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ReadOnlyActionTests.java @@ -12,6 +12,7 @@ import java.util.List; +import static org.elasticsearch.xpack.core.ilm.ReadOnlyAction.INDEXING_COMPLETE_STEP_NAME; import static org.hamcrest.Matchers.equalTo; public class ReadOnlyActionTests extends AbstractActionTestCase { @@ -46,13 +47,16 @@ public void testToSteps() { ); List steps = action.toSteps(null, phase, nextStepKey); assertNotNull(steps); - assertEquals(3, steps.size()); + assertEquals(4, steps.size()); StepKey expectedFirstStepKey = new StepKey(phase, ReadOnlyAction.NAME, CheckNotDataStreamWriteIndexStep.NAME); StepKey expectedSecondStepKey = new StepKey(phase, ReadOnlyAction.NAME, WaitUntilTimeSeriesEndTimePassesStep.NAME); StepKey expectedThirdStepKey = new StepKey(phase, ReadOnlyAction.NAME, ReadOnlyAction.NAME); + StepKey expectedFourthStepKey = new StepKey(phase, ReadOnlyAction.NAME, INDEXING_COMPLETE_STEP_NAME); + CheckNotDataStreamWriteIndexStep firstStep = (CheckNotDataStreamWriteIndexStep) steps.get(0); WaitUntilTimeSeriesEndTimePassesStep secondStep = (WaitUntilTimeSeriesEndTimePassesStep) steps.get(1); ReadOnlyStep thirdStep = (ReadOnlyStep) steps.get(2); + UpdateSettingsStep fourthStep = (UpdateSettingsStep) steps.get(3); assertThat(firstStep.getKey(), equalTo(expectedFirstStepKey)); assertThat(firstStep.getNextStepKey(), equalTo(expectedSecondStepKey)); @@ -61,7 +65,10 @@ public void testToSteps() { assertThat(secondStep.getNextStepKey(), equalTo(expectedThirdStepKey)); assertThat(thirdStep.getKey(), equalTo(expectedThirdStepKey)); - assertThat(thirdStep.getNextStepKey(), equalTo(nextStepKey)); + assertThat(thirdStep.getNextStepKey(), equalTo(expectedFourthStepKey)); + + assertThat(fourthStep.getKey(), equalTo(expectedFourthStepKey)); + assertThat(fourthStep.getNextStepKey(), equalTo(nextStepKey)); } } diff --git a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/ReadonlyActionIT.java b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/ReadonlyActionIT.java index ec0b685dd5bd0..3caf53ee3376e 100644 --- a/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/ReadonlyActionIT.java +++ b/x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/ReadonlyActionIT.java @@ -64,6 +64,7 @@ public void testReadOnly() throws Exception { assertThat(getStepKeyForIndex(client(), index), equalTo(PhaseCompleteStep.finalStep(phaseName).getKey())); assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey()), equalTo("true")); assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_METADATA_SETTING.getKey()), nullValue()); + assertThat(settings.get(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE_SETTING.getKey()), equalTo("true")); }); }