incubator-blur-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From amccu...@apache.org
Subject [13/18] git commit: Fixing a NPE in the hdfs index input class.
Date Wed, 01 Jul 2015 19:29:29 GMT
Fixing a NPE in the hdfs index input class.


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

Branch: refs/heads/blur-0.2.4-parcel
Commit: 7f837cb84ff5bb59dfd695ab00f2424dd0c21878
Parents: 397d305
Author: Aaron McCurry <amccurry@gmail.com>
Authored: Fri Jun 26 13:28:47 2015 -0400
Committer: Aaron McCurry <amccurry@gmail.com>
Committed: Fri Jun 26 13:28:47 2015 -0400

----------------------------------------------------------------------
 .../apache/blur/store/hdfs/HdfsIndexInput.java  |  3 +-
 .../blur/store/hdfs/SequentialReadControl.java  |  8 +++++-
 .../blur/store/BaseDirectoryTestSuite.java      | 29 ++++++++++++++++++++
 3 files changed, 38 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/7f837cb8/blur-store/src/main/java/org/apache/blur/store/hdfs/HdfsIndexInput.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/store/hdfs/HdfsIndexInput.java b/blur-store/src/main/java/org/apache/blur/store/hdfs/HdfsIndexInput.java
index 9f2f45e..6c4e939 100644
--- a/blur-store/src/main/java/org/apache/blur/store/hdfs/HdfsIndexInput.java
+++ b/blur-store/src/main/java/org/apache/blur/store/hdfs/HdfsIndexInput.java
@@ -78,11 +78,11 @@ public class HdfsIndexInput extends ReusedBufferedIndexInput {
         } else {
           LOG.debug("Current Pos [{0}] Prev Pos [{1}] Diff [{2}]", filePointer, _prevFilePointer,
filePointer
               - _prevFilePointer);
+          _sequentialReadControl.reset();
         }
       }
     }
     if (_sequentialReadControl.switchToSequentialRead()) {
-
       _sequentialReadControl.setEnabled(true);
       if (_sequentialInput == null) {
         Tracer trace = Trace.trace("filesystem - read - openForSequentialInput", Trace.param("file",
toString()),
@@ -131,6 +131,7 @@ public class HdfsIndexInput extends ReusedBufferedIndexInput {
     HdfsIndexInput clone = (HdfsIndexInput) super.clone();
     clone._sequentialInput = null;
     clone._sequentialReadControl = _sequentialReadControl.clone();
+    clone._sequentialReadControl.reset();
     return clone;
   }
 

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/7f837cb8/blur-store/src/main/java/org/apache/blur/store/hdfs/SequentialReadControl.java
----------------------------------------------------------------------
diff --git a/blur-store/src/main/java/org/apache/blur/store/hdfs/SequentialReadControl.java
b/blur-store/src/main/java/org/apache/blur/store/hdfs/SequentialReadControl.java
index dcf821e..ac72eb9 100644
--- a/blur-store/src/main/java/org/apache/blur/store/hdfs/SequentialReadControl.java
+++ b/blur-store/src/main/java/org/apache/blur/store/hdfs/SequentialReadControl.java
@@ -27,11 +27,12 @@ import org.apache.blur.utils.BlurConstants;
 public class SequentialReadControl implements Cloneable {
 
   private final BlurConfiguration _configuration;
+  private final boolean _sequentialReadAllowed = true;
 
   private long _sequentialReadThreshold;
   private long _sequentialReadSkipThreshold;
+
   private int _sequentialReadDetectorCounter = 0;
-  private boolean _sequentialReadAllowed = true;
   private boolean _sequentialRead;
 
   public SequentialReadControl(BlurConfiguration configuration) {
@@ -89,4 +90,9 @@ public class SequentialReadControl implements Cloneable {
     _sequentialRead = sequentialRead;
   }
 
+  public void reset() {
+    _sequentialRead = false;
+    _sequentialReadDetectorCounter = 0;
+  }
+
 }

http://git-wip-us.apache.org/repos/asf/incubator-blur/blob/7f837cb8/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 fde60b0..b1d8c8b 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
@@ -56,6 +56,8 @@ import org.junit.Before;
 import org.junit.Test;
 
 public abstract class BaseDirectoryTestSuite {
+  private static final String OUT_DAT = "out.dat";
+
   protected static final File TMPDIR = new File(System.getProperty("blur.tmp.dir",
       "./target/tmp/BaseDirectoryTestSuite"));
 
@@ -231,6 +233,33 @@ public abstract class BaseDirectoryTestSuite {
     long e = System.nanoTime();
     System.out.println("Total time [" + (e - s) / 1000000.0 + " ms]");
   }
+  
+  @Test
+  public void testLongReadAndClone() throws IOException {
+    FSDirectory control = FSDirectory.open(fileControl);
+    Directory dir = getControlDir(control, directory);
+    String name = writeFile(dir,10*1000*1000);
+    IndexInput input = dir.openInput(name, IOContext.DEFAULT);
+    readFile(input,1000*1000);
+    IndexInput clone = input.clone();
+    clone.readByte();
+    input.close();
+  }
+
+  private void readFile(IndexInput input, long length) throws IOException {
+    for (long l = 0;l<length;l++) {
+      input.readByte();
+    }
+  }
+
+  private String writeFile(Directory dir, long length) throws IOException {
+    IndexOutput output = dir.createOutput(OUT_DAT, IOContext.DEFAULT);
+    for (long l = 0;l<length;l++) {
+      output.writeByte((byte) 1);
+    }
+    output.close();
+    return OUT_DAT;
+  }
 
   private void addDocuments(IndexWriter writer, int numDocs) throws IOException {
     for (int i = 0; i < numDocs; i++) {


Mime
View raw message