From 98891dc9302bf0f01e5e2dc76a36808a292097f7 Mon Sep 17 00:00:00 2001 From: Andrei Dan Date: Tue, 23 Mar 2021 16:48:13 +0000 Subject: [PATCH] Mark Step#isRetryable abstract (#70716) This marks isRetryable and implements it in the remaining places. (cherry picked from commit b039b8077eacb1db87607ad95c0e7ce8178772a5) Signed-off-by: Andrei Dan --- .../xpack/core/ilm/AllocationRoutedStep.java | 5 +++++ .../xpack/core/ilm/ErrorStep.java | 6 ++++++ .../core/ilm/GenerateSnapshotNameStep.java | 5 +++++ .../xpack/core/ilm/PhaseCompleteStep.java | 6 ++++++ .../elasticsearch/xpack/core/ilm/Step.java | 4 +--- .../xpack/core/ilm/TerminalPolicyStep.java | 6 ++++++ .../core/ilm/WaitForIndexingCompleteStep.java | 5 +++++ .../ilm/AsyncActionBranchingStepTests.java | 20 +++++++++++++++++++ .../xpack/core/ilm/MockStep.java | 5 +++++ .../IndexLifecycleInitialisationTests.java | 5 +++++ .../xpack/ilm/IndexLifecycleRunnerTests.java | 20 +++++++++++++++++++ 11 files changed, 84 insertions(+), 3 deletions(-) diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocationRoutedStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocationRoutedStep.java index c7475b16c95a6..aed74be430ba4 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocationRoutedStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/AllocationRoutedStep.java @@ -40,6 +40,11 @@ public class AllocationRoutedStep extends ClusterStateWaitStep { super(key, nextStepKey); } + @Override + public boolean isRetryable() { + return true; + } + @Override public Result isConditionMet(Index index, ClusterState clusterState) { IndexMetadata idxMeta = clusterState.metadata().index(index); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ErrorStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ErrorStep.java index d9fda8075eafe..ce843d2e31967 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ErrorStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/ErrorStep.java @@ -18,4 +18,10 @@ public ErrorStep(StepKey key) { throw new IllegalArgumentException("An error step must have a step key whose step name is " + NAME); } } + + @Override + public boolean isRetryable() { + // this is marker step so it doesn't make sense to be retryable + return false; + } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java index 9f2d2afd4eab5..1ab0fa5577560 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/GenerateSnapshotNameStep.java @@ -88,6 +88,11 @@ public ClusterState performAction(Index index, ClusterState clusterState) { return newClusterStateBuilder.build(); } + @Override + public boolean isRetryable() { + return true; + } + @Override public int hashCode() { return Objects.hash(super.hashCode(), snapshotRepository); diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCompleteStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCompleteStep.java index 14bb7fde5b027..623d0d7b97097 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCompleteStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/PhaseCompleteStep.java @@ -20,4 +20,10 @@ public PhaseCompleteStep(StepKey key, StepKey nextStepKey) { public static PhaseCompleteStep finalStep(String phase) { return new PhaseCompleteStep(new StepKey(phase, NAME, NAME), null); } + + @Override + public boolean isRetryable() { + // this is marker step so it doesn't make sense to be retryable + return false; + } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/Step.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/Step.java index 435273cb8e8f8..ed05df13b63c8 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/Step.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/Step.java @@ -42,9 +42,7 @@ public StepKey getNextStepKey() { /** * Indicates if the step can be automatically retried when it encounters an execution error. */ - public boolean isRetryable() { - return false; - } + public abstract boolean isRetryable(); @Override public int hashCode() { diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TerminalPolicyStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TerminalPolicyStep.java index 6ac698ba7ac83..3c4aae1e93973 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TerminalPolicyStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/TerminalPolicyStep.java @@ -17,4 +17,10 @@ public class TerminalPolicyStep extends Step { TerminalPolicyStep(StepKey key, StepKey nextStepKey) { super(key, nextStepKey); } + + @Override + public boolean isRetryable() { + // this is marker step so it doesn't make sense to be retryable + return false; + } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForIndexingCompleteStep.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForIndexingCompleteStep.java index b42dec2bb040d..30b74171ba41e 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForIndexingCompleteStep.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/xpack/core/ilm/WaitForIndexingCompleteStep.java @@ -30,6 +30,11 @@ final class WaitForIndexingCompleteStep extends ClusterStateWaitStep { super(key, nextStepKey); } + @Override + public boolean isRetryable() { + return true; + } + @Override public Result isConditionMet(Index index, ClusterState clusterState) { IndexMetadata followerIndex = clusterState.metadata().index(index); diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AsyncActionBranchingStepTests.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AsyncActionBranchingStepTests.java index 5e68ef68ebb74..30b69c549e1e0 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AsyncActionBranchingStepTests.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/AsyncActionBranchingStepTests.java @@ -53,6 +53,11 @@ protected IndexMetadata getIndexMetadata() { public void testBranchStepKeyIsTheWrappedStepKey() { AsyncActionStep stepToExecute = new AsyncActionStep(randomStepKey(), randomStepKey(), client) { + @Override + public boolean isRetryable() { + return true; + } + @Override public void performAction(IndexMetadata indexMetadata, ClusterState currentClusterState, ClusterStateObserver observer, Listener listener) { @@ -65,6 +70,11 @@ public void performAction(IndexMetadata indexMetadata, ClusterState currentClust public void testBranchStepNextKeyOnCompleteResponse() { AsyncActionStep stepToExecute = new AsyncActionStep(randomStepKey(), randomStepKey(), client) { + @Override + public boolean isRetryable() { + return true; + } + @Override public void performAction(IndexMetadata indexMetadata, ClusterState currentClusterState, ClusterStateObserver observer, Listener listener) { @@ -91,6 +101,11 @@ public void onFailure(Exception e) { public void testBranchStepNextKeyOnInCompleteResponse() { AsyncActionStep stepToExecute = new AsyncActionStep(randomStepKey(), randomStepKey(), client) { + @Override + public boolean isRetryable() { + return true; + } + @Override public void performAction(IndexMetadata indexMetadata, ClusterState currentClusterState, ClusterStateObserver observer, Listener listener) { @@ -120,6 +135,11 @@ public void onFailure(Exception e) { public void testBranchStepPropagatesFailure() { NullPointerException failException = new NullPointerException("fail"); AsyncActionStep stepToExecute = new AsyncActionStep(randomStepKey(), randomStepKey(), client) { + @Override + public boolean isRetryable() { + return true; + } + @Override public void performAction(IndexMetadata indexMetadata, ClusterState currentClusterState, ClusterStateObserver observer, Listener listener) { diff --git a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MockStep.java b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MockStep.java index 2581a2e25c2be..1a8a23d2c6da8 100644 --- a/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MockStep.java +++ b/x-pack/plugin/core/src/test/java/org/elasticsearch/xpack/core/ilm/MockStep.java @@ -19,6 +19,11 @@ public MockStep(StepKey stepKey, Step.StepKey nextStepKey) { super(stepKey, nextStepKey); } + @Override + public boolean isRetryable() { + return false; + } + public MockStep(Step other) { super(other.getKey(), other.getNextStepKey()); } diff --git a/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/IndexLifecycleInitialisationTests.java b/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/IndexLifecycleInitialisationTests.java index 533a5f923edf5..28376f9aac035 100644 --- a/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/IndexLifecycleInitialisationTests.java +++ b/x-pack/plugin/ilm/src/internalClusterTest/java/org/elasticsearch/xpack/ilm/IndexLifecycleInitialisationTests.java @@ -491,6 +491,11 @@ public ObservableClusterStateWaitStep(StepKey current, StepKey next) { super(current, next); } + @Override + public boolean isRetryable() { + return false; + } + public ObservableClusterStateWaitStep(StreamInput in) throws IOException { this(new StepKey(in.readString(), in.readString(), in.readString()), readOptionalNextStepKey(in)); } diff --git a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java index a3df6926d3eec..1ea6ac7794f4e 100644 --- a/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java +++ b/x-pack/plugin/ilm/src/test/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunnerTests.java @@ -888,6 +888,11 @@ static class MockAsyncActionStep extends AsyncActionStep { super(key, nextStepKey, null); } + @Override + public boolean isRetryable() { + return false; + } + void setException(Exception exception) { this.exception = exception; } @@ -937,6 +942,11 @@ static class MockAsyncWaitStep extends AsyncWaitStep { super(key, nextStepKey, null); } + @Override + public boolean isRetryable() { + return false; + } + void setException(Exception exception) { this.exception = exception; } @@ -974,6 +984,11 @@ static class MockClusterStateActionStep extends ClusterStateActionStep { super(key, nextStepKey); } + @Override + public boolean isRetryable() { + return false; + } + public void setException(RuntimeException exception) { this.exception = exception; } @@ -1010,6 +1025,11 @@ static class MockClusterStateWaitStep extends ClusterStateWaitStep { super(key, nextStepKey); } + @Override + public boolean isRetryable() { + return false; + } + public void setException(RuntimeException exception) { this.exception = exception; }