gianm commented on code in PR #12222:
URL: https://github.com/apache/druid/pull/12222#discussion_r896236263


##########
docs/operations/api-reference.md:
##########
@@ -935,6 +935,12 @@ Returns segment information lists including server 
locations for the given query
 
 #### GET
 
+* `/druid/v2/router/cluster`

Review Comment:
   It looks like the API ended up in `/druid/router/v1/cluster`, so the docs 
here should reflect that.



##########
server/src/main/java/org/apache/druid/discovery/LocalDruidNodeDiscoveryProvider.java:
##########
@@ -0,0 +1,164 @@
+/*
+ * 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 org.apache.druid.server.DruidNode;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+import java.util.function.BooleanSupplier;
+
+/**
+ * Local node discovery. In this mode, Druid may run a number of
+ * logical servers within a single process, so that node discovery
+ * is all within the same process, but matches a true distributed
+ * node discovery.
+ * <p>
+ * Concurrency is at the level of the entire provider, which is
+ * necessary to coordinate the active state with ongoing node
+ * discovery and listener registrations. Such a "global" lock
+ * is fine because the actions don't occur frequently, nor do the
+ * actions take much time. For this same reason, we use plain old
+ * Java synchronization rather than a fancier locking mechanism.
+ * <p>
+ * At present, this class is used in unit tests so that it is
+ * possible to simulate cluster membership changes without actually running
+ * ZK, etc. The class can become the primary provider if/when Druid
+ * can run all services in a single process: in that case, we won't
+ * need ZK to tell the in-process services about each other.
+ */
+public class LocalDruidNodeDiscoveryProvider extends 
DruidNodeDiscoveryProvider implements DruidNodeAnnouncer
+{
+  private class RoleEntry implements DruidNodeDiscovery
+  {
+    private final Map<DruidNode, DiscoveryDruidNode> nodes = new HashMap<>();
+    private final List<Listener> listeners = new ArrayList<>();
+
+    private void register(DiscoveryDruidNode node)
+    {
+      List<DruidNodeDiscovery.Listener> targets;
+      synchronized (LocalDruidNodeDiscoveryProvider.this) {
+        DiscoveryDruidNode prev = nodes.put(node.getDruidNode(), node);
+        if (prev != null) {
+          return;
+        }
+        targets = new ArrayList<>(listeners);
+      }
+      for (Listener listener : targets) {
+        listener.nodesAdded(Collections.singletonList(node));
+      }
+    }
+
+    private void deregister(DiscoveryDruidNode node)
+    {
+      List<DruidNodeDiscovery.Listener> targets;
+      synchronized (LocalDruidNodeDiscoveryProvider.this) {
+        DiscoveryDruidNode prev = nodes.remove(node.getDruidNode());
+        if (prev == null) {
+          return;
+        }
+        targets = new ArrayList<>(listeners);
+      }
+      for (Listener listener : targets) {
+        listener.nodesRemoved(Collections.singletonList(node));
+      }
+    }
+
+    @Override
+    public Collection<DiscoveryDruidNode> getAllNodes()
+    {
+      synchronized (LocalDruidNodeDiscoveryProvider.this) {
+        return new ArrayList<>(nodes.values());
+      }
+    }
+
+    @Override
+    public void registerListener(Listener listener)
+    {
+      synchronized (LocalDruidNodeDiscoveryProvider.this) {
+        listeners.add(listener);
+        if (!active) {
+          return;
+        }
+      }
+      listener.nodeViewInitialized();
+    }
+
+    private synchronized boolean contains(DruidNode node)

Review Comment:
   Does this method need to be synchronized on both `RoleEntry.this` and 
`LocalDruidNodeDiscoveryProvider.this`?



-- 
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: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to