@@ -39,10 +39,7 @@ public class NodeJoiningIT 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
@@ -110,11 +107,10 @@ public void testNodeTriesToJoinClusterAndThenDifferentMasterIsElected() {
110107 if (mockTransportService .getLocalNode ().getName ().equals (newMaster ) == false ) {
111108 mockTransportService .addSendBehavior ((connection , requestId , action , request , options ) -> {
112109 if (
113- // This disables pre-voting on all nodes except the new master, forcing it to win the election
114- action .equals (StatefulPreVoteCollector .REQUEST_PRE_VOTE_ACTION_NAME )
110+ // This disables pre-voting on all nodes except the new master, forcing it to win the election
111+ action .equals (StatefulPreVoteCollector .REQUEST_PRE_VOTE_ACTION_NAME )
115112 // This forces the current master node to fail
116- || action .equals (PublicationTransportHandler .PUBLISH_STATE_ACTION_NAME )
117- ) {
113+ || action .equals (PublicationTransportHandler .PUBLISH_STATE_ACTION_NAME )) {
118114 throw new ElasticsearchException ("[{}] for [{}] denied" , action , connection .getNode ());
119115 } else {
120116 connection .sendRequest (requestId , action , request , options );
@@ -161,8 +157,8 @@ public void testNodeTriesToJoinClusterAndThenDifferentMasterIsElected() {
161157
162158 // 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)
163159 @ TestLogging (
164- reason = "test includes assertions about logging" ,
165- value = "org.elasticsearch.cluster.coordination.NodeJoinExecutor:WARN,org.elasticsearch.cluster.coordination.NodeJoinExecutor:INFO"
160+ reason = "test includes assertions about logging" ,
161+ value = "org.elasticsearch.cluster.coordination.NodeJoinExecutor:WARN,org.elasticsearch.cluster.coordination.NodeJoinExecutor:INFO"
166162 )
167163 public void testNodeTriesToJoinClusterAndThenSameMasterIsElected () {
168164 final var cleanupTasks = new ArrayList <Releasable >();
@@ -177,17 +173,24 @@ public void testNodeTriesToJoinClusterAndThenSameMasterIsElected() {
177173 List <String > namesOfDataNodesInOriginalCluster = getListOfDataNodeNamesFromCluster ();
178174
179175 // A CountDownLatch that only gets decremented when the first master node is re-elected
180- final var masterKnowsItHasBeenReElectedLatch = configureElectionLatchForReElectedMaster (originalMasterName , originalTerm , cleanupTasks );
181-
182- // A list of CountDownLatches, one for each node, that only gets decremented when it recieves a cluster state update containing the new node N
176+ final var masterKnowsItHasBeenReElectedLatch = configureElectionLatchForReElectedMaster (
177+ originalMasterName ,
178+ originalTerm ,
179+ cleanupTasks
180+ );
181+
182+ // A list of CountDownLatches, one for each node, that only gets decremented when it recieves a cluster state update containing
183+ // the new node N
183184 List <CountDownLatch > newNodeIsPresentInClusterStateLatchList = new ArrayList <>();
184185
185186 for (final var transportService : internalCluster ().getInstances (TransportService .class )) {
186187 final var mockTransportService = asInstanceOf (MockTransportService .class , transportService );
187188 cleanupTasks .add (mockTransportService ::clearAllRules );
188189
189190 String nodeName = mockTransportService .getLocalNode ().getName ();
190- newNodeIsPresentInClusterStateLatchList .add (waitUntilNewNodeIsPresentInClusterStateUpdate (nodeName , numberOfNodesOriginallyInCluster , cleanupTasks ));
191+ newNodeIsPresentInClusterStateLatchList .add (
192+ waitUntilNewNodeIsPresentInClusterStateUpdate (nodeName , numberOfNodesOriginallyInCluster , cleanupTasks )
193+ );
191194
192195 if (nodeName .equals (originalMasterName )) {
193196 mockTransportService .addSendBehavior ((connection , requestId , action , request , options ) -> {
@@ -199,15 +202,20 @@ public void testNodeTriesToJoinClusterAndThenSameMasterIsElected() {
199202 }
200203 });
201204
202- // 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
203- removeMockTransportServicePublishBanWhenMasterHasSteppedDown (originalMasterName , originalTerm , mockTransportService , cleanupTasks );
205+ // This removes the PUBLISH_STATE_ACTION_NAME mocking set above once we have triggered an election to allow the master
206+ // node to be re-elected
207+ removeMockTransportServicePublishBanWhenMasterHasSteppedDown (
208+ originalMasterName ,
209+ originalTerm ,
210+ mockTransportService ,
211+ cleanupTasks
212+ );
204213 } else {
205214 mockTransportService .addSendBehavior ((connection , requestId , action , request , options ) -> {
206215 if (
207- // This disables pre-voting on all nodes except the master, forcing it to win the election
208- action .equals (StatefulPreVoteCollector .REQUEST_PRE_VOTE_ACTION_NAME )
209- || action .equals (PublicationTransportHandler .PUBLISH_STATE_ACTION_NAME )
210- ) {
216+ // This disables pre-voting on all nodes except the master, forcing it to win the election
217+ action .equals (StatefulPreVoteCollector .REQUEST_PRE_VOTE_ACTION_NAME )
218+ || action .equals (PublicationTransportHandler .PUBLISH_STATE_ACTION_NAME )) {
211219 throw new ElasticsearchException ("[{}] for [{}] denied" , action , connection .getNode ());
212220 } else {
213221 connection .sendRequest (requestId , action , request , options );
@@ -220,7 +228,7 @@ public void testNodeTriesToJoinClusterAndThenSameMasterIsElected() {
220228 try (var mockLog = MockLog .capture (NodeJoinExecutor .class )) {
221229
222230 // We expect to see a node join message from the new node
223- // setNodeJoinMockLog(mockLog, numberOfNodesOriginallyInCluster, masterNode);
231+ // setNodeJoinMockLog(mockLog, numberOfNodesOriginallyInCluster, masterNode);
224232
225233 // We expect to see a WARN log emitted when a node attempts to rejoin a cluster without restarting
226234 mockLog .addExpectation (new MockLog .LoggingExpectation () {
@@ -272,7 +280,8 @@ public void assertMatched() {
272280
273281 logger .info ("Master has been re-elected" );
274282
275- // 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
283+ // Wait for the cluster state update containing the new node N to propagate to all nodes. This gives times for the WARN log
284+ // to be emitted
276285 for (CountDownLatch countDownLatch : newNodeIsPresentInClusterStateLatchList ) {
277286 safeAwait (countDownLatch );
278287 }
@@ -296,16 +305,8 @@ public void assertMatched() {
296305 }
297306 }
298307
299- private List <String > getListOfDataNodeNamesFromCluster (){
300- return internalCluster ()
301- .clusterService ()
302- .state ()
303- .getNodes ()
304- .getDataNodes ()
305- .values ()
306- .stream ()
307- .map (DiscoveryNode ::getName )
308- .toList ();
308+ private List <String > getListOfDataNodeNamesFromCluster () {
309+ return internalCluster ().clusterService ().state ().getNodes ().getDataNodes ().values ().stream ().map (DiscoveryNode ::getName ).toList ();
309310 }
310311
311312 private void setNodeJoinMockLog (MockLog mockLog , int numberOfNodesOriginallyInCluster , DiscoveryNode masterNode ) {
@@ -325,10 +326,10 @@ public void match(LogEvent event) {
325326 // Since we declare this log message before we add a node, we need to predict what the node description will be
326327 assert masterNode != null ;
327328 Pattern pattern = Pattern .compile (
328- "node-join: \\ ["
329- + generateNodeDescriptionForNewNode (numberOfNodesOriginallyInCluster , masterNode )
330- + "] "
331- + "with reason \\ [joining]"
329+ "node-join: \\ ["
330+ + generateNodeDescriptionForNewNode (numberOfNodesOriginallyInCluster , masterNode )
331+ + "] "
332+ + "with reason \\ [joining]"
332333 );
333334 Matcher matcher = pattern .matcher (event .getMessage ().getFormattedMessage ());
334335
@@ -350,15 +351,31 @@ private String generateNodeDescriptionForNewNode(int numberOfNodesOriginallyInCl
350351 String newNodeName = "node_s" + numberOfNodesOriginallyInCluster ;
351352 String regexToMatchAnyCharacterExceptClosingBrace = "([^}]+)" ;
352353
353- return "\\ {" + newNodeName + "}"
354- + "\\ {" + regexToMatchAnyCharacterExceptClosingBrace + "}"
355- + "\\ {" + regexToMatchAnyCharacterExceptClosingBrace + "}"
356- + "\\ {" + newNodeName + "}"
357- + "\\ {" + masterNode .getHostAddress () + "}"
358- + "\\ {" + masterNode .getHostAddress () + ":\\ d+}"
354+ return "\\ {"
355+ + newNodeName
356+ + "}"
357+ + "\\ {"
358+ + regexToMatchAnyCharacterExceptClosingBrace
359+ + "}"
360+ + "\\ {"
361+ + regexToMatchAnyCharacterExceptClosingBrace
362+ + "}"
363+ + "\\ {"
364+ + newNodeName
365+ + "}"
366+ + "\\ {"
367+ + masterNode .getHostAddress ()
368+ + "}"
369+ + "\\ {"
370+ + masterNode .getHostAddress ()
371+ + ":\\ d+}"
359372 + "\\ {d}"
360- + "\\ {" + masterNode .getVersion () + "}"
361- + "\\ {" + regexToMatchAnyCharacterExceptClosingBrace + "}" ;
373+ + "\\ {"
374+ + masterNode .getVersion ()
375+ + "}"
376+ + "\\ {"
377+ + regexToMatchAnyCharacterExceptClosingBrace
378+ + "}" ;
362379 }
363380
364381 /**
@@ -368,7 +385,12 @@ private String generateNodeDescriptionForNewNode(int numberOfNodesOriginallyInCl
368385 * @param originalTerm The term the current master node was first elected
369386 * @param cleanupTasks The list of cleanup tasks
370387 */
371- protected void removeMockTransportServicePublishBanWhenMasterHasSteppedDown (String masterNodeName , long originalTerm , MockTransportService mockTransportService , List <Releasable > cleanupTasks ) {
388+ protected void removeMockTransportServicePublishBanWhenMasterHasSteppedDown (
389+ String masterNodeName ,
390+ long originalTerm ,
391+ MockTransportService mockTransportService ,
392+ List <Releasable > cleanupTasks
393+ ) {
372394 ClusterStateApplier newMasterMonitor = event -> {
373395 DiscoveryNode masterNode = event .state ().nodes ().getMasterNode ();
374396 long currentTerm = event .state ().coordinationMetadata ().term ();
@@ -399,7 +421,11 @@ protected void removeMockTransportServicePublishBanWhenMasterHasSteppedDown(Stri
399421 * @param originalNumberOfNodes The number of nodes the cluster had before we attempted to add node N
400422 * @param cleanupTasks The list of cleanup tasks
401423 */
402- protected CountDownLatch waitUntilNewNodeIsPresentInClusterStateUpdate (String nodeName , int originalNumberOfNodes , List <Releasable > cleanupTasks ) {
424+ protected CountDownLatch waitUntilNewNodeIsPresentInClusterStateUpdate (
425+ String nodeName ,
426+ int originalNumberOfNodes ,
427+ List <Releasable > cleanupTasks
428+ ) {
403429 final AtomicBoolean nodeHasBeenAddedFirstTime = new AtomicBoolean (false );
404430 final AtomicBoolean addedNodeHasBeenRemoved = new AtomicBoolean (false );
405431 final var nodeHasBeenAddedLatch = new CountDownLatch (1 );
0 commit comments