lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From no...@apache.org
Subject svn commit: r1653822 - in /lucene/dev/trunk/solr: ./ solrj/src/java/org/apache/solr/client/solrj/impl/ solrj/src/java/org/apache/solr/common/cloud/
Date Thu, 22 Jan 2015 12:11:57 GMT
Author: noble
Date: Thu Jan 22 12:11:57 2015
New Revision: 1653822

URL: http://svn.apache.org/r1653822
Log:
SOLR-6521 CloudSolrServer should synchronize cache cluster state loading

Modified:
    lucene/dev/trunk/solr/CHANGES.txt
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
    lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java

Modified: lucene/dev/trunk/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/CHANGES.txt?rev=1653822&r1=1653821&r2=1653822&view=diff
==============================================================================
--- lucene/dev/trunk/solr/CHANGES.txt (original)
+++ lucene/dev/trunk/solr/CHANGES.txt Thu Jan 22 12:11:57 2015
@@ -794,6 +794,9 @@ Other Changes
 * SOLR-6976: Remove classes and methods deprecated in 4.x (Alan Woodward, Noble
   Paul, Chris Hostetter)
 
+* SOLR-6521: CloudSolrClient should synchronize cache cluster state loading
+    ( Noble Paul, Jessica Cheng Mallet)
+
 ==================  4.10.3 ==================
 
 Bug Fixes

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java?rev=1653822&r1=1653821&r2=1653822&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
(original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
Thu Jan 22 12:11:57 2015
@@ -126,9 +126,10 @@ public class CloudSolrClient extends Sol
 
   }
   private volatile long timeToLive = 60* 1000L;
+  private volatile List<Object> locks = objectList(3);
 
 
-  protected Map<String, ExpiringCachedDocCollection> collectionStateCache = new ConcurrentHashMap<String,
ExpiringCachedDocCollection>(){
+  protected final Map<String, ExpiringCachedDocCollection> collectionStateCache = new
ConcurrentHashMap<String, ExpiringCachedDocCollection>(){
     @Override
     public ExpiringCachedDocCollection get(Object key) {
       ExpiringCachedDocCollection val = super.get(key);
@@ -143,7 +144,7 @@ public class CloudSolrClient extends Sol
   };
 
   class ExpiringCachedDocCollection {
-    DocCollection cached;
+    final DocCollection cached;
     long cachedAt;
 
     ExpiringCachedDocCollection(DocCollection cached) {
@@ -1060,18 +1061,50 @@ public class CloudSolrClient extends Sol
     return updatesToLeaders;
   }
 
+  /**If caches are expired they are refreshed after acquiring a lock.
+   * use this to set the number of locks
+   */
+  public void setParallelCacheRefreshes(int n){ locks = objectList(n); }
+
+  private static ArrayList<Object> objectList(int n) {
+    ArrayList<Object> l =  new ArrayList<>(n);
+    for(int i=0;i<n;i++) l.add(new Object());
+    return l;
+  }
+
+
   protected DocCollection getDocCollection(ClusterState clusterState, String collection)
throws SolrException {
-    ExpiringCachedDocCollection cachedState = collectionStateCache != null ? collectionStateCache.get(collection)
: null;
-    if (cachedState != null && cachedState.cached != null) {
-      return cachedState.cached;
+    if(collection == null) return null;
+    DocCollection col = getFromCache(collection);
+    if(col != null) return col;
+
+    ClusterState.CollectionRef ref = clusterState.getCollectionRef(collection);
+    if(ref == null){
+      //no such collection exists
+      return null;
+    }
+    if(!ref.isLazilyLoaded()) {
+      //it is readily available just return it
+      return ref.get();
+    }
+    List locks = this.locks;
+    final Object lock = locks.get(collection.hashCode() % locks.size());
+    synchronized (lock){
+      //we have waited for sometime just check once again
+      col = getFromCache(collection);
+      if(col !=null) return col;
+      col = ref.get();
     }
-
-    DocCollection col = clusterState.getCollectionOrNull(collection);
     if(col == null ) return  null;
     if(col.getStateFormat() >1) collectionStateCache.put(collection, new ExpiringCachedDocCollection(col));
     return col;
   }
 
+  private DocCollection getFromCache(String c){
+    ExpiringCachedDocCollection cachedState = collectionStateCache.get(c);
+    return cachedState != null ? cachedState.cached : null;
+  }
+
 
   /**
    * Useful for determining the minimum achieved replication factor across

Modified: lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
URL: http://svn.apache.org/viewvc/lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java?rev=1653822&r1=1653821&r2=1653822&view=diff
==============================================================================
--- lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java (original)
+++ lucene/dev/trunk/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java Thu
Jan 22 12:11:57 2015
@@ -165,6 +165,9 @@ public class ClusterState implements JSO
     return coll;
   }
 
+  public CollectionRef getCollectionRef(String coll) {
+    return  collectionStates.get(coll);
+  }
 
   public DocCollection getCollectionOrNull(String coll) {
     CollectionRef ref = collectionStates.get(coll);
@@ -397,6 +400,8 @@ public class ClusterState implements JSO
       return coll;
     }
 
+    public boolean isLazilyLoaded() { return false; }
+
   }
 
 }

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=1653822&r1=1653821&r2=1653822&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 Thu
Jan 22 12:11:57 2015
@@ -471,6 +471,9 @@ public class ZkStateReader implements Cl
             public DocCollection get() {
               return getCollectionLive(ZkStateReader.this, collName);
             }
+
+            @Override
+            public boolean isLazilyLoaded() { return true; }
           });
         }
       }



Mime
View raw message