Skip to content

Commit

Permalink
Notify listener, do not throw from async method (elastic#63)
Browse files Browse the repository at this point in the history
Rethrowing a FailedToCommitClusterStateException is the wrong thing to do - it
should be passed to the listener for further processing.
  • Loading branch information
DaveCTurner authored May 31, 2018
1 parent d4ad9a1 commit f9033e1
Showing 1 changed file with 10 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -325,14 +325,15 @@ public void publish(ClusterChangedEvent clusterChangedEvent, ActionListener<Void
ClusterState newState = clusterChangedEvent.state();
assert newState.getNodes().isLocalNodeElectedMaster() : "Shouldn't publish state when not master " + clusterChangedEvent.source();

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

// state got changed locally (maybe because another master published to us)
if (clusterChangedEvent.previousState() != this.committedState.get()) {
throw new FailedToCommitClusterStateException("state was mutated while calculating new CS update");
}

pendingStatesQueue.addPending(newState);
pendingStatesQueue.addPending(newState);

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

rejoin("zen-disco-failed-to-publish");
}
throw t;

publishListener.onFailure(t);
return;
}

final DiscoveryNode localNode = newState.getNodes().getLocalNode();
Expand Down

0 comments on commit f9033e1

Please sign in to comment.