You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@druid.apache.org by GitBox <gi...@apache.org> on 2022/06/15 20:23:02 UTC
[GitHub] [druid] rohangarg commented on a diff in pull request #12222: Allow extension services to be discovered
rohangarg commented on code in PR #12222:
URL: https://github.com/apache/druid/pull/12222#discussion_r898369348
##########
server/src/main/java/org/apache/druid/discovery/NodeRoles.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.discovery;
+
+import com.google.common.collect.Collections2;
+import com.google.inject.Binder;
+import com.google.inject.multibindings.Multibinder;
+import org.apache.druid.guice.annotations.Global;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.Node;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+public class NodeRoles
+{
+ private static final Logger log = new Logger(NodeRoles.class);
+
+ /**
+ * Simulate the Guice binding of all node roles, but using just
+ * the known roles. Primarily for testing.
+ */
+ public static Set<NodeRole> knownRoles()
+ {
+ return new HashSet<>(Arrays.asList(NodeRole.values()));
+ }
+
+ public static void addKnownRoles(Binder binder)
Review Comment:
nit: `bindKnownRoles` could be used instead of `addKnownRoles`
##########
server/src/main/java/org/apache/druid/discovery/NodeRoles.java:
##########
@@ -0,0 +1,101 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+
+package org.apache.druid.discovery;
+
+import com.google.common.collect.Collections2;
+import com.google.inject.Binder;
+import com.google.inject.multibindings.Multibinder;
+import org.apache.druid.guice.annotations.Global;
+import org.apache.druid.java.util.common.logger.Logger;
+import org.apache.druid.server.Node;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+public class NodeRoles
+{
+ private static final Logger log = new Logger(NodeRoles.class);
+
+ /**
+ * Simulate the Guice binding of all node roles, but using just
+ * the known roles. Primarily for testing.
+ */
+ public static Set<NodeRole> knownRoles()
+ {
+ return new HashSet<>(Arrays.asList(NodeRole.values()));
+ }
+
+ public static void addKnownRoles(Binder binder)
+ {
+ Multibinder<NodeRole> roleBinder = binder(binder);
+ for (NodeRole role : NodeRole.values()) {
+ roleBinder.addBinding().toInstance(role);
+ }
+ }
+
+ /**
+ * Add a node role for an extension service.
+ */
+ public static void addRole(Binder binder, NodeRole role)
+ {
+ log.debug("Adding node role: %s", role.getJsonName());
+ binder(binder)
+ .addBinding()
+ .toInstance(role);
+ }
+
+ public static Multibinder<NodeRole> binder(Binder binder)
+ {
+ return Multibinder.newSetBinder(binder, NodeRole.class, Global.class);
+ }
+
+ @SuppressWarnings("unchecked")
+ public static Collection<Object> getNodes(
+ DruidNodeDiscoveryProvider provider,
+ NodeRole nodeRole,
+ boolean full)
+ {
+ if (full) {
+ return (Collection<Object>) (Collection<?>) getDiscoveryNodesForRole(provider, nodeRole);
Review Comment:
seems like these could be removed now since the methods return collections themselves - also the suppression
##########
sql/src/main/java/org/apache/druid/sql/calcite/schema/SystemSchema.java:
##########
@@ -682,13 +695,34 @@ private static DruidServer toDruidServer(DiscoveryDruidNode discoveryDruidNode)
}
}
- private static Iterator<DiscoveryDruidNode> getDruidServers(DruidNodeDiscoveryProvider druidNodeDiscoveryProvider)
+ private Iterator<DiscoveryDruidNode> getDruidServers(DruidNodeDiscoveryProvider druidNodeDiscoveryProvider)
{
- return Arrays.stream(NodeRole.values())
+ return orderedNodeRoles().stream()
.flatMap(nodeRole -> druidNodeDiscoveryProvider.getForNodeRole(nodeRole).getAllNodes().stream())
.collect(Collectors.toList())
.iterator();
}
+
+ /**
+ * Preserve backward compatibility while adding custom node roles. Prior versions
+ * listed roles in the order defined in the NodeRole enum, now class. We add
+ * custom node roles at the end. We choose alphabetical order so the the custom
+ * roles, if more than one, return in a stable, if arbitrary, order.
+ */
+ private List<NodeRole> orderedNodeRoles()
+ {
+ List<NodeRole> roles = new ArrayList<>(Arrays.asList(NodeRole.values()));
+ Set<NodeRole> stockRoles = new HashSet<>(roles);
+ List<NodeRole> customRoles = new ArrayList<>();
+ for (NodeRole role : allNodeRoles) {
Review Comment:
Possibly `Sets.difference` could be used here
##########
services/src/main/java/org/apache/druid/server/http/RouterResource.java:
##########
@@ -63,4 +81,33 @@ public Map<String, List<String>> getBrokers()
return brokersMap;
}
+
+ /**
+ * Returns a map of all services in the cluster, including extension services.
+ * Returns the map sorted by name so that output is stable. Visible on the
+ * router so clients can get a full cluster view, even if one of the services
+ * is down (assuming the router survives.)
+ *
+ * @see {@code /druid/coordinator/v1/cluster} for a similar API.
+ */
+ @GET
+ @Path("/cluster")
+ @ResourceFilters(StateResourceFilter.class)
+ @Produces(MediaType.APPLICATION_JSON)
+ public Response getCluster(@QueryParam("full") boolean full)
+ {
+ List<NodeRole> roles = new ArrayList<>(nodeRoles);
+ roles.sort((r1, r2) -> r1.getJsonName().compareTo(r2.getJsonName()));
Review Comment:
nit: this could move to the constructor or the set could be a SortedSet copy of the original
##########
server/src/main/java/org/apache/druid/initialization/Initialization.java:
##########
@@ -518,7 +519,13 @@ private boolean shouldLoadOnCurrentNodeType(Object object)
Set<NodeRole> rolesPredicate = Arrays.stream(loadScope.roles())
.map(NodeRole::fromJsonName)
.collect(Collectors.toSet());
- return rolesPredicate.stream().anyMatch(nodeRoles::contains);
+ boolean shouldLoad = rolesPredicate.stream().anyMatch(nodeRoles::contains);
+ if (!shouldLoad) {
+ log.debug(
Review Comment:
nit : maybe this could be an info log - recently I ran into an issue where a LoadScope annotated module wasn't getting installed on a PEON due to some NodeRole issue. A log here would make it much easier to debug skips and potential bugs. But OTOH, it can create decent noise as well in future.
So, I'm ok incase it is left as is too.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@druid.apache.org
For additional commands, e-mail: commits-help@druid.apache.org