.../java/org/apache/hadoop/hbase/HConstants.java | 4 +++- .../java/org/apache/hadoop/hbase/KeyValue.java | 6 ++++++ .../hadoop/hbase/io/hfile/HFileReaderV2.java | 25 +++++++++++----------- 3 files changed, 21 insertions(+), 14 deletions(-) diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java index 40f67f3..00e214b 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java @@ -953,7 +953,9 @@ public final class HConstants { * The byte array represents for NO_NEXT_INDEXED_KEY; * The actual value is irrelevant because this is always compared by reference. */ - public static final byte [] NO_NEXT_INDEXED_KEY = Bytes.toBytes("NO_NEXT_INDEXED_KEY"); + public static final byte[] NO_NEXT_INDEXED_KEY = Bytes.toBytes("NO_NEXT_INDEXED_KEY"); + public static final Cell NO_NEXT_INDEXED_KV = new KeyValue(NO_NEXT_INDEXED_KEY); + /** delimiter used between portions of a region name */ public static final int DELIMITER = ','; public static final String HBASE_CONFIG_READ_ZOOKEEPER_CONFIG = diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java index 3ae324a..1b5f8c7 100644 --- a/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java +++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/KeyValue.java @@ -2627,6 +2627,12 @@ public class KeyValue implements Cell, HeapSize, Cloneable, SettableSequenceId, this.length = length; } + public void reset() { + this.b = null; + this.offset = 0; + this.length = 0; + } + @Override public byte[] getKey() { int keylength = getKeyLength(); diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java index 5460cbd..d407c29 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/HFileReaderV2.java @@ -25,7 +25,6 @@ import java.util.List; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; -import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.fs.Path; import org.apache.hadoop.hbase.Cell; @@ -33,6 +32,7 @@ import org.apache.hadoop.hbase.CellUtil; import org.apache.hadoop.hbase.HConstants; import org.apache.hadoop.hbase.KeyValue; import org.apache.hadoop.hbase.KeyValue.KVComparator; +import org.apache.hadoop.hbase.classification.InterfaceAudience; import org.apache.hadoop.hbase.fs.HFileSystem; import org.apache.hadoop.hbase.io.FSDataInputStreamWrapper; import org.apache.hadoop.hbase.io.encoding.DataBlockEncoder; @@ -549,7 +549,7 @@ public class HFileReaderV2 extends AbstractHFileReader { * * If the nextIndexedKey is null, it means the nextIndexedKey has not been loaded yet. */ - protected byte[] nextIndexedKey; + protected KeyValue.KeyOnlyKeyValue nextIndexedKV = new KeyValue.KeyOnlyKeyValue(); public AbstractScannerV2(HFileReaderV2 r, boolean cacheBlocks, final boolean pread, final boolean isCompaction) { @@ -558,7 +558,7 @@ public class HFileReaderV2 extends AbstractHFileReader { protected abstract ByteBuffer getFirstKeyInBlock(HFileBlock curBlock); - protected abstract int loadBlockAndSeekToKey(HFileBlock seekToBlock, byte[] nextIndexedKey, + protected abstract int loadBlockAndSeekToKey(HFileBlock seekToBlock, byte[] nextIndexedKV, boolean rewind, Cell key, boolean seekBefore) throws IOException; @Override @@ -589,19 +589,17 @@ public class HFileReaderV2 extends AbstractHFileReader { return compared; } else { // The comparison with no_next_index_key has to be checked - if (this.nextIndexedKey != null && - (this.nextIndexedKey == HConstants.NO_NEXT_INDEXED_KEY || reader - .getComparator() + if (this.nextIndexedKV.getLength() != 0 + && (this.nextIndexedKV == HConstants.NO_NEXT_INDEXED_KV || reader.getComparator() .compareOnlyKeyPortion(key, - new KeyValue.KeyOnlyKeyValue(nextIndexedKey, 0, - nextIndexedKey.length)) < 0)) { + nextIndexedKV) < 0)) { // The reader shall continue to scan the current data block instead // of querying the // block index as long as it knows the target key is strictly // smaller than // the next indexed key or the current data block is the last data // block. - return loadBlockAndSeekToKey(this.block, nextIndexedKey, false, key, false); + return loadBlockAndSeekToKey(this.block, nextIndexedKV.getKey(), false, key, false); } } } @@ -886,7 +884,7 @@ public class HFileReaderV2 extends AbstractHFileReader { } // Update the nextIndexedKey - this.nextIndexedKey = nextIndexedKey; + this.nextIndexedKV.setKey(nextIndexedKey, 0, nextIndexedKey.length); return blockSeek(key, seekBefore); } @@ -913,7 +911,7 @@ public class HFileReaderV2 extends AbstractHFileReader { blockFetches++; // Reset the next indexed key - this.nextIndexedKey = null; + this.nextIndexedKV.reset(); } protected void readKeyValueLen() { @@ -1130,7 +1128,7 @@ public class HFileReaderV2 extends AbstractHFileReader { blockFetches++; // Reset the next indexed key - this.nextIndexedKey = null; + this.nextIndexedKV.reset(); } private ByteBuffer getEncodedBuffer(HFileBlock newBlock) { @@ -1241,7 +1239,8 @@ public class HFileReaderV2 extends AbstractHFileReader { } else if (rewind) { seeker.rewind(); } - this.nextIndexedKey = nextIndexedKey; + // Update the nextIndexedKey + this.nextIndexedKV.setKey(nextIndexedKey, 0, nextIndexedKey.length); return seeker.seekToKeyInBlock(key, seekBefore); }