You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hbase.apache.org by ns...@apache.org on 2011/10/11 04:23:30 UTC
svn commit: r1181592 -
/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
Author: nspiegelberg
Date: Tue Oct 11 02:23:27 2011
New Revision: 1181592
URL: http://svn.apache.org/viewvc?rev=1181592&view=rev
Log:
Don't rewind on a reseek operation in HFile v2 reader
Summary: Not doing a rewind to the first key in block on a reseek operation in
HFile v2 reader, because reseek implies going forward in the file. This fixes a
performance regression introduced in HFile v2 code. This evaded my performance
tests because it only applies to a case of sequential reads with skipping keys,
but I only did random read and contiguous sequential read tests.
Test Plan: Run unit tests. Run HBaseTest.
Reviewed By: kannan
Reviewers: kannan, nspiegelberg
CC: hbase@lists, , kannan
Revert Plan: OK
Differential Revision: 275483
Modified:
hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
Modified: hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java?rev=1181592&r1=1181591&r2=1181592&view=diff
==============================================================================
--- hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java (original)
+++ hbase/branches/0.89/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java Tue Oct 11 02:23:27 2011
@@ -501,20 +501,41 @@ public class HFileReaderV2 extends Abstr
return seekTo(key, 0, key.length);
}
- @Override
- public int seekTo(byte[] key, int offset, int length) throws IOException {
+ /**
+ * An internal API function. Seek to the given key, optionally rewinding to
+ * the first key of the block before doing the seek.
+ *
+ * @param key key byte array
+ * @param offset key offset in the key byte array
+ * @param length key length
+ * @param rewind whether to rewind to the first key of the block before
+ * doing the seek. If this is false, we are assuming we never go
+ * back, otherwise the result is undefined.
+ * @return -1 if the key is earlier than the first key of the file,
+ * 0 if we are at the given key, and 1 if we are past the given key
+ * @throws IOException
+ */
+ private int seekTo(byte[] key, int offset, int length, boolean rewind)
+ throws IOException {
HFileBlock seekToBlock =
- ((HFileReaderV2) reader).getDataBlockIndexReader().seekToDataBlock(
- key, offset, length, block);
+ ((HFileReaderV2) reader).getDataBlockIndexReader().seekToDataBlock(
+ key, offset, length, block);
if (seekToBlock == null) {
// This happens if the key e.g. falls before the beginning of the file.
return -1;
}
- return loadBlockAndSeekToKey(seekToBlock, true, key, offset, length,
+ return loadBlockAndSeekToKey(seekToBlock, rewind, key, offset, length,
false);
}
@Override
+ public int seekTo(byte[] key, int offset, int length) throws IOException {
+ // Always rewind to the first key of the block, because the given key
+ // might be before or after the current key.
+ return seekTo(key, offset, length, true);
+ }
+
+ @Override
public int reseekTo(byte[] key) throws IOException {
return reseekTo(key, 0, key.length);
}
@@ -531,7 +552,10 @@ public class HFileReaderV2 extends Abstr
return compared;
}
}
- return seekTo(key, offset, length);
+
+ // Don't rewind on a reseek operation, because reseek implies that we are
+ // always going forward in the file.
+ return seekTo(key, offset, length, false);
}
private int loadBlockAndSeekToKey(HFileBlock seekToBlock, boolean rewind,