incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject git commit: This fixes a problem with the exitablereader so that after the reader instance has been exited it can be reused.
Date Fri, 21 Feb 2014 03:53:07 GMT
Repository: incubator-blur
Updated Branches:
  refs/heads/apache-blur-0.2 393c9f53d -> eece2e53f


This fixes a problem with the exitablereader so that after the reader instance has been exited
it can be reused.


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

Branch: refs/heads/apache-blur-0.2
Commit: eece2e53faf376ea349589886038691af9e12273
Parents: 393c9f5
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Thu Feb 20 22:53:02 2014 -0500
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Thu Feb 20 22:53:02 2014 -0500

----------------------------------------------------------------------
 .../manager/writer/BlurIndexSimpleWriter.java   |  5 +-
 .../org/apache/blur/thrift/BlurClusterTest.java |  5 +-
 .../java/org/apache/blur/index/ExitObject.java  | 42 +++++++++++++++
 .../org/apache/blur/index/ExitableReader.java   | 57 ++++++++++----------
 4 files changed, 79 insertions(+), 30 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eece2e53/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 64c887b..a2da582 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
@@ -142,7 +142,7 @@ public class BlurIndexSimpleWriter extends BlurIndex {
           synchronized (_writer) {
             _writer.notify();
           }
-          _indexImporter = new IndexImporter(BlurIndexSimpleWriter.this , _shardContext,
TimeUnit.SECONDS, 10);
+          _indexImporter = new IndexImporter(BlurIndexSimpleWriter.this, _shardContext, TimeUnit.SECONDS,
10);
         } catch (IOException e) {
           LOG.error("Unknown error on index writer open.", e);
         }
@@ -164,6 +164,9 @@ public class BlurIndexSimpleWriter extends BlurIndex {
     } finally {
       _indexRefreshReadLock.unlock();
     }
+    if (indexReader instanceof ExitableReader) {
+      ((ExitableReader) indexReader).reset();
+    }
     return new IndexSearcherClosable(indexReader, _searchThreadPool) {
 
       private boolean _closed;

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eece2e53/blur-core/src/test/java/org/apache/blur/thrift/BlurClusterTest.java
----------------------------------------------------------------------
diff --git a/blur-core/src/test/java/org/apache/blur/thrift/BlurClusterTest.java b/blur-core/src/test/java/org/apache/blur/thrift/BlurClusterTest.java
index 7d79eba..7603d88 100644
--- a/blur-core/src/test/java/org/apache/blur/thrift/BlurClusterTest.java
+++ b/blur-core/src/test/java/org/apache/blur/thrift/BlurClusterTest.java
@@ -347,12 +347,11 @@ public class BlurClusterTest {
     final String tableName = "testQueryCancel";
     createTable(tableName);
     loadTable(tableName);
+    final Iface client = getClient();
     try {
       // This will make each collect in the collectors pause 250 ms per collect
       // call
       IndexManager.DEBUG_RUN_SLOW.set(true);
-
-      final Iface client = getClient();
       final BlurQuery blurQueryRow = new BlurQuery();
       Query queryRow = new Query();
       queryRow.setQuery("test.test:value");
@@ -389,6 +388,8 @@ public class BlurClusterTest {
     } finally {
       IndexManager.DEBUG_RUN_SLOW.set(false);
     }
+    // Tests that the exitable reader was reset.
+    client.terms(tableName, "test", "facet", null, (short) 100);
   }
 
   // @Test

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eece2e53/blur-store/src/main/java/org/apache/blur/index/ExitObject.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/index/ExitObject.java b/blur-store/src/main/java/org/apache/blur/index/ExitObject.java
new file mode 100644
index 0000000..92cd219
--- /dev/null
+++ b/blur-store/src/main/java/org/apache/blur/index/ExitObject.java
@@ -0,0 +1,42 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.blur.index;
+
+import java.util.concurrent.atomic.AtomicBoolean;
+
+public class ExitObject {
+
+  private final ThreadLocal<AtomicBoolean> _running = new ThreadLocal<AtomicBoolean>()
{
+    @Override
+    protected AtomicBoolean initialValue() {
+      return new AtomicBoolean(true);
+    }
+  };
+
+  public AtomicBoolean get() {
+    return _running.get();
+  }
+
+  public void set(AtomicBoolean running) {
+    _running.set(running);
+  }
+
+  public void reset() {
+    get().set(true);
+  }
+
+}

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/eece2e53/blur-store/src/main/java/org/apache/blur/index/ExitableReader.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/index/ExitableReader.java b/blur-store/src/main/java/org/apache/blur/index/ExitableReader.java
index 57c0acd..8321dd2 100644
--- a/blur-store/src/main/java/org/apache/blur/index/ExitableReader.java
+++ b/blur-store/src/main/java/org/apache/blur/index/ExitableReader.java
@@ -21,7 +21,6 @@ import java.util.Comparator;
 import java.util.Iterator;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicBoolean;
-import java.util.concurrent.atomic.AtomicReference;
 
 import org.apache.lucene.index.AtomicReader;
 import org.apache.lucene.index.DirectoryReader;
@@ -50,25 +49,25 @@ public class ExitableReader extends FilterDirectoryReader {
   }
 
   public static class ExitableSubReaderWrapper extends SubReaderWrapper {
-    private final AtomicReference<AtomicBoolean> _running;
+    private final ExitObject _exitObject;
 
-    public ExitableSubReaderWrapper(AtomicReference<AtomicBoolean> running) {
-      _running = running;
+    public ExitableSubReaderWrapper(ExitObject exitObject) {
+      _exitObject = exitObject;
     }
 
     @Override
     public AtomicReader wrap(AtomicReader reader) {
-      return new ExitableFilterAtomicReader(reader, _running);
+      return new ExitableFilterAtomicReader(reader, _exitObject);
     }
   }
 
   public static class ExitableFilterAtomicReader extends FilterAtomicReader {
 
-    private final AtomicReference<AtomicBoolean> _running;
+    private final ExitObject _exitObject;
 
-    public ExitableFilterAtomicReader(AtomicReader in, AtomicReference<AtomicBoolean>
running) {
+    public ExitableFilterAtomicReader(AtomicReader in, ExitObject exitObject) {
       super(in);
-      _running = running;
+      _exitObject = exitObject;
     }
 
     public AtomicReader getOriginalReader() {
@@ -81,7 +80,7 @@ public class ExitableReader extends FilterDirectoryReader {
       if (fields == null) {
         return null;
       }
-      return new ExitableFields(fields, _running);
+      return new ExitableFields(fields, _exitObject);
     }
 
     @Override
@@ -97,12 +96,12 @@ public class ExitableReader extends FilterDirectoryReader {
 
   public static class ExitableFields extends Fields {
 
-    private final AtomicReference<AtomicBoolean> _running;
+    private final ExitObject _exitObject;
     private final Fields _fields;
 
-    public ExitableFields(Fields fields, AtomicReference<AtomicBoolean> running) {
+    public ExitableFields(Fields fields, ExitObject exitObject) {
       _fields = fields;
-      _running = running;
+      _exitObject = exitObject;
     }
 
     @Override
@@ -111,7 +110,7 @@ public class ExitableReader extends FilterDirectoryReader {
       if (terms == null) {
         return null;
       }
-      return new ExitableTerms(terms, _running);
+      return new ExitableTerms(terms, _exitObject);
     }
 
     @Override
@@ -128,22 +127,22 @@ public class ExitableReader extends FilterDirectoryReader {
 
   public static class ExitableTerms extends Terms {
 
-    private final AtomicReference<AtomicBoolean> _running;
+    private final ExitObject _exitObject;
     private final Terms _terms;
 
-    public ExitableTerms(Terms terms, AtomicReference<AtomicBoolean> running) {
+    public ExitableTerms(Terms terms, ExitObject exitObject) {
       _terms = terms;
-      _running = running;
+      _exitObject = exitObject;
     }
 
     @Override
     public TermsEnum intersect(CompiledAutomaton compiled, BytesRef startTerm) throws IOException
{
-      return new ExitableTermsEnum(_terms.intersect(compiled, startTerm), _running);
+      return new ExitableTermsEnum(_terms.intersect(compiled, startTerm), _exitObject);
     }
 
     @Override
     public TermsEnum iterator(TermsEnum reuse) throws IOException {
-      return new ExitableTermsEnum(_terms.iterator(reuse), _running);
+      return new ExitableTermsEnum(_terms.iterator(reuse), _exitObject);
     }
 
     @Override
@@ -197,9 +196,9 @@ public class ExitableReader extends FilterDirectoryReader {
     private long _lastCheck;
     private int count = 0;
 
-    public ExitableTermsEnum(TermsEnum termsEnum, AtomicReference<AtomicBoolean> running)
{
+    public ExitableTermsEnum(TermsEnum termsEnum, ExitObject exitObject) {
       _termsEnum = termsEnum;
-      _running = running.get();
+      _running = exitObject.get();
       _lastCheck = System.nanoTime();
       checkAndThrow();
     }
@@ -284,23 +283,27 @@ public class ExitableReader extends FilterDirectoryReader {
 
   }
 
-  private final AtomicReference<AtomicBoolean> _running;
+  private final ExitObject _exitObject;
 
   public ExitableReader(DirectoryReader in) {
-    this(in, new AtomicReference<AtomicBoolean>(new AtomicBoolean(true)));
+    this(in, new ExitObject());
   }
 
-  private ExitableReader(DirectoryReader in, AtomicReference<AtomicBoolean> running)
{
-    super(in, new ExitableSubReaderWrapper(running));
-    _running = running;
+  public ExitableReader(DirectoryReader in, ExitObject exitObject) {
+    super(in, new ExitableSubReaderWrapper(exitObject));
+    _exitObject = exitObject;
   }
 
   public AtomicBoolean getRunning() {
-    return _running.get();
+    return _exitObject.get();
   }
 
   public void setRunning(AtomicBoolean running) {
-    _running.set(running);
+    _exitObject.set(running);
+  }
+
+  public void reset() {
+    _exitObject.reset();
   }
 
   @Override


Mime
View raw message