Skip to content

Commit 07650dd

Browse files
authored
ILM the delete action waits for a TSDS index time/bounds to lapse (#100207) (#100261)
This adds the `check-ts-end-time-passed` step to the delete action so, for time series indices, we wait until they're not meant to accept new writes anymore before deleting them (i.e. until the time interval the covers the ingestion for `now` has lapsed) (cherry picked from commit f32c8f5) Signed-off-by: Andrei Dan <[email protected]>
1 parent 5150040 commit 07650dd

File tree

3 files changed

+50
-14
lines changed

3 files changed

+50
-14
lines changed

docs/changelog/100207.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 100207
2+
summary: ILM the delete action waits for a TSDS index time/bounds to lapse
3+
area: ILM+SLM
4+
type: bug
5+
issues: []

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

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import org.elasticsearch.xcontent.XContentParser;
1717

1818
import java.io.IOException;
19+
import java.time.Instant;
1920
import java.util.Arrays;
2021
import java.util.List;
2122
import java.util.Objects;
@@ -80,18 +81,39 @@ public boolean isSafeAction() {
8081
@Override
8182
public List<Step> toSteps(Client client, String phase, Step.StepKey nextStepKey) {
8283
Step.StepKey waitForNoFollowerStepKey = new Step.StepKey(phase, NAME, WaitForNoFollowersStep.NAME);
84+
Step.StepKey waitTimeSeriesEndTimePassesKey = new Step.StepKey(phase, NAME, WaitUntilTimeSeriesEndTimePassesStep.NAME);
8385
Step.StepKey deleteStepKey = new Step.StepKey(phase, NAME, DeleteStep.NAME);
8486
Step.StepKey cleanSnapshotKey = new Step.StepKey(phase, NAME, CleanupSnapshotStep.NAME);
8587

8688
if (deleteSearchableSnapshot) {
87-
WaitForNoFollowersStep waitForNoFollowersStep = new WaitForNoFollowersStep(waitForNoFollowerStepKey, cleanSnapshotKey, client);
89+
WaitForNoFollowersStep waitForNoFollowersStep = new WaitForNoFollowersStep(
90+
waitForNoFollowerStepKey,
91+
waitTimeSeriesEndTimePassesKey,
92+
client
93+
);
94+
WaitUntilTimeSeriesEndTimePassesStep waitUntilTimeSeriesEndTimeStep = new WaitUntilTimeSeriesEndTimePassesStep(
95+
waitTimeSeriesEndTimePassesKey,
96+
cleanSnapshotKey,
97+
Instant::now,
98+
client
99+
);
88100
CleanupSnapshotStep cleanupSnapshotStep = new CleanupSnapshotStep(cleanSnapshotKey, deleteStepKey, client);
89101
DeleteStep deleteStep = new DeleteStep(deleteStepKey, nextStepKey, client);
90-
return Arrays.asList(waitForNoFollowersStep, cleanupSnapshotStep, deleteStep);
102+
return Arrays.asList(waitForNoFollowersStep, waitUntilTimeSeriesEndTimeStep, cleanupSnapshotStep, deleteStep);
91103
} else {
92-
WaitForNoFollowersStep waitForNoFollowersStep = new WaitForNoFollowersStep(waitForNoFollowerStepKey, deleteStepKey, client);
104+
WaitForNoFollowersStep waitForNoFollowersStep = new WaitForNoFollowersStep(
105+
waitForNoFollowerStepKey,
106+
waitTimeSeriesEndTimePassesKey,
107+
client
108+
);
109+
WaitUntilTimeSeriesEndTimePassesStep waitUntilTimeSeriesEndTimeStep = new WaitUntilTimeSeriesEndTimePassesStep(
110+
waitTimeSeriesEndTimePassesKey,
111+
deleteStepKey,
112+
Instant::now,
113+
client
114+
);
93115
DeleteStep deleteStep = new DeleteStep(deleteStepKey, nextStepKey, client);
94-
return Arrays.asList(waitForNoFollowersStep, deleteStep);
116+
return Arrays.asList(waitForNoFollowersStep, waitUntilTimeSeriesEndTimeStep, deleteStep);
95117
}
96118
}
97119

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

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -47,31 +47,40 @@ public void testToSteps() {
4747
{
4848
List<Step> steps = DeleteAction.WITH_SNAPSHOT_DELETE.toSteps(null, phase, nextStepKey);
4949
assertNotNull(steps);
50-
assertEquals(3, steps.size());
50+
assertEquals(4, steps.size());
5151
StepKey expectedFirstStepKey = new StepKey(phase, DeleteAction.NAME, WaitForNoFollowersStep.NAME);
52-
StepKey expectedSecondStepKey = new StepKey(phase, DeleteAction.NAME, CleanupSnapshotStep.NAME);
53-
StepKey expectedThirdKey = new StepKey(phase, DeleteAction.NAME, DeleteStep.NAME);
52+
StepKey expectedSecondStepKey = new StepKey(phase, DeleteAction.NAME, WaitUntilTimeSeriesEndTimePassesStep.NAME);
53+
StepKey expectedThirdKey = new StepKey(phase, DeleteAction.NAME, CleanupSnapshotStep.NAME);
54+
StepKey expectedFourthKey = new StepKey(phase, DeleteAction.NAME, DeleteStep.NAME);
5455
WaitForNoFollowersStep firstStep = (WaitForNoFollowersStep) steps.get(0);
55-
CleanupSnapshotStep secondStep = (CleanupSnapshotStep) steps.get(1);
56-
DeleteStep thirdStep = (DeleteStep) steps.get(2);
56+
WaitUntilTimeSeriesEndTimePassesStep secondStep = (WaitUntilTimeSeriesEndTimePassesStep) steps.get(1);
57+
CleanupSnapshotStep thirdStep = (CleanupSnapshotStep) steps.get(2);
58+
DeleteStep fourthStep = (DeleteStep) steps.get(3);
5759
assertEquals(expectedFirstStepKey, firstStep.getKey());
5860
assertEquals(expectedSecondStepKey, firstStep.getNextStepKey());
5961
assertEquals(expectedSecondStepKey, secondStep.getKey());
6062
assertEquals(expectedThirdKey, thirdStep.getKey());
61-
assertEquals(nextStepKey, thirdStep.getNextStepKey());
63+
assertEquals(expectedFourthKey, thirdStep.getNextStepKey());
64+
assertEquals(expectedFourthKey, fourthStep.getKey());
65+
assertEquals(nextStepKey, fourthStep.getNextStepKey());
6266
}
6367

6468
{
6569
List<Step> steps = DeleteAction.NO_SNAPSHOT_DELETE.toSteps(null, phase, nextStepKey);
6670
StepKey expectedFirstStepKey = new StepKey(phase, DeleteAction.NAME, WaitForNoFollowersStep.NAME);
67-
StepKey expectedSecondStepKey = new StepKey(phase, DeleteAction.NAME, DeleteStep.NAME);
68-
assertEquals(2, steps.size());
71+
StepKey expectedSecondStepKey = new StepKey(phase, DeleteAction.NAME, WaitUntilTimeSeriesEndTimePassesStep.NAME);
72+
StepKey expectedThirdStepKey = new StepKey(phase, DeleteAction.NAME, DeleteStep.NAME);
73+
assertEquals(3, steps.size());
6974
assertNotNull(steps);
7075
WaitForNoFollowersStep firstStep = (WaitForNoFollowersStep) steps.get(0);
71-
DeleteStep secondStep = (DeleteStep) steps.get(1);
76+
WaitUntilTimeSeriesEndTimePassesStep secondStep = (WaitUntilTimeSeriesEndTimePassesStep) steps.get(1);
77+
DeleteStep thirdStep = (DeleteStep) steps.get(2);
7278
assertEquals(expectedFirstStepKey, firstStep.getKey());
7379
assertEquals(expectedSecondStepKey, firstStep.getNextStepKey());
74-
assertEquals(nextStepKey, secondStep.getNextStepKey());
80+
assertEquals(expectedSecondStepKey, secondStep.getKey());
81+
assertEquals(expectedThirdStepKey, secondStep.getNextStepKey());
82+
assertEquals(expectedThirdStepKey, thirdStep.getKey());
83+
assertEquals(nextStepKey, thirdStep.getNextStepKey());
7584
}
7685
}
7786

0 commit comments

Comments
 (0)