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