Check term earlier in publication process (#39909)

in order to avoid tripping assertPreviousStateConsistency.

Closes #39314
This commit is contained in:
Yannick Welsch 2019-03-11 15:32:58 +01:00
parent 368b5482fa
commit b7be724e50
1 changed files with 5 additions and 4 deletions

View File

@ -982,10 +982,11 @@ public class Coordinator extends AbstractLifecycleComponent implements Discovery
public void publish(ClusterChangedEvent clusterChangedEvent, ActionListener<Void> publishListener, AckListener ackListener) {
try {
synchronized (mutex) {
if (mode != Mode.LEADER) {
logger.debug(() -> new ParameterizedMessage("[{}] failed publication as not currently leading",
clusterChangedEvent.source()));
publishListener.onFailure(new FailedToCommitClusterStateException("node stepped down as leader during publication"));
if (mode != Mode.LEADER || getCurrentTerm() != clusterChangedEvent.state().term()) {
logger.debug(() -> new ParameterizedMessage("[{}] failed publication as node is no longer master for term {}",
clusterChangedEvent.source(), clusterChangedEvent.state().term()));
publishListener.onFailure(new FailedToCommitClusterStateException("node is no longer master for term " +
clusterChangedEvent.state().term() + " while handling publication"));
return;
}