hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject [29/51] [partial] hbase-site git commit: Published site at 07b623670647686084f8f5fd2038e2bafcfdac54.
Date Wed, 30 Dec 2015 22:15:50 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/e5c3dcd1/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileReaderImpl.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileReaderImpl.html b/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileReaderImpl.html
index 5be9775..128a211 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileReaderImpl.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileReaderImpl.html
@@ -994,902 +994,908 @@
 <span class="sourceLineNo">986</span>        return new KeyValue.KeyOnlyKeyValue(keyBuf.array(), keyBuf.arrayOffset()<a name="line.986"></a>
 <span class="sourceLineNo">987</span>            + keyPair.getSecond(), currKeyLen);<a name="line.987"></a>
 <span class="sourceLineNo">988</span>      } else {<a name="line.988"></a>
-<span class="sourceLineNo">989</span>        return new ByteBufferedKeyOnlyKeyValue(keyBuf, keyPair.getSecond(), currKeyLen);<a name="line.989"></a>
-<span class="sourceLineNo">990</span>      }<a name="line.990"></a>
-<span class="sourceLineNo">991</span>    }<a name="line.991"></a>
-<span class="sourceLineNo">992</span><a name="line.992"></a>
-<span class="sourceLineNo">993</span>    private static class ShareableMemoryKeyValue extends SizeCachedKeyValue implements<a name="line.993"></a>
-<span class="sourceLineNo">994</span>        ShareableMemory {<a name="line.994"></a>
-<span class="sourceLineNo">995</span>      public ShareableMemoryKeyValue(byte[] bytes, int offset, int length, long seqId) {<a name="line.995"></a>
-<span class="sourceLineNo">996</span>        super(bytes, offset, length, seqId);<a name="line.996"></a>
-<span class="sourceLineNo">997</span>      }<a name="line.997"></a>
+<span class="sourceLineNo">989</span>        // Better to do a copy here instead of holding on to this BB so that<a name="line.989"></a>
+<span class="sourceLineNo">990</span>        // we could release the blocks referring to this key. This key is specifically used <a name="line.990"></a>
+<span class="sourceLineNo">991</span>        // in HalfStoreFileReader to get the firstkey and lastkey by creating a new scanner<a name="line.991"></a>
+<span class="sourceLineNo">992</span>        // every time. So holding onto the BB (incase of DBB) is not advised here.<a name="line.992"></a>
+<span class="sourceLineNo">993</span>        byte[] key = new byte[currKeyLen];<a name="line.993"></a>
+<span class="sourceLineNo">994</span>        ByteBufferUtils.copyFromBufferToArray(key, keyBuf, keyPair.getSecond(), 0, currKeyLen);<a name="line.994"></a>
+<span class="sourceLineNo">995</span>        return new KeyValue.KeyOnlyKeyValue(key, 0, currKeyLen);<a name="line.995"></a>
+<span class="sourceLineNo">996</span>      }<a name="line.996"></a>
+<span class="sourceLineNo">997</span>    }<a name="line.997"></a>
 <span class="sourceLineNo">998</span><a name="line.998"></a>
-<span class="sourceLineNo">999</span>      @Override<a name="line.999"></a>
-<span class="sourceLineNo">1000</span>      public Cell cloneToCell() {<a name="line.1000"></a>
-<span class="sourceLineNo">1001</span>        byte[] copy = Bytes.copy(this.bytes, this.offset, this.length);<a name="line.1001"></a>
-<span class="sourceLineNo">1002</span>        return new SizeCachedKeyValue(copy, 0, copy.length, getSequenceId());<a name="line.1002"></a>
+<span class="sourceLineNo">999</span>    private static class ShareableMemoryKeyValue extends SizeCachedKeyValue implements<a name="line.999"></a>
+<span class="sourceLineNo">1000</span>        ShareableMemory {<a name="line.1000"></a>
+<span class="sourceLineNo">1001</span>      public ShareableMemoryKeyValue(byte[] bytes, int offset, int length, long seqId) {<a name="line.1001"></a>
+<span class="sourceLineNo">1002</span>        super(bytes, offset, length, seqId);<a name="line.1002"></a>
 <span class="sourceLineNo">1003</span>      }<a name="line.1003"></a>
-<span class="sourceLineNo">1004</span>    }<a name="line.1004"></a>
-<span class="sourceLineNo">1005</span><a name="line.1005"></a>
-<span class="sourceLineNo">1006</span>    private static class ShareableMemoryNoTagsKeyValue extends SizeCachedNoTagsKeyValue implements<a name="line.1006"></a>
-<span class="sourceLineNo">1007</span>        ShareableMemory {<a name="line.1007"></a>
-<span class="sourceLineNo">1008</span>      public ShareableMemoryNoTagsKeyValue(byte[] bytes, int offset, int length, long seqId) {<a name="line.1008"></a>
-<span class="sourceLineNo">1009</span>        super(bytes, offset, length, seqId);<a name="line.1009"></a>
-<span class="sourceLineNo">1010</span>      }<a name="line.1010"></a>
+<span class="sourceLineNo">1004</span><a name="line.1004"></a>
+<span class="sourceLineNo">1005</span>      @Override<a name="line.1005"></a>
+<span class="sourceLineNo">1006</span>      public Cell cloneToCell() {<a name="line.1006"></a>
+<span class="sourceLineNo">1007</span>        byte[] copy = Bytes.copy(this.bytes, this.offset, this.length);<a name="line.1007"></a>
+<span class="sourceLineNo">1008</span>        return new SizeCachedKeyValue(copy, 0, copy.length, getSequenceId());<a name="line.1008"></a>
+<span class="sourceLineNo">1009</span>      }<a name="line.1009"></a>
+<span class="sourceLineNo">1010</span>    }<a name="line.1010"></a>
 <span class="sourceLineNo">1011</span><a name="line.1011"></a>
-<span class="sourceLineNo">1012</span>      @Override<a name="line.1012"></a>
-<span class="sourceLineNo">1013</span>      public Cell cloneToCell() {<a name="line.1013"></a>
-<span class="sourceLineNo">1014</span>        byte[] copy = Bytes.copy(this.bytes, this.offset, this.length);<a name="line.1014"></a>
-<span class="sourceLineNo">1015</span>        return new SizeCachedNoTagsKeyValue(copy, 0, copy.length, getSequenceId());<a name="line.1015"></a>
+<span class="sourceLineNo">1012</span>    private static class ShareableMemoryNoTagsKeyValue extends SizeCachedNoTagsKeyValue implements<a name="line.1012"></a>
+<span class="sourceLineNo">1013</span>        ShareableMemory {<a name="line.1013"></a>
+<span class="sourceLineNo">1014</span>      public ShareableMemoryNoTagsKeyValue(byte[] bytes, int offset, int length, long seqId) {<a name="line.1014"></a>
+<span class="sourceLineNo">1015</span>        super(bytes, offset, length, seqId);<a name="line.1015"></a>
 <span class="sourceLineNo">1016</span>      }<a name="line.1016"></a>
-<span class="sourceLineNo">1017</span>    }<a name="line.1017"></a>
-<span class="sourceLineNo">1018</span><a name="line.1018"></a>
-<span class="sourceLineNo">1019</span>    private static class ShareableMemoryOffheapKeyValue extends OffheapKeyValue implements<a name="line.1019"></a>
-<span class="sourceLineNo">1020</span>        ShareableMemory {<a name="line.1020"></a>
-<span class="sourceLineNo">1021</span>      public ShareableMemoryOffheapKeyValue(ByteBuffer buf, int offset, int length,<a name="line.1021"></a>
-<span class="sourceLineNo">1022</span>          boolean hasTags, long seqId) {<a name="line.1022"></a>
-<span class="sourceLineNo">1023</span>        super(buf, offset, length, hasTags, seqId);<a name="line.1023"></a>
-<span class="sourceLineNo">1024</span>      }<a name="line.1024"></a>
-<span class="sourceLineNo">1025</span><a name="line.1025"></a>
-<span class="sourceLineNo">1026</span>      @Override<a name="line.1026"></a>
-<span class="sourceLineNo">1027</span>      public Cell cloneToCell() {<a name="line.1027"></a>
-<span class="sourceLineNo">1028</span>        byte[] copy = new byte[this.length];<a name="line.1028"></a>
-<span class="sourceLineNo">1029</span>        ByteBufferUtils.copyFromBufferToArray(copy, this.buf, this.offset, 0, this.length);<a name="line.1029"></a>
-<span class="sourceLineNo">1030</span>        return new SizeCachedKeyValue(copy, 0, copy.length, getSequenceId());<a name="line.1030"></a>
-<span class="sourceLineNo">1031</span>      }<a name="line.1031"></a>
-<span class="sourceLineNo">1032</span>    }<a name="line.1032"></a>
-<span class="sourceLineNo">1033</span><a name="line.1033"></a>
-<span class="sourceLineNo">1034</span>    @Override<a name="line.1034"></a>
-<span class="sourceLineNo">1035</span>    public ByteBuffer getValue() {<a name="line.1035"></a>
-<span class="sourceLineNo">1036</span>      assertSeeked();<a name="line.1036"></a>
-<span class="sourceLineNo">1037</span>      // Okie to create new Pair. Not used in hot path<a name="line.1037"></a>
-<span class="sourceLineNo">1038</span>      ObjectIntPair&lt;ByteBuffer&gt; valuePair = new ObjectIntPair&lt;ByteBuffer&gt;();<a name="line.1038"></a>
-<span class="sourceLineNo">1039</span>      this.blockBuffer.asSubByteBuffer(blockBuffer.position() + KEY_VALUE_LEN_SIZE + currKeyLen,<a name="line.1039"></a>
-<span class="sourceLineNo">1040</span>        currValueLen, valuePair);<a name="line.1040"></a>
-<span class="sourceLineNo">1041</span>      ByteBuffer valBuf = valuePair.getFirst().duplicate();<a name="line.1041"></a>
-<span class="sourceLineNo">1042</span>      valBuf.position(valuePair.getSecond());<a name="line.1042"></a>
-<span class="sourceLineNo">1043</span>      valBuf.limit(currValueLen + valuePair.getSecond());<a name="line.1043"></a>
-<span class="sourceLineNo">1044</span>      return valBuf.slice();<a name="line.1044"></a>
-<span class="sourceLineNo">1045</span>    }<a name="line.1045"></a>
-<span class="sourceLineNo">1046</span><a name="line.1046"></a>
-<span class="sourceLineNo">1047</span>    protected void setNonSeekedState() {<a name="line.1047"></a>
-<span class="sourceLineNo">1048</span>      reset();<a name="line.1048"></a>
-<span class="sourceLineNo">1049</span>      blockBuffer = null;<a name="line.1049"></a>
-<span class="sourceLineNo">1050</span>      currKeyLen = 0;<a name="line.1050"></a>
-<span class="sourceLineNo">1051</span>      currValueLen = 0;<a name="line.1051"></a>
-<span class="sourceLineNo">1052</span>      currMemstoreTS = 0;<a name="line.1052"></a>
-<span class="sourceLineNo">1053</span>      currMemstoreTSLen = 0;<a name="line.1053"></a>
-<span class="sourceLineNo">1054</span>      currTagsLen = 0;<a name="line.1054"></a>
-<span class="sourceLineNo">1055</span>    }<a name="line.1055"></a>
-<span class="sourceLineNo">1056</span><a name="line.1056"></a>
-<span class="sourceLineNo">1057</span>    /**<a name="line.1057"></a>
-<span class="sourceLineNo">1058</span>     * Set the position on current backing blockBuffer.<a name="line.1058"></a>
-<span class="sourceLineNo">1059</span>     */<a name="line.1059"></a>
-<span class="sourceLineNo">1060</span>    private void positionThisBlockBuffer() {<a name="line.1060"></a>
-<span class="sourceLineNo">1061</span>      try {<a name="line.1061"></a>
-<span class="sourceLineNo">1062</span>        blockBuffer.skip(getCurCellSize());<a name="line.1062"></a>
-<span class="sourceLineNo">1063</span>      } catch (IllegalArgumentException e) {<a name="line.1063"></a>
-<span class="sourceLineNo">1064</span>        LOG.error("Current pos = " + blockBuffer.position()<a name="line.1064"></a>
-<span class="sourceLineNo">1065</span>            + "; currKeyLen = " + currKeyLen + "; currValLen = "<a name="line.1065"></a>
-<span class="sourceLineNo">1066</span>            + currValueLen + "; block limit = " + blockBuffer.limit()<a name="line.1066"></a>
-<span class="sourceLineNo">1067</span>            + "; HFile name = " + reader.getName()<a name="line.1067"></a>
-<span class="sourceLineNo">1068</span>            + "; currBlock currBlockOffset = " + this.curBlock.getOffset());<a name="line.1068"></a>
-<span class="sourceLineNo">1069</span>        throw e;<a name="line.1069"></a>
-<span class="sourceLineNo">1070</span>      }<a name="line.1070"></a>
-<span class="sourceLineNo">1071</span>    }<a name="line.1071"></a>
-<span class="sourceLineNo">1072</span><a name="line.1072"></a>
-<span class="sourceLineNo">1073</span>    /**<a name="line.1073"></a>
-<span class="sourceLineNo">1074</span>     * Set our selves up for the next 'next' invocation, set up next block.<a name="line.1074"></a>
-<span class="sourceLineNo">1075</span>     * @return True is more to read else false if at the end.<a name="line.1075"></a>
-<span class="sourceLineNo">1076</span>     * @throws IOException<a name="line.1076"></a>
-<span class="sourceLineNo">1077</span>     */<a name="line.1077"></a>
-<span class="sourceLineNo">1078</span>    private boolean positionForNextBlock() throws IOException {<a name="line.1078"></a>
-<span class="sourceLineNo">1079</span>      // Methods are small so they get inlined because they are 'hot'.<a name="line.1079"></a>
-<span class="sourceLineNo">1080</span>      long lastDataBlockOffset = reader.getTrailer().getLastDataBlockOffset();<a name="line.1080"></a>
-<span class="sourceLineNo">1081</span>      if (this.curBlock.getOffset() &gt;= lastDataBlockOffset) {<a name="line.1081"></a>
-<span class="sourceLineNo">1082</span>        setNonSeekedState();<a name="line.1082"></a>
-<span class="sourceLineNo">1083</span>        return false;<a name="line.1083"></a>
-<span class="sourceLineNo">1084</span>      }<a name="line.1084"></a>
-<span class="sourceLineNo">1085</span>      return isNextBlock();<a name="line.1085"></a>
-<span class="sourceLineNo">1086</span>    }<a name="line.1086"></a>
-<span class="sourceLineNo">1087</span><a name="line.1087"></a>
-<span class="sourceLineNo">1088</span><a name="line.1088"></a>
-<span class="sourceLineNo">1089</span>    private boolean isNextBlock() throws IOException {<a name="line.1089"></a>
-<span class="sourceLineNo">1090</span>      // Methods are small so they get inlined because they are 'hot'.<a name="line.1090"></a>
-<span class="sourceLineNo">1091</span>      HFileBlock nextBlock = readNextDataBlock();<a name="line.1091"></a>
-<span class="sourceLineNo">1092</span>      if (nextBlock == null) {<a name="line.1092"></a>
-<span class="sourceLineNo">1093</span>        setNonSeekedState();<a name="line.1093"></a>
-<span class="sourceLineNo">1094</span>        return false;<a name="line.1094"></a>
-<span class="sourceLineNo">1095</span>      }<a name="line.1095"></a>
-<span class="sourceLineNo">1096</span>      updateCurrentBlock(nextBlock);<a name="line.1096"></a>
-<span class="sourceLineNo">1097</span>      return true;<a name="line.1097"></a>
-<span class="sourceLineNo">1098</span>    }<a name="line.1098"></a>
-<span class="sourceLineNo">1099</span><a name="line.1099"></a>
-<span class="sourceLineNo">1100</span>    private final boolean _next() throws IOException {<a name="line.1100"></a>
-<span class="sourceLineNo">1101</span>      // Small method so can be inlined. It is a hot one.<a name="line.1101"></a>
-<span class="sourceLineNo">1102</span>      if (blockBuffer.remaining() &lt;= 0) {<a name="line.1102"></a>
-<span class="sourceLineNo">1103</span>        return positionForNextBlock();<a name="line.1103"></a>
-<span class="sourceLineNo">1104</span>      }<a name="line.1104"></a>
+<span class="sourceLineNo">1017</span><a name="line.1017"></a>
+<span class="sourceLineNo">1018</span>      @Override<a name="line.1018"></a>
+<span class="sourceLineNo">1019</span>      public Cell cloneToCell() {<a name="line.1019"></a>
+<span class="sourceLineNo">1020</span>        byte[] copy = Bytes.copy(this.bytes, this.offset, this.length);<a name="line.1020"></a>
+<span class="sourceLineNo">1021</span>        return new SizeCachedNoTagsKeyValue(copy, 0, copy.length, getSequenceId());<a name="line.1021"></a>
+<span class="sourceLineNo">1022</span>      }<a name="line.1022"></a>
+<span class="sourceLineNo">1023</span>    }<a name="line.1023"></a>
+<span class="sourceLineNo">1024</span><a name="line.1024"></a>
+<span class="sourceLineNo">1025</span>    private static class ShareableMemoryOffheapKeyValue extends OffheapKeyValue implements<a name="line.1025"></a>
+<span class="sourceLineNo">1026</span>        ShareableMemory {<a name="line.1026"></a>
+<span class="sourceLineNo">1027</span>      public ShareableMemoryOffheapKeyValue(ByteBuffer buf, int offset, int length,<a name="line.1027"></a>
+<span class="sourceLineNo">1028</span>          boolean hasTags, long seqId) {<a name="line.1028"></a>
+<span class="sourceLineNo">1029</span>        super(buf, offset, length, hasTags, seqId);<a name="line.1029"></a>
+<span class="sourceLineNo">1030</span>      }<a name="line.1030"></a>
+<span class="sourceLineNo">1031</span><a name="line.1031"></a>
+<span class="sourceLineNo">1032</span>      @Override<a name="line.1032"></a>
+<span class="sourceLineNo">1033</span>      public Cell cloneToCell() {<a name="line.1033"></a>
+<span class="sourceLineNo">1034</span>        byte[] copy = new byte[this.length];<a name="line.1034"></a>
+<span class="sourceLineNo">1035</span>        ByteBufferUtils.copyFromBufferToArray(copy, this.buf, this.offset, 0, this.length);<a name="line.1035"></a>
+<span class="sourceLineNo">1036</span>        return new SizeCachedKeyValue(copy, 0, copy.length, getSequenceId());<a name="line.1036"></a>
+<span class="sourceLineNo">1037</span>      }<a name="line.1037"></a>
+<span class="sourceLineNo">1038</span>    }<a name="line.1038"></a>
+<span class="sourceLineNo">1039</span><a name="line.1039"></a>
+<span class="sourceLineNo">1040</span>    @Override<a name="line.1040"></a>
+<span class="sourceLineNo">1041</span>    public ByteBuffer getValue() {<a name="line.1041"></a>
+<span class="sourceLineNo">1042</span>      assertSeeked();<a name="line.1042"></a>
+<span class="sourceLineNo">1043</span>      // Okie to create new Pair. Not used in hot path<a name="line.1043"></a>
+<span class="sourceLineNo">1044</span>      ObjectIntPair&lt;ByteBuffer&gt; valuePair = new ObjectIntPair&lt;ByteBuffer&gt;();<a name="line.1044"></a>
+<span class="sourceLineNo">1045</span>      this.blockBuffer.asSubByteBuffer(blockBuffer.position() + KEY_VALUE_LEN_SIZE + currKeyLen,<a name="line.1045"></a>
+<span class="sourceLineNo">1046</span>        currValueLen, valuePair);<a name="line.1046"></a>
+<span class="sourceLineNo">1047</span>      ByteBuffer valBuf = valuePair.getFirst().duplicate();<a name="line.1047"></a>
+<span class="sourceLineNo">1048</span>      valBuf.position(valuePair.getSecond());<a name="line.1048"></a>
+<span class="sourceLineNo">1049</span>      valBuf.limit(currValueLen + valuePair.getSecond());<a name="line.1049"></a>
+<span class="sourceLineNo">1050</span>      return valBuf.slice();<a name="line.1050"></a>
+<span class="sourceLineNo">1051</span>    }<a name="line.1051"></a>
+<span class="sourceLineNo">1052</span><a name="line.1052"></a>
+<span class="sourceLineNo">1053</span>    protected void setNonSeekedState() {<a name="line.1053"></a>
+<span class="sourceLineNo">1054</span>      reset();<a name="line.1054"></a>
+<span class="sourceLineNo">1055</span>      blockBuffer = null;<a name="line.1055"></a>
+<span class="sourceLineNo">1056</span>      currKeyLen = 0;<a name="line.1056"></a>
+<span class="sourceLineNo">1057</span>      currValueLen = 0;<a name="line.1057"></a>
+<span class="sourceLineNo">1058</span>      currMemstoreTS = 0;<a name="line.1058"></a>
+<span class="sourceLineNo">1059</span>      currMemstoreTSLen = 0;<a name="line.1059"></a>
+<span class="sourceLineNo">1060</span>      currTagsLen = 0;<a name="line.1060"></a>
+<span class="sourceLineNo">1061</span>    }<a name="line.1061"></a>
+<span class="sourceLineNo">1062</span><a name="line.1062"></a>
+<span class="sourceLineNo">1063</span>    /**<a name="line.1063"></a>
+<span class="sourceLineNo">1064</span>     * Set the position on current backing blockBuffer.<a name="line.1064"></a>
+<span class="sourceLineNo">1065</span>     */<a name="line.1065"></a>
+<span class="sourceLineNo">1066</span>    private void positionThisBlockBuffer() {<a name="line.1066"></a>
+<span class="sourceLineNo">1067</span>      try {<a name="line.1067"></a>
+<span class="sourceLineNo">1068</span>        blockBuffer.skip(getCurCellSize());<a name="line.1068"></a>
+<span class="sourceLineNo">1069</span>      } catch (IllegalArgumentException e) {<a name="line.1069"></a>
+<span class="sourceLineNo">1070</span>        LOG.error("Current pos = " + blockBuffer.position()<a name="line.1070"></a>
+<span class="sourceLineNo">1071</span>            + "; currKeyLen = " + currKeyLen + "; currValLen = "<a name="line.1071"></a>
+<span class="sourceLineNo">1072</span>            + currValueLen + "; block limit = " + blockBuffer.limit()<a name="line.1072"></a>
+<span class="sourceLineNo">1073</span>            + "; HFile name = " + reader.getName()<a name="line.1073"></a>
+<span class="sourceLineNo">1074</span>            + "; currBlock currBlockOffset = " + this.curBlock.getOffset());<a name="line.1074"></a>
+<span class="sourceLineNo">1075</span>        throw e;<a name="line.1075"></a>
+<span class="sourceLineNo">1076</span>      }<a name="line.1076"></a>
+<span class="sourceLineNo">1077</span>    }<a name="line.1077"></a>
+<span class="sourceLineNo">1078</span><a name="line.1078"></a>
+<span class="sourceLineNo">1079</span>    /**<a name="line.1079"></a>
+<span class="sourceLineNo">1080</span>     * Set our selves up for the next 'next' invocation, set up next block.<a name="line.1080"></a>
+<span class="sourceLineNo">1081</span>     * @return True is more to read else false if at the end.<a name="line.1081"></a>
+<span class="sourceLineNo">1082</span>     * @throws IOException<a name="line.1082"></a>
+<span class="sourceLineNo">1083</span>     */<a name="line.1083"></a>
+<span class="sourceLineNo">1084</span>    private boolean positionForNextBlock() throws IOException {<a name="line.1084"></a>
+<span class="sourceLineNo">1085</span>      // Methods are small so they get inlined because they are 'hot'.<a name="line.1085"></a>
+<span class="sourceLineNo">1086</span>      long lastDataBlockOffset = reader.getTrailer().getLastDataBlockOffset();<a name="line.1086"></a>
+<span class="sourceLineNo">1087</span>      if (this.curBlock.getOffset() &gt;= lastDataBlockOffset) {<a name="line.1087"></a>
+<span class="sourceLineNo">1088</span>        setNonSeekedState();<a name="line.1088"></a>
+<span class="sourceLineNo">1089</span>        return false;<a name="line.1089"></a>
+<span class="sourceLineNo">1090</span>      }<a name="line.1090"></a>
+<span class="sourceLineNo">1091</span>      return isNextBlock();<a name="line.1091"></a>
+<span class="sourceLineNo">1092</span>    }<a name="line.1092"></a>
+<span class="sourceLineNo">1093</span><a name="line.1093"></a>
+<span class="sourceLineNo">1094</span><a name="line.1094"></a>
+<span class="sourceLineNo">1095</span>    private boolean isNextBlock() throws IOException {<a name="line.1095"></a>
+<span class="sourceLineNo">1096</span>      // Methods are small so they get inlined because they are 'hot'.<a name="line.1096"></a>
+<span class="sourceLineNo">1097</span>      HFileBlock nextBlock = readNextDataBlock();<a name="line.1097"></a>
+<span class="sourceLineNo">1098</span>      if (nextBlock == null) {<a name="line.1098"></a>
+<span class="sourceLineNo">1099</span>        setNonSeekedState();<a name="line.1099"></a>
+<span class="sourceLineNo">1100</span>        return false;<a name="line.1100"></a>
+<span class="sourceLineNo">1101</span>      }<a name="line.1101"></a>
+<span class="sourceLineNo">1102</span>      updateCurrentBlock(nextBlock);<a name="line.1102"></a>
+<span class="sourceLineNo">1103</span>      return true;<a name="line.1103"></a>
+<span class="sourceLineNo">1104</span>    }<a name="line.1104"></a>
 <span class="sourceLineNo">1105</span><a name="line.1105"></a>
-<span class="sourceLineNo">1106</span>      // We are still in the same block.<a name="line.1106"></a>
-<span class="sourceLineNo">1107</span>      readKeyValueLen();<a name="line.1107"></a>
-<span class="sourceLineNo">1108</span>      return true;<a name="line.1108"></a>
-<span class="sourceLineNo">1109</span>    }<a name="line.1109"></a>
-<span class="sourceLineNo">1110</span><a name="line.1110"></a>
-<span class="sourceLineNo">1111</span>    /**<a name="line.1111"></a>
-<span class="sourceLineNo">1112</span>     * Go to the next key/value in the block section. Loads the next block if<a name="line.1112"></a>
-<span class="sourceLineNo">1113</span>     * necessary. If successful, {@link #getKey()} and {@link #getValue()} can<a name="line.1113"></a>
-<span class="sourceLineNo">1114</span>     * be called.<a name="line.1114"></a>
-<span class="sourceLineNo">1115</span>     *<a name="line.1115"></a>
-<span class="sourceLineNo">1116</span>     * @return true if successfully navigated to the next key/value<a name="line.1116"></a>
-<span class="sourceLineNo">1117</span>     */<a name="line.1117"></a>
-<span class="sourceLineNo">1118</span>    @Override<a name="line.1118"></a>
-<span class="sourceLineNo">1119</span>    public boolean next() throws IOException {<a name="line.1119"></a>
-<span class="sourceLineNo">1120</span>      // This is a hot method so extreme measures taken to ensure it is small and inlineable.<a name="line.1120"></a>
-<span class="sourceLineNo">1121</span>      // Checked by setting: -XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining -XX:+PrintCompilation<a name="line.1121"></a>
-<span class="sourceLineNo">1122</span>      assertSeeked();<a name="line.1122"></a>
-<span class="sourceLineNo">1123</span>      positionThisBlockBuffer();<a name="line.1123"></a>
-<span class="sourceLineNo">1124</span>      return _next();<a name="line.1124"></a>
-<span class="sourceLineNo">1125</span>    }<a name="line.1125"></a>
-<span class="sourceLineNo">1126</span><a name="line.1126"></a>
-<span class="sourceLineNo">1127</span>    /**<a name="line.1127"></a>
-<span class="sourceLineNo">1128</span>     * Positions this scanner at the start of the file.<a name="line.1128"></a>
-<span class="sourceLineNo">1129</span>     *<a name="line.1129"></a>
-<span class="sourceLineNo">1130</span>     * @return false if empty file; i.e. a call to next would return false and<a name="line.1130"></a>
-<span class="sourceLineNo">1131</span>     *         the current key and value are undefined.<a name="line.1131"></a>
-<span class="sourceLineNo">1132</span>     * @throws IOException<a name="line.1132"></a>
-<span class="sourceLineNo">1133</span>     */<a name="line.1133"></a>
-<span class="sourceLineNo">1134</span>    @Override<a name="line.1134"></a>
-<span class="sourceLineNo">1135</span>    public boolean seekTo() throws IOException {<a name="line.1135"></a>
-<span class="sourceLineNo">1136</span>      if (reader == null) {<a name="line.1136"></a>
-<span class="sourceLineNo">1137</span>        return false;<a name="line.1137"></a>
-<span class="sourceLineNo">1138</span>      }<a name="line.1138"></a>
-<span class="sourceLineNo">1139</span><a name="line.1139"></a>
-<span class="sourceLineNo">1140</span>      if (reader.getTrailer().getEntryCount() == 0) {<a name="line.1140"></a>
-<span class="sourceLineNo">1141</span>        // No data blocks.<a name="line.1141"></a>
-<span class="sourceLineNo">1142</span>        return false;<a name="line.1142"></a>
-<span class="sourceLineNo">1143</span>      }<a name="line.1143"></a>
-<span class="sourceLineNo">1144</span><a name="line.1144"></a>
-<span class="sourceLineNo">1145</span>      long firstDataBlockOffset = reader.getTrailer().getFirstDataBlockOffset();<a name="line.1145"></a>
-<span class="sourceLineNo">1146</span>      if (curBlock != null<a name="line.1146"></a>
-<span class="sourceLineNo">1147</span>          &amp;&amp; curBlock.getOffset() == firstDataBlockOffset) {<a name="line.1147"></a>
-<span class="sourceLineNo">1148</span>        return processFirstDataBlock();<a name="line.1148"></a>
+<span class="sourceLineNo">1106</span>    private final boolean _next() throws IOException {<a name="line.1106"></a>
+<span class="sourceLineNo">1107</span>      // Small method so can be inlined. It is a hot one.<a name="line.1107"></a>
+<span class="sourceLineNo">1108</span>      if (blockBuffer.remaining() &lt;= 0) {<a name="line.1108"></a>
+<span class="sourceLineNo">1109</span>        return positionForNextBlock();<a name="line.1109"></a>
+<span class="sourceLineNo">1110</span>      }<a name="line.1110"></a>
+<span class="sourceLineNo">1111</span><a name="line.1111"></a>
+<span class="sourceLineNo">1112</span>      // We are still in the same block.<a name="line.1112"></a>
+<span class="sourceLineNo">1113</span>      readKeyValueLen();<a name="line.1113"></a>
+<span class="sourceLineNo">1114</span>      return true;<a name="line.1114"></a>
+<span class="sourceLineNo">1115</span>    }<a name="line.1115"></a>
+<span class="sourceLineNo">1116</span><a name="line.1116"></a>
+<span class="sourceLineNo">1117</span>    /**<a name="line.1117"></a>
+<span class="sourceLineNo">1118</span>     * Go to the next key/value in the block section. Loads the next block if<a name="line.1118"></a>
+<span class="sourceLineNo">1119</span>     * necessary. If successful, {@link #getKey()} and {@link #getValue()} can<a name="line.1119"></a>
+<span class="sourceLineNo">1120</span>     * be called.<a name="line.1120"></a>
+<span class="sourceLineNo">1121</span>     *<a name="line.1121"></a>
+<span class="sourceLineNo">1122</span>     * @return true if successfully navigated to the next key/value<a name="line.1122"></a>
+<span class="sourceLineNo">1123</span>     */<a name="line.1123"></a>
+<span class="sourceLineNo">1124</span>    @Override<a name="line.1124"></a>
+<span class="sourceLineNo">1125</span>    public boolean next() throws IOException {<a name="line.1125"></a>
+<span class="sourceLineNo">1126</span>      // This is a hot method so extreme measures taken to ensure it is small and inlineable.<a name="line.1126"></a>
+<span class="sourceLineNo">1127</span>      // Checked by setting: -XX:+UnlockDiagnosticVMOptions -XX:+PrintInlining -XX:+PrintCompilation<a name="line.1127"></a>
+<span class="sourceLineNo">1128</span>      assertSeeked();<a name="line.1128"></a>
+<span class="sourceLineNo">1129</span>      positionThisBlockBuffer();<a name="line.1129"></a>
+<span class="sourceLineNo">1130</span>      return _next();<a name="line.1130"></a>
+<span class="sourceLineNo">1131</span>    }<a name="line.1131"></a>
+<span class="sourceLineNo">1132</span><a name="line.1132"></a>
+<span class="sourceLineNo">1133</span>    /**<a name="line.1133"></a>
+<span class="sourceLineNo">1134</span>     * Positions this scanner at the start of the file.<a name="line.1134"></a>
+<span class="sourceLineNo">1135</span>     *<a name="line.1135"></a>
+<span class="sourceLineNo">1136</span>     * @return false if empty file; i.e. a call to next would return false and<a name="line.1136"></a>
+<span class="sourceLineNo">1137</span>     *         the current key and value are undefined.<a name="line.1137"></a>
+<span class="sourceLineNo">1138</span>     * @throws IOException<a name="line.1138"></a>
+<span class="sourceLineNo">1139</span>     */<a name="line.1139"></a>
+<span class="sourceLineNo">1140</span>    @Override<a name="line.1140"></a>
+<span class="sourceLineNo">1141</span>    public boolean seekTo() throws IOException {<a name="line.1141"></a>
+<span class="sourceLineNo">1142</span>      if (reader == null) {<a name="line.1142"></a>
+<span class="sourceLineNo">1143</span>        return false;<a name="line.1143"></a>
+<span class="sourceLineNo">1144</span>      }<a name="line.1144"></a>
+<span class="sourceLineNo">1145</span><a name="line.1145"></a>
+<span class="sourceLineNo">1146</span>      if (reader.getTrailer().getEntryCount() == 0) {<a name="line.1146"></a>
+<span class="sourceLineNo">1147</span>        // No data blocks.<a name="line.1147"></a>
+<span class="sourceLineNo">1148</span>        return false;<a name="line.1148"></a>
 <span class="sourceLineNo">1149</span>      }<a name="line.1149"></a>
 <span class="sourceLineNo">1150</span><a name="line.1150"></a>
-<span class="sourceLineNo">1151</span>      readAndUpdateNewBlock(firstDataBlockOffset);<a name="line.1151"></a>
-<span class="sourceLineNo">1152</span>      return true;<a name="line.1152"></a>
-<span class="sourceLineNo">1153</span>    }<a name="line.1153"></a>
-<span class="sourceLineNo">1154</span><a name="line.1154"></a>
-<span class="sourceLineNo">1155</span>    protected boolean processFirstDataBlock() throws IOException{<a name="line.1155"></a>
-<span class="sourceLineNo">1156</span>      blockBuffer.rewind();<a name="line.1156"></a>
-<span class="sourceLineNo">1157</span>      readKeyValueLen();<a name="line.1157"></a>
+<span class="sourceLineNo">1151</span>      long firstDataBlockOffset = reader.getTrailer().getFirstDataBlockOffset();<a name="line.1151"></a>
+<span class="sourceLineNo">1152</span>      if (curBlock != null<a name="line.1152"></a>
+<span class="sourceLineNo">1153</span>          &amp;&amp; curBlock.getOffset() == firstDataBlockOffset) {<a name="line.1153"></a>
+<span class="sourceLineNo">1154</span>        return processFirstDataBlock();<a name="line.1154"></a>
+<span class="sourceLineNo">1155</span>      }<a name="line.1155"></a>
+<span class="sourceLineNo">1156</span><a name="line.1156"></a>
+<span class="sourceLineNo">1157</span>      readAndUpdateNewBlock(firstDataBlockOffset);<a name="line.1157"></a>
 <span class="sourceLineNo">1158</span>      return true;<a name="line.1158"></a>
 <span class="sourceLineNo">1159</span>    }<a name="line.1159"></a>
 <span class="sourceLineNo">1160</span><a name="line.1160"></a>
-<span class="sourceLineNo">1161</span>    protected void readAndUpdateNewBlock(long firstDataBlockOffset) throws IOException,<a name="line.1161"></a>
-<span class="sourceLineNo">1162</span>        CorruptHFileException {<a name="line.1162"></a>
-<span class="sourceLineNo">1163</span>      HFileBlock newBlock = reader.readBlock(firstDataBlockOffset, -1, cacheBlocks, pread,<a name="line.1163"></a>
-<span class="sourceLineNo">1164</span>          isCompaction, true, BlockType.DATA, getEffectiveDataBlockEncoding());<a name="line.1164"></a>
-<span class="sourceLineNo">1165</span>      if (newBlock.getOffset() &lt; 0) {<a name="line.1165"></a>
-<span class="sourceLineNo">1166</span>        throw new IOException("Invalid block offset: " + newBlock.getOffset());<a name="line.1166"></a>
-<span class="sourceLineNo">1167</span>      }<a name="line.1167"></a>
-<span class="sourceLineNo">1168</span>      updateCurrentBlock(newBlock);<a name="line.1168"></a>
-<span class="sourceLineNo">1169</span>    }<a name="line.1169"></a>
-<span class="sourceLineNo">1170</span><a name="line.1170"></a>
-<span class="sourceLineNo">1171</span>    protected int loadBlockAndSeekToKey(HFileBlock seekToBlock, Cell nextIndexedKey,<a name="line.1171"></a>
-<span class="sourceLineNo">1172</span>        boolean rewind, Cell key, boolean seekBefore) throws IOException {<a name="line.1172"></a>
-<span class="sourceLineNo">1173</span>      if (this.curBlock == null<a name="line.1173"></a>
-<span class="sourceLineNo">1174</span>          || this.curBlock.getOffset() != seekToBlock.getOffset()) {<a name="line.1174"></a>
-<span class="sourceLineNo">1175</span>        updateCurrentBlock(seekToBlock);<a name="line.1175"></a>
-<span class="sourceLineNo">1176</span>      } else if (rewind) {<a name="line.1176"></a>
-<span class="sourceLineNo">1177</span>        blockBuffer.rewind();<a name="line.1177"></a>
-<span class="sourceLineNo">1178</span>      }<a name="line.1178"></a>
-<span class="sourceLineNo">1179</span><a name="line.1179"></a>
-<span class="sourceLineNo">1180</span>      // Update the nextIndexedKey<a name="line.1180"></a>
-<span class="sourceLineNo">1181</span>      this.nextIndexedKey = nextIndexedKey;<a name="line.1181"></a>
-<span class="sourceLineNo">1182</span>      return blockSeek(key, seekBefore);<a name="line.1182"></a>
-<span class="sourceLineNo">1183</span>    }<a name="line.1183"></a>
-<span class="sourceLineNo">1184</span><a name="line.1184"></a>
-<span class="sourceLineNo">1185</span>    /**<a name="line.1185"></a>
-<span class="sourceLineNo">1186</span>     * @param v<a name="line.1186"></a>
-<span class="sourceLineNo">1187</span>     * @return True if v &amp;lt; 0 or v &amp;gt; current block buffer limit.<a name="line.1187"></a>
-<span class="sourceLineNo">1188</span>     */<a name="line.1188"></a>
-<span class="sourceLineNo">1189</span>    protected final boolean checkLen(final int v) {<a name="line.1189"></a>
-<span class="sourceLineNo">1190</span>      return v &lt; 0 || v &gt; this.blockBuffer.limit();<a name="line.1190"></a>
-<span class="sourceLineNo">1191</span>    }<a name="line.1191"></a>
-<span class="sourceLineNo">1192</span><a name="line.1192"></a>
-<span class="sourceLineNo">1193</span>    /**<a name="line.1193"></a>
-<span class="sourceLineNo">1194</span>     * Check key and value lengths are wholesome.<a name="line.1194"></a>
-<span class="sourceLineNo">1195</span>     */<a name="line.1195"></a>
-<span class="sourceLineNo">1196</span>    protected final void checkKeyValueLen() {<a name="line.1196"></a>
-<span class="sourceLineNo">1197</span>      if (checkLen(this.currKeyLen) || checkLen(this.currValueLen)) {<a name="line.1197"></a>
-<span class="sourceLineNo">1198</span>        throw new IllegalStateException("Invalid currKeyLen " + this.currKeyLen<a name="line.1198"></a>
-<span class="sourceLineNo">1199</span>            + " or currValueLen " + this.currValueLen + ". Block offset: "<a name="line.1199"></a>
-<span class="sourceLineNo">1200</span>            + this.curBlock.getOffset() + ", block length: "<a name="line.1200"></a>
-<span class="sourceLineNo">1201</span>            + this.blockBuffer.limit() + ", position: " + this.blockBuffer.position()<a name="line.1201"></a>
-<span class="sourceLineNo">1202</span>            + " (without header).");<a name="line.1202"></a>
-<span class="sourceLineNo">1203</span>      }<a name="line.1203"></a>
-<span class="sourceLineNo">1204</span>    }<a name="line.1204"></a>
-<span class="sourceLineNo">1205</span><a name="line.1205"></a>
-<span class="sourceLineNo">1206</span>    /**<a name="line.1206"></a>
-<span class="sourceLineNo">1207</span>     * Updates the current block to be the given {@link HFileBlock}. Seeks to<a name="line.1207"></a>
-<span class="sourceLineNo">1208</span>     * the the first key/value pair.<a name="line.1208"></a>
-<span class="sourceLineNo">1209</span>     *<a name="line.1209"></a>
-<span class="sourceLineNo">1210</span>     * @param newBlock the block to make current<a name="line.1210"></a>
-<span class="sourceLineNo">1211</span>     */<a name="line.1211"></a>
-<span class="sourceLineNo">1212</span>    protected void updateCurrentBlock(HFileBlock newBlock) throws IOException {<a name="line.1212"></a>
-<span class="sourceLineNo">1213</span>      // Set the active block on the reader<a name="line.1213"></a>
-<span class="sourceLineNo">1214</span>      // sanity check<a name="line.1214"></a>
-<span class="sourceLineNo">1215</span>      if (newBlock.getBlockType() != BlockType.DATA) {<a name="line.1215"></a>
-<span class="sourceLineNo">1216</span>        throw new IllegalStateException("ScannerV2 works only on data " + "blocks, got "<a name="line.1216"></a>
-<span class="sourceLineNo">1217</span>            + newBlock.getBlockType() + "; " + "fileName=" + reader.getName()<a name="line.1217"></a>
-<span class="sourceLineNo">1218</span>            + ", " + "dataBlockEncoder=" + reader.getDataBlockEncoding() + ", " + "isCompaction="<a name="line.1218"></a>
-<span class="sourceLineNo">1219</span>            + isCompaction);<a name="line.1219"></a>
-<span class="sourceLineNo">1220</span>      }<a name="line.1220"></a>
-<span class="sourceLineNo">1221</span><a name="line.1221"></a>
-<span class="sourceLineNo">1222</span>      updateCurrBlockRef(newBlock);<a name="line.1222"></a>
-<span class="sourceLineNo">1223</span>      blockBuffer = newBlock.getBufferWithoutHeader();<a name="line.1223"></a>
-<span class="sourceLineNo">1224</span>      readKeyValueLen();<a name="line.1224"></a>
-<span class="sourceLineNo">1225</span>      blockFetches++;<a name="line.1225"></a>
-<span class="sourceLineNo">1226</span><a name="line.1226"></a>
-<span class="sourceLineNo">1227</span>      // Reset the next indexed key<a name="line.1227"></a>
-<span class="sourceLineNo">1228</span>      this.nextIndexedKey = null;<a name="line.1228"></a>
-<span class="sourceLineNo">1229</span>    }<a name="line.1229"></a>
-<span class="sourceLineNo">1230</span><a name="line.1230"></a>
-<span class="sourceLineNo">1231</span>    protected Cell getFirstKeyCellInBlock(HFileBlock curBlock) {<a name="line.1231"></a>
-<span class="sourceLineNo">1232</span>      ByteBuff buffer = curBlock.getBufferWithoutHeader();<a name="line.1232"></a>
-<span class="sourceLineNo">1233</span>      // It is safe to manipulate this buffer because we own the buffer object.<a name="line.1233"></a>
-<span class="sourceLineNo">1234</span>      buffer.rewind();<a name="line.1234"></a>
-<span class="sourceLineNo">1235</span>      int klen = buffer.getInt();<a name="line.1235"></a>
-<span class="sourceLineNo">1236</span>      buffer.skip(Bytes.SIZEOF_INT);// Skip value len part<a name="line.1236"></a>
-<span class="sourceLineNo">1237</span>      ByteBuffer keyBuff = buffer.asSubByteBuffer(klen);<a name="line.1237"></a>
-<span class="sourceLineNo">1238</span>      if (keyBuff.hasArray()) {<a name="line.1238"></a>
-<span class="sourceLineNo">1239</span>        return new KeyValue.KeyOnlyKeyValue(keyBuff.array(), keyBuff.arrayOffset()<a name="line.1239"></a>
-<span class="sourceLineNo">1240</span>            + keyBuff.position(), klen);<a name="line.1240"></a>
-<span class="sourceLineNo">1241</span>      } else {<a name="line.1241"></a>
-<span class="sourceLineNo">1242</span>        return new ByteBufferedKeyOnlyKeyValue(keyBuff, keyBuff.position(), klen);<a name="line.1242"></a>
-<span class="sourceLineNo">1243</span>      }<a name="line.1243"></a>
-<span class="sourceLineNo">1244</span>    }<a name="line.1244"></a>
-<span class="sourceLineNo">1245</span><a name="line.1245"></a>
-<span class="sourceLineNo">1246</span>    @Override<a name="line.1246"></a>
-<span class="sourceLineNo">1247</span>    public String getKeyString() {<a name="line.1247"></a>
-<span class="sourceLineNo">1248</span>      return CellUtil.toString(getKey(), false);<a name="line.1248"></a>
-<span class="sourceLineNo">1249</span>    }<a name="line.1249"></a>
-<span class="sourceLineNo">1250</span><a name="line.1250"></a>
-<span class="sourceLineNo">1251</span>    @Override<a name="line.1251"></a>
-<span class="sourceLineNo">1252</span>    public String getValueString() {<a name="line.1252"></a>
-<span class="sourceLineNo">1253</span>      return ByteBufferUtils.toStringBinary(getValue());<a name="line.1253"></a>
-<span class="sourceLineNo">1254</span>    }<a name="line.1254"></a>
-<span class="sourceLineNo">1255</span><a name="line.1255"></a>
-<span class="sourceLineNo">1256</span>    public int compareKey(CellComparator comparator, Cell key) {<a name="line.1256"></a>
-<span class="sourceLineNo">1257</span>      blockBuffer.asSubByteBuffer(blockBuffer.position() + KEY_VALUE_LEN_SIZE, currKeyLen, pair);<a name="line.1257"></a>
-<span class="sourceLineNo">1258</span>      this.bufBackedKeyOnlyKv.setKey(pair.getFirst(), pair.getSecond(), currKeyLen);<a name="line.1258"></a>
-<span class="sourceLineNo">1259</span>      return comparator.compareKeyIgnoresMvcc(key, this.bufBackedKeyOnlyKv);<a name="line.1259"></a>
+<span class="sourceLineNo">1161</span>    protected boolean processFirstDataBlock() throws IOException{<a name="line.1161"></a>
+<span class="sourceLineNo">1162</span>      blockBuffer.rewind();<a name="line.1162"></a>
+<span class="sourceLineNo">1163</span>      readKeyValueLen();<a name="line.1163"></a>
+<span class="sourceLineNo">1164</span>      return true;<a name="line.1164"></a>
+<span class="sourceLineNo">1165</span>    }<a name="line.1165"></a>
+<span class="sourceLineNo">1166</span><a name="line.1166"></a>
+<span class="sourceLineNo">1167</span>    protected void readAndUpdateNewBlock(long firstDataBlockOffset) throws IOException,<a name="line.1167"></a>
+<span class="sourceLineNo">1168</span>        CorruptHFileException {<a name="line.1168"></a>
+<span class="sourceLineNo">1169</span>      HFileBlock newBlock = reader.readBlock(firstDataBlockOffset, -1, cacheBlocks, pread,<a name="line.1169"></a>
+<span class="sourceLineNo">1170</span>          isCompaction, true, BlockType.DATA, getEffectiveDataBlockEncoding());<a name="line.1170"></a>
+<span class="sourceLineNo">1171</span>      if (newBlock.getOffset() &lt; 0) {<a name="line.1171"></a>
+<span class="sourceLineNo">1172</span>        throw new IOException("Invalid block offset: " + newBlock.getOffset());<a name="line.1172"></a>
+<span class="sourceLineNo">1173</span>      }<a name="line.1173"></a>
+<span class="sourceLineNo">1174</span>      updateCurrentBlock(newBlock);<a name="line.1174"></a>
+<span class="sourceLineNo">1175</span>    }<a name="line.1175"></a>
+<span class="sourceLineNo">1176</span><a name="line.1176"></a>
+<span class="sourceLineNo">1177</span>    protected int loadBlockAndSeekToKey(HFileBlock seekToBlock, Cell nextIndexedKey,<a name="line.1177"></a>
+<span class="sourceLineNo">1178</span>        boolean rewind, Cell key, boolean seekBefore) throws IOException {<a name="line.1178"></a>
+<span class="sourceLineNo">1179</span>      if (this.curBlock == null<a name="line.1179"></a>
+<span class="sourceLineNo">1180</span>          || this.curBlock.getOffset() != seekToBlock.getOffset()) {<a name="line.1180"></a>
+<span class="sourceLineNo">1181</span>        updateCurrentBlock(seekToBlock);<a name="line.1181"></a>
+<span class="sourceLineNo">1182</span>      } else if (rewind) {<a name="line.1182"></a>
+<span class="sourceLineNo">1183</span>        blockBuffer.rewind();<a name="line.1183"></a>
+<span class="sourceLineNo">1184</span>      }<a name="line.1184"></a>
+<span class="sourceLineNo">1185</span><a name="line.1185"></a>
+<span class="sourceLineNo">1186</span>      // Update the nextIndexedKey<a name="line.1186"></a>
+<span class="sourceLineNo">1187</span>      this.nextIndexedKey = nextIndexedKey;<a name="line.1187"></a>
+<span class="sourceLineNo">1188</span>      return blockSeek(key, seekBefore);<a name="line.1188"></a>
+<span class="sourceLineNo">1189</span>    }<a name="line.1189"></a>
+<span class="sourceLineNo">1190</span><a name="line.1190"></a>
+<span class="sourceLineNo">1191</span>    /**<a name="line.1191"></a>
+<span class="sourceLineNo">1192</span>     * @param v<a name="line.1192"></a>
+<span class="sourceLineNo">1193</span>     * @return True if v &amp;lt; 0 or v &amp;gt; current block buffer limit.<a name="line.1193"></a>
+<span class="sourceLineNo">1194</span>     */<a name="line.1194"></a>
+<span class="sourceLineNo">1195</span>    protected final boolean checkLen(final int v) {<a name="line.1195"></a>
+<span class="sourceLineNo">1196</span>      return v &lt; 0 || v &gt; this.blockBuffer.limit();<a name="line.1196"></a>
+<span class="sourceLineNo">1197</span>    }<a name="line.1197"></a>
+<span class="sourceLineNo">1198</span><a name="line.1198"></a>
+<span class="sourceLineNo">1199</span>    /**<a name="line.1199"></a>
+<span class="sourceLineNo">1200</span>     * Check key and value lengths are wholesome.<a name="line.1200"></a>
+<span class="sourceLineNo">1201</span>     */<a name="line.1201"></a>
+<span class="sourceLineNo">1202</span>    protected final void checkKeyValueLen() {<a name="line.1202"></a>
+<span class="sourceLineNo">1203</span>      if (checkLen(this.currKeyLen) || checkLen(this.currValueLen)) {<a name="line.1203"></a>
+<span class="sourceLineNo">1204</span>        throw new IllegalStateException("Invalid currKeyLen " + this.currKeyLen<a name="line.1204"></a>
+<span class="sourceLineNo">1205</span>            + " or currValueLen " + this.currValueLen + ". Block offset: "<a name="line.1205"></a>
+<span class="sourceLineNo">1206</span>            + this.curBlock.getOffset() + ", block length: "<a name="line.1206"></a>
+<span class="sourceLineNo">1207</span>            + this.blockBuffer.limit() + ", position: " + this.blockBuffer.position()<a name="line.1207"></a>
+<span class="sourceLineNo">1208</span>            + " (without header).");<a name="line.1208"></a>
+<span class="sourceLineNo">1209</span>      }<a name="line.1209"></a>
+<span class="sourceLineNo">1210</span>    }<a name="line.1210"></a>
+<span class="sourceLineNo">1211</span><a name="line.1211"></a>
+<span class="sourceLineNo">1212</span>    /**<a name="line.1212"></a>
+<span class="sourceLineNo">1213</span>     * Updates the current block to be the given {@link HFileBlock}. Seeks to<a name="line.1213"></a>
+<span class="sourceLineNo">1214</span>     * the the first key/value pair.<a name="line.1214"></a>
+<span class="sourceLineNo">1215</span>     *<a name="line.1215"></a>
+<span class="sourceLineNo">1216</span>     * @param newBlock the block to make current<a name="line.1216"></a>
+<span class="sourceLineNo">1217</span>     */<a name="line.1217"></a>
+<span class="sourceLineNo">1218</span>    protected void updateCurrentBlock(HFileBlock newBlock) throws IOException {<a name="line.1218"></a>
+<span class="sourceLineNo">1219</span>      // Set the active block on the reader<a name="line.1219"></a>
+<span class="sourceLineNo">1220</span>      // sanity check<a name="line.1220"></a>
+<span class="sourceLineNo">1221</span>      if (newBlock.getBlockType() != BlockType.DATA) {<a name="line.1221"></a>
+<span class="sourceLineNo">1222</span>        throw new IllegalStateException("ScannerV2 works only on data " + "blocks, got "<a name="line.1222"></a>
+<span class="sourceLineNo">1223</span>            + newBlock.getBlockType() + "; " + "fileName=" + reader.getName()<a name="line.1223"></a>
+<span class="sourceLineNo">1224</span>            + ", " + "dataBlockEncoder=" + reader.getDataBlockEncoding() + ", " + "isCompaction="<a name="line.1224"></a>
+<span class="sourceLineNo">1225</span>            + isCompaction);<a name="line.1225"></a>
+<span class="sourceLineNo">1226</span>      }<a name="line.1226"></a>
+<span class="sourceLineNo">1227</span><a name="line.1227"></a>
+<span class="sourceLineNo">1228</span>      updateCurrBlockRef(newBlock);<a name="line.1228"></a>
+<span class="sourceLineNo">1229</span>      blockBuffer = newBlock.getBufferWithoutHeader();<a name="line.1229"></a>
+<span class="sourceLineNo">1230</span>      readKeyValueLen();<a name="line.1230"></a>
+<span class="sourceLineNo">1231</span>      blockFetches++;<a name="line.1231"></a>
+<span class="sourceLineNo">1232</span><a name="line.1232"></a>
+<span class="sourceLineNo">1233</span>      // Reset the next indexed key<a name="line.1233"></a>
+<span class="sourceLineNo">1234</span>      this.nextIndexedKey = null;<a name="line.1234"></a>
+<span class="sourceLineNo">1235</span>    }<a name="line.1235"></a>
+<span class="sourceLineNo">1236</span><a name="line.1236"></a>
+<span class="sourceLineNo">1237</span>    protected Cell getFirstKeyCellInBlock(HFileBlock curBlock) {<a name="line.1237"></a>
+<span class="sourceLineNo">1238</span>      ByteBuff buffer = curBlock.getBufferWithoutHeader();<a name="line.1238"></a>
+<span class="sourceLineNo">1239</span>      // It is safe to manipulate this buffer because we own the buffer object.<a name="line.1239"></a>
+<span class="sourceLineNo">1240</span>      buffer.rewind();<a name="line.1240"></a>
+<span class="sourceLineNo">1241</span>      int klen = buffer.getInt();<a name="line.1241"></a>
+<span class="sourceLineNo">1242</span>      buffer.skip(Bytes.SIZEOF_INT);// Skip value len part<a name="line.1242"></a>
+<span class="sourceLineNo">1243</span>      ByteBuffer keyBuff = buffer.asSubByteBuffer(klen);<a name="line.1243"></a>
+<span class="sourceLineNo">1244</span>      if (keyBuff.hasArray()) {<a name="line.1244"></a>
+<span class="sourceLineNo">1245</span>        return new KeyValue.KeyOnlyKeyValue(keyBuff.array(), keyBuff.arrayOffset()<a name="line.1245"></a>
+<span class="sourceLineNo">1246</span>            + keyBuff.position(), klen);<a name="line.1246"></a>
+<span class="sourceLineNo">1247</span>      } else {<a name="line.1247"></a>
+<span class="sourceLineNo">1248</span>        return new ByteBufferedKeyOnlyKeyValue(keyBuff, keyBuff.position(), klen);<a name="line.1248"></a>
+<span class="sourceLineNo">1249</span>      }<a name="line.1249"></a>
+<span class="sourceLineNo">1250</span>    }<a name="line.1250"></a>
+<span class="sourceLineNo">1251</span><a name="line.1251"></a>
+<span class="sourceLineNo">1252</span>    @Override<a name="line.1252"></a>
+<span class="sourceLineNo">1253</span>    public String getKeyString() {<a name="line.1253"></a>
+<span class="sourceLineNo">1254</span>      return CellUtil.toString(getKey(), false);<a name="line.1254"></a>
+<span class="sourceLineNo">1255</span>    }<a name="line.1255"></a>
+<span class="sourceLineNo">1256</span><a name="line.1256"></a>
+<span class="sourceLineNo">1257</span>    @Override<a name="line.1257"></a>
+<span class="sourceLineNo">1258</span>    public String getValueString() {<a name="line.1258"></a>
+<span class="sourceLineNo">1259</span>      return ByteBufferUtils.toStringBinary(getValue());<a name="line.1259"></a>
 <span class="sourceLineNo">1260</span>    }<a name="line.1260"></a>
 <span class="sourceLineNo">1261</span><a name="line.1261"></a>
-<span class="sourceLineNo">1262</span>    @Override<a name="line.1262"></a>
-<span class="sourceLineNo">1263</span>    public void shipped() throws IOException {<a name="line.1263"></a>
-<span class="sourceLineNo">1264</span>      this.returnBlocks(false);<a name="line.1264"></a>
-<span class="sourceLineNo">1265</span>    }<a name="line.1265"></a>
-<span class="sourceLineNo">1266</span>  }<a name="line.1266"></a>
+<span class="sourceLineNo">1262</span>    public int compareKey(CellComparator comparator, Cell key) {<a name="line.1262"></a>
+<span class="sourceLineNo">1263</span>      blockBuffer.asSubByteBuffer(blockBuffer.position() + KEY_VALUE_LEN_SIZE, currKeyLen, pair);<a name="line.1263"></a>
+<span class="sourceLineNo">1264</span>      this.bufBackedKeyOnlyKv.setKey(pair.getFirst(), pair.getSecond(), currKeyLen);<a name="line.1264"></a>
+<span class="sourceLineNo">1265</span>      return comparator.compareKeyIgnoresMvcc(key, this.bufBackedKeyOnlyKv);<a name="line.1265"></a>
+<span class="sourceLineNo">1266</span>    }<a name="line.1266"></a>
 <span class="sourceLineNo">1267</span><a name="line.1267"></a>
-<span class="sourceLineNo">1268</span>  public Path getPath() {<a name="line.1268"></a>
-<span class="sourceLineNo">1269</span>    return path;<a name="line.1269"></a>
-<span class="sourceLineNo">1270</span>  }<a name="line.1270"></a>
-<span class="sourceLineNo">1271</span><a name="line.1271"></a>
-<span class="sourceLineNo">1272</span>  @Override<a name="line.1272"></a>
-<span class="sourceLineNo">1273</span>  public DataBlockEncoding getDataBlockEncoding() {<a name="line.1273"></a>
-<span class="sourceLineNo">1274</span>    return dataBlockEncoder.getDataBlockEncoding();<a name="line.1274"></a>
-<span class="sourceLineNo">1275</span>  }<a name="line.1275"></a>
-<span class="sourceLineNo">1276</span><a name="line.1276"></a>
-<span class="sourceLineNo">1277</span>  @Override<a name="line.1277"></a>
-<span class="sourceLineNo">1278</span>  public Configuration getConf() {<a name="line.1278"></a>
-<span class="sourceLineNo">1279</span>    return conf;<a name="line.1279"></a>
-<span class="sourceLineNo">1280</span>  }<a name="line.1280"></a>
-<span class="sourceLineNo">1281</span><a name="line.1281"></a>
-<span class="sourceLineNo">1282</span>  @Override<a name="line.1282"></a>
-<span class="sourceLineNo">1283</span>  public void setConf(Configuration conf) {<a name="line.1283"></a>
-<span class="sourceLineNo">1284</span>    this.conf = conf;<a name="line.1284"></a>
-<span class="sourceLineNo">1285</span>  }<a name="line.1285"></a>
-<span class="sourceLineNo">1286</span><a name="line.1286"></a>
-<span class="sourceLineNo">1287</span>  /** Minor versions in HFile starting with this number have hbase checksums */<a name="line.1287"></a>
-<span class="sourceLineNo">1288</span>  public static final int MINOR_VERSION_WITH_CHECKSUM = 1;<a name="line.1288"></a>
-<span class="sourceLineNo">1289</span>  /** In HFile minor version that does not support checksums */<a name="line.1289"></a>
-<span class="sourceLineNo">1290</span>  public static final int MINOR_VERSION_NO_CHECKSUM = 0;<a name="line.1290"></a>
-<span class="sourceLineNo">1291</span><a name="line.1291"></a>
-<span class="sourceLineNo">1292</span>  /** HFile minor version that introduced pbuf filetrailer */<a name="line.1292"></a>
-<span class="sourceLineNo">1293</span>  public static final int PBUF_TRAILER_MINOR_VERSION = 2;<a name="line.1293"></a>
-<span class="sourceLineNo">1294</span><a name="line.1294"></a>
-<span class="sourceLineNo">1295</span>  /**<a name="line.1295"></a>
-<span class="sourceLineNo">1296</span>   * The size of a (key length, value length) tuple that prefixes each entry in<a name="line.1296"></a>
-<span class="sourceLineNo">1297</span>   * a data block.<a name="line.1297"></a>
-<span class="sourceLineNo">1298</span>   */<a name="line.1298"></a>
-<span class="sourceLineNo">1299</span>  public final static int KEY_VALUE_LEN_SIZE = 2 * Bytes.SIZEOF_INT;<a name="line.1299"></a>
+<span class="sourceLineNo">1268</span>    @Override<a name="line.1268"></a>
+<span class="sourceLineNo">1269</span>    public void shipped() throws IOException {<a name="line.1269"></a>
+<span class="sourceLineNo">1270</span>      this.returnBlocks(false);<a name="line.1270"></a>
+<span class="sourceLineNo">1271</span>    }<a name="line.1271"></a>
+<span class="sourceLineNo">1272</span>  }<a name="line.1272"></a>
+<span class="sourceLineNo">1273</span><a name="line.1273"></a>
+<span class="sourceLineNo">1274</span>  public Path getPath() {<a name="line.1274"></a>
+<span class="sourceLineNo">1275</span>    return path;<a name="line.1275"></a>
+<span class="sourceLineNo">1276</span>  }<a name="line.1276"></a>
+<span class="sourceLineNo">1277</span><a name="line.1277"></a>
+<span class="sourceLineNo">1278</span>  @Override<a name="line.1278"></a>
+<span class="sourceLineNo">1279</span>  public DataBlockEncoding getDataBlockEncoding() {<a name="line.1279"></a>
+<span class="sourceLineNo">1280</span>    return dataBlockEncoder.getDataBlockEncoding();<a name="line.1280"></a>
+<span class="sourceLineNo">1281</span>  }<a name="line.1281"></a>
+<span class="sourceLineNo">1282</span><a name="line.1282"></a>
+<span class="sourceLineNo">1283</span>  @Override<a name="line.1283"></a>
+<span class="sourceLineNo">1284</span>  public Configuration getConf() {<a name="line.1284"></a>
+<span class="sourceLineNo">1285</span>    return conf;<a name="line.1285"></a>
+<span class="sourceLineNo">1286</span>  }<a name="line.1286"></a>
+<span class="sourceLineNo">1287</span><a name="line.1287"></a>
+<span class="sourceLineNo">1288</span>  @Override<a name="line.1288"></a>
+<span class="sourceLineNo">1289</span>  public void setConf(Configuration conf) {<a name="line.1289"></a>
+<span class="sourceLineNo">1290</span>    this.conf = conf;<a name="line.1290"></a>
+<span class="sourceLineNo">1291</span>  }<a name="line.1291"></a>
+<span class="sourceLineNo">1292</span><a name="line.1292"></a>
+<span class="sourceLineNo">1293</span>  /** Minor versions in HFile starting with this number have hbase checksums */<a name="line.1293"></a>
+<span class="sourceLineNo">1294</span>  public static final int MINOR_VERSION_WITH_CHECKSUM = 1;<a name="line.1294"></a>
+<span class="sourceLineNo">1295</span>  /** In HFile minor version that does not support checksums */<a name="line.1295"></a>
+<span class="sourceLineNo">1296</span>  public static final int MINOR_VERSION_NO_CHECKSUM = 0;<a name="line.1296"></a>
+<span class="sourceLineNo">1297</span><a name="line.1297"></a>
+<span class="sourceLineNo">1298</span>  /** HFile minor version that introduced pbuf filetrailer */<a name="line.1298"></a>
+<span class="sourceLineNo">1299</span>  public static final int PBUF_TRAILER_MINOR_VERSION = 2;<a name="line.1299"></a>
 <span class="sourceLineNo">1300</span><a name="line.1300"></a>
-<span class="sourceLineNo">1301</span>  private boolean includesMemstoreTS = false;<a name="line.1301"></a>
-<span class="sourceLineNo">1302</span>  protected boolean decodeMemstoreTS = false;<a name="line.1302"></a>
-<span class="sourceLineNo">1303</span><a name="line.1303"></a>
-<span class="sourceLineNo">1304</span><a name="line.1304"></a>
-<span class="sourceLineNo">1305</span>  public boolean isDecodeMemstoreTS() {<a name="line.1305"></a>
-<span class="sourceLineNo">1306</span>    return this.decodeMemstoreTS;<a name="line.1306"></a>
-<span class="sourceLineNo">1307</span>  }<a name="line.1307"></a>
-<span class="sourceLineNo">1308</span><a name="line.1308"></a>
-<span class="sourceLineNo">1309</span>  public boolean shouldIncludeMemstoreTS() {<a name="line.1309"></a>
-<span class="sourceLineNo">1310</span>    return includesMemstoreTS;<a name="line.1310"></a>
-<span class="sourceLineNo">1311</span>  }<a name="line.1311"></a>
-<span class="sourceLineNo">1312</span><a name="line.1312"></a>
-<span class="sourceLineNo">1313</span>  /**<a name="line.1313"></a>
-<span class="sourceLineNo">1314</span>   * Retrieve block from cache. Validates the retrieved block's type vs {@code expectedBlockType}<a name="line.1314"></a>
-<span class="sourceLineNo">1315</span>   * and its encoding vs. {@code expectedDataBlockEncoding}. Unpacks the block as necessary.<a name="line.1315"></a>
-<span class="sourceLineNo">1316</span>   */<a name="line.1316"></a>
-<span class="sourceLineNo">1317</span>   private HFileBlock getCachedBlock(BlockCacheKey cacheKey, boolean cacheBlock, boolean useLock,<a name="line.1317"></a>
-<span class="sourceLineNo">1318</span>       boolean isCompaction, boolean updateCacheMetrics, BlockType expectedBlockType,<a name="line.1318"></a>
-<span class="sourceLineNo">1319</span>       DataBlockEncoding expectedDataBlockEncoding) throws IOException {<a name="line.1319"></a>
-<span class="sourceLineNo">1320</span>     // Check cache for block. If found return.<a name="line.1320"></a>
-<span class="sourceLineNo">1321</span>     if (cacheConf.isBlockCacheEnabled()) {<a name="line.1321"></a>
-<span class="sourceLineNo">1322</span>       BlockCache cache = cacheConf.getBlockCache();<a name="line.1322"></a>
-<span class="sourceLineNo">1323</span>       HFileBlock cachedBlock = (HFileBlock) cache.getBlock(cacheKey, cacheBlock, useLock,<a name="line.1323"></a>
-<span class="sourceLineNo">1324</span>         updateCacheMetrics);<a name="line.1324"></a>
-<span class="sourceLineNo">1325</span>       if (cachedBlock != null) {<a name="line.1325"></a>
-<span class="sourceLineNo">1326</span>         if (cacheConf.shouldCacheCompressed(cachedBlock.getBlockType().getCategory())) {<a name="line.1326"></a>
-<span class="sourceLineNo">1327</span>           HFileBlock compressedBlock = cachedBlock;<a name="line.1327"></a>
-<span class="sourceLineNo">1328</span>           cachedBlock = compressedBlock.unpack(hfileContext, fsBlockReader);<a name="line.1328"></a>
-<span class="sourceLineNo">1329</span>           // In case of compressed block after unpacking we can return the compressed block<a name="line.1329"></a>
-<span class="sourceLineNo">1330</span>          if (compressedBlock != cachedBlock) {<a name="line.1330"></a>
-<span class="sourceLineNo">1331</span>            cache.returnBlock(cacheKey, compressedBlock);<a name="line.1331"></a>
-<span class="sourceLineNo">1332</span>          }<a name="line.1332"></a>
-<span class="sourceLineNo">1333</span>        }<a name="line.1333"></a>
-<span class="sourceLineNo">1334</span>         validateBlockType(cachedBlock, expectedBlockType);<a name="line.1334"></a>
-<span class="sourceLineNo">1335</span><a name="line.1335"></a>
-<span class="sourceLineNo">1336</span>         if (expectedDataBlockEncoding == null) {<a name="line.1336"></a>
-<span class="sourceLineNo">1337</span>           return cachedBlock;<a name="line.1337"></a>
-<span class="sourceLineNo">1338</span>         }<a name="line.1338"></a>
-<span class="sourceLineNo">1339</span>         DataBlockEncoding actualDataBlockEncoding =<a name="line.1339"></a>
-<span class="sourceLineNo">1340</span>                 cachedBlock.getDataBlockEncoding();<a name="line.1340"></a>
-<span class="sourceLineNo">1341</span>         // Block types other than data blocks always have<a name="line.1341"></a>
-<span class="sourceLineNo">1342</span>         // DataBlockEncoding.NONE. To avoid false negative cache misses, only<a name="line.1342"></a>
-<span class="sourceLineNo">1343</span>         // perform this check if cached block is a data block.<a name="line.1343"></a>
-<span class="sourceLineNo">1344</span>         if (cachedBlock.getBlockType().isData() &amp;&amp;<a name="line.1344"></a>
-<span class="sourceLineNo">1345</span>                 !actualDataBlockEncoding.equals(expectedDataBlockEncoding)) {<a name="line.1345"></a>
-<span class="sourceLineNo">1346</span>           // This mismatch may happen if a Scanner, which is used for say a<a name="line.1346"></a>
-<span class="sourceLineNo">1347</span>           // compaction, tries to read an encoded block from the block cache.<a name="line.1347"></a>
-<span class="sourceLineNo">1348</span>           // The reverse might happen when an EncodedScanner tries to read<a name="line.1348"></a>
-<span class="sourceLineNo">1349</span>           // un-encoded blocks which were cached earlier.<a name="line.1349"></a>
-<span class="sourceLineNo">1350</span>           //<a name="line.1350"></a>
-<span class="sourceLineNo">1351</span>           // Because returning a data block with an implicit BlockType mismatch<a name="line.1351"></a>
-<span class="sourceLineNo">1352</span>           // will cause the requesting scanner to throw a disk read should be<a name="line.1352"></a>
-<span class="sourceLineNo">1353</span>           // forced here. This will potentially cause a significant number of<a name="line.1353"></a>
-<span class="sourceLineNo">1354</span>           // cache misses, so update so we should keep track of this as it might<a name="line.1354"></a>
-<span class="sourceLineNo">1355</span>           // justify the work on a CompoundScanner.<a name="line.1355"></a>
-<span class="sourceLineNo">1356</span>           if (!expectedDataBlockEncoding.equals(DataBlockEncoding.NONE) &amp;&amp;<a name="line.1356"></a>
-<span class="sourceLineNo">1357</span>                   !actualDataBlockEncoding.equals(DataBlockEncoding.NONE)) {<a name="line.1357"></a>
-<span class="sourceLineNo">1358</span>             // If the block is encoded but the encoding does not match the<a name="line.1358"></a>
-<span class="sourceLineNo">1359</span>             // expected encoding it is likely the encoding was changed but the<a name="line.1359"></a>
-<span class="sourceLineNo">1360</span>             // block was not yet evicted. Evictions on file close happen async<a name="line.1360"></a>
-<span class="sourceLineNo">1361</span>             // so blocks with the old encoding still linger in cache for some<a name="line.1361"></a>
-<span class="sourceLineNo">1362</span>             // period of time. This event should be rare as it only happens on<a name="line.1362"></a>
-<span class="sourceLineNo">1363</span>             // schema definition change.<a name="line.1363"></a>
-<span class="sourceLineNo">1364</span>             LOG.info("Evicting cached block with key " + cacheKey +<a name="line.1364"></a>
-<span class="sourceLineNo">1365</span>                     " because of a data block encoding mismatch" +<a name="line.1365"></a>
-<span class="sourceLineNo">1366</span>                     "; expected: " + expectedDataBlockEncoding +<a name="line.1366"></a>
-<span class="sourceLineNo">1367</span>                     ", actual: " + actualDataBlockEncoding);<a name="line.1367"></a>
-<span class="sourceLineNo">1368</span>             // This is an error scenario. so here we need to decrement the<a name="line.1368"></a>
-<span class="sourceLineNo">1369</span>             // count.<a name="line.1369"></a>
-<span class="sourceLineNo">1370</span>             cache.returnBlock(cacheKey, cachedBlock);<a name="line.1370"></a>
-<span class="sourceLineNo">1371</span>             cache.evictBlock(cacheKey);<a name="line.1371"></a>
-<span class="sourceLineNo">1372</span>           }<a name="line.1372"></a>
-<span class="sourceLineNo">1373</span>           return null;<a name="line.1373"></a>
-<span class="sourceLineNo">1374</span>         }<a name="line.1374"></a>
-<span class="sourceLineNo">1375</span>         return cachedBlock;<a name="line.1375"></a>
-<span class="sourceLineNo">1376</span>       }<a name="line.1376"></a>
-<span class="sourceLineNo">1377</span>     }<a name="line.1377"></a>
-<span class="sourceLineNo">1378</span>     return null;<a name="line.1378"></a>
-<span class="sourceLineNo">1379</span>   }<a name="line.1379"></a>
-<span class="sourceLineNo">1380</span><a name="line.1380"></a>
-<span class="sourceLineNo">1381</span>  /**<a name="line.1381"></a>
-<span class="sourceLineNo">1382</span>   * @param metaBlockName<a name="line.1382"></a>
-<span class="sourceLineNo">1383</span>   * @param cacheBlock Add block to cache, if found<a name="line.1383"></a>
-<span class="sourceLineNo">1384</span>   * @return block wrapped in a ByteBuffer, with header skipped<a name="line.1384"></a>
-<span class="sourceLineNo">1385</span>   * @throws IOException<a name="line.1385"></a>
-<span class="sourceLineNo">1386</span>   */<a name="line.1386"></a>
-<span class="sourceLineNo">1387</span>  @Override<a name="line.1387"></a>
-<span class="sourceLineNo">1388</span>  public HFileBlock getMetaBlock(String metaBlockName, boolean cacheBlock)<a name="line.1388"></a>
-<span class="sourceLineNo">1389</span>      throws IOException {<a name="line.1389"></a>
-<span class="sourceLineNo">1390</span>    if (trailer.getMetaIndexCount() == 0) {<a name="line.1390"></a>
-<span class="sourceLineNo">1391</span>      return null; // there are no meta blocks<a name="line.1391"></a>
-<span class="sourceLineNo">1392</span>    }<a name="line.1392"></a>
-<span class="sourceLineNo">1393</span>    if (metaBlockIndexReader == null) {<a name="line.1393"></a>
-<span class="sourceLineNo">1394</span>      throw new IOException("Meta index not loaded");<a name="line.1394"></a>
-<span class="sourceLineNo">1395</span>    }<a name="line.1395"></a>
-<span class="sourceLineNo">1396</span><a name="line.1396"></a>
-<span class="sourceLineNo">1397</span>    byte[] mbname = Bytes.toBytes(metaBlockName);<a name="line.1397"></a>
-<span class="sourceLineNo">1398</span>    int block = metaBlockIndexReader.rootBlockContainingKey(mbname,<a name="line.1398"></a>
-<span class="sourceLineNo">1399</span>        0, mbname.length);<a name="line.1399"></a>
-<span class="sourceLineNo">1400</span>    if (block == -1)<a name="line.1400"></a>
-<span class="sourceLineNo">1401</span>      return null;<a name="line.1401"></a>
-<span class="sourceLineNo">1402</span>    long blockSize = metaBlockIndexReader.getRootBlockDataSize(block);<a name="line.1402"></a>
-<span class="sourceLineNo">1403</span><a name="line.1403"></a>
-<span class="sourceLineNo">1404</span>    // Per meta key from any given file, synchronize reads for said block. This<a name="line.1404"></a>
-<span class="sourceLineNo">1405</span>    // is OK to do for meta blocks because the meta block index is always<a name="line.1405"></a>
-<span class="sourceLineNo">1406</span>    // single-level.<a name="line.1406"></a>
-<span class="sourceLineNo">1407</span>    synchronized (metaBlockIndexReader<a name="line.1407"></a>
-<span class="sourceLineNo">1408</span>        .getRootBlockKey(block)) {<a name="line.1408"></a>
-<span class="sourceLineNo">1409</span>      // Check cache for block. If found return.<a name="line.1409"></a>
-<span class="sourceLineNo">1410</span>      long metaBlockOffset = metaBlockIndexReader.getRootBlockOffset(block);<a name="line.1410"></a>
-<span class="sourceLineNo">1411</span>      BlockCacheKey cacheKey = new BlockCacheKey(name, metaBlockOffset,<a name="line.1411"></a>
-<span class="sourceLineNo">1412</span>        this.isPrimaryReplicaReader());<a name="line.1412"></a>
-<span class="sourceLineNo">1413</span><a name="line.1413"></a>
-<span class="sourceLineNo">1414</span>      cacheBlock &amp;= cacheConf.shouldCacheDataOnRead();<a name="line.1414"></a>
-<span class="sourceLineNo">1415</span>      if (cacheConf.isBlockCacheEnabled()) {<a name="line.1415"></a>
-<span class="sourceLineNo">1416</span>        HFileBlock cachedBlock = getCachedBlock(cacheKey, cacheBlock, false, true, true,<a name="line.1416"></a>
-<span class="sourceLineNo">1417</span>          BlockType.META, null);<a name="line.1417"></a>
-<span class="sourceLineNo">1418</span>        if (cachedBlock != null) {<a name="line.1418"></a>
-<span class="sourceLineNo">1419</span>          assert cachedBlock.isUnpacked() : "Packed block leak.";<a name="line.1419"></a>
-<span class="sourceLineNo">1420</span>          // Return a distinct 'shallow copy' of the block,<a name="line.1420"></a>
-<span class="sourceLineNo">1421</span>          // so pos does not get messed by the scanner<a name="line.1421"></a>
-<span class="sourceLineNo">1422</span>          return cachedBlock;<a name="line.1422"></a>
-<span class="sourceLineNo">1423</span>        }<a name="line.1423"></a>
-<span class="sourceLineNo">1424</span>        // Cache Miss, please load.<a name="line.1424"></a>
-<span class="sourceLineNo">1425</span>      }<a name="line.1425"></a>
-<span class="sourceLineNo">1426</span><a name="line.1426"></a>
-<span class="sourceLineNo">1427</span>      HFileBlock metaBlock = fsBlockReader.readBlockData(metaBlockOffset,<a name="line.1427"></a>
-<span class="sourceLineNo">1428</span>          blockSize, -1, true).unpack(hfileContext, fsBlockReader);<a name="line.1428"></a>
-<span class="sourceLineNo">1429</span><a name="line.1429"></a>
-<span class="sourceLineNo">1430</span>      // Cache the block<a name="line.1430"></a>
-<span class="sourceLineNo">1431</span>      if (cacheBlock) {<a name="line.1431"></a>
-<span class="sourceLineNo">1432</span>        cacheConf.getBlockCache().cacheBlock(cacheKey, metaBlock,<a name="line.1432"></a>
-<span class="sourceLineNo">1433</span>            cacheConf.isInMemory(), this.cacheConf.isCacheDataInL1());<a name="line.1433"></a>
-<span class="sourceLineNo">1434</span>      }<a name="line.1434"></a>
+<span class="sourceLineNo">1301</span>  /**<a name="line.1301"></a>
+<span class="sourceLineNo">1302</span>   * The size of a (key length, value length) tuple that prefixes each entry in<a name="line.1302"></a>
+<span class="sourceLineNo">1303</span>   * a data block.<a name="line.1303"></a>
+<span class="sourceLineNo">1304</span>   */<a name="line.1304"></a>
+<span class="sourceLineNo">1305</span>  public final static int KEY_VALUE_LEN_SIZE = 2 * Bytes.SIZEOF_INT;<a name="line.1305"></a>
+<span class="sourceLineNo">1306</span><a name="line.1306"></a>
+<span class="sourceLineNo">1307</span>  private boolean includesMemstoreTS = false;<a name="line.1307"></a>
+<span class="sourceLineNo">1308</span>  protected boolean decodeMemstoreTS = false;<a name="line.1308"></a>
+<span class="sourceLineNo">1309</span><a name="line.1309"></a>
+<span class="sourceLineNo">1310</span><a name="line.1310"></a>
+<span class="sourceLineNo">1311</span>  public boolean isDecodeMemstoreTS() {<a name="line.1311"></a>
+<span class="sourceLineNo">1312</span>    return this.decodeMemstoreTS;<a name="line.1312"></a>
+<span class="sourceLineNo">1313</span>  }<a name="line.1313"></a>
+<span class="sourceLineNo">1314</span><a name="line.1314"></a>
+<span class="sourceLineNo">1315</span>  public boolean shouldIncludeMemstoreTS() {<a name="line.1315"></a>
+<span class="sourceLineNo">1316</span>    return includesMemstoreTS;<a name="line.1316"></a>
+<span class="sourceLineNo">1317</span>  }<a name="line.1317"></a>
+<span class="sourceLineNo">1318</span><a name="line.1318"></a>
+<span class="sourceLineNo">1319</span>  /**<a name="line.1319"></a>
+<span class="sourceLineNo">1320</span>   * Retrieve block from cache. Validates the retrieved block's type vs {@code expectedBlockType}<a name="line.1320"></a>
+<span class="sourceLineNo">1321</span>   * and its encoding vs. {@code expectedDataBlockEncoding}. Unpacks the block as necessary.<a name="line.1321"></a>
+<span class="sourceLineNo">1322</span>   */<a name="line.1322"></a>
+<span class="sourceLineNo">1323</span>   private HFileBlock getCachedBlock(BlockCacheKey cacheKey, boolean cacheBlock, boolean useLock,<a name="line.1323"></a>
+<span class="sourceLineNo">1324</span>       boolean isCompaction, boolean updateCacheMetrics, BlockType expectedBlockType,<a name="line.1324"></a>
+<span class="sourceLineNo">1325</span>       DataBlockEncoding expectedDataBlockEncoding) throws IOException {<a name="line.1325"></a>
+<span class="sourceLineNo">1326</span>     // Check cache for block. If found return.<a name="line.1326"></a>
+<span class="sourceLineNo">1327</span>     if (cacheConf.isBlockCacheEnabled()) {<a name="line.1327"></a>
+<span class="sourceLineNo">1328</span>       BlockCache cache = cacheConf.getBlockCache();<a name="line.1328"></a>
+<span class="sourceLineNo">1329</span>       HFileBlock cachedBlock = (HFileBlock) cache.getBlock(cacheKey, cacheBlock, useLock,<a name="line.1329"></a>
+<span class="sourceLineNo">1330</span>         updateCacheMetrics);<a name="line.1330"></a>
+<span class="sourceLineNo">1331</span>       if (cachedBlock != null) {<a name="line.1331"></a>
+<span class="sourceLineNo">1332</span>         if (cacheConf.shouldCacheCompressed(cachedBlock.getBlockType().getCategory())) {<a name="line.1332"></a>
+<span class="sourceLineNo">1333</span>           HFileBlock compressedBlock = cachedBlock;<a name="line.1333"></a>
+<span class="sourceLineNo">1334</span>           cachedBlock = compressedBlock.unpack(hfileContext, fsBlockReader);<a name="line.1334"></a>
+<span class="sourceLineNo">1335</span>           // In case of compressed block after unpacking we can return the compressed block<a name="line.1335"></a>
+<span class="sourceLineNo">1336</span>          if (compressedBlock != cachedBlock) {<a name="line.1336"></a>
+<span class="sourceLineNo">1337</span>            cache.returnBlock(cacheKey, compressedBlock);<a name="line.1337"></a>
+<span class="sourceLineNo">1338</span>          }<a name="line.1338"></a>
+<span class="sourceLineNo">1339</span>        }<a name="line.1339"></a>
+<span class="sourceLineNo">1340</span>         validateBlockType(cachedBlock, expectedBlockType);<a name="line.1340"></a>
+<span class="sourceLineNo">1341</span><a name="line.1341"></a>
+<span class="sourceLineNo">1342</span>         if (expectedDataBlockEncoding == null) {<a name="line.1342"></a>
+<span class="sourceLineNo">1343</span>           return cachedBlock;<a name="line.1343"></a>
+<span class="sourceLineNo">1344</span>         }<a name="line.1344"></a>
+<span class="sourceLineNo">1345</span>         DataBlockEncoding actualDataBlockEncoding =<a name="line.1345"></a>
+<span class="sourceLineNo">1346</span>                 cachedBlock.getDataBlockEncoding();<a name="line.1346"></a>
+<span class="sourceLineNo">1347</span>         // Block types other than data blocks always have<a name="line.1347"></a>
+<span class="sourceLineNo">1348</span>         // DataBlockEncoding.NONE. To avoid false negative cache misses, only<a name="line.1348"></a>
+<span class="sourceLineNo">1349</span>         // perform this check if cached block is a data block.<a name="line.1349"></a>
+<span class="sourceLineNo">1350</span>         if (cachedBlock.getBlockType().isData() &amp;&amp;<a name="line.1350"></a>
+<span class="sourceLineNo">1351</span>                 !actualDataBlockEncoding.equals(expectedDataBlockEncoding)) {<a name="line.1351"></a>
+<span class="sourceLineNo">1352</span>           // This mismatch may happen if a Scanner, which is used for say a<a name="line.1352"></a>
+<span class="sourceLineNo">1353</span>           // compaction, tries to read an encoded block from the block cache.<a name="line.1353"></a>
+<span class="sourceLineNo">1354</span>           // The reverse might happen when an EncodedScanner tries to read<a name="line.1354"></a>
+<span class="sourceLineNo">1355</span>           // un-encoded blocks which were cached earlier.<a name="line.1355"></a>
+<span class="sourceLineNo">1356</span>           //<a name="line.1356"></a>
+<span class="sourceLineNo">1357</span>           // Because returning a data block with an implicit BlockType mismatch<a name="line.1357"></a>
+<span class="sourceLineNo">1358</span>           // will cause the requesting scanner to throw a disk read should be<a name="line.1358"></a>
+<span class="sourceLineNo">1359</span>           // forced here. This will potentially cause a significant number of<a name="line.1359"></a>
+<span class="sourceLineNo">1360</span>           // cache misses, so update so we should keep track of this as it might<a name="line.1360"></a>
+<span class="sourceLineNo">1361</span>           // justify the work on a CompoundScanner.<a name="line.1361"></a>
+<span class="sourceLineNo">1362</span>           if (!expectedDataBlockEncoding.equals(DataBlockEncoding.NONE) &amp;&amp;<a name="line.1362"></a>
+<span class="sourceLineNo">1363</span>                   !actualDataBlockEncoding.equals(DataBlockEncoding.NONE)) {<a name="line.1363"></a>
+<span class="sourceLineNo">1364</span>             // If the block is encoded but the encoding does not match the<a name="line.1364"></a>
+<span class="sourceLineNo">1365</span>             // expected encoding it is likely the encoding was changed but the<a name="line.1365"></a>
+<span class="sourceLineNo">1366</span>             // block was not yet evicted. Evictions on file close happen async<a name="line.1366"></a>
+<span class="sourceLineNo">1367</span>             // so blocks with the old encoding still linger in cache for some<a name="line.1367"></a>
+<span class="sourceLineNo">1368</span>             // period of time. This event should be rare as it only happens on<a name="line.1368"></a>
+<span class="sourceLineNo">1369</span>             // schema definition change.<a name="line.1369"></a>
+<span class="sourceLineNo">1370</span>             LOG.info("Evicting cached block with key " + cacheKey +<a name="line.1370"></a>
+<span class="sourceLineNo">1371</span>                     " because of a data block encoding mismatch" +<a name="line.1371"></a>
+<span class="sourceLineNo">1372</span>                     "; expected: " + expectedDataBlockEncoding +<a name="line.1372"></a>
+<span class="sourceLineNo">1373</span>                     ", actual: " + actualDataBlockEncoding);<a name="line.1373"></a>
+<span class="sourceLineNo">1374</span>             // This is an error scenario. so here we need to decrement the<a name="line.1374"></a>
+<span class="sourceLineNo">1375</span>             // count.<a name="line.1375"></a>
+<span class="sourceLineNo">1376</span>             cache.returnBlock(cacheKey, cachedBlock);<a name="line.1376"></a>
+<span class="sourceLineNo">1377</span>             cache.evictBlock(cacheKey);<a name="line.1377"></a>
+<span class="sourceLineNo">1378</span>           }<a name="line.1378"></a>
+<span class="sourceLineNo">1379</span>           return null;<a name="line.1379"></a>
+<span class="sourceLineNo">1380</span>         }<a name="line.1380"></a>
+<span class="sourceLineNo">1381</span>         return cachedBlock;<a name="line.1381"></a>
+<span class="sourceLineNo">1382</span>       }<a name="line.1382"></a>
+<span class="sourceLineNo">1383</span>     }<a name="line.1383"></a>
+<span class="sourceLineNo">1384</span>     return null;<a name="line.1384"></a>
+<span class="sourceLineNo">1385</span>   }<a name="line.1385"></a>
+<span class="sourceLineNo">1386</span><a name="line.1386"></a>
+<span class="sourceLineNo">1387</span>  /**<a name="line.1387"></a>
+<span class="sourceLineNo">1388</span>   * @param metaBlockName<a name="line.1388"></a>
+<span class="sourceLineNo">1389</span>   * @param cacheBlock Add block to cache, if found<a name="line.1389"></a>
+<span class="sourceLineNo">1390</span>   * @return block wrapped in a ByteBuffer, with header skipped<a name="line.1390"></a>
+<span class="sourceLineNo">1391</span>   * @throws IOException<a name="line.1391"></a>
+<span class="sourceLineNo">1392</span>   */<a name="line.1392"></a>
+<span class="sourceLineNo">1393</span>  @Override<a name="line.1393"></a>
+<span class="sourceLineNo">1394</span>  public HFileBlock getMetaBlock(String metaBlockName, boolean cacheBlock)<a name="line.1394"></a>
+<span class="sourceLineNo">1395</span>      throws IOException {<a name="line.1395"></a>
+<span class="sourceLineNo">1396</span>    if (trailer.getMetaIndexCount() == 0) {<a name="line.1396"></a>
+<span class="sourceLineNo">1397</span>      return null; // there are no meta blocks<a name="line.1397"></a>
+<span class="sourceLineNo">1398</span>    }<a name="line.1398"></a>
+<span class="sourceLineNo">1399</span>    if (metaBlockIndexReader == null) {<a name="line.1399"></a>
+<span class="sourceLineNo">1400</span>      throw new IOException("Meta index not loaded");<a name="line.1400"></a>
+<span class="sourceLineNo">1401</span>    }<a name="line.1401"></a>
+<span class="sourceLineNo">1402</span><a name="line.1402"></a>
+<span class="sourceLineNo">1403</span>    byte[] mbname = Bytes.toBytes(metaBlockName);<a name="line.1403"></a>
+<span class="sourceLineNo">1404</span>    int block = metaBlockIndexReader.rootBlockContainingKey(mbname,<a name="line.1404"></a>
+<span class="sourceLineNo">1405</span>        0, mbname.length);<a name="line.1405"></a>
+<span class="sourceLineNo">1406</span>    if (block == -1)<a name="line.1406"></a>
+<span class="sourceLineNo">1407</span>      return null;<a name="line.1407"></a>
+<span class="sourceLineNo">1408</span>    long blockSize = metaBlockIndexReader.getRootBlockDataSize(block);<a name="line.1408"></a>
+<span class="sourceLineNo">1409</span><a name="line.1409"></a>
+<span class="sourceLineNo">1410</span>    // Per meta key from any given file, synchronize reads for said block. This<a name="line.1410"></a>
+<span class="sourceLineNo">1411</span>    // is OK to do for meta blocks because the meta block index is always<a name="line.1411"></a>
+<span class="sourceLineNo">1412</span>    // single-level.<a name="line.1412"></a>
+<span class="sourceLineNo">1413</span>    synchronized (metaBlockIndexReader<a name="line.1413"></a>
+<span class="sourceLineNo">1414</span>        .getRootBlockKey(block)) {<a name="line.1414"></a>
+<span class="sourceLineNo">1415</span>      // Check cache for block. If found return.<a name="line.1415"></a>
+<span class="sourceLineNo">1416</span>      long metaBlockOffset = metaBlockIndexReader.getRootBlockOffset(block);<a name="line.1416"></a>
+<span class="sourceLineNo">1417</span>      BlockCacheKey cacheKey = new BlockCacheKey(name, metaBlockOffset,<a name="line.1417"></a>
+<span class="sourceLineNo">1418</span>        this.isPrimaryReplicaReader());<a name="line.1418"></a>
+<span class="sourceLineNo">1419</span><a name="line.1419"></a>
+<span class="sourceLineNo">1420</span>      cacheBlock &amp;= cacheConf.shouldCacheDataOnRead();<a name="line.1420"></a>
+<span class="sourceLineNo">1421</span>      if (cacheConf.isBlockCacheEnabled()) {<a name="line.1421"></a>
+<span class="sourceLineNo">1422</span>        HFileBlock cachedBlock = getCachedBlock(cacheKey, cacheBlock, false, true, true,<a name="line.1422"></a>
+<span class="sourceLineNo">1423</span>          BlockType.META, null);<a name="line.1423"></a>
+<span class="sourceLineNo">1424</span>        if (cachedBlock != null) {<a name="line.1424"></a>
+<span class="sourceLineNo">1425</span>          assert cachedBlock.isUnpacked() : "Packed block leak.";<a name="line.1425"></a>
+<span class="sourceLineNo">1426</span>          // Return a distinct 'shallow copy' of the block,<a name="line.1426"></a>
+<span class="sourceLineNo">1427</span>          // so pos does not get messed by the scanner<a name="line.1427"></a>
+<span class="sourceLineNo">1428</span>          return cachedBlock;<a name="line.1428"></a>
+<span class="sourceLineNo">1429</span>        }<a name="line.1429"></a>
+<span class="sourceLineNo">1430</span>        // Cache Miss, please load.<a name="line.1430"></a>
+<span class="sourceLineNo">1431</span>      }<a name="line.1431"></a>
+<span class="sourceLineNo">1432</span><a name="line.1432"></a>
+<span class="sourceLineNo">1433</span>      HFileBlock metaBlock = fsBlockReader.readBlockData(metaBlockOffset,<a name="line.1433"></a>
+<span class="sourceLineNo">1434</span>          blockSize, -1, true).unpack(hfileContext, fsBlockReader);<a name="line.1434"></a>
 <span class="sourceLineNo">1435</span><a name="line.1435">

<TRUNCATED>

Mime
View raw message