@@ -39,10 +39,7 @@ public class NodeJoiningMasterElectionIT extends MasterElectionTestCase {
3939
4040 @ Override
4141 protected Collection <Class <? extends Plugin >> nodePlugins () {
42- return CollectionUtils .appendToCopyNoNullElements (
43- super .nodePlugins (),
44- MockTransportService .TestPlugin .class
45- );
42+ return CollectionUtils .appendToCopyNoNullElements (super .nodePlugins (), MockTransportService .TestPlugin .class );
4643 }
4744
4845 @ Override
@@ -68,8 +65,7 @@ public void testNodeTriesToJoinClusterAndThenDifferentMasterIsElected() {
6865
6966 String originalMasterName = internalCluster ().getMasterName ();
7067 int numberOfNodesOriginallyInCluster = internalCluster ().clusterService ().state ().getNodes ().size ();
71- List <String > namesOfDataNodesInOriginalCluster = internalCluster ()
72- .clusterService ()
68+ List <String > namesOfDataNodesInOriginalCluster = internalCluster ().clusterService ()
7369 .state ()
7470 .getNodes ()
7571 .getDataNodes ()
@@ -90,11 +86,10 @@ public void testNodeTriesToJoinClusterAndThenDifferentMasterIsElected() {
9086 if (mockTransportService .getLocalNode ().getName ().equals (newMaster ) == false ) {
9187 mockTransportService .addSendBehavior ((connection , requestId , action , request , options ) -> {
9288 if (
93- // This disables pre-voting on all nodes except the new master, forcing it to win the election
94- action .equals (StatefulPreVoteCollector .REQUEST_PRE_VOTE_ACTION_NAME )
89+ // This disables pre-voting on all nodes except the new master, forcing it to win the election
90+ action .equals (StatefulPreVoteCollector .REQUEST_PRE_VOTE_ACTION_NAME )
9591 // This forces the current master node to fail
96- || action .equals (PublicationTransportHandler .PUBLISH_STATE_ACTION_NAME )
97- ) {
92+ || action .equals (PublicationTransportHandler .PUBLISH_STATE_ACTION_NAME )) {
9893 throw new ElasticsearchException ("[{}] for [{}] denied" , action , connection .getNode ());
9994 } else {
10095 connection .sendRequest (requestId , action , request , options );
@@ -176,10 +171,7 @@ public void assertMatched() {
176171 }
177172
178173 // Tests whether a WARN log is thrown when a node attempts to join a cluster, and then the same master node is re-elected (#126192)
179- @ TestLogging (
180- reason = "test includes assertions about logging" ,
181- value = "org.elasticsearch.cluster.coordination.NodeJoinExecutor:WARN"
182- )
174+ @ TestLogging (reason = "test includes assertions about logging" , value = "org.elasticsearch.cluster.coordination.NodeJoinExecutor:WARN" )
183175 public void testNodeTriesToJoinClusterAndThenSameMasterIsElected () {
184176 final var cleanupTasks = new ArrayList <Releasable >();
185177
@@ -190,8 +182,7 @@ public void testNodeTriesToJoinClusterAndThenSameMasterIsElected() {
190182
191183 long originalTerm = internalCluster ().clusterService ().state ().coordinationMetadata ().term ();
192184 int numberOfNodesOriginallyInCluster = internalCluster ().clusterService ().state ().getNodes ().size ();
193- List <String > namesOfDataNodesInOriginalCluster = internalCluster ()
194- .clusterService ()
185+ List <String > namesOfDataNodesInOriginalCluster = internalCluster ().clusterService ()
195186 .state ()
196187 .getNodes ()
197188 .getDataNodes ()
@@ -201,17 +192,24 @@ public void testNodeTriesToJoinClusterAndThenSameMasterIsElected() {
201192 .toList ();
202193
203194 // A CountDownLatch that only gets decremented when the first master node is re-elected
204- final var masterKnowsItHasBeenReElectedLatch = configureElectionLatchForReElectedMaster (originalMasterName , originalTerm , cleanupTasks );
205-
206- // A list of CountDownLatches, one for each node, that only gets decremented when it recieves a cluster state update containing the new node N
195+ final var masterKnowsItHasBeenReElectedLatch = configureElectionLatchForReElectedMaster (
196+ originalMasterName ,
197+ originalTerm ,
198+ cleanupTasks
199+ );
200+
201+ // A list of CountDownLatches, one for each node, that only gets decremented when it recieves a cluster state update containing
202+ // the new node N
207203 List <CountDownLatch > newNodeIsPresentInClusterStateLatchList = new ArrayList <>();
208204
209205 for (final var transportService : internalCluster ().getInstances (TransportService .class )) {
210206 final var mockTransportService = asInstanceOf (MockTransportService .class , transportService );
211207 cleanupTasks .add (mockTransportService ::clearAllRules );
212208
213209 String nodeName = mockTransportService .getLocalNode ().getName ();
214- newNodeIsPresentInClusterStateLatchList .add (waitUntilNewNodeIsPresentInClusterStateUpdate (nodeName , numberOfNodesOriginallyInCluster , cleanupTasks ));
210+ newNodeIsPresentInClusterStateLatchList .add (
211+ waitUntilNewNodeIsPresentInClusterStateUpdate (nodeName , numberOfNodesOriginallyInCluster , cleanupTasks )
212+ );
215213
216214 if (nodeName .equals (originalMasterName )) {
217215 mockTransportService .addSendBehavior ((connection , requestId , action , request , options ) -> {
@@ -223,15 +221,20 @@ public void testNodeTriesToJoinClusterAndThenSameMasterIsElected() {
223221 }
224222 });
225223
226- // This removes the PUBLISH_STATE_ACTION_NAME mocking set above once we have triggered an election to allow the master node to be re-elected
227- removeMockTransportServicePublishBanWhenMasterHasSteppedDown (originalMasterName , originalTerm , mockTransportService , cleanupTasks );
224+ // This removes the PUBLISH_STATE_ACTION_NAME mocking set above once we have triggered an election to allow the master
225+ // node to be re-elected
226+ removeMockTransportServicePublishBanWhenMasterHasSteppedDown (
227+ originalMasterName ,
228+ originalTerm ,
229+ mockTransportService ,
230+ cleanupTasks
231+ );
228232 } else {
229233 mockTransportService .addSendBehavior ((connection , requestId , action , request , options ) -> {
230234 if (
231- // This disables pre-voting on all nodes except the master, forcing it to win the election
232- action .equals (StatefulPreVoteCollector .REQUEST_PRE_VOTE_ACTION_NAME )
233- || action .equals (PublicationTransportHandler .PUBLISH_STATE_ACTION_NAME )
234- ) {
235+ // This disables pre-voting on all nodes except the master, forcing it to win the election
236+ action .equals (StatefulPreVoteCollector .REQUEST_PRE_VOTE_ACTION_NAME )
237+ || action .equals (PublicationTransportHandler .PUBLISH_STATE_ACTION_NAME )) {
235238 throw new ElasticsearchException ("[{}] for [{}] denied" , action , connection .getNode ());
236239 } else {
237240 connection .sendRequest (requestId , action , request , options );
@@ -287,14 +290,14 @@ public void assertMatched() {
287290 // Sends a node join request to the original master node. This will fail, and cause a master failover
288291 String newNodeName = internalCluster ().startDataOnlyNode ();
289292
290-
291293 // Wait until the master acknowledges its re-election. The master is only re-elected once it's publishing ban is lifted
292294 safeAwait (masterKnowsItHasBeenReElectedLatch );
293295 assertEquals (originalMasterName , internalCluster ().getMasterName ());
294296
295297 logger .info ("Master has been re-elected" );
296298
297- // Wait for the cluster state update containing the new node N to propagate to all nodes. This gives times for the WARN log to be emitted
299+ // Wait for the cluster state update containing the new node N to propagate to all nodes. This gives times for the WARN log
300+ // to be emitted
298301 for (CountDownLatch countDownLatch : newNodeIsPresentInClusterStateLatchList ) {
299302 safeAwait (countDownLatch );
300303 }
@@ -329,15 +332,31 @@ private String generateNodeDescriptionForNewNode(int numberOfNodesOriginallyInCl
329332 String newNodeName = "node_s" + numberOfNodesOriginallyInCluster ;
330333 String regexToMatchAnyCharacterExceptClosingBrace = "([^}]+)" ;
331334
332- return "\\ {" + newNodeName + "}"
333- + "\\ {" + regexToMatchAnyCharacterExceptClosingBrace + "}"
334- + "\\ {" + regexToMatchAnyCharacterExceptClosingBrace + "}"
335- + "\\ {" + newNodeName + "}"
336- + "\\ {" + masterNode .getHostAddress () + "}"
337- + "\\ {" + masterNode .getHostAddress () + ":\\ d+}"
335+ return "\\ {"
336+ + newNodeName
337+ + "}"
338+ + "\\ {"
339+ + regexToMatchAnyCharacterExceptClosingBrace
340+ + "}"
341+ + "\\ {"
342+ + regexToMatchAnyCharacterExceptClosingBrace
343+ + "}"
344+ + "\\ {"
345+ + newNodeName
346+ + "}"
347+ + "\\ {"
348+ + masterNode .getHostAddress ()
349+ + "}"
350+ + "\\ {"
351+ + masterNode .getHostAddress ()
352+ + ":\\ d+}"
338353 + "\\ {d}"
339- + "\\ {" + masterNode .getVersion () + "}"
340- + "\\ {" + regexToMatchAnyCharacterExceptClosingBrace + "}" ;
354+ + "\\ {"
355+ + masterNode .getVersion ()
356+ + "}"
357+ + "\\ {"
358+ + regexToMatchAnyCharacterExceptClosingBrace
359+ + "}" ;
341360 }
342361
343362 /**
@@ -347,7 +366,12 @@ private String generateNodeDescriptionForNewNode(int numberOfNodesOriginallyInCl
347366 * @param originalTerm The term the current master node was first elected
348367 * @param cleanupTasks The list of cleanup tasks
349368 */
350- protected void removeMockTransportServicePublishBanWhenMasterHasSteppedDown (String masterNodeName , long originalTerm , MockTransportService mockTransportService , List <Releasable > cleanupTasks ) {
369+ protected void removeMockTransportServicePublishBanWhenMasterHasSteppedDown (
370+ String masterNodeName ,
371+ long originalTerm ,
372+ MockTransportService mockTransportService ,
373+ List <Releasable > cleanupTasks
374+ ) {
351375 ClusterStateApplier newMasterMonitor = event -> {
352376 DiscoveryNode masterNode = event .state ().nodes ().getMasterNode ();
353377 long currentTerm = event .state ().coordinationMetadata ().term ();
@@ -377,7 +401,11 @@ protected void removeMockTransportServicePublishBanWhenMasterHasSteppedDown(Stri
377401 * @param originalNumberOfNodes The number of nodes the cluster had before we attempted to add node N
378402 * @param cleanupTasks The list of cleanup tasks
379403 */
380- protected CountDownLatch waitUntilNewNodeIsPresentInClusterStateUpdate (String nodeName , int originalNumberOfNodes , List <Releasable > cleanupTasks ) {
404+ protected CountDownLatch waitUntilNewNodeIsPresentInClusterStateUpdate (
405+ String nodeName ,
406+ int originalNumberOfNodes ,
407+ List <Releasable > cleanupTasks
408+ ) {
381409 final AtomicBoolean nodeHasBeenAddedFirstTime = new AtomicBoolean (false );
382410 final AtomicBoolean addedNodeHasBeenRemoved = new AtomicBoolean (false );
383411 final var nodeHasBeenAddedLatch = new CountDownLatch (1 );
0 commit comments