incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [1/6] git commit: Fixing a potential race condition.
Date Mon, 03 Feb 2014 19:51:15 GMT
Updated Branches:
  refs/heads/apache-blur-0.2 ed2da2c05 -> 64da3a8f3


Fixing a potential race condition.


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

Branch: refs/heads/apache-blur-0.2
Commit: a8e814a4e7e571b520f8c168b7cfed5414b9ae4d
Parents: ed2da2c
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Sat Feb 1 08:44:48 2014 -0500
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Sat Feb 1 08:44:48 2014 -0500

----------------------------------------------------------------------
 .../manager/writer/BlurIndexSimpleWriter.java   | 21 +++++++++++++++++---
 1 file changed, 18 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/a8e814a4/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 8ea4332..3804f1a 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
@@ -70,6 +70,9 @@ public class BlurIndexSimpleWriter extends BlurIndex {
   private IndexImporter _indexImporter;
   private final ReadWriteLock _lock = new ReentrantReadWriteLock();
   private final Lock _writeLock = _lock.writeLock();
+  private final ReadWriteLock _indexRefreshLock = new ReentrantReadWriteLock();
+  private final Lock _indexRefreshWriteLock = _indexRefreshLock.writeLock();
+  private final Lock _indexRefreshReadLock = _indexRefreshLock.writeLock();
   private Thread _optimizeThread;
   private Thread _writerOpener;
   private final IndexDeletionPolicyReader _policy;
@@ -153,8 +156,14 @@ public class BlurIndexSimpleWriter extends BlurIndex {
 
   @Override
   public IndexSearcherClosable getIndexSearcher() throws IOException {
-    final IndexReader indexReader = _indexReader.get();
-    indexReader.incRef();
+    final IndexReader indexReader;
+    _indexRefreshReadLock.lock();
+    try {
+      indexReader = _indexReader.get();
+      indexReader.incRef();
+    } finally {
+      _indexRefreshReadLock.unlock();
+    }
     return new IndexSearcherClosable(indexReader, _searchThreadPool) {
 
       private boolean _closed;
@@ -272,7 +281,13 @@ public class BlurIndexSimpleWriter extends BlurIndex {
       LOG.error("Reader should be new after commit for table [{0}] shard [{1}].", _tableContext.getTable(),
           _shardContext.getShard());
     } else {
-      _indexReader.set(wrap(newReader));
+      DirectoryReader reader = wrap(newReader);
+      _indexRefreshWriteLock.lock();
+      try {
+        _indexReader.set(reader);
+      } finally {
+        _indexRefreshWriteLock.unlock();
+      }
       _indexCloser.close(currentReader);
     }
     trace3.done();


Mime
View raw message