incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [4/7] git commit: Fixing resource leaf with the prime docs when the wrong atomic reader is used.
Date Tue, 28 Oct 2014 01:59:31 GMT
Fixing resource leaf with the prime docs when the wrong atomic reader is used.


Project: http://git-wip-us.apache.org/repos/asf/incubator-blur/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-blur/commit/9831e301
Tree: http://git-wip-us.apache.org/repos/asf/incubator-blur/tree/9831e301
Diff: http://git-wip-us.apache.org/repos/asf/incubator-blur/diff/9831e301

Branch: refs/heads/master
Commit: 9831e301904baea3f403a90a34590aa53f8e2189
Parents: d9ebd44
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Mon Oct 27 20:47:03 2014 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Mon Oct 27 20:47:03 2014 -0400

----------------------------------------------------------------------
 .../blur/lucene/search/PrimeDocCache.java       | 23 +++++++++++++++-----
 1 file changed, 18 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/9831e301/blur-query/src/main/java/org/apache/blur/lucene/search/PrimeDocCache.java
----------------------------------------------------------------------
diff --git a/blur-query/src/main/java/org/apache/blur/lucene/search/PrimeDocCache.java b/blur-query/src/main/java/org/apache/blur/lucene/search/PrimeDocCache.java
index d78b8b7..0eb9443 100644
--- a/blur-query/src/main/java/org/apache/blur/lucene/search/PrimeDocCache.java
+++ b/blur-query/src/main/java/org/apache/blur/lucene/search/PrimeDocCache.java
@@ -20,6 +20,7 @@ import java.io.IOException;
 import java.util.Map;
 import java.util.concurrent.ConcurrentHashMap;
 
+import org.apache.blur.index.ExitableReader.ExitableFilterAtomicReader;
 import org.apache.blur.log.Log;
 import org.apache.blur.log.LogFactory;
 import org.apache.lucene.index.AtomicReader;
@@ -43,8 +44,9 @@ public class PrimeDocCache {
    * creating multiple bitsets during a race condition is very low, that's why
    * this method is not synced.
    */
-  public static OpenBitSet getPrimeDocBitSet(Term primeDocTerm, AtomicReader reader) throws
IOException {
-    Object key = reader.getCoreCacheKey();
+  public static OpenBitSet getPrimeDocBitSet(Term primeDocTerm, AtomicReader providedReader)
throws IOException {
+    AtomicReader reader = getRealReader(providedReader);
+    final Object key = reader.getCoreCacheKey();
     final Map<Object, OpenBitSet> primeDocMap = getPrimeDocMap(primeDocTerm);
     OpenBitSet bitSet = primeDocMap.get(key);
     if (bitSet == null) {
@@ -52,10 +54,12 @@ public class PrimeDocCache {
         reader.addReaderClosedListener(new ReaderClosedListener() {
           @Override
           public void onClose(IndexReader reader) {
-            Object key = reader.getCoreCacheKey();
             LOG.debug("Current size [" + primeDocMap.size() + "] Prime Doc BitSet removing
for segment [" + reader
                 + "]");
-            primeDocMap.remove(key);
+            OpenBitSet openBitSet = primeDocMap.remove(key);
+            if (openBitSet == null) {
+              LOG.warn("Primedoc was missing for key [{0}]", key);
+            }
           }
         });
         LOG.debug("Prime Doc BitSet missing for segment [" + reader + "] current size ["
+ primeDocMap.size() + "]");
@@ -75,7 +79,8 @@ public class PrimeDocCache {
         if (count == docFreq) {
           primeDocMap.put(key, bs);
         } else {
-          // @TODO deal with deletes correctly...  docFreq does not reflect deletes
+          // @TODO deal with deletes correctly... docFreq does not reflect
+          // deletes
           LOG.info("PrimeDoc for reader [{0}] not stored, because count [{1}] and freq [{2}]
do not match.", reader,
               count, docFreq);
         }
@@ -85,6 +90,14 @@ public class PrimeDocCache {
     return bitSet;
   }
 
+  private static AtomicReader getRealReader(AtomicReader providedReader) {
+    if (providedReader instanceof ExitableFilterAtomicReader) {
+      ExitableFilterAtomicReader exitableFilterAtomicReader = (ExitableFilterAtomicReader)
providedReader;
+      return exitableFilterAtomicReader.getOriginalReader();
+    }
+    return providedReader;
+  }
+
   private static Map<Object, OpenBitSet> getPrimeDocMap(Term primeDocTerm) {
     Map<Object, OpenBitSet> map = termPrimeDocMap.get(primeDocTerm);
     if (map == null) {


Mime
View raw message