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

Add _coordinating_only for nodes resolving in nodes API #30313

Merged
merged 9 commits into from
May 9, 2018
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@
*/
public class DiscoveryNode implements Writeable, ToXContentFragment {

static final String COORDINATING_ONLY = "coordinating_only";

public static boolean nodeRequiresLocalStorage(Settings settings) {
boolean localStorageEnable = Node.NODE_LOCAL_STORAGE_SETTING.get(settings);
if (localStorageEnable == false &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,19 @@ public ImmutableOpenMap<String, DiscoveryNode> getMasterAndDataNodes() {
return nodes.build();
}

/**
* Get a {@link Map} of the coordinating only nodes (nodes which are neither master, nor data, nor ingest nodes) arranged by their ids
*
* @return {@link Map} of the coordinating only nodes arranged by their ids
*/
public ImmutableOpenMap<String, DiscoveryNode> getCoordinatingOnlyNodes() {
ImmutableOpenMap.Builder<String, DiscoveryNode> nodes = ImmutableOpenMap.builder(this.nodes);
nodes.removeAll(masterNodes.keys());
nodes.removeAll(dataNodes.keys());
nodes.removeAll(ingestNodes.keys());
return nodes.build();
}

/**
* Get a node by its id
*
Expand Down Expand Up @@ -297,7 +310,7 @@ public DiscoveryNode resolveNode(String node) {
* - "_local" or "_master" for the relevant nodes
* - a node id
* - a wild card pattern that will be matched against node names
* - a "attr:value" pattern, where attr can be a node role (master, data, ingest etc.) in which case the value can be true of false
* - a "attr:value" pattern, where attr can be a node role (master, data, ingest etc.) in which case the value can be true or false,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

* or a generic node attribute name in which case value will be treated as a wildcard and matched against the node attribute values.
*/
public String[] resolveNodes(String... nodes) {
Expand Down Expand Up @@ -349,6 +362,12 @@ public String[] resolveNodes(String... nodes) {
} else {
resolvedNodesIds.removeAll(ingestNodes.keys());
}
} else if (DiscoveryNode.COORDINATING_ONLY.equals(matchAttrName)) {
if (Booleans.parseBoolean(matchAttrValue, true)) {
resolvedNodesIds.addAll(getCoordinatingOnlyNodes().keys());
} else {
resolvedNodesIds.removeAll(getCoordinatingOnlyNodes().keys());
}
} else {
for (DiscoveryNode node : this) {
for (Map.Entry<String, String> entry : node.getAttributes().entrySet()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -102,9 +102,17 @@ public void testCoordinatorOnlyNodes() {
.map(DiscoveryNode::getId)
.toArray(String[]::new);

assertThat(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it'd be good to keep this assertion here too.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good now, thanks 👍

discoveryNodes.resolveNodes("_all", "data:false", "ingest:false", "master:false"),
arrayContainingInAnyOrder(coordinatorOnlyNodes));
final String[] nonCoordinatorOnlyNodes =
StreamSupport.stream(discoveryNodes.getNodes().values().spliterator(), false)
.map(n -> n.value)
.filter(n -> n.isMasterNode() || n.isDataNode() || n.isIngestNode())
.map(DiscoveryNode::getId)
.toArray(String[]::new);

assertThat(discoveryNodes.resolveNodes("coordinating_only:true"), arrayContainingInAnyOrder(coordinatorOnlyNodes));
assertThat(discoveryNodes.resolveNodes("_all", "data:false", "ingest:false", "master:false"),
arrayContainingInAnyOrder(coordinatorOnlyNodes));
assertThat(discoveryNodes.resolveNodes("_all", "coordinating_only:false"), arrayContainingInAnyOrder(nonCoordinatorOnlyNodes));
}

public void testResolveNodesIds() {
Expand Down Expand Up @@ -254,6 +262,13 @@ Set<String> matchingNodeIds(DiscoveryNodes nodes) {
Set<String> matchingNodeIds(DiscoveryNodes nodes) {
return Collections.singleton(nodes.getMasterNodeId());
}
}, COORDINATING_ONLY("_coordinating_only") {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks like a hangover of the previous approach - should be coordinating_only:true I think.

@Override
Set<String> matchingNodeIds(DiscoveryNodes nodes) {
Set<String> ids = new HashSet<>();
nodes.getCoordinatingOnlyNodes().keysIt().forEachRemaining(ids::add);
return ids;
}
}, MASTER_ELIGIBLE(DiscoveryNode.Role.MASTER.getRoleName() + ":true") {
@Override
Set<String> matchingNodeIds(DiscoveryNodes nodes) {
Expand Down