Skip to content

Commit f9033e1

Browse files
authored
Notify listener, do not throw from async method (elastic#63)
Rethrowing a FailedToCommitClusterStateException is the wrong thing to do - it should be passed to the listener for further processing.
1 parent d4ad9a1 commit f9033e1

File tree

1 file changed

+10
-7
lines changed

1 file changed

+10
-7
lines changed

server/src/main/java/org/elasticsearch/discovery/zen/ZenDiscovery.java

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -325,14 +325,15 @@ public void publish(ClusterChangedEvent clusterChangedEvent, ActionListener<Void
325325
ClusterState newState = clusterChangedEvent.state();
326326
assert newState.getNodes().isLocalNodeElectedMaster() : "Shouldn't publish state when not master " + clusterChangedEvent.source();
327327

328-
// state got changed locally (maybe because another master published to us)
329-
if (clusterChangedEvent.previousState() != this.committedState.get()) {
330-
throw new FailedToCommitClusterStateException("state was mutated while calculating new CS update");
331-
}
328+
try {
329+
330+
// state got changed locally (maybe because another master published to us)
331+
if (clusterChangedEvent.previousState() != this.committedState.get()) {
332+
throw new FailedToCommitClusterStateException("state was mutated while calculating new CS update");
333+
}
332334

333-
pendingStatesQueue.addPending(newState);
335+
pendingStatesQueue.addPending(newState);
334336

335-
try {
336337
publishClusterState.publish(clusterChangedEvent, electMaster.minimumMasterNodes(), ackListener);
337338
} catch (FailedToCommitClusterStateException t) {
338339
// cluster service logs a WARN message
@@ -345,7 +346,9 @@ public void publish(ClusterChangedEvent clusterChangedEvent, ActionListener<Void
345346

346347
rejoin("zen-disco-failed-to-publish");
347348
}
348-
throw t;
349+
350+
publishListener.onFailure(t);
351+
return;
349352
}
350353

351354
final DiscoveryNode localNode = newState.getNodes().getLocalNode();

0 commit comments

Comments
 (0)