Skip to content

Commit fe8a3aa

Browse files
committed
ILM sets indexing_complete from ReadOnly action
1 parent 4dab46a commit fe8a3aa

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

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

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import org.elasticsearch.common.Strings;
1111
import org.elasticsearch.common.io.stream.StreamInput;
1212
import org.elasticsearch.common.io.stream.StreamOutput;
13+
import org.elasticsearch.common.settings.Settings;
1314
import org.elasticsearch.xcontent.ObjectParser;
1415
import org.elasticsearch.xcontent.XContentBuilder;
1516
import org.elasticsearch.xcontent.XContentParser;
@@ -27,6 +28,10 @@ public class ReadOnlyAction implements LifecycleAction {
2728

2829
private static final ObjectParser<ReadOnlyAction, Void> PARSER = new ObjectParser<>(NAME, false, ReadOnlyAction::new);
2930

31+
public static final String INDEXING_COMPLETE_STEP_NAME = "set-indexing-complete";
32+
33+
private static final Settings INDEXING_COMPLETE = Settings.builder().put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, true).build();
34+
3035
public static ReadOnlyAction parse(XContentParser parser) {
3136
return PARSER.apply(parser, null);
3237
}
@@ -60,6 +65,8 @@ public List<Step> toSteps(Client client, String phase, StepKey nextStepKey) {
6065
StepKey checkNotWriteIndex = new StepKey(phase, NAME, CheckNotDataStreamWriteIndexStep.NAME);
6166
StepKey waitTimeSeriesEndTimePassesKey = new StepKey(phase, NAME, WaitUntilTimeSeriesEndTimePassesStep.NAME);
6267
StepKey readOnlyKey = new StepKey(phase, NAME, NAME);
68+
StepKey setIndexingCompleteStepKey = new StepKey(phase, NAME, INDEXING_COMPLETE_STEP_NAME);
69+
6370
CheckNotDataStreamWriteIndexStep checkNotWriteIndexStep = new CheckNotDataStreamWriteIndexStep(
6471
checkNotWriteIndex,
6572
waitTimeSeriesEndTimePassesKey
@@ -69,8 +76,16 @@ public List<Step> toSteps(Client client, String phase, StepKey nextStepKey) {
6976
readOnlyKey,
7077
Instant::now
7178
);
72-
ReadOnlyStep readOnlyStep = new ReadOnlyStep(readOnlyKey, nextStepKey, client, true);
73-
return List.of(checkNotWriteIndexStep, waitUntilTimeSeriesEndTimeStep, readOnlyStep);
79+
ReadOnlyStep readOnlyStep = new ReadOnlyStep(readOnlyKey, setIndexingCompleteStepKey, client, true);
80+
81+
UpdateSettingsStep setIndexingCompleteStep = new UpdateSettingsStep(
82+
setIndexingCompleteStepKey,
83+
nextStepKey,
84+
client,
85+
INDEXING_COMPLETE
86+
);
87+
88+
return List.of(checkNotWriteIndexStep, waitUntilTimeSeriesEndTimeStep, readOnlyStep, setIndexingCompleteStep);
7489
}
7590

7691
@Override

x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/ReadOnlyActionTests.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212

1313
import java.util.List;
1414

15+
import static org.elasticsearch.xpack.core.ilm.ReadOnlyAction.INDEXING_COMPLETE_STEP_NAME;
1516
import static org.hamcrest.Matchers.equalTo;
1617

1718
public class ReadOnlyActionTests extends AbstractActionTestCase<ReadOnlyAction> {
@@ -46,13 +47,16 @@ public void testToSteps() {
4647
);
4748
List<Step> steps = action.toSteps(null, phase, nextStepKey);
4849
assertNotNull(steps);
49-
assertEquals(3, steps.size());
50+
assertEquals(4, steps.size());
5051
StepKey expectedFirstStepKey = new StepKey(phase, ReadOnlyAction.NAME, CheckNotDataStreamWriteIndexStep.NAME);
5152
StepKey expectedSecondStepKey = new StepKey(phase, ReadOnlyAction.NAME, WaitUntilTimeSeriesEndTimePassesStep.NAME);
5253
StepKey expectedThirdStepKey = new StepKey(phase, ReadOnlyAction.NAME, ReadOnlyAction.NAME);
54+
StepKey expectedFourthStepKey = new StepKey(phase, ReadOnlyAction.NAME, INDEXING_COMPLETE_STEP_NAME);
55+
5356
CheckNotDataStreamWriteIndexStep firstStep = (CheckNotDataStreamWriteIndexStep) steps.get(0);
5457
WaitUntilTimeSeriesEndTimePassesStep secondStep = (WaitUntilTimeSeriesEndTimePassesStep) steps.get(1);
5558
ReadOnlyStep thirdStep = (ReadOnlyStep) steps.get(2);
59+
UpdateSettingsStep fourthStep = (UpdateSettingsStep) steps.get(3);
5660

5761
assertThat(firstStep.getKey(), equalTo(expectedFirstStepKey));
5862
assertThat(firstStep.getNextStepKey(), equalTo(expectedSecondStepKey));
@@ -61,7 +65,10 @@ public void testToSteps() {
6165
assertThat(secondStep.getNextStepKey(), equalTo(expectedThirdStepKey));
6266

6367
assertThat(thirdStep.getKey(), equalTo(expectedThirdStepKey));
64-
assertThat(thirdStep.getNextStepKey(), equalTo(nextStepKey));
68+
assertThat(thirdStep.getNextStepKey(), equalTo(expectedFourthStepKey));
69+
70+
assertThat(fourthStep.getKey(), equalTo(expectedFourthStepKey));
71+
assertThat(fourthStep.getNextStepKey(), equalTo(nextStepKey));
6572
}
6673

6774
}

x-pack/plugin/ilm/qa/multi-node/src/javaRestTest/java/org/elasticsearch/xpack/ilm/actions/ReadonlyActionIT.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@ public void testReadOnly() throws Exception {
6464
assertThat(getStepKeyForIndex(client(), index), equalTo(PhaseCompleteStep.finalStep(phaseName).getKey()));
6565
assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_WRITE_SETTING.getKey()), equalTo("true"));
6666
assertThat(settings.get(IndexMetadata.INDEX_BLOCKS_METADATA_SETTING.getKey()), nullValue());
67+
assertThat(settings.get(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE_SETTING.getKey()), equalTo("true"));
6768
});
6869
}
6970

0 commit comments

Comments
 (0)