Skip to content

Commit adf3bcb

Browse files
authored
Tidy up ClusterApplierService (#76837) (#77083)
* Tidy up ClusterApplierService (#76837) This commit cleans up some cruft left over from older versions of the `ClusterApplierService`: - `UpdateTask` doesn't need to implement lots of interfaces and give access to its internals, it can just pass appropriate arguments to `runTasks()`. - No need for the `runOnApplierThread` override with a default priority, just have callers be explicit about the priority. - `submitStateUpdateTask` takes a config which never has a timeout, may as well just pass the priority and remove the dead code - `SafeClusterApplyListener` doesn't need to be a `ClusterApplyListener`, may as well just be an `ActionListener<Void>`. - No implementations of `ClusterApplyListener` care about the source argument, may as well drop it. - Adds assertions to prevent `ClusterApplyListener` implementations from throwing exceptions since we just swallow them. - No need to override getting the current time in the `ClusterApplierService`, we can control this from the `ThreadPool`. * Missed git add
1 parent 371ac2e commit adf3bcb

File tree

18 files changed

+329
-274
lines changed

18 files changed

+329
-274
lines changed

server/src/internalClusterTest/java/org/elasticsearch/indices/store/IndicesStoreIntegrationIT.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -432,12 +432,12 @@ public void testShardActiveElseWhere() throws Exception {
432432
CountDownLatch latch = new CountDownLatch(1);
433433
clusterApplierService.onNewClusterState("test", () -> newState, new ClusterApplyListener() {
434434
@Override
435-
public void onSuccess(String source) {
435+
public void onSuccess() {
436436
latch.countDown();
437437
}
438438

439439
@Override
440-
public void onFailure(String source, Exception e) {
440+
public void onFailure(Exception e) {
441441
latch.countDown();
442442
throw new AssertionError("Expected a proper response", e);
443443
}

server/src/main/java/org/elasticsearch/cluster/ClusterStateTaskListener.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -14,18 +14,18 @@ public interface ClusterStateTaskListener {
1414
/**
1515
* A callback for when task execution fails.
1616
*
17-
* Implementations of this callback should not throw exceptions: an exception thrown here is logged by the master service at {@code
18-
* ERROR} level and otherwise ignored. If log-and-ignore is the right behaviour then implementations should do so themselves, typically
19-
* using a more specific logger and at a less dramatic log level.
17+
* Implementations of this callback must not throw exceptions: an exception thrown here is logged by the master service at {@code ERROR}
18+
* level and otherwise ignored, except in tests where it raises an {@link AssertionError}. If log-and-ignore is the right behaviour then
19+
* implementations must do so themselves, typically using a more specific logger and at a less dramatic log level.
2020
*/
2121
void onFailure(String source, Exception e);
2222

2323
/**
2424
* A callback for when the task was rejected because the processing node is no longer the elected master.
2525
*
26-
* Implementations of this callback should not throw exceptions: an exception thrown here is logged by the master service at {@code
27-
* ERROR} level and otherwise ignored. If log-and-ignore is the right behaviour then implementations should do so themselves, typically
28-
* using a more specific logger and at a less dramatic log level.
26+
* Implementations of this callback must not throw exceptions: an exception thrown here is logged by the master service at {@code ERROR}
27+
* level and otherwise ignored, except in tests where it raises an {@link AssertionError}. If log-and-ignore is the right behaviour then
28+
* implementations must do so themselves, typically using a more specific logger and at a less dramatic log level.
2929
*/
3030
default void onNoLongerMaster(String source) {
3131
onFailure(source, new NotMasterException("no longer master. source: [" + source + "]"));
@@ -35,9 +35,9 @@ default void onNoLongerMaster(String source) {
3535
* Called when the result of the {@link ClusterStateTaskExecutor#execute(ClusterState, List)} have been processed
3636
* properly by all listeners.
3737
*
38-
* Implementations of this callback should not throw exceptions: an exception thrown here is logged by the master service at {@code
39-
* ERROR} level and otherwise ignored. If log-and-ignore is the right behaviour then implementations should do so themselves, typically
40-
* using a more specific logger and at a less dramatic log level.
38+
* Implementations of this callback must not throw exceptions: an exception thrown here is logged by the master service at {@code ERROR}
39+
* level and otherwise ignored, except in tests where it raises an {@link AssertionError}. If log-and-ignore is the right behaviour then
40+
* implementations must do so themselves, typically using a more specific logger and at a less dramatic log level.
4141
*/
4242
default void clusterStateProcessed(String source, ClusterState oldState, ClusterState newState) {
4343
}

server/src/main/java/org/elasticsearch/cluster/coordination/Coordinator.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -271,12 +271,12 @@ private void handleApplyCommit(ApplyCommitRequest applyCommitRequest, ActionList
271271
new ClusterApplyListener() {
272272

273273
@Override
274-
public void onFailure(String source, Exception e) {
274+
public void onFailure(Exception e) {
275275
applyListener.onFailure(e);
276276
}
277277

278278
@Override
279-
public void onSuccess(String source) {
279+
public void onSuccess() {
280280
applyListener.onResponse(null);
281281
}
282282
});
@@ -560,7 +560,7 @@ void becomeCandidate(String method) {
560560

561561
if (applierState.nodes().getMasterNodeId() != null) {
562562
applierState = clusterStateWithNoMasterBlock(applierState);
563-
clusterApplier.onNewClusterState("becoming candidate: " + method, () -> applierState, (source, e) -> {
563+
clusterApplier.onNewClusterState("becoming candidate: " + method, () -> applierState, e -> {
564564
});
565565
}
566566
}
@@ -1418,7 +1418,7 @@ public void onResponse(Void ignore) {
14181418
clusterApplier.onNewClusterState(CoordinatorPublication.this.toString(), () -> applierState,
14191419
new ClusterApplyListener() {
14201420
@Override
1421-
public void onFailure(String source, Exception e) {
1421+
public void onFailure(Exception e) {
14221422
synchronized (mutex) {
14231423
removePublicationAndPossiblyBecomeCandidate("clusterApplier#onNewClusterState");
14241424
}
@@ -1428,7 +1428,7 @@ public void onFailure(String source, Exception e) {
14281428
}
14291429

14301430
@Override
1431-
public void onSuccess(String source) {
1431+
public void onSuccess() {
14321432
clusterStatePublicationEvent.setMasterApplyElapsedMillis(
14331433
transportService.getThreadPool().rawRelativeTimeInMillis() - completionTimeMillis);
14341434
synchronized (mutex) {

server/src/main/java/org/elasticsearch/cluster/service/ClusterApplier.java

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,17 +33,26 @@ public interface ClusterApplier {
3333
*/
3434
interface ClusterApplyListener {
3535
/**
36-
* Called on successful cluster state application
37-
* @param source information where the cluster state came from
36+
* Called on successful cluster state application.
37+
*
38+
* Implementations of this callback must not throw exceptions: an exception thrown here is logged by the cluster applier service at
39+
* {@code ERROR} level and otherwise ignored, except in tests where it raises an {@link AssertionError}. If log-and-ignore is the
40+
* right behaviour then implementations must do so themselves, typically using a more specific logger and at a less dramatic log
41+
* level.
3842
*/
39-
default void onSuccess(String source) {
43+
default void onSuccess() {
4044
}
4145

4246
/**
43-
* Called on failure during cluster state application
44-
* @param source information where the cluster state came from
47+
* Called on failure during cluster state application.
48+
*
49+
* Implementations of this callback must not throw exceptions: an exception thrown here is logged by the cluster applier service at
50+
* {@code ERROR} level and otherwise ignored, except in tests where it raises an {@link AssertionError}. If log-and-ignore is the
51+
* right behaviour then implementations must do so themselves, typically using a more specific logger and at a less dramatic log
52+
* level.
53+
*
4554
* @param e exception that occurred
4655
*/
47-
void onFailure(String source, Exception e);
56+
void onFailure(Exception e);
4857
}
4958
}

0 commit comments

Comments
 (0)