geode-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From upthewatersp...@apache.org
Subject incubator-geode git commit: Fixing a resource leak in IndexRepositoryImpl
Date Tue, 01 Sep 2015 18:19:16 GMT
Repository: incubator-geode
Updated Branches:
  refs/heads/feature/GEODE-11 e4220113e -> 746bb3140


Fixing a resource leak in IndexRepositoryImpl

The IndexRepositoryImpl was not closing the old DirectoryReader when it
refreshed. Instead of using Directory reader, using SearcherManager to
get an IndexSearcher and refresh the searcher after changes.


Project: http://git-wip-us.apache.org/repos/asf/incubator-geode/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-geode/commit/746bb314
Tree: http://git-wip-us.apache.org/repos/asf/incubator-geode/tree/746bb314
Diff: http://git-wip-us.apache.org/repos/asf/incubator-geode/diff/746bb314

Branch: refs/heads/feature/GEODE-11
Commit: 746bb3140837bdc110c122d8e8fdc6ff12b60f2e
Parents: e422011
Author: Dan Smith <upthewaterspout@apache.org>
Authored: Tue Sep 1 11:17:23 2015 -0700
Committer: Dan Smith <upthewaterspout@apache.org>
Committed: Tue Sep 1 11:17:23 2015 -0700

----------------------------------------------------------------------
 .../repository/IndexRepositoryImpl.java         | 29 ++++++++++----------
 1 file changed, 14 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-geode/blob/746bb314/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImpl.java
----------------------------------------------------------------------
diff --git a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImpl.java
b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImpl.java
index 57037d1..4c0b21b 100644
--- a/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImpl.java
+++ b/gemfire-lucene/src/main/java/com/gemstone/gemfire/cache/lucene/internal/repository/IndexRepositoryImpl.java
@@ -3,12 +3,12 @@ package com.gemstone.gemfire.cache.lucene.internal.repository;
 import java.io.IOException;
 
 import org.apache.lucene.document.Document;
-import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.Term;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.Query;
 import org.apache.lucene.search.ScoreDoc;
+import org.apache.lucene.search.SearcherManager;
 import org.apache.lucene.search.TopDocs;
 
 import com.gemstone.gemfire.cache.lucene.internal.repository.serializer.LuceneSerializer;
@@ -25,12 +25,11 @@ public class IndexRepositoryImpl implements IndexRepository {
   
   private final IndexWriter writer;
   private final LuceneSerializer serializer;
-  private volatile DirectoryReader reader;
-  private volatile IndexSearcher searcher;
+  private final SearcherManager searcherManager;
   
   public IndexRepositoryImpl(IndexWriter writer, LuceneSerializer serializer) throws IOException
{
     this.writer = writer;
-    reader = DirectoryReader.open(writer, APPLY_ALL_DELETES);
+    searcherManager = new SearcherManager(writer, APPLY_ALL_DELETES, null);
     this.serializer = serializer;
   }
 
@@ -58,22 +57,22 @@ public class IndexRepositoryImpl implements IndexRepository {
 
   @Override
   public void query(Query query, int limit, IndexResultCollector collector) throws IOException
{
-    IndexSearcher searcherSnapshot = searcher;
-    TopDocs docs = searcherSnapshot.search(query, limit);
-    for(ScoreDoc scoreDoc : docs.scoreDocs) {
-      Document doc = searcher.doc(scoreDoc.doc);
-      Object key = SerializerUtil.getKey(doc);
-      collector.collect(key, scoreDoc.score);
+    IndexSearcher searcher = searcherManager.acquire();
+    try {
+      TopDocs docs = searcher.search(query, limit);
+      for(ScoreDoc scoreDoc : docs.scoreDocs) {
+        Document doc = searcher.doc(scoreDoc.doc);
+        Object key = SerializerUtil.getKey(doc);
+        collector.collect(key, scoreDoc.score);
+      }
+    } finally {
+      searcherManager.release(searcher);
     }
   }
 
   @Override
   public synchronized void commit() throws IOException {
     writer.commit();
-    DirectoryReader newReader = DirectoryReader.openIfChanged(reader);
-    if(newReader != null) {
-      reader = newReader;
-      searcher = new IndexSearcher(reader);
-    }
+    searcherManager.maybeRefresh();
   }
 }


Mime
View raw message