lucene-java-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mikemcc...@apache.org
Subject svn commit: r900387 - in /lucene/java/branches/flex_1458: CHANGES.txt src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexInput.java src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexOutput.java
Date Mon, 18 Jan 2010 13:17:53 GMT
Author: mikemccand
Date: Mon Jan 18 13:17:52 2010
New Revision: 900387

URL: http://svn.apache.org/viewvc?rev=900387&view=rev
Log:
LUCENE-2222: FixedIntBlockIndexInput was inserting block of 0s at the start

Modified:
    lucene/java/branches/flex_1458/CHANGES.txt
    lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexInput.java
    lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexOutput.java

Modified: lucene/java/branches/flex_1458/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/CHANGES.txt?rev=900387&r1=900386&r2=900387&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/CHANGES.txt (original)
+++ lucene/java/branches/flex_1458/CHANGES.txt Mon Jan 18 13:17:52 2010
@@ -1,6 +1,11 @@
 Lucene Change Log
 $Id$
 
+Bug fixes
+
+ * LUCENE-2222: FixedIntBlockIndexInput incorrectly read one block of
+   0s before the actual data.  (Renaud Delbru via Mike McCandless)
+
 ======================= Trunk (not yet released) =======================
 Changes in backwards compatibility policy
 

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexInput.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexInput.java?rev=900387&r1=900386&r2=900387&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexInput.java
(original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexInput.java
Mon Jan 18 13:17:52 2010
@@ -30,23 +30,26 @@
  *  from an IndexInput.  While this is a simple approach, a
  *  more performant approach would directly create an impl
  *  of IntIndexInput inside Directory.  Wrapping a generic
- *  IndexInput will likely cost performance.  */
+ *  IndexInput will likely cost performance.
+ *
+ * @lucene.experimental
+ */
 public abstract class FixedIntBlockIndexInput extends IntIndexInput {
 
   private IndexInput in;
   protected int blockSize;
 
-  protected void init(IndexInput in) throws IOException {
+  protected void init(final IndexInput in) throws IOException {
     this.in = in;
     blockSize = in.readVInt();
   }
 
   @Override
   public Reader reader() throws IOException {
-    int[] buffer = new int[blockSize];
-    IndexInput clone = (IndexInput) in.clone();
+    final int[] buffer = new int[blockSize];
+    final IndexInput clone = (IndexInput) in.clone();
     // nocommit -- awkward
-    return new Reader(clone, buffer, getBlockReader(clone, buffer));
+    return new Reader(clone, buffer, this.getBlockReader(clone, buffer));
   }
 
   @Override
@@ -80,15 +83,17 @@
 
     private final BulkReadResult result = new BulkReadResult();
 
-    public Reader(IndexInput in, int[] pending, BlockReader blockReader) {
+    public Reader(final IndexInput in, final int[] pending, final BlockReader blockReader)
+    throws IOException {
       this.in = in;
       this.pending = pending;
       this.blockSize = pending.length;
       result.buffer = pending;
       this.blockReader = blockReader;
+      upto = blockSize;
     }
 
-    void seek(long fp, int upto) {
+    void seek(final long fp, final int upto) {
       pendingFP = fp;
       pendingUpto = upto;
       seekPending = true;
@@ -109,7 +114,7 @@
 
     @Override
     public int next() throws IOException {
-      maybeSeek();
+      this.maybeSeek();
       if (upto == blockSize) {
         lastBlockFP = in.getFilePointer();
         blockReader.readBlock();
@@ -120,8 +125,8 @@
     }
 
     @Override
-    public BulkReadResult read(int[] buffer, int count) throws IOException {
-      maybeSeek();
+    public BulkReadResult read(final int[] buffer, final int count) throws IOException {
+      this.maybeSeek();
       if (upto == blockSize) {
         blockReader.readBlock();
         upto = 0;
@@ -149,7 +154,7 @@
     private int upto;
 
     @Override
-    public void read(IndexInput indexIn, boolean absolute) throws IOException {
+    public void read(final IndexInput indexIn, final boolean absolute) throws IOException
{
       if (absolute) {
         fp = indexIn.readVLong();
         upto = indexIn.readVInt();
@@ -168,17 +173,17 @@
     }
 
     @Override
-    public void seek(IntIndexInput.Reader other) throws IOException {
+    public void seek(final IntIndexInput.Reader other) throws IOException {
       ((Reader) other).seek(fp, upto);
     }
 
     @Override
-    public void set(IntIndexInput.Index other) {
-      Index idx = (Index) other;
+    public void set(final IntIndexInput.Index other) {
+      final Index idx = (Index) other;
       fp = idx.fp;
       upto = idx.upto;
     }
-    
+
     public class State extends IndexState {
       long fp;
       int upto;
@@ -187,7 +192,7 @@
     // nocommit handle with set and/or clone?
     @Override
     public IndexState captureState() {
-      State state = new State();
+      final State state = new State();
       state.fp = fp;
       state.upto = upto;
       return state;
@@ -195,11 +200,11 @@
 
     // nocommit handle with set and/or clone?
     @Override
-    public void setState(IndexState state) {
-      State iState = (State) state;
+    public void setState(final IndexState state) {
+      final State iState = (State) state;
       this.fp = iState.fp;
       this.upto = iState.upto;
-      
+
     }
   }
-}
\ No newline at end of file
+}

Modified: lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexOutput.java
URL: http://svn.apache.org/viewvc/lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexOutput.java?rev=900387&r1=900386&r2=900387&view=diff
==============================================================================
--- lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexOutput.java
(original)
+++ lucene/java/branches/flex_1458/src/java/org/apache/lucene/index/codecs/intblock/FixedIntBlockIndexOutput.java
Mon Jan 18 13:17:52 2010
@@ -26,6 +26,14 @@
 import org.apache.lucene.index.codecs.sep.IntIndexOutput;
 import org.apache.lucene.store.IndexOutput;
 
+/** Abstract base class that writes fixed-size blocks of ints
+ *  to an IndexOutput.  While this is a simple approach, a
+ *  more performant approach would directly create an impl
+ *  of IntIndexOutput inside Directory.  Wrapping a generic
+ *  IndexInput will likely cost performance.
+ *
+ * @lucene.experimental
+ */
 public abstract class FixedIntBlockIndexOutput extends IntIndexOutput {
 
   private IndexOutput out;
@@ -102,11 +110,12 @@
 
   @Override
   public void close() throws IOException {
-    // NOTE: entries in the block after current upto are
-    // invalid
-    // nocommit -- zero fill?
     try {
-      flushBlock(pending, out);
+      if (upto > 0) {
+      // NOTE: entries in the block after current upto are
+      // invalid
+        flushBlock(pending, out);
+      }
     } finally {
       out.close();
     }



Mime
View raw message