Skip to content

Commit 264c415

Browse files
authored
Readd index.lifecycle.skip setting (#128736) (#128901)
We want to be able to skip specific indices in ILM again for #109206. This is essentially just a revert of #34823. (cherry picked from commit 269fbbc) # Conflicts: # server/src/main/java/org/elasticsearch/TransportVersions.java
1 parent be082ac commit 264c415

File tree

11 files changed

+142
-71
lines changed

11 files changed

+142
-71
lines changed

docs/changelog/128736.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
pr: 128736
2+
summary: Add `index.lifecycle.skip` index-scoped setting to instruct ILM to skip processing specific indices
3+
area: ILM+SLM
4+
type: enhancement
5+
issues: []

server/src/main/java/org/elasticsearch/TransportVersions.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,7 @@ static TransportVersion def(int id) {
233233
public static final TransportVersion IDP_CUSTOM_SAML_ATTRIBUTES_ADDED_8_19 = def(8_841_0_40);
234234
public static final TransportVersion DATA_STREAM_OPTIONS_API_REMOVE_INCLUDE_DEFAULTS_8_19 = def(8_841_0_41);
235235
public static final TransportVersion JOIN_ON_ALIASES_8_19 = def(8_841_0_42);
236+
public static final TransportVersion ILM_ADD_SKIP_SETTING_8_19 = def(8_841_0_43);
236237
/*
237238
* STOP! READ THIS FIRST! No, really,
238239
* ____ _____ ___ ____ _ ____ _____ _ ____ _____ _ _ ___ ____ _____ ___ ____ ____ _____ _

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

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
5555
private static final ParseField REPOSITORY_NAME = new ParseField("repository_name");
5656
private static final ParseField SHRINK_INDEX_NAME = new ParseField("shrink_index_name");
5757
private static final ParseField SNAPSHOT_NAME = new ParseField("snapshot_name");
58+
private static final ParseField SKIP_NAME = new ParseField("skip");
5859

5960
public static final ConstructingObjectParser<IndexLifecycleExplainResponse, Void> PARSER = new ConstructingObjectParser<>(
6061
"index_lifecycle_explain_response",
@@ -78,7 +79,8 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
7879
(String) a[18],
7980
(BytesReference) a[11],
8081
(BytesReference) a[21],
81-
(PhaseExecutionInfo) a[12]
82+
(PhaseExecutionInfo) a[12],
83+
Objects.requireNonNullElse((Boolean) a[22], false)
8284
// a[13] == "age"
8385
// a[20] == "time_since_index_creation"
8486
)
@@ -118,6 +120,7 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
118120
builder.copyCurrentStructure(p);
119121
return BytesReference.bytes(builder);
120122
}, PREVIOUS_STEP_INFO_FIELD);
123+
PARSER.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), SKIP_NAME);
121124
}
122125

123126
private final String index;
@@ -140,6 +143,7 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
140143
private final String repositoryName;
141144
private final String snapshotName;
142145
private final String shrinkIndexName;
146+
private final boolean skip;
143147

144148
Supplier<Long> nowSupplier = System::currentTimeMillis; // Can be changed for testing
145149

@@ -162,7 +166,8 @@ public static IndexLifecycleExplainResponse newManagedIndexResponse(
162166
String shrinkIndexName,
163167
BytesReference stepInfo,
164168
BytesReference previousStepInfo,
165-
PhaseExecutionInfo phaseExecutionInfo
169+
PhaseExecutionInfo phaseExecutionInfo,
170+
boolean skip
166171
) {
167172
return new IndexLifecycleExplainResponse(
168173
index,
@@ -184,7 +189,8 @@ public static IndexLifecycleExplainResponse newManagedIndexResponse(
184189
shrinkIndexName,
185190
stepInfo,
186191
previousStepInfo,
187-
phaseExecutionInfo
192+
phaseExecutionInfo,
193+
skip
188194
);
189195
}
190196

@@ -209,7 +215,8 @@ public static IndexLifecycleExplainResponse newUnmanagedIndexResponse(String ind
209215
null,
210216
null,
211217
null,
212-
null
218+
null,
219+
false
213220
);
214221
}
215222

@@ -233,7 +240,8 @@ private IndexLifecycleExplainResponse(
233240
String shrinkIndexName,
234241
BytesReference stepInfo,
235242
BytesReference previousStepInfo,
236-
PhaseExecutionInfo phaseExecutionInfo
243+
PhaseExecutionInfo phaseExecutionInfo,
244+
boolean skip
237245
) {
238246
if (managedByILM) {
239247
if (policyName == null) {
@@ -301,6 +309,7 @@ private IndexLifecycleExplainResponse(
301309
this.repositoryName = repositoryName;
302310
this.snapshotName = snapshotName;
303311
this.shrinkIndexName = shrinkIndexName;
312+
this.skip = skip;
304313
}
305314

306315
public IndexLifecycleExplainResponse(StreamInput in) throws IOException {
@@ -333,6 +342,11 @@ public IndexLifecycleExplainResponse(StreamInput in) throws IOException {
333342
} else {
334343
previousStepInfo = null;
335344
}
345+
if (in.getTransportVersion().onOrAfter(TransportVersions.ILM_ADD_SKIP_SETTING_8_19)) {
346+
skip = in.readBoolean();
347+
} else {
348+
skip = false;
349+
}
336350
} else {
337351
policyName = null;
338352
lifecycleDate = null;
@@ -352,6 +366,7 @@ public IndexLifecycleExplainResponse(StreamInput in) throws IOException {
352366
snapshotName = null;
353367
shrinkIndexName = null;
354368
indexCreationDate = null;
369+
skip = false;
355370
}
356371
}
357372

@@ -382,6 +397,9 @@ public void writeTo(StreamOutput out) throws IOException {
382397
if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_16_0)) {
383398
out.writeOptionalBytesReference(previousStepInfo);
384399
}
400+
if (out.getTransportVersion().onOrAfter(TransportVersions.ILM_ADD_SKIP_SETTING_8_19)) {
401+
out.writeBoolean(skip);
402+
}
385403
}
386404
}
387405

@@ -481,6 +499,10 @@ public String getShrinkIndexName() {
481499
return shrinkIndexName;
482500
}
483501

502+
public boolean getSkip() {
503+
return skip;
504+
}
505+
484506
@Override
485507
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
486508
builder.startObject();
@@ -564,6 +586,7 @@ public XContentBuilder toXContent(XContentBuilder builder, Params params) throws
564586
if (phaseExecutionInfo != null) {
565587
builder.field(PHASE_EXECUTION_INFO.getPreferredName(), phaseExecutionInfo);
566588
}
589+
builder.field(SKIP_NAME.getPreferredName(), skip);
567590
}
568591
builder.endObject();
569592
return builder;
@@ -591,7 +614,8 @@ public int hashCode() {
591614
shrinkIndexName,
592615
stepInfo,
593616
previousStepInfo,
594-
phaseExecutionInfo
617+
phaseExecutionInfo,
618+
skip
595619
);
596620
}
597621

@@ -623,7 +647,8 @@ public boolean equals(Object obj) {
623647
&& Objects.equals(shrinkIndexName, other.shrinkIndexName)
624648
&& Objects.equals(stepInfo, other.stepInfo)
625649
&& Objects.equals(previousStepInfo, other.previousStepInfo)
626-
&& Objects.equals(phaseExecutionInfo, other.phaseExecutionInfo);
650+
&& Objects.equals(phaseExecutionInfo, other.phaseExecutionInfo)
651+
&& Objects.equals(skip, other.skip);
627652
}
628653

629654
@Override

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ public class LifecycleSettings {
2323
public static final String LIFECYCLE_STEP_MASTER_TIMEOUT = "indices.lifecycle.step.master_timeout";
2424
public static final String LIFECYCLE_STEP_WAIT_TIME_THRESHOLD = "index.lifecycle.step.wait_time_threshold";
2525
public static final String LIFECYCLE_ROLLOVER_ONLY_IF_HAS_DOCUMENTS = "indices.lifecycle.rollover.only_if_has_documents";
26+
public static final String LIFECYCLE_SKIP = "index.lifecycle.skip";
2627

2728
public static final String SLM_HISTORY_INDEX_ENABLED = "slm.history_index_enabled";
2829
public static final String SLM_RETENTION_SCHEDULE = "slm.retention_schedule";
@@ -82,6 +83,12 @@ public class LifecycleSettings {
8283
Setting.Property.NodeScope,
8384
Setting.Property.DeprecatedWarning
8485
);
86+
public static final Setting<Boolean> LIFECYCLE_SKIP_SETTING = Setting.boolSetting(
87+
LIFECYCLE_SKIP,
88+
false,
89+
Setting.Property.Dynamic,
90+
Setting.Property.IndexScope
91+
);
8592

8693
public static final Setting<Boolean> SLM_HISTORY_INDEX_ENABLED_SETTING = Setting.boolSetting(
8794
SLM_HISTORY_INDEX_ENABLED,

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,8 @@ private static IndexLifecycleExplainResponse randomManagedIndexExplainResponse()
7474
stepNull ? null : randomAlphaOfLength(10),
7575
randomBoolean() ? null : new BytesArray(new RandomStepInfo(() -> randomAlphaOfLength(10)).toString()),
7676
randomBoolean() ? null : new BytesArray(new RandomStepInfo(() -> randomAlphaOfLength(10)).toString()),
77-
randomBoolean() ? null : PhaseExecutionInfoTests.randomPhaseExecutionInfo("")
77+
randomBoolean() ? null : PhaseExecutionInfoTests.randomPhaseExecutionInfo(""),
78+
randomBoolean()
7879
);
7980
}
8081

@@ -101,7 +102,8 @@ public void testInvalidStepDetails() {
101102
randomBoolean() ? null : randomAlphaOfLength(10),
102103
randomBoolean() ? null : new BytesArray(new RandomStepInfo(() -> randomAlphaOfLength(10)).toString()),
103104
randomBoolean() ? null : new BytesArray(new RandomStepInfo(() -> randomAlphaOfLength(10)).toString()),
104-
randomBoolean() ? null : PhaseExecutionInfoTests.randomPhaseExecutionInfo("")
105+
randomBoolean() ? null : PhaseExecutionInfoTests.randomPhaseExecutionInfo(""),
106+
randomBoolean()
105107
)
106108
);
107109
assertThat(exception.getMessage(), startsWith("managed index response must have complete step details"));
@@ -135,7 +137,8 @@ public void testIndexAges() {
135137
null,
136138
null,
137139
null,
138-
null
140+
null,
141+
false
139142
);
140143
assertThat(managedExplainResponse.getLifecycleDate(), is(notNullValue()));
141144
Long now = 1_000_000L;
@@ -196,9 +199,10 @@ protected IndexLifecycleExplainResponse mutateInstance(IndexLifecycleExplainResp
196199
BytesReference stepInfo = instance.getStepInfo();
197200
BytesReference previousStepInfo = instance.getPreviousStepInfo();
198201
PhaseExecutionInfo phaseExecutionInfo = instance.getPhaseExecutionInfo();
202+
boolean skip = instance.getSkip();
199203

200204
if (managed) {
201-
switch (between(0, 15)) {
205+
switch (between(0, 16)) {
202206
case 0 -> index += randomAlphaOfLengthBetween(1, 5);
203207
case 1 -> policy += randomAlphaOfLengthBetween(1, 5);
204208
case 2 -> {
@@ -257,6 +261,7 @@ protected IndexLifecycleExplainResponse mutateInstance(IndexLifecycleExplainResp
257261
case 13 -> repositoryName = randomValueOtherThan(repositoryName, () -> randomAlphaOfLengthBetween(5, 10));
258262
case 14 -> snapshotName = randomValueOtherThan(snapshotName, () -> randomAlphaOfLengthBetween(5, 10));
259263
case 15 -> shrinkIndexName = randomValueOtherThan(shrinkIndexName, () -> randomAlphaOfLengthBetween(5, 10));
264+
case 16 -> skip = skip == false;
260265
default -> throw new AssertionError("Illegal randomisation branch");
261266
}
262267

@@ -279,7 +284,8 @@ protected IndexLifecycleExplainResponse mutateInstance(IndexLifecycleExplainResp
279284
shrinkIndexName,
280285
stepInfo,
281286
previousStepInfo,
282-
phaseExecutionInfo
287+
phaseExecutionInfo,
288+
skip
283289
);
284290
} else {
285291
return switch (between(0, 1)) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ public List<Setting<?>> getSettings() {
128128
LifecycleSettings.LIFECYCLE_STEP_MASTER_TIMEOUT_SETTING,
129129
LifecycleSettings.LIFECYCLE_STEP_WAIT_TIME_THRESHOLD_SETTING,
130130
LifecycleSettings.LIFECYCLE_ROLLOVER_ONLY_IF_HAS_DOCUMENTS_SETTING,
131+
LifecycleSettings.LIFECYCLE_SKIP_SETTING,
131132
RolloverAction.LIFECYCLE_ROLLOVER_ALIAS_SETTING,
132133
IlmHealthIndicatorService.MAX_TIME_ON_ACTION_SETTING,
133134
IlmHealthIndicatorService.MAX_TIME_ON_STEP_SETTING,

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.elasticsearch.xpack.core.ilm.ClusterStateActionStep;
3232
import org.elasticsearch.xpack.core.ilm.ClusterStateWaitStep;
3333
import org.elasticsearch.xpack.core.ilm.ErrorStep;
34+
import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
3435
import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep;
3536
import org.elasticsearch.xpack.core.ilm.Step;
3637
import org.elasticsearch.xpack.core.ilm.Step.StepKey;
@@ -176,6 +177,10 @@ boolean isReadyToTransitionToThisPhase(final String policy, final IndexMetadata
176177
*/
177178
void runPeriodicStep(String policy, Metadata metadata, IndexMetadata indexMetadata) {
178179
String index = indexMetadata.getIndex().getName();
180+
if (LifecycleSettings.LIFECYCLE_SKIP_SETTING.get(indexMetadata.getSettings())) {
181+
logger.info("[{}] skipping policy [{}] because [{}] is true", index, policy, LifecycleSettings.LIFECYCLE_SKIP);
182+
return;
183+
}
179184
LifecycleExecutionState lifecycleState = indexMetadata.getLifecycleExecutionState();
180185
final Step currentStep;
181186
try {
@@ -303,6 +308,10 @@ void onErrorMaybeRetryFailedStep(String policy, StepKey currentStep, IndexMetada
303308
*/
304309
void maybeRunAsyncAction(ClusterState currentState, IndexMetadata indexMetadata, String policy, StepKey expectedStepKey) {
305310
String index = indexMetadata.getIndex().getName();
311+
if (LifecycleSettings.LIFECYCLE_SKIP_SETTING.get(indexMetadata.getSettings())) {
312+
logger.info("[{}] skipping policy [{}] because [{}] is true", index, policy, LifecycleSettings.LIFECYCLE_SKIP);
313+
return;
314+
}
306315
LifecycleExecutionState lifecycleState = indexMetadata.getLifecycleExecutionState();
307316
final Step currentStep;
308317
try {
@@ -383,6 +392,10 @@ public void onFailure(Exception e) {
383392
*/
384393
void runPolicyAfterStateChange(String policy, IndexMetadata indexMetadata) {
385394
String index = indexMetadata.getIndex().getName();
395+
if (LifecycleSettings.LIFECYCLE_SKIP_SETTING.get(indexMetadata.getSettings())) {
396+
logger.info("[{}] skipping policy [{}] because [{}] is true", index, policy, LifecycleSettings.LIFECYCLE_SKIP);
397+
return;
398+
}
386399
LifecycleExecutionState lifecycleState = indexMetadata.getLifecycleExecutionState();
387400
final StepKey currentStepKey = Step.getCurrentStepKey(lifecycleState);
388401
if (busyIndices.contains(Tuple.tuple(indexMetadata.getIndex(), currentStepKey))) {

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -477,6 +477,7 @@ private static IndexMetadata.Builder removePolicyForIndex(IndexMetadata indexMet
477477

478478
notChanged &= Strings.isNullOrEmpty(newSettings.remove(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey()));
479479
notChanged &= Strings.isNullOrEmpty(newSettings.remove(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE_SETTING.getKey()));
480+
notChanged &= Strings.isNullOrEmpty(newSettings.remove(LifecycleSettings.LIFECYCLE_SKIP_SETTING.getKey()));
480481
notChanged &= Strings.isNullOrEmpty(newSettings.remove(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS_SETTING.getKey()));
481482
long newSettingsVersion = notChanged ? indexMetadata.getSettingsVersion() : 1 + indexMetadata.getSettingsVersion();
482483

x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/action/TransportExplainLifecycleAction.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,8 @@ static IndexLifecycleExplainResponse getIndexLifecycleExplainResponse(
188188
lifecycleState.shrinkIndexName(),
189189
stepInfoBytes,
190190
previousStepInfoBytes,
191-
phaseExecutionInfo
191+
phaseExecutionInfo,
192+
LifecycleSettings.LIFECYCLE_SKIP_SETTING.get(idxSettings)
192193
);
193194
} else {
194195
indexResponse = null;

0 commit comments

Comments
 (0)