Skip to content

Remove ClusterState param from ILM AsyncBranchingStep #129076

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
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,9 @@
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.ClusterStateObserver;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.common.TriConsumer;

import java.util.Objects;
import java.util.function.BiConsumer;

/**
* This step changes its {@link #getNextStepKey()} depending on the
Expand All @@ -26,14 +26,14 @@ public class AsyncBranchingStep extends AsyncActionStep {

private final StepKey nextStepKeyOnFalse;
private final StepKey nextStepKeyOnTrue;
private final TriConsumer<IndexMetadata, ClusterState, ActionListener<Boolean>> asyncPredicate;
private final BiConsumer<IndexMetadata, ActionListener<Boolean>> asyncPredicate;
private final SetOnce<Boolean> predicateValue;

public AsyncBranchingStep(
StepKey key,
StepKey nextStepKeyOnFalse,
StepKey nextStepKeyOnTrue,
TriConsumer<IndexMetadata, ClusterState, ActionListener<Boolean>> asyncPredicate,
BiConsumer<IndexMetadata, ActionListener<Boolean>> asyncPredicate,
Client client
) {
// super.nextStepKey is set to null since it is not used by this step
Expand All @@ -56,7 +56,7 @@ public void performAction(
ClusterStateObserver observer,
ActionListener<Void> listener
) {
asyncPredicate.apply(indexMetadata, currentClusterState, listener.safeMap(value -> {
asyncPredicate.accept(indexMetadata, listener.safeMap(value -> {
predicateValue.set(value);
return null;
}));
Expand Down Expand Up @@ -87,7 +87,7 @@ final StepKey getNextStepKeyOnTrue() {
/**
* @return the next step if {@code predicate} is true
*/
final TriConsumer<IndexMetadata, ClusterState, ActionListener<Boolean>> getAsyncPredicate() {
final BiConsumer<IndexMetadata, ActionListener<Boolean>> getAsyncPredicate() {
return asyncPredicate;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ public List<Step> toSteps(Client client, String phase, Step.StepKey nextStepKey)
preShrinkBranchingKey,
checkNotWriteIndex,
lastOrNextStep,
(indexMetadata, clusterState, listener) -> {
(indexMetadata, listener) -> {
if (indexMetadata.getSettings().get(LifecycleSettings.SNAPSHOT_INDEX_NAME) != null) {
logger.warn(
"[{}] action is configured for index [{}] in policy [{}] which is mounted as searchable snapshot. "
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@
import org.elasticsearch.cluster.ClusterState;
import org.elasticsearch.cluster.metadata.IndexMetadata;
import org.elasticsearch.cluster.metadata.Metadata;
import org.elasticsearch.common.TriConsumer;
import org.elasticsearch.index.IndexVersion;
import org.elasticsearch.xpack.core.ilm.Step.StepKey;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import java.util.function.BiConsumer;

import static org.hamcrest.Matchers.equalTo;

Expand All @@ -34,15 +34,15 @@ public void testPredicateNextStepChange() throws InterruptedException {
StepKey nextStepKey = new StepKey(randomAlphaOfLength(6), randomAlphaOfLength(6), BranchingStep.NAME);
StepKey nextSkipKey = new StepKey(randomAlphaOfLength(7), randomAlphaOfLength(7), BranchingStep.NAME);
{
AsyncBranchingStep step = new AsyncBranchingStep(stepKey, nextStepKey, nextSkipKey, (i, c, l) -> l.onResponse(true), client);
AsyncBranchingStep step = new AsyncBranchingStep(stepKey, nextStepKey, nextSkipKey, (i, l) -> l.onResponse(true), client);
expectThrows(IllegalStateException.class, step::getNextStepKey);
CountDownLatch latch = new CountDownLatch(1);
step.performAction(state.metadata().getProject().index(indexName), state, null, new Listener(latch));
assertTrue(latch.await(5, TimeUnit.SECONDS));
assertThat(step.getNextStepKey(), equalTo(step.getNextStepKeyOnTrue()));
}
{
AsyncBranchingStep step = new AsyncBranchingStep(stepKey, nextStepKey, nextSkipKey, (i, c, l) -> l.onResponse(false), client);
AsyncBranchingStep step = new AsyncBranchingStep(stepKey, nextStepKey, nextSkipKey, (i, l) -> l.onResponse(false), client);
expectThrows(IllegalStateException.class, step::getNextStepKey);
CountDownLatch latch = new CountDownLatch(1);
step.performAction(state.metadata().getProject().index(indexName), state, null, new Listener(latch));
Expand All @@ -56,15 +56,15 @@ public AsyncBranchingStep 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 AsyncBranchingStep(stepKey, nextStepKey, nextSkipKey, (i, c, l) -> l.onResponse(randomBoolean()), client);
return new AsyncBranchingStep(stepKey, nextStepKey, nextSkipKey, (i, l) -> l.onResponse(randomBoolean()), client);
}

@Override
public AsyncBranchingStep mutateInstance(AsyncBranchingStep instance) {
StepKey key = instance.getKey();
StepKey nextStepKey = instance.getNextStepKeyOnFalse();
StepKey nextSkipStepKey = instance.getNextStepKeyOnTrue();
TriConsumer<IndexMetadata, ClusterState, ActionListener<Boolean>> asyncPredicate = instance.getAsyncPredicate();
BiConsumer<IndexMetadata, ActionListener<Boolean>> asyncPredicate = instance.getAsyncPredicate();

switch (between(0, 2)) {
case 0 -> key = new StepKey(key.phase(), key.action(), key.name() + randomAlphaOfLength(5));
Expand Down