@@ -265,8 +265,6 @@ public InternalTestCluster(long clusterSeed, Path baseDir,
265
265
this .nodePrefix = nodePrefix ;
266
266
267
267
assert nodePrefix != null ;
268
- ArrayList <Class <? extends Plugin >> tmpMockPlugins = new ArrayList <>(mockPlugins );
269
-
270
268
271
269
this .mockPlugins = mockPlugins ;
272
270
@@ -461,14 +459,9 @@ private synchronized NodeAndClient getRandomNodeAndClient() {
461
459
462
460
private synchronized NodeAndClient getRandomNodeAndClient (Predicate <NodeAndClient > predicate ) {
463
461
ensureOpen ();
464
- Collection <NodeAndClient > values = nodes .values ().stream ().filter (predicate ).collect (Collectors .toCollection (ArrayList ::new ));
465
- if (!values .isEmpty ()) {
466
- int whichOne = random .nextInt (values .size ());
467
- for (NodeAndClient nodeAndClient : values ) {
468
- if (whichOne -- == 0 ) {
469
- return nodeAndClient ;
470
- }
471
- }
462
+ List <NodeAndClient > values = nodes .values ().stream ().filter (predicate ).collect (Collectors .toList ());
463
+ if (values .isEmpty () == false ) {
464
+ return randomFrom (random , values );
472
465
}
473
466
return null ;
474
467
}
@@ -479,18 +472,14 @@ private synchronized NodeAndClient getRandomNodeAndClient(Predicate<NodeAndClien
479
472
* stop any of the running nodes.
480
473
*/
481
474
public synchronized void ensureAtLeastNumDataNodes (int n ) {
482
- boolean added = false ;
483
475
int size = numDataNodes ();
484
- for ( int i = size ; i < n ; i ++ ) {
476
+ if ( size < n ) {
485
477
logger .info ("increasing cluster size from {} to {}" , size , n );
486
- added = true ;
487
478
if (numSharedDedicatedMasterNodes > 0 ) {
488
- startDataOnlyNode ( Settings . EMPTY );
479
+ startDataOnlyNodes ( n - size );
489
480
} else {
490
- startNode ( Settings . EMPTY );
481
+ startNodes ( n - size );
491
482
}
492
- }
493
- if (added ) {
494
483
validateClusterFormed ();
495
484
}
496
485
}
@@ -1364,8 +1353,9 @@ private synchronized void startAndPublishNodesAndClients(List<NodeAndClient> nod
1364
1353
.filter (nac -> nodes .containsKey (nac .name ) == false ) // filter out old masters
1365
1354
.count ();
1366
1355
final int currentMasters = getMasterNodesCount ();
1367
- if (autoManageMinMasterNodes && currentMasters > 1 && newMasters > 0 ) {
1368
- // special case for 1 node master - we can't update the min master nodes before we add more nodes.
1356
+ if (autoManageMinMasterNodes && currentMasters > 0 && newMasters > 0 &&
1357
+ getMinMasterNodes (currentMasters + newMasters ) <= currentMasters ) {
1358
+ // if we're adding too many master-eligible nodes at once, we can't update the min master setting before adding the nodes.
1369
1359
updateMinMasterNodes (currentMasters + newMasters );
1370
1360
}
1371
1361
List <Future <?>> futures = nodeAndClients .stream ().map (node -> executor .submit (node ::startNode )).collect (Collectors .toList ());
@@ -1380,7 +1370,8 @@ private synchronized void startAndPublishNodesAndClients(List<NodeAndClient> nod
1380
1370
}
1381
1371
nodeAndClients .forEach (this ::publishNode );
1382
1372
1383
- if (autoManageMinMasterNodes && currentMasters == 1 && newMasters > 0 ) {
1373
+ if (autoManageMinMasterNodes && currentMasters > 0 && newMasters > 0 &&
1374
+ getMinMasterNodes (currentMasters + newMasters ) > currentMasters ) {
1384
1375
// update once masters have joined
1385
1376
validateClusterFormed ();
1386
1377
updateMinMasterNodes (currentMasters + newMasters );
@@ -1635,27 +1626,24 @@ public synchronized Set<String> nodesInclude(String index) {
1635
1626
}
1636
1627
1637
1628
/**
1638
- * Starts a node with default settings and returns it's name.
1629
+ * Starts a node with default settings and returns its name.
1639
1630
*/
1640
1631
public synchronized String startNode () {
1641
1632
return startNode (Settings .EMPTY );
1642
1633
}
1643
1634
1644
1635
/**
1645
- * Starts a node with the given settings builder and returns it's name.
1636
+ * Starts a node with the given settings builder and returns its name.
1646
1637
*/
1647
1638
public synchronized String startNode (Settings .Builder settings ) {
1648
1639
return startNode (settings .build ());
1649
1640
}
1650
1641
1651
1642
/**
1652
- * Starts a node with the given settings and returns it's name.
1643
+ * Starts a node with the given settings and returns its name.
1653
1644
*/
1654
1645
public synchronized String startNode (Settings settings ) {
1655
- final int defaultMinMasterNodes = getMinMasterNodes (getMasterNodesCount () + (Node .NODE_MASTER_SETTING .get (settings ) ? 1 : 0 ));
1656
- NodeAndClient buildNode = buildNode (settings , defaultMinMasterNodes );
1657
- startAndPublishNodesAndClients (Collections .singletonList (buildNode ));
1658
- return buildNode .name ;
1646
+ return startNodes (settings ).get (0 );
1659
1647
}
1660
1648
1661
1649
/**
0 commit comments