Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Smaller aesthetic fixes to InternalTestCluster #31831

Merged
merged 3 commits into from
Jul 6, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -263,8 +263,6 @@ public InternalTestCluster(long clusterSeed, Path baseDir,
this.nodePrefix = nodePrefix;

assert nodePrefix != null;
ArrayList<Class<? extends Plugin>> tmpMockPlugins = new ArrayList<>(mockPlugins);


this.mockPlugins = mockPlugins;

Expand Down Expand Up @@ -458,14 +456,9 @@ private synchronized NodeAndClient getRandomNodeAndClient() {

private synchronized NodeAndClient getRandomNodeAndClient(Predicate<NodeAndClient> predicate) {
ensureOpen();
Collection<NodeAndClient> values = nodes.values().stream().filter(predicate).collect(Collectors.toCollection(ArrayList::new));
if (!values.isEmpty()) {
int whichOne = random.nextInt(values.size());
for (NodeAndClient nodeAndClient : values) {
if (whichOne-- == 0) {
return nodeAndClient;
}
}
List<NodeAndClient> values = nodes.values().stream().filter(predicate).collect(Collectors.toList());
if (values.isEmpty() == false) {
return randomFrom(random, values);
}
return null;
}
Expand All @@ -476,18 +469,14 @@ private synchronized NodeAndClient getRandomNodeAndClient(Predicate<NodeAndClien
* stop any of the running nodes.
*/
public synchronized void ensureAtLeastNumDataNodes(int n) {
boolean added = false;
int size = numDataNodes();
for (int i = size; i < n; i++) {
if (size < n) {
logger.info("increasing cluster size from {} to {}", size, n);
added = true;
if (numSharedDedicatedMasterNodes > 0) {
startDataOnlyNode(Settings.EMPTY);
startDataOnlyNodes(n - size);
} else {
startNode(Settings.EMPTY);
startNodes(n - size);
}
}
if (added) {
validateClusterFormed();
}
}
Expand Down Expand Up @@ -1361,8 +1350,9 @@ private synchronized void startAndPublishNodesAndClients(List<NodeAndClient> nod
.filter(nac -> nodes.containsKey(nac.name) == false) // filter out old masters
.count();
final int currentMasters = getMasterNodesCount();
if (autoManageMinMasterNodes && currentMasters > 1 && newMasters > 0) {
// special case for 1 node master - we can't update the min master nodes before we add more nodes.
if (autoManageMinMasterNodes && currentMasters > 0 && newMasters > 0 &&
getMinMasterNodes(currentMasters + newMasters) <= currentMasters) {
// if we're adding too many master-eligible nodes at once, we can't update the min master setting before adding the nodes.
updateMinMasterNodes(currentMasters + newMasters);
}
List<Future<?>> futures = nodeAndClients.stream().map(node -> executor.submit(node::startNode)).collect(Collectors.toList());
Expand All @@ -1377,7 +1367,8 @@ private synchronized void startAndPublishNodesAndClients(List<NodeAndClient> nod
}
nodeAndClients.forEach(this::publishNode);

if (autoManageMinMasterNodes && currentMasters == 1 && newMasters > 0) {
if (autoManageMinMasterNodes && currentMasters > 0 && newMasters > 0 &&
getMinMasterNodes(currentMasters + newMasters) > currentMasters) {
// update once masters have joined
validateClusterFormed();
updateMinMasterNodes(currentMasters + newMasters);
Expand Down Expand Up @@ -1632,27 +1623,24 @@ public synchronized Set<String> nodesInclude(String index) {
}

/**
* Starts a node with default settings and returns it's name.
* Starts a node with default settings and returns its name.
*/
public synchronized String startNode() {
return startNode(Settings.EMPTY);
}

/**
* Starts a node with the given settings builder and returns it's name.
* Starts a node with the given settings builder and returns its name.
*/
public synchronized String startNode(Settings.Builder settings) {
return startNode(settings.build());
}

/**
* Starts a node with the given settings and returns it's name.
* Starts a node with the given settings and returns its name.
*/
public synchronized String startNode(Settings settings) {
final int defaultMinMasterNodes = getMinMasterNodes(getMasterNodesCount() + (Node.NODE_MASTER_SETTING.get(settings) ? 1 : 0));
NodeAndClient buildNode = buildNode(settings, defaultMinMasterNodes);
startAndPublishNodesAndClients(Collections.singletonList(buildNode));
return buildNode.name;
return startNodes(settings).get(0);
}

/**
Expand Down