Skip to content

Commit 3908def

Browse files
Merge branch 'main' into fix/es-10982
2 parents 91a6442 + 7d62ea6 commit 3908def

File tree

15 files changed

+245
-182
lines changed

15 files changed

+245
-182
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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -279,7 +279,8 @@ static TransportVersion def(int id) {
279279
public static final TransportVersion ESQL_REGEX_MATCH_WITH_CASE_INSENSITIVITY = def(9_086_0_00);
280280
public static final TransportVersion IDP_CUSTOM_SAML_ATTRIBUTES = def(9_087_0_00);
281281
public static final TransportVersion JOIN_ON_ALIASES = def(9_088_0_00);
282-
public static final TransportVersion SNAPSHOT_INDEX_SHARD_STATUS_MISSING_STATS = def(9_089_0_00);
282+
public static final TransportVersion ILM_ADD_SKIP_SETTING = def(9_089_0_00);
283+
public static final TransportVersion SNAPSHOT_INDEX_SHARD_STATUS_MISSING_STATS = def(9_090_0_00);
283284

284285
/*
285286
* STOP! READ THIS FIRST! No, really,

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)) {
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)) {
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/ExecuteStepsUpdateTask.java

Lines changed: 24 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -127,14 +127,18 @@ public ClusterState doExecute(final ClusterState currentState) throws IOExceptio
127127
return state;
128128
} else {
129129
logger.trace("[{}] moving cluster state to next step [{}]", index.getName(), nextStepKey);
130-
state = IndexLifecycleTransition.moveClusterStateToStep(
131-
index,
132-
state,
133-
nextStepKey,
134-
nowSupplier,
135-
policyStepsRegistry,
136-
false
137-
);
130+
state = ClusterState.builder(state)
131+
.putProjectMetadata(
132+
IndexLifecycleTransition.moveIndexToStep(
133+
index,
134+
state.metadata().getProject(),
135+
nextStepKey,
136+
nowSupplier,
137+
policyStepsRegistry,
138+
false
139+
)
140+
)
141+
.build();
138142
}
139143
} else {
140144
// cluster state wait step so evaluate the
@@ -170,14 +174,18 @@ public ClusterState doExecute(final ClusterState currentState) throws IOExceptio
170174
if (nextStepKey == null) {
171175
return state;
172176
} else {
173-
state = IndexLifecycleTransition.moveClusterStateToStep(
174-
index,
175-
state,
176-
nextStepKey,
177-
nowSupplier,
178-
policyStepsRegistry,
179-
false
180-
);
177+
state = ClusterState.builder(state)
178+
.putProjectMetadata(
179+
IndexLifecycleTransition.moveIndexToStep(
180+
index,
181+
state.metadata().getProject(),
182+
nextStepKey,
183+
nowSupplier,
184+
policyStepsRegistry,
185+
false
186+
)
187+
)
188+
.build();
181189
}
182190
} else {
183191
final ToXContentObject stepInfo = result.informationContext();

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
@@ -126,6 +126,7 @@ public List<Setting<?>> getSettings() {
126126
LifecycleSettings.LIFECYCLE_STEP_MASTER_TIMEOUT_SETTING,
127127
LifecycleSettings.LIFECYCLE_STEP_WAIT_TIME_THRESHOLD_SETTING,
128128
LifecycleSettings.LIFECYCLE_ROLLOVER_ONLY_IF_HAS_DOCUMENTS_SETTING,
129+
LifecycleSettings.LIFECYCLE_SKIP_SETTING,
129130
RolloverAction.LIFECYCLE_ROLLOVER_ALIAS_SETTING,
130131
IlmHealthIndicatorService.MAX_TIME_ON_ACTION_SETTING,
131132
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/IndexLifecycleService.java

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -153,26 +153,21 @@ public StepKey resolveStepKey(ClusterState state, Index index, String phase, @Nu
153153
}
154154

155155
/**
156-
* Move the cluster state to an arbitrary step for the provided index.
156+
* Move the project to an arbitrary step for the provided index.
157157
*
158158
* In order to avoid a check-then-set race condition, the current step key
159159
* is required in order to validate that the index is currently on the
160160
* provided step. If it is not, an {@link IllegalArgumentException} is
161161
* thrown.
162162
* @throws IllegalArgumentException if the step movement cannot be validated
163163
*/
164-
public ClusterState moveClusterStateToStep(ClusterState currentState, Index index, StepKey currentStepKey, StepKey newStepKey) {
164+
public ProjectMetadata moveIndexToStep(ProjectMetadata project, Index index, StepKey currentStepKey, StepKey newStepKey) {
165165
// We manually validate here, because any API must correctly specify the current step key
166166
// when moving to an arbitrary step key (to avoid race conditions between the
167-
// check-and-set). moveClusterStateToStep also does its own validation, but doesn't take
167+
// check-and-set). moveProjectToStep also does its own validation, but doesn't take
168168
// the user-input for the current step (which is why we validate here for a passed in step)
169-
IndexLifecycleTransition.validateTransition(
170-
currentState.getMetadata().getProject().index(index),
171-
currentStepKey,
172-
newStepKey,
173-
policyRegistry
174-
);
175-
return IndexLifecycleTransition.moveClusterStateToStep(index, currentState, newStepKey, nowSupplier, policyRegistry, true);
169+
IndexLifecycleTransition.validateTransition(project.index(index), currentStepKey, newStepKey, policyRegistry);
170+
return IndexLifecycleTransition.moveIndexToStep(index, project, newStepKey, nowSupplier, policyRegistry, true);
176171
}
177172

178173
public ClusterState moveClusterStateToPreviouslyFailedStep(ClusterState currentState, String[] indices) {

0 commit comments

Comments
 (0)