diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/create/AutoCreateAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/create/AutoCreateAction.java index 94611ea9ec9ed..9f3dc1d4a4824 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/create/AutoCreateAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/create/AutoCreateAction.java @@ -161,11 +161,6 @@ public void onFailure(Exception e) { listener.onFailure(e); } - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "should not be called"; - } - private ClusterStateAckListener getAckListener(String indexName) { return new ClusterStateAckListener() { @Override diff --git a/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java b/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java index cd11ecfbd30d3..c5d6ce67f24d1 100644 --- a/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java +++ b/server/src/main/java/org/elasticsearch/action/admin/indices/rollover/TransportRolloverAction.java @@ -241,16 +241,10 @@ record RolloverTask( RolloverResponse trialRolloverResponse, ActionListener listener ) implements ClusterStateTaskListener { - @Override public void onFailure(Exception e) { listener.onFailure(e); } - - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "not called"; - } } record RolloverExecutor( diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterStateTaskExecutor.java b/server/src/main/java/org/elasticsearch/cluster/ClusterStateTaskExecutor.java index 69a54e5068a5b..02192b01991ce 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterStateTaskExecutor.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterStateTaskExecutor.java @@ -73,23 +73,6 @@ default String describeTasks(List tasks) { return output.toString(); } - /** - * A {@link Consumer} for passing to {@link ClusterStateTaskExecutor.TaskContext#success} which preserves the - * legacy behaviour of calling {@link ClusterStateTaskListener#clusterStateProcessed} or {@link ClusterStateTaskListener#onFailure}. - *

- * New implementations should use a dedicated listener rather than relying on this legacy behaviour. - */ - // TODO remove all remaining usages of this listener - @Deprecated - record LegacyClusterTaskResultActionListener(ClusterStateTaskListener task, ClusterState originalState) - implements - Consumer { - @Override - public void accept(ClusterState publishedState) { - task.clusterStateProcessed(originalState, publishedState); - } - } - /** * A task to be executed, along with callbacks for the executor to record the outcome of this task's execution. The executor must * call exactly one of these methods for every task in its batch. @@ -108,10 +91,7 @@ interface TaskContext { * method and must instead call {@link #success(Runnable, ClusterStateAckListener)}, passing the task itself as the {@code * clusterStateAckListener} argument. * - * @param onPublicationSuccess An action executed when (if?) the cluster state update succeeds. The task's {@link - * ClusterStateTaskListener#clusterStateProcessed} method is not called directly by the master - * service once the task execution has succeeded, but legacy implementations may supply a listener - * which calls this methods. + * @param onPublicationSuccess An action executed when (if?) the cluster state update succeeds. */ void success(Runnable onPublicationSuccess); @@ -122,10 +102,7 @@ interface TaskContext { * method and must instead call {@link #success(Consumer, ClusterStateAckListener)}, passing the task itself as the {@code * clusterStateAckListener} argument. * - * @param publishedStateConsumer A consumer of the cluster state that was ultimately published. The task's {@link - * ClusterStateTaskListener#clusterStateProcessed} method is not called directly by the master - * service once the task execution has succeeded, but legacy implementations may supply a listener - * which calls this methods. + * @param publishedStateConsumer A consumer of the cluster state that was ultimately published. *

* The consumer should prefer not to use the published state for things like determining the result * of a task. The task may have been executed as part of a batch, and later tasks in the batch may @@ -143,10 +120,7 @@ interface TaskContext { * Note that some tasks implement {@link ClusterStateAckListener} and can listen for acks themselves. If so, you must pass the task * itself as the {@code clusterStateAckListener} argument. * - * @param onPublicationSuccess An action executed when (if?) the cluster state update succeeds. The task's {@link - * ClusterStateTaskListener#clusterStateProcessed} method is not called directly by the master - * service once the task execution has succeeded, but legacy implementations may supply a listener - * which calls this methods. + * @param onPublicationSuccess An action executed when (if?) the cluster state update succeeds. * * @param clusterStateAckListener A listener for acknowledgements from nodes. If the publication succeeds then this listener is * completed as nodes ack the state update. If the publication fails then the failure @@ -160,10 +134,7 @@ interface TaskContext { * Note that some tasks implement {@link ClusterStateAckListener} and can listen for acks themselves. If so, you must pass the task * itself as the {@code clusterStateAckListener} argument. * - * @param publishedStateConsumer A consumer of the cluster state that was ultimately published. The task's {@link - * ClusterStateTaskListener#clusterStateProcessed} method is not called directly by the master - * service once the task execution has succeeded, but legacy implementations may supply a listener - * which calls this methods. + * @param publishedStateConsumer A consumer of the cluster state that was ultimately published. *

* The consumer should prefer not to use the published state for things like determining the result * of a task. The task may have been executed as part of a batch, and later tasks in the batch may diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterStateTaskListener.java b/server/src/main/java/org/elasticsearch/cluster/ClusterStateTaskListener.java index 1e383a6da7df6..85305529b6a4d 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterStateTaskListener.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterStateTaskListener.java @@ -12,7 +12,6 @@ import org.elasticsearch.cluster.service.MasterService; public interface ClusterStateTaskListener { - /** * A callback for when task execution fails. May receive a {@link NotMasterException} if this node stopped being the master before this * task was executed or a {@link ProcessClusterEventTimeoutException} if the task timed out before it was executed. If the task fails @@ -28,19 +27,4 @@ public interface ClusterStateTaskListener { * implementations must do so themselves, typically using a more specific logger and at a less dramatic log level. */ void onFailure(Exception e); - - /** - * Called when the result of the {@link ClusterStateTaskExecutor#execute} method has been processed properly by all listeners. - * - * The {@param newState} parameter is the state that was ultimately published. This can lead to surprising behaviour if tasks are - * batched together: a later task in the batch may undo or overwrite the changes made by an earlier task. In general you should prefer - * to ignore the published state and instead handle the success of a publication via the listener that the executor passes to - * {@link ClusterStateTaskExecutor.TaskContext#success}. - * - * Implementations of this callback must not throw exceptions: an exception thrown here is logged by the master service at {@code ERROR} - * level and otherwise ignored, except in tests where it raises an {@link AssertionError}. If log-and-ignore is the right behaviour then - * implementations must do so themselves, typically using a more specific logger and at a less dramatic log level. - */ - // TODO: replace all remaining usages of this method with dedicated listeners and then remove it. - default void clusterStateProcessed(ClusterState oldState, ClusterState newState) {} } diff --git a/server/src/main/java/org/elasticsearch/cluster/ClusterStateUpdateTask.java b/server/src/main/java/org/elasticsearch/cluster/ClusterStateUpdateTask.java index 1b8986b45f490..ac31d87ee67ca 100644 --- a/server/src/main/java/org/elasticsearch/cluster/ClusterStateUpdateTask.java +++ b/server/src/main/java/org/elasticsearch/cluster/ClusterStateUpdateTask.java @@ -8,9 +8,6 @@ package org.elasticsearch.cluster; -import org.elasticsearch.cluster.coordination.FailedToCommitClusterStateException; -import org.elasticsearch.cluster.metadata.ProcessClusterEventTimeoutException; -import org.elasticsearch.cluster.service.MasterService; import org.elasticsearch.common.Priority; import org.elasticsearch.core.Nullable; import org.elasticsearch.core.TimeValue; @@ -50,20 +47,15 @@ public ClusterStateUpdateTask(Priority priority, TimeValue timeout) { public abstract ClusterState execute(ClusterState currentState) throws Exception; /** - * A callback for when task execution fails. May receive a {@link NotMasterException} if this node stopped being the master before this - * task was executed or a {@link ProcessClusterEventTimeoutException} if the task timed out before it was executed. If the task fails - * during execution then this method receives the corresponding exception. If the task executes successfully but the resulting cluster - * state publication fails then this method receives a {@link FailedToCommitClusterStateException}. If publication fails then a new - * master is elected and the update might or might not take effect, depending on whether or not the newly-elected master accepted the - * published state that failed to be committed. - *

- * Use {@link MasterService#isPublishFailureException} to detect the "expected" master failure cases if needed. - *

- * Implementations of this callback should not throw exceptions: an exception thrown here is logged by the master service at {@code - * ERROR} level and otherwise ignored. If log-and-ignore is the right behaviour then implementations should do so themselves, typically - * using a more specific logger and at a less dramatic log level. + * Called when the result of the {@link #execute} method has been processed properly by all listeners. + * + * The {@param newState} parameter is the state that was ultimately published. + * + * Implementations of this callback must not throw exceptions: an exception thrown here is logged by the master service at {@code ERROR} + * level and otherwise ignored, except in tests where it raises an {@link AssertionError}. If log-and-ignore is the right behaviour then + * implementations must do so themselves, typically using a more specific logger and at a less dramatic log level. */ - public abstract void onFailure(Exception e); + public void clusterStateProcessed(ClusterState initialState, ClusterState newState) {} /** * If the cluster state update task wasn't processed by the provided timeout, call diff --git a/server/src/main/java/org/elasticsearch/cluster/LocalMasterServiceTask.java b/server/src/main/java/org/elasticsearch/cluster/LocalMasterServiceTask.java index 033f6d1f8dd39..5b1d0ff22e201 100644 --- a/server/src/main/java/org/elasticsearch/cluster/LocalMasterServiceTask.java +++ b/server/src/main/java/org/elasticsearch/cluster/LocalMasterServiceTask.java @@ -25,11 +25,6 @@ public LocalMasterServiceTask(Priority priority) { protected void execute(ClusterState currentState) {} - @Override - public final void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "not called"; - } - protected void onPublicationComplete() {} public void submit(MasterService masterService, String source) { diff --git a/server/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java b/server/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java index 200a2024a610b..21747049cb57a 100644 --- a/server/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java +++ b/server/src/main/java/org/elasticsearch/cluster/action/shard/ShardStateAction.java @@ -538,7 +538,6 @@ public int hashCode() { public record FailedShardUpdateTask(FailedShardEntry entry, ActionListener listener) implements ClusterStateTaskListener { - @Override public void onFailure(Exception e) { logger.log( @@ -548,11 +547,6 @@ public void onFailure(Exception e) { ); listener.onFailure(e); } - - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "should not be called"; - } } public void shardStarted( @@ -859,11 +853,6 @@ public void onFailure(Exception e) { listener.onFailure(e); } - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "should not be called"; - } - @Override public String toString() { return "StartedShardUpdateTask{entry=" + entry + ", listener=" + listener + "}"; diff --git a/server/src/main/java/org/elasticsearch/cluster/coordination/JoinTask.java b/server/src/main/java/org/elasticsearch/cluster/coordination/JoinTask.java index 61cc9196c2a96..10121337a85ca 100644 --- a/server/src/main/java/org/elasticsearch/cluster/coordination/JoinTask.java +++ b/server/src/main/java/org/elasticsearch/cluster/coordination/JoinTask.java @@ -9,7 +9,6 @@ package org.elasticsearch.cluster.coordination; import org.elasticsearch.action.ActionListener; -import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateTaskListener; import org.elasticsearch.cluster.node.DiscoveryNode; @@ -38,11 +37,6 @@ public void onFailure(Exception e) { } } - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "not called"; - } - @Override public String toString() { final StringBuilder stringBuilder = new StringBuilder(); diff --git a/server/src/main/java/org/elasticsearch/cluster/coordination/NodeRemovalClusterStateTaskExecutor.java b/server/src/main/java/org/elasticsearch/cluster/coordination/NodeRemovalClusterStateTaskExecutor.java index af59b6a065109..7cf929d6da87a 100644 --- a/server/src/main/java/org/elasticsearch/cluster/coordination/NodeRemovalClusterStateTaskExecutor.java +++ b/server/src/main/java/org/elasticsearch/cluster/coordination/NodeRemovalClusterStateTaskExecutor.java @@ -32,11 +32,6 @@ public void onFailure(final Exception e) { logger.log(MasterService.isPublishFailureException(e) ? Level.DEBUG : Level.ERROR, "unexpected failure during [node-left]", e); } - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "not called"; - } - @Override public String toString() { final StringBuilder stringBuilder = new StringBuilder(); diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexStateService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexStateService.java index 1243d9bb26d19..827ab9d9d81d1 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexStateService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexStateService.java @@ -211,16 +211,10 @@ public ClusterState execute(BatchExecutionContext batchExe private record AddBlocksToCloseTask(CloseIndexClusterStateUpdateRequest request, ActionListener listener) implements ClusterStateTaskListener { - @Override public void onFailure(Exception e) { listener.onFailure(e); } - - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "not called"; - } } private class CloseIndicesExecutor implements ClusterStateTaskExecutor { @@ -292,16 +286,10 @@ private record CloseIndicesTask( Map verifyResults, ActionListener listener ) implements ClusterStateTaskListener { - @Override public void onFailure(Exception e) { listener.onFailure(e); } - - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "not called"; - } } /** @@ -547,11 +535,6 @@ private record AddBlocksTask(AddIndexBlockClusterStateUpdateRequest request, Act public void onFailure(Exception e) { listener.onFailure(e); } - - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "not called"; - } } private static class FinalizeBlocksExecutor implements ClusterStateTaskExecutor { @@ -592,16 +575,10 @@ private record FinalizeBlocksTask( Map verifyResults, ActionListener listener ) implements ClusterStateTaskListener { - @Override public void onFailure(Exception e) { listener.onFailure(e); } - - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "not called"; - } } /** @@ -1243,10 +1220,5 @@ public void onAckTimeout() { public TimeValue ackTimeout() { return request.ackTimeout(); } - - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "not called"; - } } } diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java index 3dc021cea6daa..e1ff12280222c 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataIndexTemplateService.java @@ -158,11 +158,6 @@ private abstract static class TemplateClusterStateUpdateTask implements ClusterS public void onFailure(Exception e) { listener.onFailure(e); } - - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "not called"; - } } @Inject diff --git a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataUpdateSettingsService.java b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataUpdateSettingsService.java index 8ec1e210d9d20..1634c860cf547 100644 --- a/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataUpdateSettingsService.java +++ b/server/src/main/java/org/elasticsearch/cluster/metadata/MetadataUpdateSettingsService.java @@ -136,11 +136,6 @@ public void onFailure(Exception e) { listener.onFailure(e); } - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "should not be called"; - } - ClusterState execute(ClusterState currentState) { final Settings normalizedSettings = Settings.builder() .put(request.settings()) diff --git a/server/src/main/java/org/elasticsearch/health/metadata/HealthMetadataService.java b/server/src/main/java/org/elasticsearch/health/metadata/HealthMetadataService.java index 91aeab6799da2..3d5ddb2e36d17 100644 --- a/server/src/main/java/org/elasticsearch/health/metadata/HealthMetadataService.java +++ b/server/src/main/java/org/elasticsearch/health/metadata/HealthMetadataService.java @@ -155,11 +155,6 @@ public static List getNamedWriteables() { */ abstract static class UpsertHealthMetadataTask implements ClusterStateTaskListener { - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "never called"; - } - @Override public void onFailure(@Nullable Exception e) { logger.error("failure during health metadata update", e); diff --git a/server/src/main/java/org/elasticsearch/ingest/IngestService.java b/server/src/main/java/org/elasticsearch/ingest/IngestService.java index 5f66dbb2daa07..d2e671550a39a 100644 --- a/server/src/main/java/org/elasticsearch/ingest/IngestService.java +++ b/server/src/main/java/org/elasticsearch/ingest/IngestService.java @@ -146,11 +146,6 @@ abstract static class PipelineClusterStateUpdateTask implements ClusterStateTask public void onFailure(Exception e) { listener.onFailure(e); } - - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "should not be called"; - } } public IngestService( diff --git a/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java b/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java index f6a617c5c8011..62b207e252b87 100644 --- a/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java +++ b/server/src/main/java/org/elasticsearch/snapshots/SnapshotsService.java @@ -3381,11 +3381,6 @@ public void onFailure(Exception e) { listener.onFailure(e); } - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "never called"; - } - @Override public boolean equals(Object other) { if (this == other) { diff --git a/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java b/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java index 1dedcd06b72d6..2742b521ebdb5 100644 --- a/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/coordination/CoordinatorTests.java @@ -16,7 +16,6 @@ import org.elasticsearch.Version; import org.elasticsearch.cluster.AbstractNamedDiffable; import org.elasticsearch.cluster.ClusterState; -import org.elasticsearch.cluster.ClusterStateTaskListener; import org.elasticsearch.cluster.SimpleDiffable; import org.elasticsearch.cluster.block.ClusterBlock; import org.elasticsearch.cluster.coordination.AbstractCoordinatorTestCase.Cluster.ClusterNode; @@ -1133,7 +1132,7 @@ public void testMasterStatsOnNoOpUpdate() { leader.submitUpdateTask("unchanged", cs -> { computeAdvancer.advanceTime(); return cs; - }, new ClusterStateTaskListener() { + }, new CoordinatorTestClusterStateUpdateTask() { @Override public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { notifyAdvancer.advanceTime(); @@ -1220,7 +1219,7 @@ protected List extraNamedWriteables() { leader.submitUpdateTask("update", cs -> { computeAdvancer.advanceTime(); return ClusterState.builder(cs).putCustom(customName, new DelayedCustom(contextAdvancer)).build(); - }, new ClusterStateTaskListener() { + }, new CoordinatorTestClusterStateUpdateTask() { @Override public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { notifyAdvancer.advanceTime(); @@ -1281,7 +1280,7 @@ public void testMasterStatsOnFailedUpdate() { leader.submitUpdateTask("update", cs -> { computeAdvancer.advanceTime(); return ClusterState.builder(cs).build(); - }, new ClusterStateTaskListener() { + }, new CoordinatorTestClusterStateUpdateTask() { @Override public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { fail("shouldn't have processed cluster state"); diff --git a/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexStateServiceBatchingTests.java b/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexStateServiceBatchingTests.java index e52a3726cc046..3e61fb7fe9855 100644 --- a/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexStateServiceBatchingTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/metadata/MetadataIndexStateServiceBatchingTests.java @@ -8,7 +8,6 @@ package org.elasticsearch.cluster.metadata; -import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateListener; import org.elasticsearch.cluster.ClusterStateTaskConfig; import org.elasticsearch.cluster.ClusterStateTaskListener; @@ -235,11 +234,5 @@ private static class ExpectSuccessTask implements ClusterStateTaskListener { public void onFailure(Exception e) { throw new AssertionError("should not be called", e); } - - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - // see parent method javadoc, we use dedicated listeners rather than calling this method - throw new AssertionError("should not be called"); - } } } diff --git a/server/src/test/java/org/elasticsearch/cluster/service/MasterServiceTests.java b/server/src/test/java/org/elasticsearch/cluster/service/MasterServiceTests.java index cd7aa8d8918ca..b9bfe2ff4e5ba 100644 --- a/server/src/test/java/org/elasticsearch/cluster/service/MasterServiceTests.java +++ b/server/src/test/java/org/elasticsearch/cluster/service/MasterServiceTests.java @@ -667,11 +667,6 @@ public void onFailure(Exception e) { throw new AssertionError("should not be called", e); } - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - throw new AssertionError("should not be called"); - } - @Override public boolean equals(Object o) { if (this == o) { @@ -849,11 +844,6 @@ class Task implements ClusterStateTaskListener { this.expectedHeaderValue = expectedHeaderValue; } - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - throw new AssertionError("should not complete task"); - } - @Override public void onFailure(Exception e) { assertThat(e, instanceOf(RuntimeException.class)); @@ -927,11 +917,6 @@ class Task implements ClusterStateTaskListener { this.publishListener = publishListener; } - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - throw new AssertionError("should not complete task"); - } - @Override public void onFailure(Exception e) { publishListener.onFailure(e); @@ -1419,11 +1404,6 @@ class Task extends LatchAckListener implements ClusterStateTaskListener { public void onFailure(Exception e) { throw new AssertionError(e); } - - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - fail(); - } } masterService.submitStateUpdateTask( @@ -1466,16 +1446,10 @@ public void clusterStateProcessed(ClusterState oldState, ClusterState newState) }); class Task implements ClusterStateTaskListener { - @Override public void onFailure(Exception e) { throw new AssertionError(e); } - - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - fail(); - } } masterService.submitStateUpdateTask( @@ -1508,16 +1482,10 @@ public void clusterStateProcessed(ClusterState oldState, ClusterState newState) }); class Task implements ClusterStateTaskListener { - @Override public void onFailure(Exception e) { throw new AssertionError(e); } - - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - fail(); - } } masterService.submitStateUpdateTask( @@ -1550,16 +1518,10 @@ public void clusterStateProcessed(ClusterState oldState, ClusterState newState) }); class Task implements ClusterStateTaskListener { - @Override public void onFailure(Exception e) { throw new AssertionError(e); } - - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - fail(); - } } masterService.submitStateUpdateTask( @@ -1991,11 +1953,5 @@ private static class ExpectSuccessTask implements ClusterStateTaskListener { public void onFailure(Exception e) { throw new AssertionError("should not be called", e); } - - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - // see parent method javadoc, we use dedicated listeners rather than calling this method - throw new AssertionError("should not be called"); - } } } diff --git a/test/framework/src/main/java/org/elasticsearch/cluster/coordination/AbstractCoordinatorTestCase.java b/test/framework/src/main/java/org/elasticsearch/cluster/coordination/AbstractCoordinatorTestCase.java index 3f820e9772518..0f4df5fd9b442 100644 --- a/test/framework/src/main/java/org/elasticsearch/cluster/coordination/AbstractCoordinatorTestCase.java +++ b/test/framework/src/main/java/org/elasticsearch/cluster/coordination/AbstractCoordinatorTestCase.java @@ -1435,7 +1435,7 @@ AckCollector submitValue(final int key, final long value) { return submitUpdateTask( "new value [" + key + "=" + value + "]", cs -> setValue(cs, key, value), - new ClusterStateTaskListener() { + new CoordinatorTestClusterStateUpdateTask() { @Override public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { history.respond(eventId, value(oldState, key)); @@ -1460,7 +1460,7 @@ public void onFailure(Exception e) { void readValue(int key) { final int eventId = history.invoke(new Tuple<>(key, null)); - submitUpdateTask("read value", cs -> ClusterState.builder(cs).build(), new ClusterStateTaskListener() { + submitUpdateTask("read value", cs -> ClusterState.builder(cs).build(), new CoordinatorTestClusterStateUpdateTask() { @Override public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { history.respond(eventId, value(newState, key)); @@ -1478,7 +1478,7 @@ public void onFailure(Exception e) { AckCollector submitUpdateTask( String source, UnaryOperator clusterStateUpdate, - ClusterStateTaskListener taskListener + CoordinatorTestClusterStateUpdateTask taskListener ) { final AckCollector ackCollector = new AckCollector(); onNode(() -> { @@ -1956,4 +1956,8 @@ void clear() { } } + + public interface CoordinatorTestClusterStateUpdateTask extends ClusterStateTaskListener { + default void clusterStateProcessed(ClusterState oldState, ClusterState newState) {} + } } diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/StartBasicClusterTask.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/StartBasicClusterTask.java index 5c81fde14bd26..b9356c71a212f 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/StartBasicClusterTask.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/StartBasicClusterTask.java @@ -49,11 +49,6 @@ public class StartBasicClusterTask implements ClusterStateTaskListener { this.clock = clock; } - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "never called"; - } - public LicensesMetadata execute( LicensesMetadata currentLicensesMetadata, DiscoveryNodes discoveryNodes, diff --git a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/StartTrialClusterTask.java b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/StartTrialClusterTask.java index bb4bb6adcb073..b6431ecd77c3a 100644 --- a/x-pack/plugin/core/src/main/java/org/elasticsearch/license/StartTrialClusterTask.java +++ b/x-pack/plugin/core/src/main/java/org/elasticsearch/license/StartTrialClusterTask.java @@ -56,11 +56,6 @@ public class StartTrialClusterTask implements ClusterStateTaskListener { this.clock = clock; } - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "never called"; - } - private LicensesMetadata execute( LicensesMetadata currentLicensesMetadata, DiscoveryNodes discoveryNodes, diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleClusterStateUpdateTask.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleClusterStateUpdateTask.java index 196e703540abd..193a4b110c596 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleClusterStateUpdateTask.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleClusterStateUpdateTask.java @@ -10,6 +10,7 @@ import org.elasticsearch.action.ActionListener; import org.elasticsearch.cluster.ClusterState; import org.elasticsearch.cluster.ClusterStateTaskListener; +import org.elasticsearch.cluster.ClusterStateUpdateTask; import org.elasticsearch.common.util.concurrent.ListenableFuture; import org.elasticsearch.index.Index; import org.elasticsearch.xpack.core.ilm.Step; @@ -52,7 +53,6 @@ public final ClusterState execute(ClusterState currentState) throws Exception { protected abstract ClusterState doExecute(ClusterState currentState) throws Exception; - @Override public final void clusterStateProcessed(ClusterState oldState, ClusterState newState) { listener.onResponse(null); if (executed) { @@ -76,9 +76,9 @@ public final void addListener(ActionListener actionListener) { } /** - * This method is functionally the same as {@link ClusterStateTaskListener#clusterStateProcessed(ClusterState, ClusterState)} + * This method is functionally the same as {@link ClusterStateUpdateTask#clusterStateProcessed} * and implementations can override it as they would override {@code ClusterStateUpdateTask#clusterStateProcessed}. - * The only difference to {@code ClusterStateUpdateTask#clusterStateProcessed} is that if the {@link #execute(ClusterState)} + * The only difference to {@link ClusterStateUpdateTask#clusterStateProcessed} is that if the {@link #execute(ClusterState)} * implementation was a noop and returned the input cluster state, then this method will not be invoked. */ protected void onClusterStateProcessed(ClusterState newState) {} diff --git a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java index 68208dc808465..c1e1fdfe130ab 100644 --- a/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java +++ b/x-pack/plugin/ilm/src/main/java/org/elasticsearch/xpack/ilm/IndexLifecycleRunner.java @@ -69,7 +69,7 @@ public ClusterState execute(BatchExecutionContext task.clusterStateProcessed(batchExecutionContext.initialState(), publishedState) ); } catch (Exception e) { taskContext.onFailure(e); diff --git a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/v2/TransportRollupAction.java b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/v2/TransportRollupAction.java index e70a99e47bd2f..80c8f84b63823 100644 --- a/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/v2/TransportRollupAction.java +++ b/x-pack/plugin/rollup/src/main/java/org/elasticsearch/xpack/rollup/v2/TransportRollupAction.java @@ -658,10 +658,5 @@ private abstract static class RollupClusterStateUpdateTask implements ClusterSta public void onFailure(Exception e) { listener.onFailure(e); } - - @Override - public void clusterStateProcessed(ClusterState oldState, ClusterState newState) { - assert false : "not called"; - } } }