Skip to content

Commit d577ba1

Browse files
Replace pre publication FailedToCommitClusterStateExceptions (#135706)
Replaces three `FailedToCommitClusterStateExceptions` thrown prior to publishing the cluster state with `NotMasterExceptions` Relates to: ES-13061
1 parent 0884fc4 commit d577ba1

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1568,7 +1568,8 @@ public void publish(
15681568
clusterStatePublicationEvent.getSummary()
15691569
)
15701570
);
1571-
throw new FailedToCommitClusterStateException("publication " + currentPublication.get() + " already in progress");
1571+
// If there is another publication in progress then we are not the master node
1572+
throw new NotMasterException("publication " + currentPublication.get() + " already in progress");
15721573
}
15731574

15741575
assert assertPreviousStateConsistency(clusterStatePublicationEvent);
@@ -1586,8 +1587,9 @@ assert getLocalNode().equals(clusterState.getNodes().get(getLocalNode().getId())
15861587
publicationContext = publicationHandler.newPublicationContext(clusterStatePublicationEvent);
15871588
} catch (Exception e) {
15881589
logger.debug(() -> "[" + clusterStatePublicationEvent.getSummary() + "] publishing failed during context creation", e);
1590+
// Calling becomeCandidate here means this node steps down from being master
15891591
becomeCandidate("publication context creation");
1590-
throw new FailedToCommitClusterStateException("publishing failed during context creation", e);
1592+
throw new NotMasterException("publishing failed during context creation", e);
15911593
}
15921594

15931595
try (Releasable ignored = publicationContext::decRef) {
@@ -1607,8 +1609,9 @@ assert getLocalNode().equals(clusterState.getNodes().get(getLocalNode().getId())
16071609
+ "]",
16081610
e
16091611
);
1612+
// Calling becomeCandidate here means this node steps down from being master
16101613
becomeCandidate("publication creation");
1611-
throw new FailedToCommitClusterStateException("publishing failed while starting", e);
1614+
throw new NotMasterException("publishing failed while starting", e);
16121615
}
16131616

16141617
try {

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

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,19 @@
1616
import java.io.IOException;
1717

1818
/**
19-
* Thrown when a cluster state publication fails to commit the new cluster state. If publication fails then a new master is elected but the
20-
* update might or might not take effect, depending on whether the newly-elected master accepted the published state that failed to
21-
* be committed. This exception should only be used when there is <i>ambiguity</i> whether a state update took effect or not.
22-
*
23-
* This is different from {@link NotMasterException} where we know for certain that a state update never took effect.
24-
*
25-
* This exception is retryable within {@link TransportMasterNodeAction}.
26-
*
19+
* Exception indicating a cluster state update was published and may or may not have been committed.
20+
* <p>
21+
* If this exception is thrown, then the cluster state update was published, but is not guaranteed
22+
* to be committed, including the next master node. This exception should only be thrown when there is
23+
* <i>ambiguity</i> whether a cluster state update has been committed.
24+
* <p>
25+
* For exceptions thrown prior to publication,
26+
* when the cluster update has <i>definitely</i> failed, use a different exception.
27+
* <p>
28+
* If during a cluster state update the node is no longer master, use a {@link NotMasterException}
29+
* <p>
30+
* This is a retryable exception inside {@link TransportMasterNodeAction}
31+
* <p>
2732
* See {@link ClusterStatePublisher} for more details.
2833
*/
2934
public class FailedToCommitClusterStateException extends ElasticsearchException {

0 commit comments

Comments
 (0)