You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by no...@apache.org on 2015/01/22 11:23:35 UTC
svn commit: r1653801 - in /lucene/dev/branches/lucene_solr_5_0/solr: ./
solrj/src/java/org/apache/solr/client/solrj/impl/
solrj/src/java/org/apache/solr/common/cloud/
Author: noble
Date: Thu Jan 22 10:23:35 2015
New Revision: 1653801
URL: http://svn.apache.org/r1653801
Log:
SOLR-6521 CloudSolrServer should synchronize cache cluster state loading
Modified:
lucene/dev/branches/lucene_solr_5_0/solr/CHANGES.txt
lucene/dev/branches/lucene_solr_5_0/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
lucene/dev/branches/lucene_solr_5_0/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
lucene/dev/branches/lucene_solr_5_0/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
Modified: lucene/dev/branches/lucene_solr_5_0/solr/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_5_0/solr/CHANGES.txt?rev=1653801&r1=1653800&r2=1653801&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_5_0/solr/CHANGES.txt (original)
+++ lucene/dev/branches/lucene_solr_5_0/solr/CHANGES.txt Thu Jan 22 10:23:35 2015
@@ -713,6 +713,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/branches/lucene_solr_5_0/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_5_0/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java?rev=1653801&r1=1653800&r2=1653801&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_5_0/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java (original)
+++ lucene/dev/branches/lucene_solr_5_0/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java Thu Jan 22 10:23:35 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) {
@@ -1068,18 +1069,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/branches/lucene_solr_5_0/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_5_0/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java?rev=1653801&r1=1653800&r2=1653801&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_5_0/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java (original)
+++ lucene/dev/branches/lucene_solr_5_0/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java Thu Jan 22 10:23:35 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/branches/lucene_solr_5_0/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/lucene_solr_5_0/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java?rev=1653801&r1=1653800&r2=1653801&view=diff
==============================================================================
--- lucene/dev/branches/lucene_solr_5_0/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java (original)
+++ lucene/dev/branches/lucene_solr_5_0/solr/solrj/src/java/org/apache/solr/common/cloud/ZkStateReader.java Thu Jan 22 10:23:35 2015
@@ -468,6 +468,9 @@ public class ZkStateReader implements Cl
public DocCollection get() {
return getCollectionLive(ZkStateReader.this, collName);
}
+
+ @Override
+ public boolean isLazilyLoaded() { return true; }
});
}
}