incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [2/4] git commit: Fixing a potential memory leak in the bitset cache used to enforce access control.
Date Mon, 21 Sep 2015 14:43:03 GMT
Fixing a potential memory leak in the bitset cache used to enforce access control.


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

Branch: refs/heads/master
Commit: 901543cb1837a10ffd8dbc2fd7f2adab018820fb
Parents: 3c30ddd
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Mon Sep 21 10:40:59 2015 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Mon Sep 21 10:40:59 2015 -0400

----------------------------------------------------------------------
 .../manager/writer/BlurIndexSimpleWriter.java   | 12 +++++--
 ...etDocumentVisibilityFilterCacheStrategy.java | 34 +++++++++++++++++++-
 2 files changed, 42 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/901543cb/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndexSimpleWriter.java
----------------------------------------------------------------------
diff --git a/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndexSimpleWriter.java
b/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndexSimpleWriter.java
index 71da14a..acc8f39 100644
--- a/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndexSimpleWriter.java
+++ b/blur-core/src/main/java/org/apache/blur/manager/writer/BlurIndexSimpleWriter.java
@@ -75,7 +75,6 @@ import org.apache.blur.trace.Tracer;
 import org.apache.blur.user.User;
 import org.apache.blur.user.UserContext;
 import org.apache.blur.utils.BlurConstants;
-import org.apache.blur.utils.BlurUtil;
 import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileStatus;
 import org.apache.hadoop.fs.FileSystem;
@@ -103,7 +102,6 @@ import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
 import org.apache.lucene.index.TieredMergePolicy;
 import org.apache.lucene.search.MatchAllDocsQuery;
-import org.apache.lucene.search.TermQuery;
 import org.apache.lucene.search.TopDocs;
 import org.apache.lucene.store.Directory;
 
@@ -537,11 +535,19 @@ public class BlurIndexSimpleWriter extends BlurIndex {
       } finally {
         _indexRefreshWriteLock.unlock();
       }
-      _indexCloser.close(currentReader);
+      _indexCloser.close(getRealReader(currentReader));
     }
     trace3.done();
   }
 
+  private IndexReader getRealReader(DirectoryReader reader) {
+    if (reader instanceof ExitableReader) {
+      ExitableReader exitableReader = (ExitableReader) reader;
+      return getRealReader(exitableReader.getIn());
+    }
+    return reader;
+  }
+
   @Override
   public void process(IndexAction indexAction) throws IOException {
     _writesWaiting.incrementAndGet();

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/901543cb/blur-document-security/src/main/java/org/apache/blur/lucene/security/search/BitSetDocumentVisibilityFilterCacheStrategy.java
----------------------------------------------------------------------
diff --git a/blur-document-security/src/main/java/org/apache/blur/lucene/security/search/BitSetDocumentVisibilityFilterCacheStrategy.java
b/blur-document-security/src/main/java/org/apache/blur/lucene/security/search/BitSetDocumentVisibilityFilterCacheStrategy.java
index 0a387f6..8a142cf 100644
--- a/blur-document-security/src/main/java/org/apache/blur/lucene/security/search/BitSetDocumentVisibilityFilterCacheStrategy.java
+++ b/blur-document-security/src/main/java/org/apache/blur/lucene/security/search/BitSetDocumentVisibilityFilterCacheStrategy.java
@@ -17,14 +17,18 @@
 package org.apache.blur.lucene.security.search;
 
 import java.io.IOException;
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
 import java.util.concurrent.ConcurrentMap;
 
+import org.apache.blur.lucene.security.index.SecureAtomicReader;
 import org.apache.commons.logging.Log;
 import org.apache.commons.logging.LogFactory;
 import org.apache.lucene.index.AtomicReader;
 import org.apache.lucene.index.DocsEnum;
 import org.apache.lucene.index.IndexReader;
 import org.apache.lucene.index.IndexReader.ReaderClosedListener;
+import org.apache.lucene.index.SegmentReader;
 import org.apache.lucene.search.DocIdSet;
 import org.apache.lucene.search.DocIdSetIterator;
 import org.apache.lucene.util.BytesRef;
@@ -72,7 +76,9 @@ public class BitSetDocumentVisibilityFilterCacheStrategy extends DocumentVisibil
 
       @Override
       public DocIdSet getDocIdSet() throws IOException {
-        reader.addReaderClosedListener(new ReaderClosedListener() {
+        LOG.debug("Building bitset for key [" + key + "]");
+        SegmentReader segmentReader = getSegmentReader(reader);
+        segmentReader.addReaderClosedListener(new ReaderClosedListener() {
           @Override
           public void onClose(IndexReader reader) {
             LOG.debug("Removing old bitset for key [" + key + "]");
@@ -88,6 +94,32 @@ public class BitSetDocumentVisibilityFilterCacheStrategy extends DocumentVisibil
     };
   }
 
+  public static SegmentReader getSegmentReader(IndexReader indexReader) throws IOException
{
+    if (indexReader instanceof SegmentReader) {
+      return (SegmentReader) indexReader;
+    } else if (indexReader instanceof SecureAtomicReader) {
+      SecureAtomicReader atomicReader = (SecureAtomicReader) indexReader;
+      AtomicReader originalReader = atomicReader.getOriginalReader();
+      return getSegmentReader(originalReader);
+    } else {
+      try {
+        Method method = indexReader.getClass().getDeclaredMethod("getOriginalReader", new
Class[] {});
+        return getSegmentReader((IndexReader) method.invoke(indexReader, new Object[] {}));
+      } catch (NoSuchMethodException e) {
+        LOG.error("IndexReader cannot find method [getOriginalReader]");
+      } catch (SecurityException e) {
+        throw new IOException(e);
+      } catch (IllegalAccessException e) {
+        throw new IOException(e);
+      } catch (IllegalArgumentException e) {
+        throw new IOException(e);
+      } catch (InvocationTargetException e) {
+        throw new IOException(e);
+      }
+    }
+    throw new IOException("SegmentReader could not be found [" + indexReader + "].");
+  }
+
   private static class Key {
 
     private final Object _object;


Mime
View raw message