@@ -41,10 +41,7 @@ public class NodeJoiningIT extends MasterElectionTestCase {
41
41
42
42
@ Override
43
43
protected Collection <Class <? extends Plugin >> nodePlugins () {
44
- return CollectionUtils .appendToCopyNoNullElements (
45
- super .nodePlugins (),
46
- MockTransportService .TestPlugin .class
47
- );
44
+ return CollectionUtils .appendToCopyNoNullElements (super .nodePlugins (), MockTransportService .TestPlugin .class );
48
45
}
49
46
50
47
@ Override
@@ -123,11 +120,10 @@ public void testNodeTriesToJoinClusterAndThenDifferentMasterIsElected() {
123
120
if (mockTransportService .getLocalNode ().getName ().equals (newMasterNodeName ) == false ) {
124
121
mockTransportService .addSendBehavior ((connection , requestId , action , request , options ) -> {
125
122
if (
126
- // This disables pre-voting on all nodes except the new master, forcing it to win the election
127
- action .equals (StatefulPreVoteCollector .REQUEST_PRE_VOTE_ACTION_NAME )
123
+ // This disables pre-voting on all nodes except the new master, forcing it to win the election
124
+ action .equals (StatefulPreVoteCollector .REQUEST_PRE_VOTE_ACTION_NAME )
128
125
// This forces the current master node to fail
129
- || action .equals (PublicationTransportHandler .PUBLISH_STATE_ACTION_NAME )
130
- ) {
126
+ || action .equals (PublicationTransportHandler .PUBLISH_STATE_ACTION_NAME )) {
131
127
throw new ElasticsearchException ("[{}] for [{}] denied" , action , connection .getNode ());
132
128
} else {
133
129
connection .sendRequest (requestId , action , request , options );
@@ -179,8 +175,12 @@ public void testNodeTriesToJoinClusterAndThenDifferentMasterIsElected() {
179
175
180
176
// 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)
181
177
@ TestLogging (
182
- reason = "test includes assertions about logging" ,
183
- value = "org.elasticsearch.cluster.coordination.NodeJoinExecutor:WARN,org.elasticsearch.cluster.coordination.NodeJoinExecutor:INFO,org.elasticsearch.cluster.coordination.MasterService:WARN,org.elasticsearch.cluster.coordination.MasterService:INFO,org.elasticsearch.cluster.coordination.ClusterApplierService:WARN"
178
+ reason = "test includes assertions about logging" ,
179
+ value = "org.elasticsearch.cluster.coordination.NodeJoinExecutor:WARN,"
180
+ + "org.elasticsearch.cluster.coordination.NodeJoinExecutor:INFO,"
181
+ + "org.elasticsearch.cluster.coordination.MasterService:WARN,"
182
+ + "org.elasticsearch.cluster.coordination.MasterService:INFO,"
183
+ + "org.elasticsearch.cluster.coordination.ClusterApplierService:WARN"
184
184
)
185
185
public void testNodeTriesToJoinClusterAndThenSameMasterIsElected_DoesNotIncludeWarnLog () {
186
186
final var cleanupTasks = new ArrayList <Releasable >();
@@ -210,10 +210,18 @@ public void testNodeTriesToJoinClusterAndThenSameMasterIsElected_DoesNotIncludeW
210
210
});
211
211
212
212
// Latch to remove publishing ban to allow re-election
213
- CountDownLatch publishingBanRemovedLatch = removeMockTransportServicePublishBanWhenMasterHasSteppedDown (masterNodeName , masterNodeTransportService , cleanupTasks );
213
+ CountDownLatch publishingBanRemovedLatch = removeMockTransportServicePublishBanWhenMasterHasSteppedDown (
214
+ masterNodeName ,
215
+ masterNodeTransportService ,
216
+ cleanupTasks
217
+ );
214
218
215
219
// A CountDownLatch that only gets decremented when the first master node is re-elected
216
- final var masterKnowsItHasBeenReElectedLatch = configureElectionLatchForReElectedMaster (masterNodeName , originalTerm , cleanupTasks );
220
+ final var masterKnowsItHasBeenReElectedLatch = configureElectionLatchForReElectedMaster (
221
+ masterNodeName ,
222
+ originalTerm ,
223
+ cleanupTasks
224
+ );
217
225
218
226
for (String nodeName : internalCluster ().getNodeNames ()) {
219
227
final var mockTransportService = MockTransportService .getInstance (nodeName );
@@ -280,9 +288,9 @@ public void testNodeTriesToJoinClusterAndThenSameMasterIsElected_DoesNotIncludeW
280
288
// Await for N to be in the cluster state of all nodes
281
289
for (String nodeName : namesOfAllNodesInOriginalCluster ) {
282
290
ClusterServiceUtils .awaitClusterState (
283
- logger ,
284
- clusterState -> clusterState .nodes ().nodeExistsWithName (newNodeName ),
285
- internalCluster ().clusterService (nodeName )
291
+ logger ,
292
+ clusterState -> clusterState .nodes ().nodeExistsWithName (newNodeName ),
293
+ internalCluster ().clusterService (nodeName )
286
294
);
287
295
}
288
296
} catch (Exception e ) {
@@ -309,10 +317,8 @@ public void testNodeTriesToJoinClusterAndThenSameMasterIsElected_DoesNotIncludeW
309
317
}
310
318
}
311
319
312
-
313
- private List <String > getListOfDataNodeNamesFromCluster (String nodeName ){
314
- return internalCluster ()
315
- .clusterService (nodeName )
320
+ private List <String > getListOfDataNodeNamesFromCluster (String nodeName ) {
321
+ return internalCluster ().clusterService (nodeName )
316
322
.state ()
317
323
.getNodes ()
318
324
.getDataNodes ()
@@ -336,12 +342,7 @@ public void match(LogEvent event) {
336
342
return ;
337
343
}
338
344
339
- Pattern pattern = Pattern .compile (
340
- "node-join: \\ ["
341
- + expectedNewNodeAsString
342
- + "] "
343
- + "with reason \\ [joining]"
344
- );
345
+ Pattern pattern = Pattern .compile ("node-join: \\ [" + expectedNewNodeAsString + "] " + "with reason \\ [joining]" );
345
346
Matcher matcher = pattern .matcher (event .getMessage ().getFormattedMessage ());
346
347
347
348
if (matcher .find ()) {
@@ -370,11 +371,15 @@ public void match(LogEvent event) {
370
371
}
371
372
372
373
Pattern pattern = Pattern .compile (
373
- "node-join\\ ["
374
+ "node-join\\ ["
374
375
+ expectedNewNodeAsString
375
376
+ " joining],"
376
- + " term: " + term + ","
377
- + " version: " + version + ","
377
+ + " term: "
378
+ + term
379
+ + ","
380
+ + " version: "
381
+ + version
382
+ + ","
378
383
+ " delta: added \\ {"
379
384
+ expectedNewNodeAsString
380
385
+ "}"
@@ -407,9 +412,11 @@ public void match(LogEvent event) {
407
412
}
408
413
409
414
Pattern pattern = Pattern .compile (
410
- "failing \\ [node-join\\ ["
411
- + expectedNewNodeAsString
412
- + " joining]]: failed to commit cluster state version \\ [" + version +"]"
415
+ "failing \\ [node-join\\ ["
416
+ + expectedNewNodeAsString
417
+ + " joining]]: failed to commit cluster state version \\ ["
418
+ + version
419
+ + "]"
413
420
);
414
421
Matcher matcher = pattern .matcher (event .getMessage ().getFormattedMessage ());
415
422
@@ -440,13 +447,14 @@ public void match(LogEvent event) {
440
447
441
448
String regexToMatchAnyCharacterExceptClosingBrace = "([^}]+)" ;
442
449
Pattern pattern = Pattern .compile (
443
- "node-join: \\ ["
444
- + expectedNewNodeAsString
445
- + "] "
446
- + "with reason \\ [joining, removed \\ ["
447
- + regexToMatchAnyCharacterExceptClosingBrace
448
- + "] ago with reason \\ [disconnected]]; "
449
- + "for troubleshooting guidance, see https://www.elastic.co/docs/troubleshoot/elasticsearch/troubleshooting-unstable-cluster\\ ?version=master"
450
+ "node-join: \\ ["
451
+ + expectedNewNodeAsString
452
+ + "] "
453
+ + "with reason \\ [joining, removed \\ ["
454
+ + regexToMatchAnyCharacterExceptClosingBrace
455
+ + "] ago with reason \\ [disconnected]]; "
456
+ + "for troubleshooting guidance, see "
457
+ + "https://www.elastic.co/docs/troubleshoot/elasticsearch/troubleshooting-unstable-cluster\\ ?version=master"
450
458
);
451
459
Matcher matcher = pattern .matcher (event .getMessage ().getFormattedMessage ());
452
460
@@ -462,7 +470,10 @@ public void assertMatched() {
462
470
});
463
471
}
464
472
465
- private void addNodeJoinProcessedDuringNewElectionAndClusterStatePublicationExpectation (MockLog mockLog , String expectedNewNodeAsString ) {
473
+ private void addNodeJoinProcessedDuringNewElectionAndClusterStatePublicationExpectation (
474
+ MockLog mockLog ,
475
+ String expectedNewNodeAsString
476
+ ) {
466
477
mockLog .addExpectation (new MockLog .LoggingExpectation () {
467
478
boolean matched = false ;
468
479
@@ -475,11 +486,7 @@ public void match(LogEvent event) {
475
486
return ;
476
487
}
477
488
478
- Pattern pattern = Pattern .compile (
479
- "added \\ {"
480
- + expectedNewNodeAsString
481
- + "}"
482
- );
489
+ Pattern pattern = Pattern .compile ("added \\ {" + expectedNewNodeAsString + "}" );
483
490
Matcher matcher = pattern .matcher (event .getMessage ().getFormattedMessage ());
484
491
485
492
if (matcher .find ()) {
@@ -500,15 +507,31 @@ private String generateNodeDescriptionForNewDiscoveryNode(int numberOfNodesOrigi
500
507
String newNodeName = "node_s" + numberOfNodesOriginallyInCluster ;
501
508
String regexToMatchAnyCharacterExceptClosingBrace = "([^}]+)" ;
502
509
503
- return "\\ {" + newNodeName + "}"
504
- + "\\ {" + regexToMatchAnyCharacterExceptClosingBrace + "}"
505
- + "\\ {" + regexToMatchAnyCharacterExceptClosingBrace + "}"
506
- + "\\ {" + newNodeName + "}"
507
- + "\\ {" + masterNode .getHostAddress () + "}"
508
- + "\\ {" + masterNode .getHostAddress () + ":\\ d+}"
510
+ return "\\ {"
511
+ + newNodeName
512
+ + "}"
513
+ + "\\ {"
514
+ + regexToMatchAnyCharacterExceptClosingBrace
515
+ + "}"
516
+ + "\\ {"
517
+ + regexToMatchAnyCharacterExceptClosingBrace
518
+ + "}"
519
+ + "\\ {"
520
+ + newNodeName
521
+ + "}"
522
+ + "\\ {"
523
+ + masterNode .getHostAddress ()
524
+ + "}"
525
+ + "\\ {"
526
+ + masterNode .getHostAddress ()
527
+ + ":\\ d+}"
509
528
+ "\\ {d}"
510
- + "\\ {" + masterNode .getVersion () + "}"
511
- + "\\ {" + regexToMatchAnyCharacterExceptClosingBrace + "}" ;
529
+ + "\\ {"
530
+ + masterNode .getVersion ()
531
+ + "}"
532
+ + "\\ {"
533
+ + regexToMatchAnyCharacterExceptClosingBrace
534
+ + "}" ;
512
535
}
513
536
514
537
/**
@@ -518,7 +541,11 @@ private String generateNodeDescriptionForNewDiscoveryNode(int numberOfNodesOrigi
518
541
* @param mockTransportService The transport service to remove the `addSendBehavior` from
519
542
* @param cleanupTasks The list of cleanup tasks
520
543
*/
521
- protected CountDownLatch removeMockTransportServicePublishBanWhenMasterHasSteppedDown (String masterNodeName , MockTransportService mockTransportService , List <Releasable > cleanupTasks ) {
544
+ protected CountDownLatch removeMockTransportServicePublishBanWhenMasterHasSteppedDown (
545
+ String masterNodeName ,
546
+ MockTransportService mockTransportService ,
547
+ List <Releasable > cleanupTasks
548
+ ) {
522
549
CountDownLatch latch = new CountDownLatch (1 );
523
550
ClusterStateApplier newMasterMonitor = event -> {
524
551
DiscoveryNode masterNode = event .state ().nodes ().getMasterNode ();
0 commit comments