You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by ma...@apache.org on 2020/11/13 22:22:34 UTC

[lucene-solr] branch reference_impl_dev updated: @1180 Don't watch before we check in get leader.

This is an automated email from the ASF dual-hosted git repository.

markrmiller pushed a commit to branch reference_impl_dev
in repository https://gitbox.apache.org/repos/asf/lucene-solr.git


The following commit(s) were added to refs/heads/reference_impl_dev by this push:
     new 77860fa  @1180 Don't watch before we check in get leader.
77860fa is described below

commit 77860fac60bac985b6b9c59f0651b6057bc37ace
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Fri Nov 13 16:19:04 2020 -0600

    @1180 Don't watch before we check in get leader.
---
 .../java/org/apache/solr/common/cloud/ZkStateReader.java   | 14 +++++++++++++-
 1 file changed, 13 insertions(+), 1 deletion(-)

diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
index b9be943..6be1bfc 100644
--- a/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
+++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
@@ -168,7 +168,7 @@ public class ZkStateReader implements SolrCloseable, Replica.NodeNameToBaseUrl {
   protected volatile ClusterState stateClusterState = new ClusterState(Collections.emptySet(), Collections.emptyMap());
 
 
-  private final int GET_LEADER_RETRY_DEFAULT_TIMEOUT = Integer.parseInt(System.getProperty("zkReaderGetLeaderRetryTimeoutMs", "1000"));
+  private final int GET_LEADER_RETRY_DEFAULT_TIMEOUT = Integer.parseInt(System.getProperty("zkReaderGetLeaderRetryTimeoutMs", "5000"));
 
   public static final String LEADER_ELECT_ZKNODE = "leader_elect";
 
@@ -920,6 +920,18 @@ public class ZkStateReader implements SolrCloseable, Replica.NodeNameToBaseUrl {
    */
   public Replica getLeaderRetry(String collection, String shard, int timeout) throws InterruptedException {
 
+    DocCollection coll = getClusterState().getCollectionOrNull(collection);
+
+    if (coll != null) {
+      Slice slice = coll.getSlice(shard);
+      if (slice != null) {
+        Replica leader = slice.getLeader();
+        if (leader != null) {
+          return leader;
+        }
+      }
+    }
+
     AtomicReference<Replica> returnLeader = new AtomicReference<>();
     try {
       waitForState(collection, timeout, TimeUnit.MILLISECONDS, (n, c) -> {