You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by GitBox <gi...@apache.org> on 2023/01/01 06:26:53 UTC

[GitHub] [solr] dsmiley commented on a diff in pull request #1258: Refactoring to move live nodes handling out of ZkStateReader and into own class

dsmiley commented on code in PR #1258:
URL: https://github.com/apache/solr/pull/1258#discussion_r1059710790


##########
solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkLiveNodes.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.solr.common.cloud;
+
+import static java.util.Collections.emptySortedSet;
+
+import java.lang.invoke.MethodHandles;
+import java.util.List;
+import java.util.Set;
+import java.util.SortedSet;
+import java.util.TreeSet;
+import java.util.concurrent.ConcurrentHashMap;
+import org.apache.solr.common.SolrException;
+import org.apache.zookeeper.KeeperException;
+import org.apache.zookeeper.WatchedEvent;
+import org.apache.zookeeper.Watcher;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ZkLiveNodes implements Watcher {
+  public static final String LIVE_NODES_ZKNODE = "/live_nodes";
+  private static final Logger log = LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+  private volatile SortedSet<String> liveNodes = emptySortedSet();
+  private final Set<LiveNodesListener> liveNodesListeners = ConcurrentHashMap.newKeySet();
+  private final SolrZkClient zkClient;
+
+  public ZkLiveNodes(SolrZkClient zkClient) {
+    this.zkClient = zkClient;
+  }
+
+  public SortedSet<String> getLiveNodes() {
+    return liveNodes;
+  }
+
+  protected void setLiveNodes(SortedSet<String> liveNodes) {
+    this.liveNodes = liveNodes;
+  }
+
+  public Set<LiveNodesListener> getLiveNodesListeners() {
+    return liveNodesListeners;
+  }
+
+  public void addLiveNodesListener(LiveNodesListener liveNodesListener) {
+    this.liveNodesListeners.add(liveNodesListener);
+  }
+
+  public void removeLiveNodesListener(LiveNodesListener liveNodesListener) {
+    this.liveNodesListeners.remove(liveNodesListener);
+  }
+
+  /* Refresh live nodes */
+  public synchronized void refreshLiveNodes() throws KeeperException, InterruptedException {

Review Comment:
   I think the methods on this class don't need "LiveNodes" in them.



##########
solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkStateReader.java:
##########
@@ -679,7 +679,13 @@ private void constructState(Set<String> changedCollections) {
       result.putIfAbsent(entry.getKey(), entry.getValue());
     }
 
-    this.clusterState = new ClusterState(result, liveNodes);
+    this.clusterState = new ClusterState(result, zkLiveNodes.getLiveNodes());
+    // Listen for future live nodes changes to update ClusterState
+    zkLiveNodes.addLiveNodesListener(
+        (o, n) -> {
+          clusterState.setLiveNodes(n);
+          return false;
+        });

Review Comment:
   is this new?



##########
solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkStateReader.java:
##########
@@ -105,7 +104,6 @@ public class ZkStateReader implements SolrCloseable {
   public static final String MAX_WAIT_SECONDS_PROP = "maxWaitSeconds";
   public static final String STATE_TIMESTAMP_PROP = "stateTimestamp";
   public static final String COLLECTIONS_ZKNODE = "/collections";
-  public static final String LIVE_NODES_ZKNODE = "/live_nodes";

Review Comment:
   Shrug; it's also rather internal to SolrCloud internals.



-- 
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: issues-unsubscribe@solr.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@solr.apache.org
For additional commands, e-mail: issues-help@solr.apache.org