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/02 22:54:43 UTC

svn commit: r1226556 - /lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/TransactionLog.java

Author: yonik
Date: Mon Jan  2 21:54:43 2012
New Revision: 1226556

URL: http://svn.apache.org/viewvc?rev=1226556&view=rev
Log:
tlog: align records at end of block when seeking with reverse reader

Modified:
    lucene/dev/branches/solrcloud/solr/core/src/java/org/apache/solr/update/TransactionLog.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=1226556&r1=1226555&r2=1226556&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 Mon Jan  2 21:54:43 2012
@@ -574,6 +574,8 @@ public class TransactionLog {
     public Object next() throws IOException {
       if (prevPos <= 0) return null;
 
+      long endOfThisRecord = prevPos;
+
       int thisLength = nextLength;
 
       long recordStart = prevPos - thisLength;  // back up to the beginning of the next record
@@ -581,7 +583,19 @@ public class TransactionLog {
 
       if (prevPos <= 0) return null;  // this record is the header
 
-      // TODO: nocommit: seek based on underlying buffer size of 8192
+      long bufferPos = fis.getBufferPos();
+      if (prevPos >= bufferPos) {
+        // nothing to do... we're within the current buffer
+      } else {
+        // Position buffer so that this record is at the end.
+        // For small records, this will cause subsequent calls to next() to be within the buffer.
+        long seekPos =  endOfThisRecord - 8192;
+        seekPos = Math.min(seekPos, prevPos); // seek to the start of the record if it's larger then the block size.
+        seekPos = Math.max(seekPos, 0);
+        fis.seek(seekPos);
+        fis.peek();  // cause buffer to be filled
+      }
+
       fis.seek(prevPos);
       nextLength = fis.readInt();     // this is the length of the *next* record (i.e. closer to the beginning)
 
@@ -648,6 +662,11 @@ class ChannelFastInputStream extends Fas
     }
   }
 
+  /** where is the start of the buffer relative to the while file */
+  public long getBufferPos() {
+    return readFromStream - end;
+  }
+
   @Override
   public void close() throws IOException {
     ch.close();