incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [5/6] git commit: Fixing issue in the cached index input class where the seek method would throw an IOException when seeking beyond the end of the file. The behavior that Lucene allows is to allow the seek be throw an EOFException during the first read.
Date Mon, 03 Feb 2014 19:51:19 GMT
Fixing issue in the cached index input class where the seek method would throw an IOException
when seeking beyond the end of the file.  The behavior that Lucene allows is to allow the
seek be throw an EOFException during the first read.


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

Branch: refs/heads/apache-blur-0.2
Commit: c21108663a6e67ebd01d315d8715d910694f1c72
Parents: cc9c6d3
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Mon Feb 3 14:41:15 2014 -0500
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Mon Feb 3 14:41:15 2014 -0500

----------------------------------------------------------------------
 .../blur/store/blockcache_v2/CacheIndexInput.java       | 11 ++++++++++-
 .../org/apache/blur/store/BaseDirectoryTestSuite.java   | 12 ++++++++++++
 2 files changed, 22 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c2110866/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheIndexInput.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheIndexInput.java
b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheIndexInput.java
index 35a03e6..3fdb5b3 100644
--- a/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheIndexInput.java
+++ b/blur-store/src/main/java/org/apache/blur/store/blockcache_v2/CacheIndexInput.java
@@ -17,6 +17,7 @@
  */
 package org.apache.blur.store.blockcache_v2;
 
+import java.io.EOFException;
 import java.io.IOException;
 
 import org.apache.blur.store.buffer.BufferStore;
@@ -224,11 +225,18 @@ public class CacheIndexInput extends IndexInput {
     return _position;
   }
 
+  private void checkEOF() throws EOFException {
+    if (_position >= _fileLength) {
+      throw new EOFException("read past EOF: " + this.toString());
+    }
+  }
+
   @Override
   public void seek(long pos) throws IOException {
     ensureOpen();
     if (pos >= _fileLength) {
-      throw new IOException("Can not seek past end of file [" + pos + "] filelength [" +
_fileLength + "]");
+      _position = pos;
+      return;
     }
     if (_position == pos) {
       // Seeking to same position
@@ -287,6 +295,7 @@ public class CacheIndexInput extends IndexInput {
   }
 
   private void tryToFill() throws IOException {
+    checkEOF();
     if (!isCacheValueValid() || remaining() == 0) {
       releaseCache();
       fill();

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/c2110866/blur-store/src/test/java/org/apache/blur/store/BaseDirectoryTestSuite.java
----------------------------------------------------------------------
diff --git a/blur-store/src/test/java/org/apache/blur/store/BaseDirectoryTestSuite.java b/blur-store/src/test/java/org/apache/blur/store/BaseDirectoryTestSuite.java
index 03a0358..0f37aab 100644
--- a/blur-store/src/test/java/org/apache/blur/store/BaseDirectoryTestSuite.java
+++ b/blur-store/src/test/java/org/apache/blur/store/BaseDirectoryTestSuite.java
@@ -28,6 +28,7 @@ import java.util.HashSet;
 import java.util.Random;
 import java.util.Set;
 
+import org.apache.blur.index.IndexDeletionPolicyReader;
 import org.apache.blur.lucene.LuceneVersionConstant;
 import org.apache.blur.store.blockcache.LastModified;
 import org.apache.blur.store.buffer.BufferStore;
@@ -38,6 +39,7 @@ import org.apache.lucene.document.IntField;
 import org.apache.lucene.index.DirectoryReader;
 import org.apache.lucene.index.IndexWriter;
 import org.apache.lucene.index.IndexWriterConfig;
+import org.apache.lucene.index.KeepOnlyLastCommitDeletionPolicy;
 import org.apache.lucene.search.IndexSearcher;
 import org.apache.lucene.search.NumericRangeQuery;
 import org.apache.lucene.search.TopDocs;
@@ -185,6 +187,9 @@ public abstract class BaseDirectoryTestSuite {
   public void testCreateIndex() throws IOException {
     long s = System.nanoTime();
     IndexWriterConfig conf = new IndexWriterConfig(LuceneVersionConstant.LUCENE_VERSION,
new KeywordAnalyzer());
+    IndexDeletionPolicyReader indexDeletionPolicy = new IndexDeletionPolicyReader(
+        new KeepOnlyLastCommitDeletionPolicy());
+    conf.setIndexDeletionPolicy(indexDeletionPolicy);
     FSDirectory control = FSDirectory.open(fileControl);
     Directory dir = getControlDir(control, directory);
     // The serial merge scheduler can be useful for debugging.
@@ -192,16 +197,23 @@ public abstract class BaseDirectoryTestSuite {
     IndexWriter writer = new IndexWriter(dir, conf);
     int numDocs = 10000;
     DirectoryReader reader = null;
+    long gen = 0;
     for (int i = 0; i < 100; i++) {
       if (reader == null) {
         reader = DirectoryReader.open(writer, true);
+        gen = reader.getIndexCommit().getGeneration();
+        indexDeletionPolicy.register(gen);
       } else {
         DirectoryReader old = reader;
         reader = DirectoryReader.openIfChanged(old, writer, true);
         if (reader == null) {
           reader = old;
         } else {
+          long newGen = reader.getIndexCommit().getGeneration();
+          indexDeletionPolicy.register(newGen);
+          indexDeletionPolicy.unregister(gen);
           old.close();
+          gen = newGen;
         }
       }
       assertEquals(i * numDocs, reader.numDocs());


Mime
View raw message