Skip to content

Commit 1d88dbc

Browse files
Changes FailedToCommitClusterStateException to NotMasterException (#135548)
Changes a FailedToCommitClusterStateException incorrectly thrown prior to cluster state update publication to a NotMasterException Relates to ES-13061
1 parent 2586fbd commit 1d88dbc

File tree

3 files changed

+37
-8
lines changed

3 files changed

+37
-8
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@ public NotMasterException(StreamInput in) throws IOException {
3434
super(in);
3535
}
3636

37+
public NotMasterException(String msg, Object... args) {
38+
super(msg, args);
39+
}
40+
3741
public NotMasterException(String msg, Throwable cause, Object... args) {
3842
super(msg, cause, args);
3943
}

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

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
import org.elasticsearch.cluster.ClusterStatePublicationEvent;
2525
import org.elasticsearch.cluster.ClusterStateUpdateTask;
2626
import org.elasticsearch.cluster.LocalMasterServiceTask;
27+
import org.elasticsearch.cluster.NotMasterException;
2728
import org.elasticsearch.cluster.block.ClusterBlocks;
2829
import org.elasticsearch.cluster.coordination.ClusterFormationFailureHelper.ClusterFormationState;
2930
import org.elasticsearch.cluster.coordination.CoordinationMetadata.VotingConfigExclusion;
@@ -1552,7 +1553,7 @@ public void publish(
15521553
clusterStatePublicationEvent.getNewState().term()
15531554
)
15541555
);
1555-
throw new FailedToCommitClusterStateException(
1556+
throw new NotMasterException(
15561557
"node is no longer master for term "
15571558
+ clusterStatePublicationEvent.getNewState().term()
15581559
+ " while handling publication"
@@ -1638,8 +1639,8 @@ assert getLocalNode().equals(clusterState.getNodes().get(getLocalNode().getId())
16381639
}
16391640
}
16401641
}
1641-
} catch (FailedToCommitClusterStateException failedToCommitClusterStateException) {
1642-
publishListener.onFailure(failedToCommitClusterStateException);
1642+
} catch (FailedToCommitClusterStateException | NotMasterException e) {
1643+
publishListener.onFailure(e);
16431644
} catch (Exception e) {
16441645
assert false : e; // all exceptions should already be caught and wrapped in a FailedToCommitClusterStateException
16451646
logger.error(() -> "[" + clusterStatePublicationEvent.getSummary() + "] publishing unexpectedly failed", e);

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

Lines changed: 29 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -415,13 +415,30 @@ public void onResponse(Void unused) {
415415

416416
@Override
417417
public void onFailure(Exception exception) {
418-
if (exception instanceof FailedToCommitClusterStateException failedToCommitClusterStateException) {
418+
if (exception instanceof FailedToCommitClusterStateException || exception instanceof NotMasterException) {
419419
final long notificationStartTime = threadPool.rawRelativeTimeInMillis();
420420
final long version = newClusterState.version();
421-
logger.warn(() -> format("failing [%s]: failed to commit cluster state version [%s]", summary, version), exception);
421+
422+
if (exception instanceof FailedToCommitClusterStateException) {
423+
logger.warn(
424+
() -> format("Failing [%s]: failed to commit cluster state version [%s]", summary, version),
425+
exception
426+
);
427+
} else {
428+
logger.debug(
429+
() -> format(
430+
"Failing [%s]: node is no longer the master. Failed to publish cluster state version [%s]",
431+
summary,
432+
version
433+
),
434+
exception
435+
);
436+
}
437+
422438
for (final var executionResult : executionResults) {
423-
executionResult.onPublishFailure(failedToCommitClusterStateException);
439+
executionResult.onPublishFailure(exception);
424440
}
441+
425442
final long notificationMillis = threadPool.rawRelativeTimeInMillis() - notificationStartTime;
426443
clusterStateUpdateStatsTracker.onPublicationFailure(
427444
threadPool.rawRelativeTimeInMillis(),
@@ -985,11 +1002,18 @@ void onClusterStateUnchanged(ClusterState clusterState) {
9851002
}
9861003
}
9871004

988-
void onPublishFailure(FailedToCommitClusterStateException e) {
1005+
void onPublishFailure(Exception e) {
1006+
assert e instanceof FailedToCommitClusterStateException || e instanceof NotMasterException : e;
9891007
if (publishedStateConsumer == null && onPublicationSuccess == null) {
9901008
assert failure != null;
9911009
var taskFailure = failure;
992-
failure = new FailedToCommitClusterStateException(e.getMessage(), e);
1010+
1011+
if (e instanceof FailedToCommitClusterStateException) {
1012+
failure = new FailedToCommitClusterStateException(e.getMessage(), e);
1013+
} else {
1014+
failure = new NotMasterException(e.getMessage(), e);
1015+
}
1016+
9931017
failure.addSuppressed(taskFailure);
9941018
notifyFailure();
9951019
return;

0 commit comments

Comments
 (0)