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 2021/02/03 05:59:07 UTC

[lucene-solr] branch reference_impl updated: @1316 Fix this lazy collection get now that its not fully sync'd.

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

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


The following commit(s) were added to refs/heads/reference_impl by this push:
     new 18f0ef6  @1316 Fix this lazy collection get now that its not fully sync'd.
18f0ef6 is described below

commit 18f0ef63d7f2f0a598b0d720cc04b8326014d7ac
Author: markrmiller@gmail.com <ma...@gmail.com>
AuthorDate: Tue Feb 2 23:58:15 2021 -0600

    @1316 Fix this lazy collection get now that its not fully sync'd.
---
 .../src/java/org/apache/solr/common/cloud/ZkStateReader.java  | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

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 075ef7b..f48752d 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
@@ -734,8 +734,8 @@ public class ZkStateReader implements SolrCloseable, Replica.NodeNameToBaseUrl {
 
   private class LazyCollectionRef extends ClusterState.CollectionRef {
     private final String collName;
-    private long lastUpdateTime;
-    private DocCollection cachedDocCollection;
+    private volatile long lastUpdateTime;
+    private volatile DocCollection cachedDocCollection;
 
     public LazyCollectionRef(String collName) {
       super(null);
@@ -748,7 +748,8 @@ public class ZkStateReader implements SolrCloseable, Replica.NodeNameToBaseUrl {
       gets.incrementAndGet();
       if (!allowCached || lastUpdateTime < 0 || System.nanoTime() - lastUpdateTime > LAZY_CACHE_TIME) {
         boolean shouldFetch = true;
-        if (cachedDocCollection != null) {
+        DocCollection cached = cachedDocCollection;
+        if (cached != null) {
           Stat exists = null;
           try {
             exists = zkClient.exists(getCollectionPath(collName), null, true);
@@ -761,8 +762,10 @@ public class ZkStateReader implements SolrCloseable, Replica.NodeNameToBaseUrl {
           }
         }
         if (shouldFetch) {
-          cachedDocCollection = getCollectionLive(ZkStateReader.this, collName);
+          cached = getCollectionLive(ZkStateReader.this, collName);
           lastUpdateTime = System.nanoTime();
+          cachedDocCollection = cached;
+          return cached;
         }
       }
       if (log.isDebugEnabled() && cachedDocCollection == null) {