You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@lucene.apache.org by yo...@apache.org on 2012/01/03 21:51:08 UTC

svn commit: r1226943 - in /lucene/dev/branches/solrcloud/solr: core/src/java/org/apache/solr/update/TransactionLog.java solrj/src/java/org/apache/solr/common/util/FastInputStream.java

Author: yonik
Date: Tue Jan  3 20:51:07 2012
New Revision: 1226943

URL: http://svn.apache.org/viewvc?rev=1226943&view=rev
Log:
fix positioning bug in FastInputStream

Modified:
    lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/TransactionLog.java
    lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/util/FastInputStream.java

Modified: lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/TransactionLog.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/TransactionLog.java?rev=1226943&r1=1226942&r2=1226943&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/TransactionLog.java (original)
+++ lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/TransactionLog.java Tue Jan  3 20:51:07 2012
@@ -356,6 +356,7 @@ public class TransactionLog {
     synchronized (this) {
       try {
         long pos = fos.size();   // if we had flushed, this should be equal to channel.position()
+        log.error("COMMIT STARTING AT " + pos);   // nocommit
         if (pos == 0) {
           writeLogHeader(codec);
           pos = fos.size();
@@ -366,9 +367,12 @@ public class TransactionLog {
         codec.writeLong(cmd.getVersion());
         codec.writeStr(END_MESSAGE);  // ensure these bytes are (almost) last in the file
 
+        log.error("COMMIT STARTING AT " + pos + " ENDING AT " +fos.size());
+
         endRecord(pos);
         
         fos.flush();  // flush since this will be the last record in a log file
+        log.error("COMMIT END BACK POINTER RECORD AT" +fos.size());
 
         return pos;
       } catch (IOException e) {
@@ -602,9 +606,6 @@ public class TransactionLog {
       // TODO: optionally skip document data
       Object o = codec.readVal(fis);
 
-      if (fis.position() != prevPos + 4 + thisLength) {
-        System.out.println("set breakpoint here");
-      }
       assert fis.position() == prevPos + 4 + thisLength;  // this is only true if we read all the data
 
       return o;
@@ -637,7 +638,7 @@ class ChannelFastInputStream extends Fas
   private FileChannel ch;
 
   public ChannelFastInputStream(FileChannel ch, long chPosition) {
-    // super(null, new byte[10],0,0);    // a small buffer size for testing purposes     // nocommit!!! this currently causes failures!
+    // super(null, new byte[10],0,0);    // a small buffer size for testing purposes
     super(null);
     this.ch = ch;
     super.readFromStream = chPosition;
@@ -650,17 +651,20 @@ class ChannelFastInputStream extends Fas
     return ret;
   }
 
-  public void seek(long position) {
-    if (position >= readFromStream && position <= readFromStream + end) {
+  public void seek(long position) throws IOException {
+    if (position <= readFromStream && position >= getBufferPos()) {
       // seek within buffer
-      pos = (int)(position - readFromStream);
+      pos = (int)(position - getBufferPos());
     } else {
+      // long currSize = ch.size();   // not needed - underlying read should handle (unless read never done)
+      // if (position > currSize) throw new EOFException("Read past EOF: seeking to " + position + " on file of size " + currSize + " file=" + ch);
       readFromStream = position;
       end = pos = 0;
     }
+    assert position() == position;
   }
 
-  /** where is the start of the buffer relative to the while file */
+  /** where is the start of the buffer relative to the whole file */
   public long getBufferPos() {
     return readFromStream - end;
   }
@@ -673,5 +677,10 @@ class ChannelFastInputStream extends Fas
   public void close() throws IOException {
     ch.close();
   }
+  
+  @Override
+  public String toString() {
+    return "readFromStream="+readFromStream +" pos="+pos +" end="+end + " bufferPos="+getBufferPos() + " position="+position() ;
+  }
 }
 

Modified: lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/util/FastInputStream.java
URL: http://svn.apache.org/viewvc/lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/util/FastInputStream.java?rev=1226943&r1=1226942&r2=1226943&view=diff
==============================================================================
--- lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/util/FastInputStream.java (original)
+++ lucene/dev/branches/solrcloud/solr/solrj/src/java/org/apache/solr/common/util/FastInputStream.java Tue Jan  3 20:51:07 2012
@@ -95,11 +95,12 @@ public class FastInputStream extends Inp
 
   @Override
   public int read(byte b[], int off, int len) throws IOException {
-    int r=0;  // number of bytes read
+    int r=0;  // number of bytes we have read
+
     // first read from our buffer;
     if (end-pos > 0) {
       r = Math.min(end-pos, len);
-      System.arraycopy(buf, pos, b, off, r);      
+      System.arraycopy(buf, pos, b, off, r);
       pos += r;
     }
 
@@ -108,15 +109,19 @@ public class FastInputStream extends Inp
     // amount left to read is >= buffer size
     if (len-r >= buf.length) {
       int ret = readWrappedStream(b, off+r, len-r);
-      if (ret > 0) readFromStream += end;
-      if (ret==-1) return r==0 ? -1 : r;
-      r += ret;
-      return r;
+      if (ret >= 0) {
+        readFromStream += ret;
+        r += ret;
+        return r;
+      } else {
+        // negative return code
+        return r > 0 ? r : -1;
+      }
     }
 
     refill();
 
-    // first read from our buffer;
+    // read rest from our buffer
     if (end-pos > 0) {
       int toRead = Math.min(end-pos, len-r);
       System.arraycopy(buf, pos, b, off+r, toRead);
@@ -124,7 +129,7 @@ public class FastInputStream extends Inp
       r += toRead;
       return r;
     }
-    
+
     return r > 0 ? r : -1;
   }