Skip to content

Commit 9a11f13

Browse files
authored
[9.0] Deprecate ILM Freeze Action & remove min_age check (#119456)
1 parent 9f2d1e4 commit 9a11f13

File tree

12 files changed

+140
-183
lines changed

12 files changed

+140
-183
lines changed

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

Lines changed: 12 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,10 @@
66
*/
77
package org.elasticsearch.xpack.core.ilm;
88

9-
import org.apache.logging.log4j.LogManager;
10-
import org.apache.logging.log4j.Logger;
119
import org.elasticsearch.client.internal.Client;
12-
import org.elasticsearch.cluster.metadata.IndexMetadata;
1310
import org.elasticsearch.common.Strings;
1411
import org.elasticsearch.common.io.stream.StreamOutput;
12+
import org.elasticsearch.core.UpdateForV10;
1513
import org.elasticsearch.xcontent.ObjectParser;
1614
import org.elasticsearch.xcontent.XContentBuilder;
1715
import org.elasticsearch.xcontent.XContentParser;
@@ -21,10 +19,14 @@
2119
import java.util.List;
2220

2321
/**
24-
* A {@link LifecycleAction} which freezes the index.
22+
* A noop {@link LifecycleAction} that replaces the removed freeze action. We keep it for backwards compatibility purposes in case we
23+
* encounter a policy or an index that refers to this action and its steps in the lifecycle state.
24+
* At 10.x we would like to sanitize the freeze action from input and expunge from the lifecycle execution
25+
* state of indices.
2526
*/
27+
@Deprecated
28+
@UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT)
2629
public class FreezeAction implements LifecycleAction {
27-
private static final Logger logger = LogManager.getLogger(FreezeAction.class);
2830

2931
public static final String NAME = "freeze";
3032
public static final String CONDITIONAL_SKIP_FREEZE_STEP = BranchingStep.NAME + "-freeze-check-prerequisites";
@@ -34,6 +36,7 @@ public class FreezeAction implements LifecycleAction {
3436
private static final ObjectParser<FreezeAction, Void> PARSER = new ObjectParser<>(NAME, () -> INSTANCE);
3537

3638
public static FreezeAction parse(XContentParser parser) {
39+
3740
return PARSER.apply(parser, null);
3841
}
3942

@@ -63,40 +66,10 @@ public boolean isSafeAction() {
6366
public List<Step> toSteps(Client client, String phase, StepKey nextStepKey) {
6467
StepKey preFreezeMergeBranchingKey = new StepKey(phase, NAME, CONDITIONAL_SKIP_FREEZE_STEP);
6568
StepKey checkNotWriteIndex = new StepKey(phase, NAME, CheckNotDataStreamWriteIndexStep.NAME);
66-
StepKey freezeStepKey = new StepKey(phase, NAME, FreezeStep.NAME);
67-
68-
BranchingStep conditionalSkipFreezeStep = new BranchingStep(
69-
preFreezeMergeBranchingKey,
70-
checkNotWriteIndex,
71-
nextStepKey,
72-
(index, clusterState) -> {
73-
IndexMetadata indexMetadata = clusterState.getMetadata().index(index);
74-
assert indexMetadata != null : "index " + index.getName() + " must exist in the cluster state";
75-
String policyName = indexMetadata.getLifecyclePolicyName();
76-
if (indexMetadata.getSettings().get(LifecycleSettings.SNAPSHOT_INDEX_NAME) != null) {
77-
logger.warn(
78-
"[{}] action is configured for index [{}] in policy [{}] which is mounted as searchable snapshot. "
79-
+ "Skipping this action",
80-
FreezeAction.NAME,
81-
index.getName(),
82-
policyName
83-
);
84-
return true;
85-
}
86-
if (indexMetadata.getSettings().getAsBoolean("index.frozen", false)) {
87-
logger.debug(
88-
"skipping [{}] action for index [{}] in policy [{}] as the index is already frozen",
89-
FreezeAction.NAME,
90-
index.getName(),
91-
policyName
92-
);
93-
return true;
94-
}
95-
return false;
96-
}
97-
);
98-
CheckNotDataStreamWriteIndexStep checkNoWriteIndexStep = new CheckNotDataStreamWriteIndexStep(checkNotWriteIndex, freezeStepKey);
99-
FreezeStep freezeStep = new FreezeStep(freezeStepKey, nextStepKey, client);
69+
StepKey freezeStepKey = new StepKey(phase, NAME, NAME);
70+
NoopStep conditionalSkipFreezeStep = new NoopStep(preFreezeMergeBranchingKey, nextStepKey);
71+
NoopStep checkNoWriteIndexStep = new NoopStep(checkNotWriteIndex, nextStepKey);
72+
NoopStep freezeStep = new NoopStep(freezeStepKey, nextStepKey);
10073
return List.of(conditionalSkipFreezeStep, checkNoWriteIndexStep, freezeStep);
10174
}
10275

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

Lines changed: 0 additions & 35 deletions
This file was deleted.

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
import org.elasticsearch.common.io.stream.StreamInput;
1414
import org.elasticsearch.common.io.stream.StreamOutput;
1515
import org.elasticsearch.core.Nullable;
16+
import org.elasticsearch.core.UpdateForV10;
1617
import org.elasticsearch.license.XPackLicenseState;
1718
import org.elasticsearch.xcontent.ConstructingObjectParser;
1819
import org.elasticsearch.xcontent.ParseField;
@@ -33,6 +34,8 @@
3334
import java.util.function.Function;
3435
import java.util.stream.Collectors;
3536

37+
import static org.elasticsearch.xpack.core.ilm.TimeseriesLifecycleType.COLD_PHASE;
38+
3639
/**
3740
* Represents the lifecycle of an index from creation to deletion. A
3841
* {@link LifecyclePolicy} is made up of a set of {@link Phase}s which it will
@@ -365,4 +368,13 @@ public boolean equals(Object obj) {
365368
public String toString() {
366369
return Strings.toString(this, true, true);
367370
}
371+
372+
@UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT)
373+
public boolean maybeAddDeprecationWarningForFreezeAction(String policyName) {
374+
Phase coldPhase = phases.get(COLD_PHASE);
375+
if (coldPhase != null) {
376+
return coldPhase.maybeAddDeprecationWarningForFreezeAction(policyName);
377+
}
378+
return false;
379+
}
368380
}

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

Lines changed: 26 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -6,15 +6,15 @@
66
*/
77
package org.elasticsearch.xpack.core.ilm;
88

9-
import org.apache.logging.log4j.LogManager;
10-
import org.apache.logging.log4j.Logger;
119
import org.elasticsearch.common.Strings;
1210
import org.elasticsearch.common.io.stream.StreamInput;
1311
import org.elasticsearch.common.io.stream.StreamOutput;
1412
import org.elasticsearch.common.io.stream.Writeable;
13+
import org.elasticsearch.common.logging.DeprecationCategory;
14+
import org.elasticsearch.common.logging.DeprecationLogger;
1515
import org.elasticsearch.common.util.Maps;
1616
import org.elasticsearch.core.TimeValue;
17-
import org.elasticsearch.core.UpdateForV9;
17+
import org.elasticsearch.core.UpdateForV10;
1818
import org.elasticsearch.xcontent.ConstructingObjectParser;
1919
import org.elasticsearch.xcontent.ContextParser;
2020
import org.elasticsearch.xcontent.ObjectParser.ValueType;
@@ -34,7 +34,7 @@
3434
* particular point in the lifecycle of an index.
3535
*/
3636
public class Phase implements ToXContentObject, Writeable {
37-
private static final Logger logger = LogManager.getLogger(Phase.class);
37+
private static final DeprecationLogger deprecationLogger = DeprecationLogger.getLogger(Phase.class);
3838

3939
public static final ParseField MIN_AGE = new ParseField("min_age");
4040
public static final ParseField ACTIONS_FIELD = new ParseField("actions");
@@ -51,19 +51,12 @@ public class Phase implements ToXContentObject, Writeable {
5151
return new Phase(name, (TimeValue) a[0], map);
5252
});
5353
static {
54-
PARSER.declareField(ConstructingObjectParser.optionalConstructorArg(), (ContextParser<String, Object>) (p, c) -> {
55-
// In earlier versions it was possible to create a Phase with a negative `min_age` which would then cause errors
56-
// when the phase is read from the cluster state during startup (even before negative timevalues were strictly
57-
// disallowed) so this is a hack to treat negative `min_age`s as 0 to prevent those errors.
58-
// They will be saved as `0` so this hack can be removed once we no longer have to read cluster states from 7.x.
59-
@UpdateForV9(owner = UpdateForV9.Owner.DATA_MANAGEMENT) // remove this hack now that we don't have to read 7.x cluster states
60-
final String timeValueString = p.text();
61-
if (timeValueString.startsWith("-")) {
62-
logger.warn("phase has negative min_age value of [{}] - this will be treated as a min_age of 0", timeValueString);
63-
return TimeValue.ZERO;
64-
}
65-
return TimeValue.parseTimeValue(timeValueString, MIN_AGE.getPreferredName());
66-
}, MIN_AGE, ValueType.VALUE);
54+
PARSER.declareField(
55+
ConstructingObjectParser.optionalConstructorArg(),
56+
(ContextParser<String, Object>) (p, c) -> TimeValue.parseTimeValue(p.text(), MIN_AGE.getPreferredName()),
57+
MIN_AGE,
58+
ValueType.VALUE
59+
);
6760
PARSER.declareNamedObjects(
6861
ConstructingObjectParser.constructorArg(),
6962
(p, c, n) -> p.namedObject(LifecycleAction.class, n, null),
@@ -183,4 +176,20 @@ public String toString() {
183176
return Strings.toString(this, true, true);
184177
}
185178

179+
@UpdateForV10(owner = UpdateForV10.Owner.DATA_MANAGEMENT)
180+
public boolean maybeAddDeprecationWarningForFreezeAction(String policyName) {
181+
if (getActions().containsKey(FreezeAction.NAME)) {
182+
deprecationLogger.warn(
183+
DeprecationCategory.OTHER,
184+
"ilm_freeze_action_deprecation",
185+
"The freeze action in ILM is deprecated and will be removed in a future version;"
186+
+ " this action is already a noop so it can be safely removed. Please remove the freeze action from the '"
187+
+ policyName
188+
+ "' policy."
189+
);
190+
return true;
191+
}
192+
return false;
193+
}
194+
186195
}

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

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,8 @@ protected FreezeAction createTestInstance() {
2929

3030
@Override
3131
protected FreezeAction mutateInstance(FreezeAction instance) {
32-
return null;// TODO implement https://github.com/elastic/elasticsearch/issues/25929
32+
// This class is a singleton
33+
return null;
3334
}
3435

3536
@Override
@@ -50,16 +51,15 @@ public void testToSteps() {
5051
assertEquals(3, steps.size());
5152
StepKey expectedFirstStepKey = new StepKey(phase, FreezeAction.NAME, FreezeAction.CONDITIONAL_SKIP_FREEZE_STEP);
5253
StepKey expectedSecondStepKey = new StepKey(phase, FreezeAction.NAME, CheckNotDataStreamWriteIndexStep.NAME);
53-
StepKey expectedThirdStepKey = new StepKey(phase, FreezeAction.NAME, FreezeStep.NAME);
54-
55-
BranchingStep firstStep = (BranchingStep) steps.get(0);
56-
CheckNotDataStreamWriteIndexStep secondStep = (CheckNotDataStreamWriteIndexStep) steps.get(1);
57-
FreezeStep thirdStep = (FreezeStep) steps.get(2);
54+
StepKey expectedThirdStepKey = new StepKey(phase, FreezeAction.NAME, FreezeAction.NAME);
5855

56+
NoopStep firstStep = (NoopStep) steps.get(0);
5957
assertThat(firstStep.getKey(), equalTo(expectedFirstStepKey));
60-
58+
assertThat(firstStep.getNextStepKey(), equalTo(nextStepKey));
59+
NoopStep secondStep = (NoopStep) steps.get(1);
6160
assertEquals(expectedSecondStepKey, secondStep.getKey());
62-
assertEquals(expectedThirdStepKey, secondStep.getNextStepKey());
61+
assertEquals(nextStepKey, secondStep.getNextStepKey());
62+
NoopStep thirdStep = (NoopStep) steps.get(2);
6363
assertEquals(expectedThirdStepKey, thirdStep.getKey());
6464
assertEquals(nextStepKey, thirdStep.getNextStepKey());
6565
}

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

Lines changed: 0 additions & 43 deletions
This file was deleted.

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@
3535

3636
public class LifecyclePolicyTests extends AbstractXContentSerializingTestCase<LifecyclePolicy> {
3737

38+
// Excluding the deprecated freeze action and test it separately
3839
private String lifecycleName;
3940

4041
@Override

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

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99

1010
import org.elasticsearch.client.Request;
1111
import org.elasticsearch.client.Response;
12+
import org.elasticsearch.client.WarningFailureException;
1213
import org.elasticsearch.cluster.metadata.DataStream;
1314
import org.elasticsearch.cluster.metadata.IndexMetadata;
1415
import org.elasticsearch.cluster.metadata.Template;
@@ -216,29 +217,27 @@ public void testReadOnlyAction() throws Exception {
216217
}
217218

218219
public void testFreezeAction() throws Exception {
219-
createNewSingletonPolicy(client(), policyName, "cold", FreezeAction.INSTANCE);
220+
try {
221+
createNewSingletonPolicy(client(), policyName, "cold", FreezeAction.INSTANCE);
222+
} catch (WarningFailureException e) {
223+
assertThat(e.getMessage(), containsString("The freeze action in ILM is deprecated and will be removed in a future version"));
224+
}
220225
createComposableTemplate(client(), template, dataStream + "*", getTemplate(policyName));
221226
indexDocument(client(), dataStream, true);
222227

228+
// The freeze action is a noop action with only noop steps and should pass through to complete the phase asap.
223229
String backingIndexName = DataStream.getDefaultBackingIndexName(dataStream, 1);
224-
assertBusy(
225-
() -> assertThat(
226-
"index must wait in the " + CheckNotDataStreamWriteIndexStep.NAME + " until it is not the write index anymore",
227-
explainIndex(client(), backingIndexName).get("step"),
228-
is(CheckNotDataStreamWriteIndexStep.NAME)
229-
),
230-
30,
231-
TimeUnit.SECONDS
232-
);
233-
234-
// Manual rollover the original index such that it's not the write index in the data stream anymore
235-
rolloverMaxOneDocCondition(client(), dataStream);
236-
237-
assertBusy(
238-
() -> assertThat(explainIndex(client(), backingIndexName).get("step"), is(PhaseCompleteStep.NAME)),
239-
30,
240-
TimeUnit.SECONDS
241-
);
230+
assertBusy(() -> {
231+
try {
232+
assertThat(explainIndex(client(), backingIndexName).get("step"), is(PhaseCompleteStep.NAME));
233+
fail("expected a deprecation warning");
234+
} catch (WarningFailureException e) {
235+
assertThat(
236+
e.getMessage(),
237+
containsString("The freeze action in ILM is deprecated and will be removed in a future version")
238+
);
239+
}
240+
}, 30, TimeUnit.SECONDS);
242241

243242
Map<String, Object> settings = getOnlyIndexSettings(client(), backingIndexName);
244243
assertNull(settings.get("index.frozen"));

0 commit comments

Comments
 (0)