You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@solr.apache.org by "tflobbe (via GitHub)" <gi...@apache.org> on 2023/01/30 17:53:39 UTC

[GitHub] [solr] tflobbe commented on a diff in pull request #1318: SOLR-16636: ZkStateReader.waitForState should not register a watch if state already matches predicate

tflobbe commented on code in PR #1318:
URL: https://github.com/apache/solr/pull/1318#discussion_r1090959156


##########
solr/solrj-zookeeper/src/java/org/apache/solr/common/cloud/ZkStateReader.java:
##########
@@ -1682,6 +1687,37 @@ public DocCollection getCollectionLive(String coll) {
     }
   }
 
+  /**
+   * fetch the collection that is already cached. This may return a null if it is not already cached
+   * This is an optimization to avoid fetching state if it is not modified. this is particularly
+   * true for PRS collections where state is rarely modified
+   */
+  private DocCollection fetchCachedCollection(String coll) {
+    String collectionPath = DocCollection.getCollectionPath(coll);
+    DocCollection c = null;
+    ClusterState.CollectionRef ref = clusterState.getCollectionRef(coll);
+    if (ref == null) return null;
+    c = ref.getOrNull();
+    if (c == null) return null;
+    Stat stat = null;
+    try {
+      stat = zkClient.exists(collectionPath, null, false);
+    } catch (Exception e) {
+      return null;
+    }
+    if (stat != null) {
+      if (!c.isModified(stat.getVersion(), stat.getCversion())) {
+        // we have the latest collection state
+        return c;
+      }
+      if (c.isPerReplicaState() && c.getChildNodesVersion() < stat.getCversion()) {
+        // only PRS is modified. just fetch it and return the new collection
+        return c.copyWith(PerReplicaStatesFetcher.fetch(collectionPath, zkClient, null));
+      }

Review Comment:
   This wouldn't add the updated DocCollection to the cache, right? So any future calls to this method will continue on the same path (exists + fetch), until some other code path updates the cache, is that right?



-- 
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