-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Skip Shrink when numberOfShards not changed #37953
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from 2 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
37b0dc7
Skip Shrink when numberOfShards not changed
talevy 49d1bcc
fix doc test
talevy 5e3159e
respond to changes
talevy 91528dd
Merge remote-tracking branch 'upstream/master' into skip-step-ilm
talevy 26304dd
Merge remote-tracking branch 'upstream/master' into skip-step-ilm
talevy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
109 changes: 109 additions & 0 deletions
109
.../plugin/core/src/main/java/org/elasticsearch/xpack/core/indexlifecycle/BranchingStep.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,109 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
|
|
||
| package org.elasticsearch.xpack.core.indexlifecycle; | ||
|
|
||
| import org.apache.logging.log4j.LogManager; | ||
| import org.apache.logging.log4j.Logger; | ||
| import org.apache.lucene.util.SetOnce; | ||
| import org.elasticsearch.cluster.ClusterState; | ||
| import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
| import org.elasticsearch.index.Index; | ||
|
|
||
| import java.util.Objects; | ||
| import java.util.function.BiPredicate; | ||
|
|
||
| public class BranchingStep extends ClusterStateActionStep { | ||
| public static final String NAME = "branch"; | ||
|
|
||
| private static final Logger logger = LogManager.getLogger(BranchingStep.class); | ||
|
|
||
| private StepKey nextStepKeyOnFalse; | ||
| private StepKey nextStepKeyOnTrue; | ||
| private BiPredicate<Index, ClusterState> predicate; | ||
| private SetOnce<Boolean> predicateValue; | ||
|
|
||
| /** | ||
| * {@link BranchingStep} is a step whose next step is based on | ||
| * the return value of a specific predicate. | ||
| * | ||
| * @param key the step's key | ||
| * @param nextStepKeyOnFalse the key of the step to run if predicate returns false | ||
| * @param nextStepKeyOnTrue the key of the step to run if predicate returns true | ||
| * @param predicate the condition to check when deciding which step to run next | ||
| */ | ||
| public BranchingStep(StepKey key, StepKey nextStepKeyOnFalse, StepKey nextStepKeyOnTrue, BiPredicate<Index, ClusterState> predicate) { | ||
| // super.nextStepKey is set to null since it is not used by this step | ||
| super(key, null); | ||
| this.nextStepKeyOnFalse = nextStepKeyOnFalse; | ||
| this.nextStepKeyOnTrue = nextStepKeyOnTrue; | ||
| this.predicate = predicate; | ||
| this.predicateValue = new SetOnce<>(); | ||
| } | ||
|
|
||
| @Override | ||
| public ClusterState performAction(Index index, ClusterState clusterState) { | ||
| IndexMetaData indexMetaData = clusterState.metaData().index(index); | ||
| if (indexMetaData == null) { | ||
| // Index must have been since deleted, ignore it | ||
| logger.debug("[{}] lifecycle action for index [{}] executed but index no longer exists", getKey().getAction(), index.getName()); | ||
| return clusterState; | ||
| } | ||
| predicateValue.set(predicate.test(index, clusterState)); | ||
| return clusterState; | ||
| } | ||
|
|
||
| /** | ||
| * This method returns the next step to execute based on the predicate. If | ||
| * the predicate returned true, then nextStepKeyOnTrue is the key of the | ||
| * next step to run, otherwise nextStepKeyOnFalse is. | ||
| * | ||
| * throws {@link UnsupportedOperationException} if performAction was not called yet | ||
| * | ||
| * @return next step to execute | ||
| */ | ||
| @Override | ||
| public final StepKey getNextStepKey() { | ||
| if (predicateValue.get() == null) { | ||
| throw new UnsupportedOperationException("Cannot call getNextStepKey before performAction"); | ||
talevy marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
| return predicateValue.get() ? nextStepKeyOnTrue : nextStepKeyOnFalse; | ||
| } | ||
|
|
||
| /** | ||
| * @return the next step if {@code predicate} is false | ||
| */ | ||
| final StepKey getNextStepKeyOnFalse() { | ||
| return nextStepKeyOnFalse; | ||
| } | ||
|
|
||
| /** | ||
| * @return the next step if {@code predicate} is true | ||
| */ | ||
| final StepKey getNextStepKeyOnTrue() { | ||
| return nextStepKeyOnTrue; | ||
| } | ||
|
|
||
| public final BiPredicate<Index, ClusterState> getPredicate() { | ||
| return predicate; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean equals(Object o) { | ||
| if (this == o) return true; | ||
| if (o == null || getClass() != o.getClass()) return false; | ||
| if (!super.equals(o)) return false; | ||
| BranchingStep that = (BranchingStep) o; | ||
| return super.equals(o) | ||
| && Objects.equals(nextStepKeyOnFalse, that.nextStepKeyOnFalse) | ||
| && Objects.equals(nextStepKeyOnTrue, that.nextStepKeyOnTrue); | ||
| } | ||
|
|
||
| @Override | ||
| public int hashCode() { | ||
| return Objects.hash(super.hashCode(), nextStepKeyOnFalse, nextStepKeyOnTrue); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
85 changes: 85 additions & 0 deletions
85
...in/core/src/test/java/org/elasticsearch/xpack/core/indexlifecycle/BranchingStepTests.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,85 @@ | ||
| /* | ||
| * Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one | ||
| * or more contributor license agreements. Licensed under the Elastic License; | ||
| * you may not use this file except in compliance with the Elastic License. | ||
| */ | ||
| package org.elasticsearch.xpack.core.indexlifecycle; | ||
|
|
||
| import org.apache.lucene.util.SetOnce; | ||
| import org.elasticsearch.Version; | ||
| import org.elasticsearch.cluster.ClusterName; | ||
| import org.elasticsearch.cluster.ClusterState; | ||
| import org.elasticsearch.cluster.metadata.IndexMetaData; | ||
| import org.elasticsearch.cluster.metadata.MetaData; | ||
| import org.elasticsearch.index.Index; | ||
| import org.elasticsearch.xpack.core.indexlifecycle.Step.StepKey; | ||
|
|
||
| import java.util.function.BiPredicate; | ||
|
|
||
| import static org.hamcrest.Matchers.equalTo; | ||
|
|
||
| public class BranchingStepTests extends AbstractStepTestCase<BranchingStep> { | ||
|
|
||
| public void testPredicateNextStepChange() { | ||
| String indexName = randomAlphaOfLength(5); | ||
| ClusterState state = ClusterState.builder(ClusterName.DEFAULT).metaData(MetaData.builder() | ||
| .put(IndexMetaData.builder(indexName).settings(settings(Version.CURRENT)) | ||
| .numberOfShards(1).numberOfReplicas(0))).build(); | ||
| StepKey stepKey = new StepKey(randomAlphaOfLength(5), randomAlphaOfLength(5), BranchingStep.NAME); | ||
| StepKey nextStepKey = new StepKey(randomAlphaOfLength(6), randomAlphaOfLength(6), BranchingStep.NAME); | ||
| StepKey nextSkipKey = new StepKey(randomAlphaOfLength(7), randomAlphaOfLength(7), BranchingStep.NAME); | ||
| { | ||
| BranchingStep step = new BranchingStep(stepKey, nextStepKey, nextSkipKey, (i, c) -> true); | ||
| expectThrows(UnsupportedOperationException.class, step::getNextStepKey); | ||
| step.performAction(state.metaData().index(indexName).getIndex(), state); | ||
| assertThat(step.getNextStepKey(), equalTo(step.getNextStepKeyOnTrue())); | ||
| expectThrows(SetOnce.AlreadySetException.class, () -> step.performAction(state.metaData().index(indexName).getIndex(), state)); | ||
| } | ||
| { | ||
| BranchingStep step = new BranchingStep(stepKey, nextStepKey, nextSkipKey, (i, c) -> false); | ||
| expectThrows(UnsupportedOperationException.class, step::getNextStepKey); | ||
| step.performAction(state.metaData().index(indexName).getIndex(), state); | ||
| assertThat(step.getNextStepKey(), equalTo(step.getNextStepKeyOnFalse())); | ||
| expectThrows(SetOnce.AlreadySetException.class, () -> step.performAction(state.metaData().index(indexName).getIndex(), state)); | ||
| } | ||
| } | ||
|
|
||
| @Override | ||
| public BranchingStep createRandomInstance() { | ||
| StepKey stepKey = new StepKey(randomAlphaOfLength(5), randomAlphaOfLength(5), BranchingStep.NAME); | ||
| StepKey nextStepKey = new StepKey(randomAlphaOfLength(6), randomAlphaOfLength(6), BranchingStep.NAME); | ||
| StepKey nextSkipKey = new StepKey(randomAlphaOfLength(7), randomAlphaOfLength(7), BranchingStep.NAME); | ||
| return new BranchingStep(stepKey, nextStepKey, nextSkipKey, (i, c) -> randomBoolean()); | ||
| } | ||
|
|
||
| @Override | ||
| public BranchingStep mutateInstance(BranchingStep instance) { | ||
| StepKey key = instance.getKey(); | ||
| StepKey nextStepKey = instance.getNextStepKeyOnFalse(); | ||
| StepKey nextSkipStepKey = instance.getNextStepKeyOnTrue(); | ||
| BiPredicate<Index, ClusterState> predicate = instance.getPredicate(); | ||
|
|
||
| switch (between(0, 2)) { | ||
| case 0: | ||
| key = new StepKey(key.getPhase(), key.getAction(), key.getName() + randomAlphaOfLength(5)); | ||
| break; | ||
| case 1: | ||
| nextStepKey = new StepKey(nextStepKey.getPhase(), nextStepKey.getAction(), nextStepKey.getName() + randomAlphaOfLength(5)); | ||
| break; | ||
| case 2: | ||
| nextSkipStepKey = new StepKey(nextSkipStepKey.getPhase(), nextSkipStepKey.getAction(), | ||
| nextSkipStepKey.getName() + randomAlphaOfLength(5)); | ||
| break; | ||
| default: | ||
| throw new AssertionError("Illegal randomisation branch"); | ||
| } | ||
|
|
||
| return new BranchingStep(key, nextStepKey, nextSkipStepKey, predicate); | ||
| } | ||
|
|
||
| @Override | ||
| public BranchingStep copyInstance(BranchingStep instance) { | ||
| return new BranchingStep(instance.getKey(), instance.getNextStepKeyOnFalse(), instance.getNextStepKeyOnTrue(), | ||
| instance.getPredicate()); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.