You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by sh...@apache.org on 2014/10/27 15:51:09 UTC

svn commit: r1634554 - /lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java

Author: shalin
Date: Mon Oct 27 14:51:08 2014
New Revision: 1634554

URL: http://svn.apache.org/r1634554
Log:
SOLR-6591: ZkStateReader.updateClusterState should refresh cluster state for watched collections

Modified:
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java?rev=1634554&r1=1634553&r2=1634554&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java Mon Oct 27 14:51:08 2014
@@ -448,20 +448,25 @@ public class ZkStateReader implements Cl
                                                     // collections in
                                                     // clusterstate.json
     for (String s : getIndividualColls()) {
-      DocCollection watched = watchedCollectionStates.get(s);
-      if (watched != null) {
-        // if it is a watched collection, add too
-        result.put(s, new ClusterState.CollectionRef(watched));
-      } else {
-        // if it is not collection, then just create a reference which can fetch 
-        // the collection object just in time from ZK
-        final String collName = s;
-        result.put(s, new ClusterState.CollectionRef(null) {
-          @Override
-          public DocCollection get() {
-            return getCollectionLive(ZkStateReader.this, collName);
-          }
-        });
+      synchronized (this) {
+        if (watchedCollections.contains(s)) {
+          DocCollection live = getCollectionLive(this, s);
+          watchedCollectionStates.put(s, live);
+          // if it is a watched collection, add too
+          result.put(s, new ClusterState.CollectionRef(live));
+        } else {
+          // if it is not collection, then just create a reference which can fetch
+          // the collection object just in time from ZK
+          // this is also cheap (lazy loaded) so we put it inside the synchronized
+          // block although it is not required
+          final String collName = s;
+          result.put(s, new ClusterState.CollectionRef(null) {
+            @Override
+            public DocCollection get() {
+              return getCollectionLive(ZkStateReader.this, collName);
+            }
+          });
+        }
       }
     }
     return new ClusterState(ln, result, stat.getVersion());