Browse Source

Enhancement: ILM sets indexing_complete to true from ReadOnly action (#129945)

* ILM sets indexing_complete from ReadOnly action

* Update docs/changelog/129945.yaml

---------

Co-authored-by: Joe Gallo <joe.gallo@elastic.co>
Graeme Mjehovich 3 months ago
parent
commit
a43aaa8417

+ 5 - 0
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: []

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

@@ -10,6 +10,7 @@ import org.elasticsearch.client.internal.Client;
 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<ReadOnlyAction, Void> 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 class ReadOnlyAction implements LifecycleAction {
         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 class ReadOnlyAction implements LifecycleAction {
             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

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

@@ -12,6 +12,7 @@ import org.elasticsearch.xpack.core.ilm.Step.StepKey;
 
 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<ReadOnlyAction> {
@@ -46,13 +47,16 @@ public class ReadOnlyActionTests extends AbstractActionTestCase<ReadOnlyAction>
         );
         List<Step> 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 class ReadOnlyActionTests extends AbstractActionTestCase<ReadOnlyAction>
         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));
     }
 
 }

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

@@ -64,6 +64,7 @@ public class ReadonlyActionIT extends ESRestTestCase {
             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"));
         });
     }