Add setting to bypass Rollover action (#36235)

Adds a setting that indicates that an index is done indexing, set by ILM
when the Rollover action completes. This indicates that the Rollover
action should be skipped in any future invocations, as long as the index
is no longer the write index for its alias.

This enables 1) an index with a policy that involves the Rollover action
to have the policy removed and switched to another one without use of
the move-to-step API, and 2) integrations with Beats and CCR.
This commit is contained in:
Gordon Brown 2018-12-11 08:53:05 -07:00 committed by GitHub
parent c556b9ef19
commit 6481f2e380
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
12 changed files with 274 additions and 20 deletions

View File

@ -124,3 +124,36 @@ suffix number for each subsequent index.
When the rollover is performed, the newly-created index is set as the write
index for the rolled over alias. Documents sent to the alias are indexed into
the new index, enabling indexing to continue uninterrupted.
=== Skipping Rollover
beta[]
After an index has been rolled over by {ilm}, the
`index.lifecycle.indexing_complete` setting will be set to `true` on the index.
This indicates to {ilm} that this index has already been rolled over, and does
not need to be rolled over again. If you <<ilm-remove-policy,remove the policy>>
from an index and set it to use another policy, this setting indicates that the
new policy should skip execution of the Rollover action.
You can also set this setting to `true` manually if you want to indicate that
{ilm} should not roll over a particular index. This is useful if you need to
make an exception to your normal Lifecycle Policy and switching the alias to a
different index by hand, but do not want to remove the index from {ilm}
completely.
IMPORTANT: If `index.lifecycle.indexing_complete` is set to `true` on an index,
it will not be rolled over by {ilm}, but {ilm} will verify that this index is no
longer the write index for the alias specified by
`index.lifecycle.rollover_alias`. If that setting is missing, or if the index is
still the write index for that alias, this index will be moved to the
<<index-lifecycle-error-handling,error step>>.
For example, if you wish to change the name of new indices while retaining
previous data in accordance with your configured policy, you can create the
template for the new index name pattern and the first index with the new name
manually, change the write index of the alias using the <<indices-aliases, Index
Aliases API>>, and set `index.lifecycle.indexing_complete` to `true` on the old
index to indicate that it does not need to be rolled over. This way, {ilm} will
continue to manage the old index in accordance with its existing policy, as well
as the new one, with no interruption.

View File

@ -14,9 +14,12 @@ import org.elasticsearch.common.unit.TimeValue;
public class LifecycleSettings {
public static final String LIFECYCLE_POLL_INTERVAL = "indices.lifecycle.poll_interval";
public static final String LIFECYCLE_NAME = "index.lifecycle.name";
public static final String LIFECYCLE_INDEXING_COMPLETE = "index.lifecycle.indexing_complete";
public static final Setting<TimeValue> LIFECYCLE_POLL_INTERVAL_SETTING = Setting.positiveTimeSetting(LIFECYCLE_POLL_INTERVAL,
TimeValue.timeValueMinutes(10), Setting.Property.Dynamic, Setting.Property.NodeScope);
public static final Setting<String> LIFECYCLE_NAME_SETTING = Setting.simpleString(LIFECYCLE_NAME,
Setting.Property.Dynamic, Setting.Property.IndexScope);
public static final Setting<Boolean> LIFECYCLE_INDEXING_COMPLETE_SETTING = Setting.boolSetting(LIFECYCLE_INDEXING_COMPLETE, false,
Setting.Property.Dynamic, Setting.Property.IndexScope);
}

View File

@ -11,6 +11,7 @@ import org.elasticsearch.common.Strings;
import org.elasticsearch.common.io.stream.StreamInput;
import org.elasticsearch.common.io.stream.StreamOutput;
import org.elasticsearch.common.settings.Setting;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.unit.ByteSizeValue;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.common.xcontent.ConstructingObjectParser;
@ -29,6 +30,7 @@ import java.util.Objects;
*/
public class RolloverAction implements LifecycleAction {
public static final String NAME = "rollover";
public static final String INDEXING_COMPLETE_STEP_NAME = "set-indexing-complete";
public static final ParseField MAX_SIZE_FIELD = new ParseField("max_size");
public static final ParseField MAX_DOCS_FIELD = new ParseField("max_docs");
public static final ParseField MAX_AGE_FIELD = new ParseField("max_age");
@ -132,15 +134,21 @@ public class RolloverAction implements LifecycleAction {
@Override
public List<Step> toSteps(Client client, String phase, Step.StepKey nextStepKey) {
Settings indexingComplete = Settings.builder().put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, true).build();
StepKey waitForRolloverReadyStepKey = new StepKey(phase, NAME, WaitForRolloverReadyStep.NAME);
StepKey rolloverStepKey = new StepKey(phase, NAME, RolloverStep.NAME);
StepKey updateDateStepKey = new StepKey(phase, NAME, UpdateRolloverLifecycleDateStep.NAME);
StepKey setIndexingCompleteStepKey = new StepKey(phase, NAME, INDEXING_COMPLETE_STEP_NAME);
WaitForRolloverReadyStep waitForRolloverReadyStep = new WaitForRolloverReadyStep(waitForRolloverReadyStepKey, rolloverStepKey,
client, maxSize, maxAge, maxDocs);
RolloverStep rolloverStep = new RolloverStep(rolloverStepKey, updateDateStepKey, client);
UpdateRolloverLifecycleDateStep updateDateStep = new UpdateRolloverLifecycleDateStep(updateDateStepKey, nextStepKey);
return Arrays.asList(waitForRolloverReadyStep, rolloverStep, updateDateStep);
UpdateRolloverLifecycleDateStep updateDateStep = new UpdateRolloverLifecycleDateStep(updateDateStepKey, setIndexingCompleteStepKey,
System::currentTimeMillis);
UpdateSettingsStep setIndexingCompleteStep = new UpdateSettingsStep(setIndexingCompleteStepKey, nextStepKey,
client, indexingComplete);
return Arrays.asList(waitForRolloverReadyStep, rolloverStep, updateDateStep, setIndexingCompleteStep);
}
@Override
@ -148,7 +156,8 @@ public class RolloverAction implements LifecycleAction {
StepKey rolloverReadyStepKey = new StepKey(phase, NAME, WaitForRolloverReadyStep.NAME);
StepKey rolloverStepKey = new StepKey(phase, NAME, RolloverStep.NAME);
StepKey updateDateStepKey = new StepKey(phase, NAME, UpdateRolloverLifecycleDateStep.NAME);
return Arrays.asList(rolloverReadyStepKey, rolloverStepKey, updateDateStepKey);
StepKey setIndexingCompleteStepKey = new StepKey(phase, NAME, INDEXING_COMPLETE_STEP_NAME);
return Arrays.asList(rolloverReadyStepKey, rolloverStepKey, updateDateStepKey, setIndexingCompleteStepKey);
}
@Override

View File

@ -5,6 +5,8 @@
*/
package org.elasticsearch.xpack.core.indexlifecycle;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
import org.elasticsearch.client.Client;
@ -19,6 +21,8 @@ import java.util.Objects;
* Unconditionally rolls over an index using the Rollover API.
*/
public class RolloverStep extends AsyncActionStep {
private static final Logger logger = LogManager.getLogger(RolloverStep.class);
public static final String NAME = "attempt-rollover";
public RolloverStep(StepKey key, StepKey nextStepKey, Client client) {
@ -27,6 +31,13 @@ public class RolloverStep extends AsyncActionStep {
@Override
public void performAction(IndexMetaData indexMetaData, ClusterState currentClusterState, Listener listener) {
boolean indexingComplete = LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE_SETTING.get(indexMetaData.getSettings());
if (indexingComplete) {
logger.trace(indexMetaData.getIndex() + " has lifecycle complete set, skipping " + RolloverStep.NAME);
listener.onResponse(true);
return;
}
String rolloverAlias = RolloverAction.LIFECYCLE_ROLLOVER_ALIAS_SETTING.get(indexMetaData.getSettings());
if (Strings.isNullOrEmpty(rolloverAlias)) {

View File

@ -5,6 +5,8 @@
*/
package org.elasticsearch.xpack.core.indexlifecycle;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.admin.indices.rollover.RolloverInfo;
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetaData;
@ -12,6 +14,8 @@ import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.common.Strings;
import org.elasticsearch.index.Index;
import java.util.function.LongSupplier;
import static org.elasticsearch.xpack.core.indexlifecycle.LifecycleExecutionState.ILM_CUSTOM_METADATA_KEY;
/**
@ -19,30 +23,47 @@ import static org.elasticsearch.xpack.core.indexlifecycle.LifecycleExecutionStat
* Used so that the "age" of an index doesn't get reset on rollover.
*/
public class UpdateRolloverLifecycleDateStep extends ClusterStateActionStep {
private static final Logger logger = LogManager.getLogger(UpdateRolloverLifecycleDateStep.class);
public static final String NAME = "update-rollover-lifecycle-date";
public UpdateRolloverLifecycleDateStep(StepKey key, StepKey nextStepKey) {
private final LongSupplier fallbackTimeSupplier;
public UpdateRolloverLifecycleDateStep(StepKey key, StepKey nextStepKey, LongSupplier fallbackTimeSupplier) {
super(key, nextStepKey);
this.fallbackTimeSupplier = fallbackTimeSupplier;
}
@Override
public ClusterState performAction(Index index, ClusterState currentState) {
IndexMetaData indexMetaData = currentState.metaData().getIndexSafe(index);
// find the newly created index from the rollover and fetch its index.creation_date
String rolloverAlias = RolloverAction.LIFECYCLE_ROLLOVER_ALIAS_SETTING.get(indexMetaData.getSettings());
if (Strings.isNullOrEmpty(rolloverAlias)) {
throw new IllegalStateException("setting [" + RolloverAction.LIFECYCLE_ROLLOVER_ALIAS
+ "] is not set on index [" + indexMetaData.getIndex().getName() + "]");
}
RolloverInfo rolloverInfo = indexMetaData.getRolloverInfos().get(rolloverAlias);
if (rolloverInfo == null) {
throw new IllegalStateException("no rollover info found for [" + indexMetaData.getIndex().getName() + "] with alias [" +
rolloverAlias + "], the index has not yet rolled over with that alias");
long newIndexTime;
boolean indexingComplete = LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE_SETTING.get(indexMetaData.getSettings());
if (indexingComplete) {
logger.trace(indexMetaData.getIndex() + " has lifecycle complete set, skipping " + UpdateRolloverLifecycleDateStep.NAME);
// The index won't have RolloverInfo if this is a Following index and indexing_complete was set by CCR,
// so just use the current time.
newIndexTime = fallbackTimeSupplier.getAsLong();
} else {
// find the newly created index from the rollover and fetch its index.creation_date
String rolloverAlias = RolloverAction.LIFECYCLE_ROLLOVER_ALIAS_SETTING.get(indexMetaData.getSettings());
if (Strings.isNullOrEmpty(rolloverAlias)) {
throw new IllegalStateException("setting [" + RolloverAction.LIFECYCLE_ROLLOVER_ALIAS
+ "] is not set on index [" + indexMetaData.getIndex().getName() + "]");
}
RolloverInfo rolloverInfo = indexMetaData.getRolloverInfos().get(rolloverAlias);
if (rolloverInfo == null) {
throw new IllegalStateException("no rollover info found for [" + indexMetaData.getIndex().getName() + "] with alias [" +
rolloverAlias + "], the index has not yet rolled over with that alias");
}
newIndexTime = rolloverInfo.getTime();
}
LifecycleExecutionState.Builder newLifecycleState = LifecycleExecutionState
.builder(LifecycleExecutionState.fromIndexMetadata(indexMetaData));
newLifecycleState.setIndexCreationDate(rolloverInfo.getTime());
newLifecycleState.setIndexCreationDate(newIndexTime);
IndexMetaData.Builder newIndexMetadata = IndexMetaData.builder(indexMetaData);
newIndexMetadata.putCustom(ILM_CUSTOM_METADATA_KEY, newLifecycleState.build().asMap());

View File

@ -6,6 +6,8 @@
package org.elasticsearch.xpack.core.indexlifecycle;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.elasticsearch.action.ActionListener;
import org.elasticsearch.action.admin.indices.rollover.RolloverRequest;
import org.elasticsearch.client.Client;
@ -24,6 +26,7 @@ import java.util.Objects;
* Waits for at least one rollover condition to be satisfied, using the Rollover API's dry_run option.
*/
public class WaitForRolloverReadyStep extends AsyncWaitStep {
private static final Logger logger = LogManager.getLogger(WaitForRolloverReadyStep.class);
public static final String NAME = "check-rollover-ready";
@ -57,6 +60,21 @@ public class WaitForRolloverReadyStep extends AsyncWaitStep {
return;
}
boolean indexingComplete = LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE_SETTING.get(indexMetaData.getSettings());
if (indexingComplete) {
logger.trace(indexMetaData.getIndex() + " has lifecycle complete set, skipping " + WaitForRolloverReadyStep.NAME);
Boolean isWriteIndex = indexMetaData.getAliases().get(rolloverAlias).writeIndex();
if (Boolean.TRUE.equals(isWriteIndex)) {
listener.onFailure(new IllegalStateException(String.format(Locale.ROOT,
"index [%s] has [%s] set to [true], but is still the write index for alias [%s]",
indexMetaData.getIndex().getName(), LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, rolloverAlias)));
return;
}
listener.onResponse(true, new WaitForRolloverReadyStep.EmptyInfo());
return;
}
RolloverRequest rolloverRequest = new RolloverRequest(rolloverAlias, null);
rolloverRequest.dryRun(true);
if (maxAge != null) {

View File

@ -80,21 +80,25 @@ public class RolloverActionTests extends AbstractActionTestCase<RolloverAction>
randomAlphaOfLengthBetween(1, 10));
List<Step> steps = action.toSteps(null, phase, nextStepKey);
assertNotNull(steps);
assertEquals(3, steps.size());
assertEquals(4, steps.size());
StepKey expectedFirstStepKey = new StepKey(phase, RolloverAction.NAME, WaitForRolloverReadyStep.NAME);
StepKey expectedSecondStepKey = new StepKey(phase, RolloverAction.NAME, RolloverStep.NAME);
StepKey expectedThirdStepKey = new StepKey(phase, RolloverAction.NAME, UpdateRolloverLifecycleDateStep.NAME);
StepKey expectedFourthStepKey = new StepKey(phase, RolloverAction.NAME, RolloverAction.INDEXING_COMPLETE_STEP_NAME);
WaitForRolloverReadyStep firstStep = (WaitForRolloverReadyStep) steps.get(0);
RolloverStep secondStep = (RolloverStep) steps.get(1);
UpdateRolloverLifecycleDateStep thirdStep = (UpdateRolloverLifecycleDateStep) steps.get(2);
UpdateSettingsStep fourthStep = (UpdateSettingsStep) steps.get(3);
assertEquals(expectedFirstStepKey, firstStep.getKey());
assertEquals(expectedSecondStepKey, secondStep.getKey());
assertEquals(expectedThirdStepKey, thirdStep.getKey());
assertEquals(expectedFourthStepKey, fourthStep.getKey());
assertEquals(secondStep.getKey(), firstStep.getNextStepKey());
assertEquals(thirdStep.getKey(), secondStep.getNextStepKey());
assertEquals(fourthStep.getKey(), thirdStep.getNextStepKey());
assertEquals(action.getMaxSize(), firstStep.getMaxSize());
assertEquals(action.getMaxAge(), firstStep.getMaxAge());
assertEquals(action.getMaxDocs(), firstStep.getMaxDocs());
assertEquals(nextStepKey, thirdStep.getNextStepKey());
assertEquals(nextStepKey, fourthStep.getNextStepKey());
}
}

View File

@ -126,6 +126,34 @@ public class RolloverStepTests extends AbstractStepTestCase<RolloverStep> {
Mockito.verify(indicesClient, Mockito.only()).rolloverIndex(Mockito.any(), Mockito.any());
}
public void testPerformActionWithIndexingComplete() {
String alias = randomAlphaOfLength(5);
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))
.putAlias(AliasMetaData.builder(alias))
.settings(settings(Version.CURRENT)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias)
.put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, true))
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
RolloverStep step = createRandomInstance();
SetOnce<Boolean> actionCompleted = new SetOnce<>();
step.performAction(indexMetaData, null, new AsyncActionStep.Listener() {
@Override
public void onResponse(boolean complete) {
actionCompleted.set(complete);
}
@Override
public void onFailure(Exception e) {
throw new AssertionError("Unexpected method call", e);
}
});
assertEquals(true, actionCompleted.get());
}
public void testPerformActionFailure() {
String alias = randomAlphaOfLength(5);
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))

View File

@ -16,6 +16,7 @@ import org.elasticsearch.cluster.metadata.MetaData;
import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey;
import java.util.Collections;
import java.util.function.LongSupplier;
import static org.hamcrest.Matchers.equalTo;
@ -23,9 +24,13 @@ public class UpdateRolloverLifecycleDateStepTests extends AbstractStepTestCase<U
@Override
public UpdateRolloverLifecycleDateStep createRandomInstance() {
return createRandomInstanceWithFallbackTime(null);
}
public UpdateRolloverLifecycleDateStep createRandomInstanceWithFallbackTime(LongSupplier fallbackTimeSupplier) {
StepKey stepKey = randomStepKey();
StepKey nextStepKey = randomStepKey();
return new UpdateRolloverLifecycleDateStep(stepKey, nextStepKey);
return new UpdateRolloverLifecycleDateStep(stepKey, nextStepKey, fallbackTimeSupplier);
}
@Override
@ -39,12 +44,12 @@ public class UpdateRolloverLifecycleDateStepTests extends AbstractStepTestCase<U
nextKey = new StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5));
}
return new UpdateRolloverLifecycleDateStep(key, nextKey);
return new UpdateRolloverLifecycleDateStep(key, nextKey, null);
}
@Override
public UpdateRolloverLifecycleDateStep copyInstance(UpdateRolloverLifecycleDateStep instance) {
return new UpdateRolloverLifecycleDateStep(instance.getKey(), instance.getNextStepKey());
return new UpdateRolloverLifecycleDateStep(instance.getKey(), instance.getNextStepKey(), null);
}
@SuppressWarnings("unchecked")
@ -105,4 +110,26 @@ public class UpdateRolloverLifecycleDateStepTests extends AbstractStepTestCase<U
assertThat(exceptionThrown.getMessage(),
equalTo("setting [index.lifecycle.rollover_alias] is not set on index [" + indexMetaData.getIndex().getName() +"]"));
}
public void testPerformActionWithIndexingComplete() {
String alias = randomAlphaOfLength(3);
long creationDate = randomLongBetween(0, 1000000);
long rolloverTime = randomValueOtherThan(creationDate, () -> randomNonNegativeLong());
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))
.settings(settings(Version.CURRENT)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias)
.put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, true))
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
ClusterState clusterState = ClusterState.builder(ClusterName.DEFAULT)
.metaData(MetaData.builder()
.put(indexMetaData, false)).build();
UpdateRolloverLifecycleDateStep step = createRandomInstanceWithFallbackTime(() -> rolloverTime);
ClusterState newState = step.performAction(indexMetaData.getIndex(), clusterState);
long actualRolloverTime = LifecycleExecutionState
.fromIndexMetadata(newState.metaData().index(indexMetaData.getIndex()))
.getLifecycleDate();
assertThat(actualRolloverTime, equalTo(rolloverTime));
}
}

View File

@ -173,6 +173,63 @@ public class WaitForRolloverReadyStepTests extends AbstractStepTestCase<WaitForR
Mockito.verify(indicesClient, Mockito.only()).rolloverIndex(Mockito.any(), Mockito.any());
}
public void testPerformActionWithIndexingComplete() {
String alias = randomAlphaOfLength(5);
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))
.putAlias(AliasMetaData.builder(alias).writeIndex(randomFrom(false, null)))
.settings(settings(Version.CURRENT)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias)
.put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, true))
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
WaitForRolloverReadyStep step = createRandomInstance();
SetOnce<Boolean> conditionsMet = new SetOnce<>();
step.evaluateCondition(indexMetaData, new AsyncWaitStep.Listener() {
@Override
public void onResponse(boolean complete, ToXContentObject infomationContext) {
conditionsMet.set(complete);
}
@Override
public void onFailure(Exception e) {
throw new AssertionError("Unexpected method call", e);
}
});
assertEquals(true, conditionsMet.get());
}
public void testPerformActionWithIndexingCompleteStillWriteIndex() {
String alias = randomAlphaOfLength(5);
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))
.putAlias(AliasMetaData.builder(alias).writeIndex(true))
.settings(settings(Version.CURRENT)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, alias)
.put(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE, true))
.numberOfShards(randomIntBetween(1, 5)).numberOfReplicas(randomIntBetween(0, 5)).build();
WaitForRolloverReadyStep step = createRandomInstance();
SetOnce<Boolean> correctFailureCalled = new SetOnce<>();
step.evaluateCondition(indexMetaData, new AsyncWaitStep.Listener() {
@Override
public void onResponse(boolean complete, ToXContentObject infomationContext) {
throw new AssertionError("Should have failed with indexing_complete but index is not write index");
}
@Override
public void onFailure(Exception e) {
assertTrue(e instanceof IllegalStateException);
correctFailureCalled.set(true);
}
});
assertEquals(true, correctFailureCalled.get());
}
public void testPerformActionNotComplete() {
String alias = randomAlphaOfLength(5);
IndexMetaData indexMetaData = IndexMetaData.builder(randomAlphaOfLength(10))

View File

@ -26,6 +26,7 @@ import org.elasticsearch.xpack.core.indexlifecycle.ErrorStep;
import org.elasticsearch.xpack.core.indexlifecycle.ForceMergeAction;
import org.elasticsearch.xpack.core.indexlifecycle.LifecycleAction;
import org.elasticsearch.xpack.core.indexlifecycle.LifecyclePolicy;
import org.elasticsearch.xpack.core.indexlifecycle.LifecycleSettings;
import org.elasticsearch.xpack.core.indexlifecycle.Phase;
import org.elasticsearch.xpack.core.indexlifecycle.ReadOnlyAction;
import org.elasticsearch.xpack.core.indexlifecycle.RolloverAction;
@ -230,6 +231,47 @@ public class TimeSeriesLifecycleActionsIT extends ESRestTestCase {
index(client(), originalIndex, "_id", "foo", "bar");
assertBusy(() -> assertTrue(indexExists(secondIndex)));
assertBusy(() -> assertTrue(indexExists(originalIndex)));
assertBusy(() -> assertEquals("true", getOnlyIndexSettings(originalIndex).get(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE)));
}
public void testRolloverActionWithIndexingComplete() throws Exception {
String originalIndex = index + "-000001";
String secondIndex = index + "-000002";
createIndexWithSettings(originalIndex, Settings.builder().put(IndexMetaData.SETTING_NUMBER_OF_SHARDS, 1)
.put(IndexMetaData.SETTING_NUMBER_OF_REPLICAS, 0)
.put(RolloverAction.LIFECYCLE_ROLLOVER_ALIAS, "alias"));
Request updateSettingsRequest = new Request("PUT", "/" + originalIndex + "/_settings");
updateSettingsRequest.setJsonEntity("{\n" +
" \"settings\": {\n" +
" \"" + LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE + "\": true\n" +
" }\n" +
"}");
client().performRequest(updateSettingsRequest);
Request updateAliasRequest = new Request("POST", "/_aliases");
updateAliasRequest.setJsonEntity("{\n" +
" \"actions\": [\n" +
" {\n" +
" \"add\": {\n" +
" \"index\": \"" + originalIndex + "\",\n" +
" \"alias\": \"alias\",\n" +
" \"is_write_index\": false\n" +
" }\n" +
" }\n" +
" ]\n" +
"}");
client().performRequest(updateAliasRequest);
// create policy
createNewSingletonPolicy("hot", new RolloverAction(null, null, 1L));
// update policy on index
updatePolicy(originalIndex, policy);
// index document {"foo": "bar"} to trigger rollover
index(client(), originalIndex, "_id", "foo", "bar");
assertBusy(() -> assertEquals(TerminalPolicyStep.KEY, getStepKeyForIndex(originalIndex)));
assertBusy(() -> assertTrue(indexExists(originalIndex)));
assertBusy(() -> assertFalse(indexExists(secondIndex)));
assertBusy(() -> assertEquals("true", getOnlyIndexSettings(originalIndex).get(LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE)));
}
public void testRolloverAlreadyExists() throws Exception {

View File

@ -120,6 +120,7 @@ public class IndexLifecycle extends Plugin implements ActionPlugin {
return Arrays.asList(
LifecycleSettings.LIFECYCLE_POLL_INTERVAL_SETTING,
LifecycleSettings.LIFECYCLE_NAME_SETTING,
LifecycleSettings.LIFECYCLE_INDEXING_COMPLETE_SETTING,
RolloverAction.LIFECYCLE_ROLLOVER_ALIAS_SETTING);
}