Skip to content

Commit cdb482e

Browse files
Fix RareClusterStateIT (#42430)
* It looks like we might be cancelling a previous publication instead of the one triggered by the given request with a very low likelihood. * Fixed by adding a wait for no in-progress publications * Also added debug logging that would've identified this problem * Closes #36813
1 parent 7936275 commit cdb482e

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1165,9 +1165,13 @@ public Iterable<DiscoveryNode> getFoundPeers() {
11651165
*/
11661166
boolean cancelCommittedPublication() {
11671167
synchronized (mutex) {
1168-
if (currentPublication.isPresent() && currentPublication.get().isCommitted()) {
1169-
currentPublication.get().cancel("cancelCommittedPublication");
1170-
return true;
1168+
if (currentPublication.isPresent()) {
1169+
final CoordinatorPublication publication = currentPublication.get();
1170+
if (publication.isCommitted()) {
1171+
publication.cancel("cancelCommittedPublication");
1172+
logger.debug("Cancelled publication of [{}].", publication);
1173+
return true;
1174+
}
11711175
}
11721176
return false;
11731177
}

server/src/test/java/org/elasticsearch/cluster/coordination/RareClusterStateIT.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,10 @@ public void onFailure(String source, Exception e) {
141141

142142
private <Req extends ActionRequest, Res extends ActionResponse> ActionFuture<Res> executeAndCancelCommittedPublication(
143143
ActionRequestBuilder<Req, Res> req) throws Exception {
144+
// Wait for no publication in progress to not accidentally cancel a publication different from the one triggered by the given
145+
// request.
146+
assertBusy(
147+
() -> assertFalse(((Coordinator) internalCluster().getCurrentMasterNodeInstance(Discovery.class)).publicationInProgress()));
144148
ActionFuture<Res> future = req.execute();
145149
assertBusy(
146150
() -> assertTrue(((Coordinator)internalCluster().getCurrentMasterNodeInstance(Discovery.class)).cancelCommittedPublication()));

0 commit comments

Comments
 (0)