diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt index bb31232817d..0949a6691b6 100644 --- a/solr/CHANGES.txt +++ b/solr/CHANGES.txt @@ -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 diff --git a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java index 628f0973112..e8c66d5e0c5 100644 --- a/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java +++ b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java @@ -126,9 +126,10 @@ public class CloudSolrClient extends SolrClient { } private volatile long timeToLive = 60* 1000L; + private volatile List locks = objectList(3); - protected Map collectionStateCache = new ConcurrentHashMap(){ + protected final Map collectionStateCache = new ConcurrentHashMap(){ @Override public ExpiringCachedDocCollection get(Object key) { ExpiringCachedDocCollection val = super.get(key); @@ -143,7 +144,7 @@ public class CloudSolrClient extends SolrClient { }; class ExpiringCachedDocCollection { - DocCollection cached; + final DocCollection cached; long cachedAt; ExpiringCachedDocCollection(DocCollection cached) { @@ -1060,18 +1061,50 @@ public class CloudSolrClient extends SolrClient { return updatesToLeaders; } - 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 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); } - DocCollection col = clusterState.getCollectionOrNull(collection); + private static ArrayList objectList(int n) { + ArrayList l = new ArrayList<>(n); + for(int i=0;i1) 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 diff --git a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java index ceac4ecaf66..9e653a9b0d0 100644 --- a/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java +++ b/solr/solrj/src/java/org/apache/solr/common/cloud/ClusterState.java @@ -165,6 +165,9 @@ public class ClusterState implements JSONWriter.Writable { 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 JSONWriter.Writable { return coll; } + public boolean isLazilyLoaded() { return false; } + } } 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 07c09fa5a3f..f36f4c9e2da 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 @@ -471,6 +471,9 @@ public class ZkStateReader implements Closeable { public DocCollection get() { return getCollectionLive(ZkStateReader.this, collName); } + + @Override + public boolean isLazilyLoaded() { return true; } }); } }