lucene-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sar...@apache.org
Subject [14/40] lucene-solr:apiv2: SOLR-9334: CloudSolrClient.collectionStateCache is unbounded
Date Tue, 02 Aug 2016 01:07:34 GMT
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/4ed68bc8
Tree: http://git-wip-us.apache.org/repos/asf/lucene-solr/tree/4ed68bc8
Diff: http://git-wip-us.apache.org/repos/asf/lucene-solr/diff/4ed68bc8

Branch: refs/heads/apiv2
Commit: 4ed68bc80e7990f4acd1b73dce3b5b8cd16d9fe5
Parents: dcc9a4b
Author: Noble Paul <noble@apache.org>
Authored: Mon Jul 25 20:47:19 2016 +0530
Committer: Noble Paul <noble@apache.org>
Committed: Mon Jul 25 20:47:19 2016 +0530

----------------------------------------------------------------------
 solr/CHANGES.txt                                |  3 +++
 .../solr/client/solrj/impl/CloudSolrClient.java | 23 +++++++++++++++++++-
 2 files changed, 25 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4ed68bc8/solr/CHANGES.txt
----------------------------------------------------------------------
diff --git a/solr/CHANGES.txt b/solr/CHANGES.txt
index 55fae47..e392df3 100644
--- a/solr/CHANGES.txt
+++ b/solr/CHANGES.txt
@@ -161,6 +161,9 @@ Bug Fixes
 
 * SOLR-9309: Fix SolrCloud RTG response structure when multi ids requested but only 1 found
(hossman)
 
+* SOLR-9334: CloudSolrClient.collectionStateCache is unbounded (noble)
+
+
 Optimizations
 ----------------------
 

http://git-wip-us.apache.org/repos/asf/lucene-solr/blob/4ed68bc8/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 876f7f8..b4c9b4f 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
@@ -38,6 +38,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;
@@ -147,10 +149,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;
@@ -158,6 +166,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 {


Mime
View raw message