throw exception when ilm-rollover-step runs on index without rollover alias (#35065)
The ILM Rollover Step can execute on the incorrect index if the rollover alias exists on another valid index, but not the one the step is executing against. This is a problem and is now guarded against
This commit is contained in:
parent
5141084048
commit
fdb0db30c4
|
@ -45,6 +45,13 @@ public class RolloverStep extends AsyncWaitStep {
|
|||
return;
|
||||
}
|
||||
|
||||
if (indexMetaData.getAliases().containsKey(rolloverAlias) == false) {
|
||||
listener.onFailure(new IllegalArgumentException(String.format(Locale.ROOT,
|
||||
"%s [%s] does not point to index [%s]", RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, rolloverAlias,
|
||||
indexMetaData.getIndex().getName())));
|
||||
return;
|
||||
}
|
||||
|
||||
RolloverRequest rolloverRequest = new RolloverRequest(rolloverAlias, null);
|
||||
if (maxAge != null) {
|
||||
rolloverRequest.addMaxIndexAgeCondition(maxAge);
|
||||
|
|
|
@ -17,6 +17,7 @@ import org.elasticsearch.action.admin.indices.rollover.RolloverResponse;
|
|||
import org.elasticsearch.client.AdminClient;
|
||||
import org.elasticsearch.client.Client;
|
||||
import org.elasticsearch.client.IndicesAdminClient;
|
||||
import org.elasticsearch.cluster.metadata.AliasMetaData;
|
||||
import org.elasticsearch.cluster.metadata.IndexMetaData;
|
||||
import org.elasticsearch.common.unit.ByteSizeUnit;
|
||||
import org.elasticsearch.common.unit.ByteSizeValue;
|
||||
|
@ -113,6 +114,7 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
|||
public void testPerformAction() {
|
||||
String alias = randomAlphaOfLength(5);
|
||||
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))
|
||||
.putAlias(AliasMetaData.builder(alias))
|
||||
.settings(settings(Version.CURRENT).put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias))
|
||||
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
|
||||
|
||||
|
@ -171,6 +173,7 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
|||
public void testPerformActionNotComplete() {
|
||||
String alias = randomAlphaOfLength(5);
|
||||
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))
|
||||
.putAlias(AliasMetaData.builder(alias))
|
||||
.settings(settings(Version.CURRENT).put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias))
|
||||
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
|
||||
RolloverStep step = createRandomInstance();
|
||||
|
@ -228,6 +231,7 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
|||
public void testPerformActionFailure() {
|
||||
String alias = randomAlphaOfLength(5);
|
||||
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))
|
||||
.putAlias(AliasMetaData.builder(alias))
|
||||
.settings(settings(Version.CURRENT).put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias))
|
||||
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
|
||||
Exception exception = new RuntimeException();
|
||||
|
@ -309,4 +313,29 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
|
|||
indexMetaData.getIndex().getName())));
|
||||
}
|
||||
|
||||
public void testPerformActionAliasDoesNotPointToIndex() {
|
||||
String alias = randomAlphaOfLength(5);
|
||||
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))
|
||||
.settings(settings(Version.CURRENT).put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias))
|
||||
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
|
||||
RolloverStep step = createRandomInstance();
|
||||
|
||||
SetOnce<Exception> exceptionThrown = new SetOnce<>();
|
||||
step.evaluateCondition(indexMetaData, new AsyncWaitStep.Listener() {
|
||||
@Override
|
||||
public void onResponse(boolean complete, ToXContentObject obj) {
|
||||
throw new AssertionError("Unexpected method call");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFailure(Exception e) {
|
||||
exceptionThrown.set(e);
|
||||
}
|
||||
});
|
||||
assertThat(exceptionThrown.get().getClass(), equalTo(IllegalArgumentException.class));
|
||||
assertThat(exceptionThrown.get().getMessage(), equalTo(String.format(Locale.ROOT,
|
||||
"%s [%s] does not point to index [%s]", RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias,
|
||||
indexMetaData.getIndex().getName())));
|
||||
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue