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 2016/07/26 07:49:12 UTC
lucene-solr:branch_5_5: SOLR-9334:
CloudSolrClient.collectionStateCache is unbounded
Repository: lucene-solr
Updated Branches:
refs/heads/branch_5_5 e2c45c7b9 -> 6933999b6
SOLR-9334: CloudSolrClient.collectionStateCache is unbounded
Project: http://git-wip-us.apache.org/repos/asf/lucene-solr/repo
Commit: http://git-wip-us.apache.org/repos/asf/lucene-solr/commit/6933999b
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/6933999b
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/6933999b
Branch: refs/heads/branch_5_5
Commit: 6933999b6a2991767bb45754853fe4c0b18defa8
Parents: e2c45c7
Author: Noble Paul <no...@apache.org>
Authored: Mon Jul 25 21:13:35 2016 +0530
Committer: Noble Paul <no...@apache.org>
Committed: Tue Jul 26 13:19:02 2016 +0530
----------------------------------------------------------------------
.../solr/client/solrj/impl/CloudSolrClient.java | 23 +++++++++++++++++++-
1 file changed, 22 insertions(+), 1 deletion(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/6933999b/solr/solrj/src/java/org/apache/solr/client/solrj/impl/CloudSolrClient.java
----------------------------------------------------------------------
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 a6b8a29..835098e 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
@@ -39,6 +39,8 @@ import java.util.concurrent.ExecutorService;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
+import java.util.concurrent.locks.Lock;
+import java.util.concurrent.locks.ReentrantLock;
import org.apache.http.NoHttpResponseException;
import org.apache.http.client.HttpClient;
@@ -142,10 +144,16 @@ public class CloudSolrClient extends SolrClient {
protected final Map<String, ExpiringCachedDocCollection> collectionStateCache = new ConcurrentHashMap<String, ExpiringCachedDocCollection>(){
+ final Lock evictLock = new ReentrantLock(true);
@Override
public ExpiringCachedDocCollection get(Object key) {
ExpiringCachedDocCollection val = super.get(key);
- if(val == null) return null;
+ if(val == null) {
+ // a new collection is likely to be added now.
+ //check if there are stale items and remove them
+ evictStale();
+ return null;
+ }
if(val.isExpired(timeToLive)) {
super.remove(key);
return null;
@@ -153,6 +161,19 @@ public class CloudSolrClient extends SolrClient {
return val;
}
+ void evictStale() {
+ if(!evictLock.tryLock()) return;
+ try {
+ for (Entry<String, ExpiringCachedDocCollection> e : entrySet()) {
+ if(e.getValue().isExpired(timeToLive)){
+ super.remove(e.getKey());
+ }
+ }
+ } finally {
+ evictLock.unlock();
+ }
+ }
+
};
class ExpiringCachedDocCollection {