Readd `index.lifecycle.skip` setting (#128736)
We want to be able to skip specific indices in ILM again for #109206. This is essentially just a revert of #34823.
This commit is contained in:
parent
1ba21c2db6
commit
269fbbc289
|
@ -0,0 +1,5 @@
|
|||
pr: 128736
|
||||
summary: Add `index.lifecycle.skip` index-scoped setting to instruct ILM to skip processing specific indices
|
||||
area: ILM+SLM
|
||||
type: enhancement
|
||||
issues: []
|
|
@ -279,6 +279,7 @@ public class TransportVersions {
|
|||
public static final TransportVersion ESQL_REGEX_MATCH_WITH_CASE_INSENSITIVITY = def(9_086_0_00);
|
||||
public static final TransportVersion IDP_CUSTOM_SAML_ATTRIBUTES = def(9_087_0_00);
|
||||
public static final TransportVersion JOIN_ON_ALIASES = def(9_088_0_00);
|
||||
public static final TransportVersion ILM_ADD_SKIP_SETTING = def(9_089_0_00);
|
||||
|
||||
/*
|
||||
* STOP! READ THIS FIRST! No, really,
|
||||
|
|
|
@ -55,6 +55,7 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
|
|||
private static final ParseField REPOSITORY_NAME = new ParseField("repository_name");
|
||||
private static final ParseField SHRINK_INDEX_NAME = new ParseField("shrink_index_name");
|
||||
private static final ParseField SNAPSHOT_NAME = new ParseField("snapshot_name");
|
||||
private static final ParseField SKIP_NAME = new ParseField("skip");
|
||||
|
||||
public static final ConstructingObjectParser<IndexLifecycleExplainResponse, Void> PARSER = new ConstructingObjectParser<>(
|
||||
"index_lifecycle_explain_response",
|
||||
|
@ -78,7 +79,8 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
|
|||
(String) a[18],
|
||||
(BytesReference) a[11],
|
||||
(BytesReference) a[21],
|
||||
(PhaseExecutionInfo) a[12]
|
||||
(PhaseExecutionInfo) a[12],
|
||||
Objects.requireNonNullElse((Boolean) a[22], false)
|
||||
// a[13] == "age"
|
||||
// a[20] == "time_since_index_creation"
|
||||
)
|
||||
|
@ -118,6 +120,7 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
|
|||
builder.copyCurrentStructure(p);
|
||||
return BytesReference.bytes(builder);
|
||||
}, PREVIOUS_STEP_INFO_FIELD);
|
||||
PARSER.declareBoolean(ConstructingObjectParser.optionalConstructorArg(), SKIP_NAME);
|
||||
}
|
||||
|
||||
private final String index;
|
||||
|
@ -140,6 +143,7 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
|
|||
private final String repositoryName;
|
||||
private final String snapshotName;
|
||||
private final String shrinkIndexName;
|
||||
private final boolean skip;
|
||||
|
||||
Supplier<Long> nowSupplier = System::currentTimeMillis; // Can be changed for testing
|
||||
|
||||
|
@ -162,7 +166,8 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
|
|||
String shrinkIndexName,
|
||||
BytesReference stepInfo,
|
||||
BytesReference previousStepInfo,
|
||||
PhaseExecutionInfo phaseExecutionInfo
|
||||
PhaseExecutionInfo phaseExecutionInfo,
|
||||
boolean skip
|
||||
) {
|
||||
return new IndexLifecycleExplainResponse(
|
||||
index,
|
||||
|
@ -184,7 +189,8 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
|
|||
shrinkIndexName,
|
||||
stepInfo,
|
||||
previousStepInfo,
|
||||
phaseExecutionInfo
|
||||
phaseExecutionInfo,
|
||||
skip
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -209,7 +215,8 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
|
|||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
null,
|
||||
false
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -233,7 +240,8 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
|
|||
String shrinkIndexName,
|
||||
BytesReference stepInfo,
|
||||
BytesReference previousStepInfo,
|
||||
PhaseExecutionInfo phaseExecutionInfo
|
||||
PhaseExecutionInfo phaseExecutionInfo,
|
||||
boolean skip
|
||||
) {
|
||||
if (managedByILM) {
|
||||
if (policyName == null) {
|
||||
|
@ -301,6 +309,7 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
|
|||
this.repositoryName = repositoryName;
|
||||
this.snapshotName = snapshotName;
|
||||
this.shrinkIndexName = shrinkIndexName;
|
||||
this.skip = skip;
|
||||
}
|
||||
|
||||
public IndexLifecycleExplainResponse(StreamInput in) throws IOException {
|
||||
|
@ -333,6 +342,11 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
|
|||
} else {
|
||||
previousStepInfo = null;
|
||||
}
|
||||
if (in.getTransportVersion().onOrAfter(TransportVersions.ILM_ADD_SKIP_SETTING)) {
|
||||
skip = in.readBoolean();
|
||||
} else {
|
||||
skip = false;
|
||||
}
|
||||
} else {
|
||||
policyName = null;
|
||||
lifecycleDate = null;
|
||||
|
@ -352,6 +366,7 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
|
|||
snapshotName = null;
|
||||
shrinkIndexName = null;
|
||||
indexCreationDate = null;
|
||||
skip = false;
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -382,6 +397,9 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
|
|||
if (out.getTransportVersion().onOrAfter(TransportVersions.V_8_16_0)) {
|
||||
out.writeOptionalBytesReference(previousStepInfo);
|
||||
}
|
||||
if (out.getTransportVersion().onOrAfter(TransportVersions.ILM_ADD_SKIP_SETTING)) {
|
||||
out.writeBoolean(skip);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -481,6 +499,10 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
|
|||
return shrinkIndexName;
|
||||
}
|
||||
|
||||
public boolean getSkip() {
|
||||
return skip;
|
||||
}
|
||||
|
||||
@Override
|
||||
public XContentBuilder toXContent(XContentBuilder builder, Params params) throws IOException {
|
||||
builder.startObject();
|
||||
|
@ -564,6 +586,7 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
|
|||
if (phaseExecutionInfo != null) {
|
||||
builder.field(PHASE_EXECUTION_INFO.getPreferredName(), phaseExecutionInfo);
|
||||
}
|
||||
builder.field(SKIP_NAME.getPreferredName(), skip);
|
||||
}
|
||||
builder.endObject();
|
||||
return builder;
|
||||
|
@ -591,7 +614,8 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
|
|||
shrinkIndexName,
|
||||
stepInfo,
|
||||
previousStepInfo,
|
||||
phaseExecutionInfo
|
||||
phaseExecutionInfo,
|
||||
skip
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -623,7 +647,8 @@ public class IndexLifecycleExplainResponse implements ToXContentObject, Writeabl
|
|||
&& Objects.equals(shrinkIndexName, other.shrinkIndexName)
|
||||
&& Objects.equals(stepInfo, other.stepInfo)
|
||||
&& Objects.equals(previousStepInfo, other.previousStepInfo)
|
||||
&& Objects.equals(phaseExecutionInfo, other.phaseExecutionInfo);
|
||||
&& Objects.equals(phaseExecutionInfo, other.phaseExecutionInfo)
|
||||
&& Objects.equals(skip, other.skip);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,6 +23,7 @@ public class LifecycleSettings {
|
|||
public static final String LIFECYCLE_STEP_MASTER_TIMEOUT = "indices.lifecycle.step.master_timeout";
|
||||
public static final String LIFECYCLE_STEP_WAIT_TIME_THRESHOLD = "index.lifecycle.step.wait_time_threshold";
|
||||
public static final String LIFECYCLE_ROLLOVER_ONLY_IF_HAS_DOCUMENTS = "indices.lifecycle.rollover.only_if_has_documents";
|
||||
public static final String LIFECYCLE_SKIP = "index.lifecycle.skip";
|
||||
|
||||
public static final String SLM_HISTORY_INDEX_ENABLED = "slm.history_index_enabled";
|
||||
public static final String SLM_RETENTION_SCHEDULE = "slm.retention_schedule";
|
||||
|
@ -82,6 +83,12 @@ public class LifecycleSettings {
|
|||
Setting.Property.NodeScope,
|
||||
Setting.Property.DeprecatedWarning
|
||||
);
|
||||
public static final Setting<Boolean> LIFECYCLE_SKIP_SETTING = Setting.boolSetting(
|
||||
LIFECYCLE_SKIP,
|
||||
false,
|
||||
Setting.Property.Dynamic,
|
||||
Setting.Property.IndexScope
|
||||
);
|
||||
|
||||
public static final Setting<Boolean> SLM_HISTORY_INDEX_ENABLED_SETTING = Setting.boolSetting(
|
||||
SLM_HISTORY_INDEX_ENABLED,
|
||||
|
|
|
@ -74,7 +74,8 @@ public class IndexLifecycleExplainResponseTests extends AbstractXContentSerializ
|
|||
stepNull ? null : randomAlphaOfLength(10),
|
||||
randomBoolean() ? null : new BytesArray(new RandomStepInfo(() -> randomAlphaOfLength(10)).toString()),
|
||||
randomBoolean() ? null : new BytesArray(new RandomStepInfo(() -> randomAlphaOfLength(10)).toString()),
|
||||
randomBoolean() ? null : PhaseExecutionInfoTests.randomPhaseExecutionInfo("")
|
||||
randomBoolean() ? null : PhaseExecutionInfoTests.randomPhaseExecutionInfo(""),
|
||||
randomBoolean()
|
||||
);
|
||||
}
|
||||
|
||||
|
@ -101,7 +102,8 @@ public class IndexLifecycleExplainResponseTests extends AbstractXContentSerializ
|
|||
randomBoolean() ? null : randomAlphaOfLength(10),
|
||||
randomBoolean() ? null : new BytesArray(new RandomStepInfo(() -> randomAlphaOfLength(10)).toString()),
|
||||
randomBoolean() ? null : new BytesArray(new RandomStepInfo(() -> randomAlphaOfLength(10)).toString()),
|
||||
randomBoolean() ? null : PhaseExecutionInfoTests.randomPhaseExecutionInfo("")
|
||||
randomBoolean() ? null : PhaseExecutionInfoTests.randomPhaseExecutionInfo(""),
|
||||
randomBoolean()
|
||||
)
|
||||
);
|
||||
assertThat(exception.getMessage(), startsWith("managed index response must have complete step details"));
|
||||
|
@ -135,7 +137,8 @@ public class IndexLifecycleExplainResponseTests extends AbstractXContentSerializ
|
|||
null,
|
||||
null,
|
||||
null,
|
||||
null
|
||||
null,
|
||||
false
|
||||
);
|
||||
assertThat(managedExplainResponse.getLifecycleDate(), is(notNullValue()));
|
||||
Long now = 1_000_000L;
|
||||
|
@ -196,9 +199,10 @@ public class IndexLifecycleExplainResponseTests extends AbstractXContentSerializ
|
|||
BytesReference stepInfo = instance.getStepInfo();
|
||||
BytesReference previousStepInfo = instance.getPreviousStepInfo();
|
||||
PhaseExecutionInfo phaseExecutionInfo = instance.getPhaseExecutionInfo();
|
||||
boolean skip = instance.getSkip();
|
||||
|
||||
if (managed) {
|
||||
switch (between(0, 15)) {
|
||||
switch (between(0, 16)) {
|
||||
case 0 -> index += randomAlphaOfLengthBetween(1, 5);
|
||||
case 1 -> policy += randomAlphaOfLengthBetween(1, 5);
|
||||
case 2 -> {
|
||||
|
@ -257,6 +261,7 @@ public class IndexLifecycleExplainResponseTests extends AbstractXContentSerializ
|
|||
case 13 -> repositoryName = randomValueOtherThan(repositoryName, () -> randomAlphaOfLengthBetween(5, 10));
|
||||
case 14 -> snapshotName = randomValueOtherThan(snapshotName, () -> randomAlphaOfLengthBetween(5, 10));
|
||||
case 15 -> shrinkIndexName = randomValueOtherThan(shrinkIndexName, () -> randomAlphaOfLengthBetween(5, 10));
|
||||
case 16 -> skip = skip == false;
|
||||
default -> throw new AssertionError("Illegal randomisation branch");
|
||||
}
|
||||
|
||||
|
@ -279,7 +284,8 @@ public class IndexLifecycleExplainResponseTests extends AbstractXContentSerializ
|
|||
shrinkIndexName,
|
||||
stepInfo,
|
||||
previousStepInfo,
|
||||
phaseExecutionInfo
|
||||
phaseExecutionInfo,
|
||||
skip
|
||||
);
|
||||
} else {
|
||||
return switch (between(0, 1)) {
|
||||
|
|
|
@ -126,6 +126,7 @@ public class IndexLifecycle extends Plugin implements ActionPlugin, HealthPlugin
|
|||
LifecycleSettings.LIFECYCLE_STEP_MASTER_TIMEOUT_SETTING,
|
||||
LifecycleSettings.LIFECYCLE_STEP_WAIT_TIME_THRESHOLD_SETTING,
|
||||
LifecycleSettings.LIFECYCLE_ROLLOVER_ONLY_IF_HAS_DOCUMENTS_SETTING,
|
||||
LifecycleSettings.LIFECYCLE_SKIP_SETTING,
|
||||
RolloverAction.LIFECYCLE_ROLLOVER_ALIAS_SETTING,
|
||||
IlmHealthIndicatorService.MAX_TIME_ON_ACTION_SETTING,
|
||||
IlmHealthIndicatorService.MAX_TIME_ON_STEP_SETTING,
|
||||
|
|
|
@ -31,6 +31,7 @@ import org.elasticsearch.xpack.core.ilm.AsyncWaitStep;
|
|||
import org.elasticsearch.xpack.core.ilm.ClusterStateActionStep;
|
||||
import org.elasticsearch.xpack.core.ilm.ClusterStateWaitStep;
|
||||
import org.elasticsearch.xpack.core.ilm.ErrorStep;
|
||||
import org.elasticsearch.xpack.core.ilm.LifecycleSettings;
|
||||
import org.elasticsearch.xpack.core.ilm.PhaseCompleteStep;
|
||||
import org.elasticsearch.xpack.core.ilm.Step;
|
||||
import org.elasticsearch.xpack.core.ilm.Step.StepKey;
|
||||
|
@ -176,6 +177,10 @@ class IndexLifecycleRunner {
|
|||
*/
|
||||
void runPeriodicStep(String policy, Metadata metadata, IndexMetadata indexMetadata) {
|
||||
String index = indexMetadata.getIndex().getName();
|
||||
if (LifecycleSettings.LIFECYCLE_SKIP_SETTING.get(indexMetadata.getSettings())) {
|
||||
logger.info("[{}] skipping policy [{}] because [{}] is true", index, policy, LifecycleSettings.LIFECYCLE_SKIP);
|
||||
return;
|
||||
}
|
||||
LifecycleExecutionState lifecycleState = indexMetadata.getLifecycleExecutionState();
|
||||
final Step currentStep;
|
||||
try {
|
||||
|
@ -303,6 +308,10 @@ class IndexLifecycleRunner {
|
|||
*/
|
||||
void maybeRunAsyncAction(ClusterState currentState, IndexMetadata indexMetadata, String policy, StepKey expectedStepKey) {
|
||||
String index = indexMetadata.getIndex().getName();
|
||||
if (LifecycleSettings.LIFECYCLE_SKIP_SETTING.get(indexMetadata.getSettings())) {
|
||||
logger.info("[{}] skipping policy [{}] because [{}] is true", index, policy, LifecycleSettings.LIFECYCLE_SKIP);
|
||||
return;
|
||||
}
|
||||
LifecycleExecutionState lifecycleState = indexMetadata.getLifecycleExecutionState();
|
||||
final Step currentStep;
|
||||
try {
|
||||
|
@ -383,6 +392,10 @@ class IndexLifecycleRunner {
|
|||
*/
|
||||
void runPolicyAfterStateChange(String policy, IndexMetadata indexMetadata) {
|
||||
String index = indexMetadata.getIndex().getName();
|
||||
if (LifecycleSettings.LIFECYCLE_SKIP_SETTING.get(indexMetadata.getSettings())) {
|
||||
logger.info("[{}] skipping policy [{}] because [{}] is true", index, policy, LifecycleSettings.LIFECYCLE_SKIP);
|
||||
return;
|
||||
}
|
||||
LifecycleExecutionState lifecycleState = indexMetadata.getLifecycleExecutionState();
|
||||
final StepKey currentStepKey = Step.getCurrentStepKey(lifecycleState);
|
||||
if (busyIndices.contains(Tuple.tuple(indexMetadata.getIndex(), currentStepKey))) {
|
||||
|
|
|
@ -494,6 +494,7 @@ public final class IndexLifecycleTransition {
|
|||
|
||||
notChanged &= Strings.isNullOrEmpty(newSettings.remove(LifecycleSettings.LIFECYCLE_NAME_SETTING.getKey()));
|
||||
notChanged &= Strings.isNullOrEmpty(newSettings.remove(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE_SETTING.getKey()));
|
||||
notChanged &= Strings.isNullOrEmpty(newSettings.remove(LifecycleSettings.LIFECYCLE_SKIP_SETTING.getKey()));
|
||||
notChanged &= Strings.isNullOrEmpty(newSettings.remove(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS_SETTING.getKey()));
|
||||
long newSettingsVersion = notChanged ? indexMetadata.getSettingsVersion() : 1 + indexMetadata.getSettingsVersion();
|
||||
|
||||
|
|
|
@ -222,7 +222,8 @@ public class TransportExplainLifecycleAction extends TransportLocalProjectMetada
|
|||
lifecycleState.shrinkIndexName(),
|
||||
stepInfoBytes,
|
||||
previousStepInfoBytes,
|
||||
phaseExecutionInfo
|
||||
phaseExecutionInfo,
|
||||
LifecycleSettings.LIFECYCLE_SKIP_SETTING.get(idxSettings)
|
||||
);
|
||||
} else {
|
||||
indexResponse = null;
|
||||
|
|
|
@ -137,11 +137,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
PolicyStepsRegistry stepRegistry = createOneStepPolicyStepRegistry(policyName, step);
|
||||
ClusterService clusterService = mock(ClusterService.class);
|
||||
IndexLifecycleRunner runner = new IndexLifecycleRunner(stepRegistry, historyStore, clusterService, threadPool, () -> 0L);
|
||||
IndexMetadata indexMetadata = IndexMetadata.builder("my_index")
|
||||
.settings(settings(IndexVersion.current()))
|
||||
.numberOfShards(randomIntBetween(1, 5))
|
||||
.numberOfReplicas(randomIntBetween(0, 5))
|
||||
.build();
|
||||
IndexMetadata indexMetadata = createIndex("my_index");
|
||||
|
||||
runner.runPolicyAfterStateChange(policyName, indexMetadata);
|
||||
|
||||
|
@ -155,11 +151,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
PolicyStepsRegistry stepRegistry = createOneStepPolicyStepRegistry(policyName, step);
|
||||
ClusterService clusterService = mock(ClusterService.class);
|
||||
IndexLifecycleRunner runner = new IndexLifecycleRunner(stepRegistry, historyStore, clusterService, threadPool, () -> 0L);
|
||||
IndexMetadata indexMetadata = IndexMetadata.builder("my_index")
|
||||
.settings(settings(IndexVersion.current()))
|
||||
.numberOfShards(randomIntBetween(1, 5))
|
||||
.numberOfReplicas(randomIntBetween(0, 5))
|
||||
.build();
|
||||
IndexMetadata indexMetadata = createIndex("my_index");
|
||||
|
||||
runner.runPolicyAfterStateChange(policyName, indexMetadata);
|
||||
runner.runPeriodicStep(policyName, Metadata.builder().put(indexMetadata, true).build(), indexMetadata);
|
||||
|
@ -185,11 +177,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
ClusterService clusterService = mock(ClusterService.class);
|
||||
MasterServiceTaskQueue<IndexLifecycleClusterStateUpdateTask> taskQueue = newMockTaskQueue(clusterService);
|
||||
IndexLifecycleRunner runner = new IndexLifecycleRunner(stepRegistry, historyStore, clusterService, threadPool, () -> 0L);
|
||||
IndexMetadata indexMetadata = IndexMetadata.builder("my_index")
|
||||
.settings(settings(IndexVersion.current()))
|
||||
.numberOfShards(randomIntBetween(1, 5))
|
||||
.numberOfReplicas(randomIntBetween(0, 5))
|
||||
.build();
|
||||
IndexMetadata indexMetadata = createIndex("my_index");
|
||||
|
||||
runner.runPolicyAfterStateChange(policyName, indexMetadata);
|
||||
runner.runPeriodicStep(policyName, Metadata.builder().put(indexMetadata, true).build(), indexMetadata);
|
||||
|
@ -219,10 +207,8 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
newState.setStep(ErrorStep.NAME);
|
||||
newState.setPhaseDefinition(phaseJson);
|
||||
IndexMetadata indexMetadata = IndexMetadata.builder("test")
|
||||
.settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_NAME, policyName))
|
||||
.settings(randomIndexSettings())
|
||||
.putCustom(ILM_CUSTOM_METADATA_KEY, newState.build().asMap())
|
||||
.numberOfShards(randomIntBetween(1, 5))
|
||||
.numberOfReplicas(randomIntBetween(0, 5))
|
||||
.build();
|
||||
|
||||
runner.runPolicyAfterStateChange(policyName, indexMetadata);
|
||||
|
@ -231,6 +217,48 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
Mockito.verifyNoMoreInteractions(clusterService);
|
||||
}
|
||||
|
||||
public void testSkip_afterStateChange() {
|
||||
final var policyName = randomAlphaOfLength(10);
|
||||
ClusterService clusterService = mock(ClusterService.class);
|
||||
final var runner = new IndexLifecycleRunner(null, null, clusterService, null, () -> 0L);
|
||||
final var index = IndexMetadata.builder(randomAlphaOfLength(5))
|
||||
.settings(randomIndexSettings().put(LifecycleSettings.LIFECYCLE_SKIP, true))
|
||||
.build();
|
||||
|
||||
runner.runPolicyAfterStateChange(policyName, index);
|
||||
|
||||
Mockito.verify(clusterService).createTaskQueue(anyString(), any(Priority.class), any());
|
||||
Mockito.verifyNoMoreInteractions(clusterService);
|
||||
}
|
||||
|
||||
public void testSkip_periodicRun() {
|
||||
final var policyName = randomAlphaOfLength(10);
|
||||
ClusterService clusterService = mock(ClusterService.class);
|
||||
final var runner = new IndexLifecycleRunner(null, null, clusterService, null, () -> 0L);
|
||||
final var index = IndexMetadata.builder(randomAlphaOfLength(5))
|
||||
.settings(randomIndexSettings().put(LifecycleSettings.LIFECYCLE_SKIP, true))
|
||||
.build();
|
||||
|
||||
runner.runPeriodicStep(policyName, null, index);
|
||||
|
||||
Mockito.verify(clusterService).createTaskQueue(anyString(), any(Priority.class), any());
|
||||
Mockito.verifyNoMoreInteractions(clusterService);
|
||||
}
|
||||
|
||||
public void testSkip_asyncAction() {
|
||||
final var policyName = randomAlphaOfLength(10);
|
||||
ClusterService clusterService = mock(ClusterService.class);
|
||||
final var runner = new IndexLifecycleRunner(null, null, clusterService, null, () -> 0L);
|
||||
final var index = IndexMetadata.builder(randomAlphaOfLength(5))
|
||||
.settings(randomIndexSettings().put(LifecycleSettings.LIFECYCLE_SKIP, true))
|
||||
.build();
|
||||
|
||||
runner.maybeRunAsyncAction(null, index, policyName, null);
|
||||
|
||||
Mockito.verify(clusterService).createTaskQueue(anyString(), any(Priority.class), any());
|
||||
Mockito.verifyNoMoreInteractions(clusterService);
|
||||
}
|
||||
|
||||
public void testRunPolicyErrorStepOnRetryableFailedStep() {
|
||||
String policyName = "rollover_policy";
|
||||
String phaseName = "hot";
|
||||
|
@ -263,10 +291,8 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
newState.setStep(ErrorStep.NAME);
|
||||
newState.setPhaseDefinition(phaseJson);
|
||||
IndexMetadata indexMetadata = IndexMetadata.builder("test")
|
||||
.settings(settings(IndexVersion.current()).put(LifecycleSettings.LIFECYCLE_NAME, policyName))
|
||||
.settings(randomIndexSettings().put(LifecycleSettings.LIFECYCLE_NAME, policyName))
|
||||
.putCustom(ILM_CUSTOM_METADATA_KEY, newState.build().asMap())
|
||||
.numberOfShards(randomIntBetween(1, 5))
|
||||
.numberOfReplicas(randomIntBetween(0, 5))
|
||||
.build();
|
||||
|
||||
runner.runPeriodicStep(policyName, Metadata.builder().put(indexMetadata, true).build(), indexMetadata);
|
||||
|
@ -281,7 +307,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
PolicyStepsRegistry stepRegistry = createOneStepPolicyStepRegistry(policyName, step);
|
||||
ThreadPool threadPool = new TestThreadPool("name");
|
||||
IndexMetadata indexMetadata = IndexMetadata.builder("test")
|
||||
.settings(indexSettings(IndexVersion.current(), 1, 1).put(LifecycleSettings.LIFECYCLE_NAME, policyName))
|
||||
.settings(randomIndexSettings().put(LifecycleSettings.LIFECYCLE_NAME, policyName))
|
||||
.build();
|
||||
ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool);
|
||||
DiscoveryNode node = clusterService.localNode();
|
||||
|
@ -332,7 +358,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
.setStep("cluster_state_action_step")
|
||||
.build();
|
||||
IndexMetadata indexMetadata = IndexMetadata.builder("test")
|
||||
.settings(indexSettings(IndexVersion.current(), 1, 1).put(LifecycleSettings.LIFECYCLE_NAME, policyName))
|
||||
.settings(randomIndexSettings().put(LifecycleSettings.LIFECYCLE_NAME, policyName))
|
||||
.putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, les.asMap())
|
||||
.build();
|
||||
ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool);
|
||||
|
@ -420,7 +446,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
.setStep("cluster_state_action_step")
|
||||
.build();
|
||||
IndexMetadata indexMetadata = IndexMetadata.builder("test")
|
||||
.settings(indexSettings(IndexVersion.current(), 1, 1).put(LifecycleSettings.LIFECYCLE_NAME, policyName))
|
||||
.settings(randomIndexSettings().put(LifecycleSettings.LIFECYCLE_NAME, policyName))
|
||||
.putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, les.asMap())
|
||||
.build();
|
||||
ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool);
|
||||
|
@ -471,7 +497,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
PolicyStepsRegistry stepRegistry = createOneStepPolicyStepRegistry(policyName, step);
|
||||
ThreadPool threadPool = new TestThreadPool("name");
|
||||
IndexMetadata indexMetadata = IndexMetadata.builder("test")
|
||||
.settings(indexSettings(IndexVersion.current(), 1, 1).put(LifecycleSettings.LIFECYCLE_NAME, policyName))
|
||||
.settings(randomIndexSettings().put(LifecycleSettings.LIFECYCLE_NAME, policyName))
|
||||
.build();
|
||||
ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool);
|
||||
DiscoveryNode node = clusterService.localNode();
|
||||
|
@ -520,7 +546,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
.setStep("cluster_state_action_step")
|
||||
.build();
|
||||
IndexMetadata indexMetadata = IndexMetadata.builder("test")
|
||||
.settings(indexSettings(IndexVersion.current(), 1, 1).put(LifecycleSettings.LIFECYCLE_NAME, policyName))
|
||||
.settings(randomIndexSettings().put(LifecycleSettings.LIFECYCLE_NAME, policyName))
|
||||
.putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, les.asMap())
|
||||
.build();
|
||||
ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool);
|
||||
|
@ -597,7 +623,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
.setStep("cluster_state_action_step")
|
||||
.build();
|
||||
IndexMetadata indexMetadata = IndexMetadata.builder("test")
|
||||
.settings(indexSettings(IndexVersion.current(), 1, 1).put(LifecycleSettings.LIFECYCLE_NAME, policyName))
|
||||
.settings(randomIndexSettings().put(LifecycleSettings.LIFECYCLE_NAME, policyName))
|
||||
.putCustom(LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY, les.asMap())
|
||||
.build();
|
||||
ClusterService clusterService = ClusterServiceUtils.createClusterService(threadPool);
|
||||
|
@ -635,11 +661,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
ClusterService clusterService = mock(ClusterService.class);
|
||||
MasterServiceTaskQueue<IndexLifecycleClusterStateUpdateTask> taskQueue = newMockTaskQueue(clusterService);
|
||||
IndexLifecycleRunner runner = new IndexLifecycleRunner(stepRegistry, historyStore, clusterService, threadPool, () -> 0L);
|
||||
IndexMetadata indexMetadata = IndexMetadata.builder("my_index")
|
||||
.settings(settings(IndexVersion.current()))
|
||||
.numberOfShards(randomIntBetween(1, 5))
|
||||
.numberOfReplicas(randomIntBetween(0, 5))
|
||||
.build();
|
||||
IndexMetadata indexMetadata = createIndex("my_index");
|
||||
|
||||
runner.runPolicyAfterStateChange(policyName, indexMetadata);
|
||||
|
||||
|
@ -664,11 +686,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
ClusterService clusterService = mock(ClusterService.class);
|
||||
MasterServiceTaskQueue<IndexLifecycleClusterStateUpdateTask> taskQueue = newMockTaskQueue(clusterService);
|
||||
IndexLifecycleRunner runner = new IndexLifecycleRunner(stepRegistry, historyStore, clusterService, threadPool, () -> 0L);
|
||||
IndexMetadata indexMetadata = IndexMetadata.builder("my_index")
|
||||
.settings(settings(IndexVersion.current()))
|
||||
.numberOfShards(randomIntBetween(1, 5))
|
||||
.numberOfReplicas(randomIntBetween(0, 5))
|
||||
.build();
|
||||
IndexMetadata indexMetadata = createIndex("my_index");
|
||||
|
||||
runner.runPolicyAfterStateChange(policyName, indexMetadata);
|
||||
|
||||
|
@ -694,11 +712,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
PolicyStepsRegistry stepRegistry = createOneStepPolicyStepRegistry(policyName, step);
|
||||
ClusterService clusterService = mock(ClusterService.class);
|
||||
IndexLifecycleRunner runner = new IndexLifecycleRunner(stepRegistry, historyStore, clusterService, threadPool, () -> 0L);
|
||||
IndexMetadata indexMetadata = IndexMetadata.builder("my_index")
|
||||
.settings(settings(IndexVersion.current()))
|
||||
.numberOfShards(randomIntBetween(1, 5))
|
||||
.numberOfReplicas(randomIntBetween(0, 5))
|
||||
.build();
|
||||
IndexMetadata indexMetadata = createIndex("my_index");
|
||||
|
||||
runner.runPolicyAfterStateChange(policyName, indexMetadata);
|
||||
|
||||
|
@ -716,11 +730,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
PolicyStepsRegistry stepRegistry = createOneStepPolicyStepRegistry(policyName, step);
|
||||
ClusterService clusterService = mock(ClusterService.class);
|
||||
IndexLifecycleRunner runner = new IndexLifecycleRunner(stepRegistry, historyStore, clusterService, threadPool, () -> 0L);
|
||||
IndexMetadata indexMetadata = IndexMetadata.builder("my_index")
|
||||
.settings(settings(IndexVersion.current()))
|
||||
.numberOfShards(randomIntBetween(1, 5))
|
||||
.numberOfReplicas(randomIntBetween(0, 5))
|
||||
.build();
|
||||
IndexMetadata indexMetadata = createIndex("my_index");
|
||||
|
||||
runner.runPolicyAfterStateChange(policyName, indexMetadata);
|
||||
|
||||
|
@ -740,11 +750,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
threadPool,
|
||||
() -> 0L
|
||||
);
|
||||
IndexMetadata indexMetadata = IndexMetadata.builder("my_index")
|
||||
.settings(settings(IndexVersion.current()))
|
||||
.numberOfShards(randomIntBetween(1, 5))
|
||||
.numberOfReplicas(randomIntBetween(0, 5))
|
||||
.build();
|
||||
IndexMetadata indexMetadata = createIndex("my_index");
|
||||
// verify that no exception is thrown
|
||||
runner.runPolicyAfterStateChange(policyName, indexMetadata);
|
||||
final SetStepInfoUpdateTaskMatcher taskMatcher = new SetStepInfoUpdateTaskMatcher(
|
||||
|
@ -791,7 +797,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
String phaseJson = Strings.toString(pei);
|
||||
LifecycleAction action = randomValueOtherThan(MigrateAction.DISABLED, () -> randomFrom(phase.getActions().values()));
|
||||
Step step = randomFrom(action.toSteps(client, phaseName, MOCK_STEP_KEY, null));
|
||||
Settings indexSettings = indexSettings(IndexVersion.current(), 1, 0).put(LifecycleSettings.LIFECYCLE_NAME, policyName).build();
|
||||
Settings indexSettings = randomIndexSettings().put(LifecycleSettings.LIFECYCLE_NAME, policyName).build();
|
||||
LifecycleExecutionState.Builder lifecycleState = LifecycleExecutionState.builder();
|
||||
lifecycleState.setPhaseDefinition(phaseJson);
|
||||
lifecycleState.setPhase(step.getKey().phase());
|
||||
|
@ -847,11 +853,7 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
ClusterService clusterService = mock(ClusterService.class);
|
||||
final AtomicLong now = new AtomicLong(5);
|
||||
IndexLifecycleRunner runner = new IndexLifecycleRunner(policyStepsRegistry, historyStore, clusterService, threadPool, now::get);
|
||||
IndexMetadata indexMetadata = IndexMetadata.builder("my_index")
|
||||
.settings(settings(IndexVersion.current()))
|
||||
.numberOfShards(randomIntBetween(1, 5))
|
||||
.numberOfReplicas(randomIntBetween(0, 5))
|
||||
.build();
|
||||
IndexMetadata indexMetadata = createIndex("my_index");
|
||||
// With no time, always transition
|
||||
assertTrue(
|
||||
"index should be able to transition with no creation date",
|
||||
|
@ -948,6 +950,14 @@ public class IndexLifecycleRunnerTests extends ESTestCase {
|
|||
assertEquals(null, newLifecycleState.stepInfo());
|
||||
}
|
||||
|
||||
private static IndexMetadata createIndex(String name) {
|
||||
return IndexMetadata.builder(name).settings(randomIndexSettings()).build();
|
||||
}
|
||||
|
||||
private static Settings.Builder randomIndexSettings() {
|
||||
return indexSettings(IndexVersion.current(), randomIntBetween(1, 5), randomIntBetween(0, 5));
|
||||
}
|
||||
|
||||
static class MockAsyncActionStep extends AsyncActionStep {
|
||||
|
||||
private Exception exception;
|
||||
|
|
|
@ -1310,6 +1310,7 @@ public class IndexLifecycleTransitionTests extends ESTestCase {
|
|||
assertFalse(LifecycleSettings.LIFECYCLE_NAME_SETTING.exists(indexSettings));
|
||||
assertFalse(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS_SETTING.exists(indexSettings));
|
||||
assertFalse(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE_SETTING.exists(indexSettings));
|
||||
assertFalse(LifecycleSettings.LIFECYCLE_SKIP_SETTING.exists(indexSettings));
|
||||
}
|
||||
|
||||
public static void assertClusterStateOnNextStep(
|
||||
|
|
Loading…
Reference in New Issue