hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mi...@apache.org
Subject [17/23] hbase-site git commit: Published site at 2cf8af5bf1d501156cbb3b421cf75c1051ead7d9.
Date Thu, 04 Feb 2016 17:31:37 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/32672884/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileBlock.BlockIterator.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileBlock.BlockIterator.html b/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileBlock.BlockIterator.html
index 745e703..1587e5e 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileBlock.BlockIterator.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileBlock.BlockIterator.html
@@ -1361,609 +1361,610 @@
 <span class="sourceLineNo">1353</span>    /** The filesystem used to access data */<a name="line.1353"></a>
 <span class="sourceLineNo">1354</span>    protected HFileSystem hfs;<a name="line.1354"></a>
 <span class="sourceLineNo">1355</span><a name="line.1355"></a>
-<span class="sourceLineNo">1356</span>    /** The path (if any) where this data is coming from */<a name="line.1356"></a>
-<span class="sourceLineNo">1357</span>    protected Path path;<a name="line.1357"></a>
-<span class="sourceLineNo">1358</span><a name="line.1358"></a>
-<span class="sourceLineNo">1359</span>    private final Lock streamLock = new ReentrantLock();<a name="line.1359"></a>
+<span class="sourceLineNo">1356</span>    private final Lock streamLock = new ReentrantLock();<a name="line.1356"></a>
+<span class="sourceLineNo">1357</span><a name="line.1357"></a>
+<span class="sourceLineNo">1358</span>    /** The default buffer size for our buffered streams */<a name="line.1358"></a>
+<span class="sourceLineNo">1359</span>    public static final int DEFAULT_BUFFER_SIZE = 1 &lt;&lt; 20;<a name="line.1359"></a>
 <span class="sourceLineNo">1360</span><a name="line.1360"></a>
-<span class="sourceLineNo">1361</span>    /** The default buffer size for our buffered streams */<a name="line.1361"></a>
-<span class="sourceLineNo">1362</span>    public static final int DEFAULT_BUFFER_SIZE = 1 &lt;&lt; 20;<a name="line.1362"></a>
-<span class="sourceLineNo">1363</span><a name="line.1363"></a>
-<span class="sourceLineNo">1364</span>    protected HFileContext fileContext;<a name="line.1364"></a>
-<span class="sourceLineNo">1365</span><a name="line.1365"></a>
-<span class="sourceLineNo">1366</span>    public FSReaderImpl(FSDataInputStreamWrapper stream, long fileSize, HFileSystem hfs, Path path,<a name="line.1366"></a>
-<span class="sourceLineNo">1367</span>        HFileContext fileContext) throws IOException {<a name="line.1367"></a>
-<span class="sourceLineNo">1368</span>      this.fileSize = fileSize;<a name="line.1368"></a>
-<span class="sourceLineNo">1369</span>      this.hfs = hfs;<a name="line.1369"></a>
-<span class="sourceLineNo">1370</span>      this.path = path;<a name="line.1370"></a>
-<span class="sourceLineNo">1371</span>      this.fileContext = fileContext;<a name="line.1371"></a>
-<span class="sourceLineNo">1372</span>      this.hdrSize = headerSize(fileContext.isUseHBaseChecksum());<a name="line.1372"></a>
-<span class="sourceLineNo">1373</span><a name="line.1373"></a>
-<span class="sourceLineNo">1374</span>      this.streamWrapper = stream;<a name="line.1374"></a>
-<span class="sourceLineNo">1375</span>      // Older versions of HBase didn't support checksum.<a name="line.1375"></a>
-<span class="sourceLineNo">1376</span>      this.streamWrapper.prepareForBlockReader(!fileContext.isUseHBaseChecksum());<a name="line.1376"></a>
-<span class="sourceLineNo">1377</span>      defaultDecodingCtx = new HFileBlockDefaultDecodingContext(fileContext);<a name="line.1377"></a>
-<span class="sourceLineNo">1378</span>      encodedBlockDecodingCtx = defaultDecodingCtx;<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>     * A constructor that reads files with the latest minor version.<a name="line.1382"></a>
-<span class="sourceLineNo">1383</span>     * This is used by unit tests only.<a name="line.1383"></a>
-<span class="sourceLineNo">1384</span>     */<a name="line.1384"></a>
-<span class="sourceLineNo">1385</span>    FSReaderImpl(FSDataInputStream istream, long fileSize, HFileContext fileContext)<a name="line.1385"></a>
-<span class="sourceLineNo">1386</span>    throws IOException {<a name="line.1386"></a>
-<span class="sourceLineNo">1387</span>      this(new FSDataInputStreamWrapper(istream), fileSize, null, null, fileContext);<a name="line.1387"></a>
-<span class="sourceLineNo">1388</span>    }<a name="line.1388"></a>
-<span class="sourceLineNo">1389</span><a name="line.1389"></a>
-<span class="sourceLineNo">1390</span>    public BlockIterator blockRange(final long startOffset, final long endOffset) {<a name="line.1390"></a>
-<span class="sourceLineNo">1391</span>      final FSReader owner = this; // handle for inner class<a name="line.1391"></a>
-<span class="sourceLineNo">1392</span>      return new BlockIterator() {<a name="line.1392"></a>
-<span class="sourceLineNo">1393</span>        private long offset = startOffset;<a name="line.1393"></a>
-<span class="sourceLineNo">1394</span><a name="line.1394"></a>
-<span class="sourceLineNo">1395</span>        @Override<a name="line.1395"></a>
-<span class="sourceLineNo">1396</span>        public HFileBlock nextBlock() throws IOException {<a name="line.1396"></a>
-<span class="sourceLineNo">1397</span>          if (offset &gt;= endOffset)<a name="line.1397"></a>
-<span class="sourceLineNo">1398</span>            return null;<a name="line.1398"></a>
-<span class="sourceLineNo">1399</span>          HFileBlock b = readBlockData(offset, -1, -1, false);<a name="line.1399"></a>
-<span class="sourceLineNo">1400</span>          offset += b.getOnDiskSizeWithHeader();<a name="line.1400"></a>
-<span class="sourceLineNo">1401</span>          return b.unpack(fileContext, owner);<a name="line.1401"></a>
-<span class="sourceLineNo">1402</span>        }<a name="line.1402"></a>
-<span class="sourceLineNo">1403</span><a name="line.1403"></a>
-<span class="sourceLineNo">1404</span>        @Override<a name="line.1404"></a>
-<span class="sourceLineNo">1405</span>        public HFileBlock nextBlockWithBlockType(BlockType blockType)<a name="line.1405"></a>
-<span class="sourceLineNo">1406</span>            throws IOException {<a name="line.1406"></a>
-<span class="sourceLineNo">1407</span>          HFileBlock blk = nextBlock();<a name="line.1407"></a>
-<span class="sourceLineNo">1408</span>          if (blk.getBlockType() != blockType) {<a name="line.1408"></a>
-<span class="sourceLineNo">1409</span>            throw new IOException("Expected block of type " + blockType<a name="line.1409"></a>
-<span class="sourceLineNo">1410</span>                + " but found " + blk.getBlockType());<a name="line.1410"></a>
-<span class="sourceLineNo">1411</span>          }<a name="line.1411"></a>
-<span class="sourceLineNo">1412</span>          return blk;<a name="line.1412"></a>
-<span class="sourceLineNo">1413</span>        }<a name="line.1413"></a>
-<span class="sourceLineNo">1414</span>      };<a name="line.1414"></a>
-<span class="sourceLineNo">1415</span>    }<a name="line.1415"></a>
-<span class="sourceLineNo">1416</span><a name="line.1416"></a>
-<span class="sourceLineNo">1417</span>    /**<a name="line.1417"></a>
-<span class="sourceLineNo">1418</span>     * Does a positional read or a seek and read into the given buffer. Returns<a name="line.1418"></a>
-<span class="sourceLineNo">1419</span>     * the on-disk size of the next block, or -1 if it could not be determined.<a name="line.1419"></a>
-<span class="sourceLineNo">1420</span>     *<a name="line.1420"></a>
-<span class="sourceLineNo">1421</span>     * @param dest destination buffer<a name="line.1421"></a>
-<span class="sourceLineNo">1422</span>     * @param destOffset offset in the destination buffer<a name="line.1422"></a>
-<span class="sourceLineNo">1423</span>     * @param size size of the block to be read<a name="line.1423"></a>
-<span class="sourceLineNo">1424</span>     * @param peekIntoNextBlock whether to read the next block's on-disk size<a name="line.1424"></a>
-<span class="sourceLineNo">1425</span>     * @param fileOffset position in the stream to read at<a name="line.1425"></a>
-<span class="sourceLineNo">1426</span>     * @param pread whether we should do a positional read<a name="line.1426"></a>
-<span class="sourceLineNo">1427</span>     * @param istream The input source of data<a name="line.1427"></a>
-<span class="sourceLineNo">1428</span>     * @return the on-disk size of the next block with header size included, or<a name="line.1428"></a>
-<span class="sourceLineNo">1429</span>     *         -1 if it could not be determined<a name="line.1429"></a>
-<span class="sourceLineNo">1430</span>     * @throws IOException<a name="line.1430"></a>
-<span class="sourceLineNo">1431</span>     */<a name="line.1431"></a>
-<span class="sourceLineNo">1432</span>    protected int readAtOffset(FSDataInputStream istream,<a name="line.1432"></a>
-<span class="sourceLineNo">1433</span>        byte[] dest, int destOffset, int size,<a name="line.1433"></a>
-<span class="sourceLineNo">1434</span>        boolean peekIntoNextBlock, long fileOffset, boolean pread)<a name="line.1434"></a>
-<span class="sourceLineNo">1435</span>        throws IOException {<a name="line.1435"></a>
-<span class="sourceLineNo">1436</span>      if (peekIntoNextBlock &amp;&amp;<a name="line.1436"></a>
-<span class="sourceLineNo">1437</span>          destOffset + size + hdrSize &gt; dest.length) {<a name="line.1437"></a>
-<span class="sourceLineNo">1438</span>        // We are asked to read the next block's header as well, but there is<a name="line.1438"></a>
-<span class="sourceLineNo">1439</span>        // not enough room in the array.<a name="line.1439"></a>
-<span class="sourceLineNo">1440</span>        throw new IOException("Attempted to read " + size + " bytes and " +<a name="line.1440"></a>
-<span class="sourceLineNo">1441</span>            hdrSize + " bytes of next header into a " + dest.length +<a name="line.1441"></a>
-<span class="sourceLineNo">1442</span>            "-byte array at offset " + destOffset);<a name="line.1442"></a>
-<span class="sourceLineNo">1443</span>      }<a name="line.1443"></a>
-<span class="sourceLineNo">1444</span><a name="line.1444"></a>
-<span class="sourceLineNo">1445</span>      if (!pread &amp;&amp; streamLock.tryLock()) {<a name="line.1445"></a>
-<span class="sourceLineNo">1446</span>        // Seek + read. Better for scanning.<a name="line.1446"></a>
-<span class="sourceLineNo">1447</span>        try {<a name="line.1447"></a>
-<span class="sourceLineNo">1448</span>          istream.seek(fileOffset);<a name="line.1448"></a>
-<span class="sourceLineNo">1449</span><a name="line.1449"></a>
-<span class="sourceLineNo">1450</span>          long realOffset = istream.getPos();<a name="line.1450"></a>
-<span class="sourceLineNo">1451</span>          if (realOffset != fileOffset) {<a name="line.1451"></a>
-<span class="sourceLineNo">1452</span>            throw new IOException("Tried to seek to " + fileOffset + " to "<a name="line.1452"></a>
-<span class="sourceLineNo">1453</span>                + "read " + size + " bytes, but pos=" + realOffset<a name="line.1453"></a>
-<span class="sourceLineNo">1454</span>                + " after seek");<a name="line.1454"></a>
-<span class="sourceLineNo">1455</span>          }<a name="line.1455"></a>
-<span class="sourceLineNo">1456</span><a name="line.1456"></a>
-<span class="sourceLineNo">1457</span>          if (!peekIntoNextBlock) {<a name="line.1457"></a>
-<span class="sourceLineNo">1458</span>            IOUtils.readFully(istream, dest, destOffset, size);<a name="line.1458"></a>
-<span class="sourceLineNo">1459</span>            return -1;<a name="line.1459"></a>
-<span class="sourceLineNo">1460</span>          }<a name="line.1460"></a>
-<span class="sourceLineNo">1461</span><a name="line.1461"></a>
-<span class="sourceLineNo">1462</span>          // Try to read the next block header.<a name="line.1462"></a>
-<span class="sourceLineNo">1463</span>          if (!readWithExtra(istream, dest, destOffset, size, hdrSize))<a name="line.1463"></a>
-<span class="sourceLineNo">1464</span>            return -1;<a name="line.1464"></a>
-<span class="sourceLineNo">1465</span>        } finally {<a name="line.1465"></a>
-<span class="sourceLineNo">1466</span>          streamLock.unlock();<a name="line.1466"></a>
-<span class="sourceLineNo">1467</span>        }<a name="line.1467"></a>
-<span class="sourceLineNo">1468</span>      } else {<a name="line.1468"></a>
-<span class="sourceLineNo">1469</span>        // Positional read. Better for random reads; or when the streamLock is already locked.<a name="line.1469"></a>
-<span class="sourceLineNo">1470</span>        int extraSize = peekIntoNextBlock ? hdrSize : 0;<a name="line.1470"></a>
-<span class="sourceLineNo">1471</span>        if (!positionalReadWithExtra(istream, fileOffset, dest, destOffset,<a name="line.1471"></a>
-<span class="sourceLineNo">1472</span>            size, extraSize)) {<a name="line.1472"></a>
-<span class="sourceLineNo">1473</span>          return -1;<a name="line.1473"></a>
-<span class="sourceLineNo">1474</span>        }<a name="line.1474"></a>
-<span class="sourceLineNo">1475</span>      }<a name="line.1475"></a>
-<span class="sourceLineNo">1476</span><a name="line.1476"></a>
-<span class="sourceLineNo">1477</span>      assert peekIntoNextBlock;<a name="line.1477"></a>
-<span class="sourceLineNo">1478</span>      return Bytes.toInt(dest, destOffset + size + BlockType.MAGIC_LENGTH) + hdrSize;<a name="line.1478"></a>
-<span class="sourceLineNo">1479</span>    }<a name="line.1479"></a>
-<span class="sourceLineNo">1480</span><a name="line.1480"></a>
-<span class="sourceLineNo">1481</span>    /**<a name="line.1481"></a>
-<span class="sourceLineNo">1482</span>     * Reads a version 2 block (version 1 blocks not supported and not expected). Tries to do as<a name="line.1482"></a>
-<span class="sourceLineNo">1483</span>     * little memory allocation as possible, using the provided on-disk size.<a name="line.1483"></a>
-<span class="sourceLineNo">1484</span>     *<a name="line.1484"></a>
-<span class="sourceLineNo">1485</span>     * @param offset the offset in the stream to read at<a name="line.1485"></a>
-<span class="sourceLineNo">1486</span>     * @param onDiskSizeWithHeaderL the on-disk size of the block, including<a name="line.1486"></a>
-<span class="sourceLineNo">1487</span>     *          the header, or -1 if unknown<a name="line.1487"></a>
-<span class="sourceLineNo">1488</span>     * @param uncompressedSize the uncompressed size of the the block. Always<a name="line.1488"></a>
-<span class="sourceLineNo">1489</span>     *          expected to be -1. This parameter is only used in version 1.<a name="line.1489"></a>
-<span class="sourceLineNo">1490</span>     * @param pread whether to use a positional read<a name="line.1490"></a>
-<span class="sourceLineNo">1491</span>     */<a name="line.1491"></a>
-<span class="sourceLineNo">1492</span>    @Override<a name="line.1492"></a>
-<span class="sourceLineNo">1493</span>    public HFileBlock readBlockData(long offset, long onDiskSizeWithHeaderL,<a name="line.1493"></a>
-<span class="sourceLineNo">1494</span>        int uncompressedSize, boolean pread)<a name="line.1494"></a>
-<span class="sourceLineNo">1495</span>    throws IOException {<a name="line.1495"></a>
-<span class="sourceLineNo">1496</span><a name="line.1496"></a>
-<span class="sourceLineNo">1497</span>      // get a copy of the current state of whether to validate<a name="line.1497"></a>
-<span class="sourceLineNo">1498</span>      // hbase checksums or not for this read call. This is not<a name="line.1498"></a>
-<span class="sourceLineNo">1499</span>      // thread-safe but the one constaint is that if we decide<a name="line.1499"></a>
-<span class="sourceLineNo">1500</span>      // to skip hbase checksum verification then we are<a name="line.1500"></a>
-<span class="sourceLineNo">1501</span>      // guaranteed to use hdfs checksum verification.<a name="line.1501"></a>
-<span class="sourceLineNo">1502</span>      boolean doVerificationThruHBaseChecksum = streamWrapper.shouldUseHBaseChecksum();<a name="line.1502"></a>
-<span class="sourceLineNo">1503</span>      FSDataInputStream is = streamWrapper.getStream(doVerificationThruHBaseChecksum);<a name="line.1503"></a>
-<span class="sourceLineNo">1504</span><a name="line.1504"></a>
-<span class="sourceLineNo">1505</span>      HFileBlock blk = readBlockDataInternal(is, offset,<a name="line.1505"></a>
-<span class="sourceLineNo">1506</span>                         onDiskSizeWithHeaderL,<a name="line.1506"></a>
-<span class="sourceLineNo">1507</span>                         uncompressedSize, pread,<a name="line.1507"></a>
-<span class="sourceLineNo">1508</span>                         doVerificationThruHBaseChecksum);<a name="line.1508"></a>
-<span class="sourceLineNo">1509</span>      if (blk == null) {<a name="line.1509"></a>
-<span class="sourceLineNo">1510</span>        HFile.LOG.warn("HBase checksum verification failed for file " +<a name="line.1510"></a>
-<span class="sourceLineNo">1511</span>                       path + " at offset " +<a name="line.1511"></a>
-<span class="sourceLineNo">1512</span>                       offset + " filesize " + fileSize +<a name="line.1512"></a>
-<span class="sourceLineNo">1513</span>                       ". Retrying read with HDFS checksums turned on...");<a name="line.1513"></a>
-<span class="sourceLineNo">1514</span><a name="line.1514"></a>
-<span class="sourceLineNo">1515</span>        if (!doVerificationThruHBaseChecksum) {<a name="line.1515"></a>
-<span class="sourceLineNo">1516</span>          String msg = "HBase checksum verification failed for file " +<a name="line.1516"></a>
-<span class="sourceLineNo">1517</span>                       path + " at offset " +<a name="line.1517"></a>
-<span class="sourceLineNo">1518</span>                       offset + " filesize " + fileSize +<a name="line.1518"></a>
-<span class="sourceLineNo">1519</span>                       " but this cannot happen because doVerify is " +<a name="line.1519"></a>
-<span class="sourceLineNo">1520</span>                       doVerificationThruHBaseChecksum;<a name="line.1520"></a>
-<span class="sourceLineNo">1521</span>          HFile.LOG.warn(msg);<a name="line.1521"></a>
-<span class="sourceLineNo">1522</span>          throw new IOException(msg); // cannot happen case here<a name="line.1522"></a>
-<span class="sourceLineNo">1523</span>        }<a name="line.1523"></a>
-<span class="sourceLineNo">1524</span>        HFile.checksumFailures.incrementAndGet(); // update metrics<a name="line.1524"></a>
-<span class="sourceLineNo">1525</span><a name="line.1525"></a>
-<span class="sourceLineNo">1526</span>        // If we have a checksum failure, we fall back into a mode where<a name="line.1526"></a>
-<span class="sourceLineNo">1527</span>        // the next few reads use HDFS level checksums. We aim to make the<a name="line.1527"></a>
-<span class="sourceLineNo">1528</span>        // next CHECKSUM_VERIFICATION_NUM_IO_THRESHOLD reads avoid<a name="line.1528"></a>
-<span class="sourceLineNo">1529</span>        // hbase checksum verification, but since this value is set without<a name="line.1529"></a>
-<span class="sourceLineNo">1530</span>        // holding any locks, it can so happen that we might actually do<a name="line.1530"></a>
-<span class="sourceLineNo">1531</span>        // a few more than precisely this number.<a name="line.1531"></a>
-<span class="sourceLineNo">1532</span>        is = this.streamWrapper.fallbackToFsChecksum(CHECKSUM_VERIFICATION_NUM_IO_THRESHOLD);<a name="line.1532"></a>
-<span class="sourceLineNo">1533</span>        doVerificationThruHBaseChecksum = false;<a name="line.1533"></a>
-<span class="sourceLineNo">1534</span>        blk = readBlockDataInternal(is, offset, onDiskSizeWithHeaderL,<a name="line.1534"></a>
-<span class="sourceLineNo">1535</span>                                    uncompressedSize, pread,<a name="line.1535"></a>
-<span class="sourceLineNo">1536</span>                                    doVerificationThruHBaseChecksum);<a name="line.1536"></a>
-<span class="sourceLineNo">1537</span>        if (blk != null) {<a name="line.1537"></a>
-<span class="sourceLineNo">1538</span>          HFile.LOG.warn("HDFS checksum verification suceeded for file " +<a name="line.1538"></a>
-<span class="sourceLineNo">1539</span>                         path + " at offset " +<a name="line.1539"></a>
-<span class="sourceLineNo">1540</span>                         offset + " filesize " + fileSize);<a name="line.1540"></a>
-<span class="sourceLineNo">1541</span>        }<a name="line.1541"></a>
-<span class="sourceLineNo">1542</span>      }<a name="line.1542"></a>
-<span class="sourceLineNo">1543</span>      if (blk == null &amp;&amp; !doVerificationThruHBaseChecksum) {<a name="line.1543"></a>
-<span class="sourceLineNo">1544</span>        String msg = "readBlockData failed, possibly due to " +<a name="line.1544"></a>
-<span class="sourceLineNo">1545</span>                     "checksum verification failed for file " + path +<a name="line.1545"></a>
-<span class="sourceLineNo">1546</span>                     " at offset " + offset + " filesize " + fileSize;<a name="line.1546"></a>
-<span class="sourceLineNo">1547</span>        HFile.LOG.warn(msg);<a name="line.1547"></a>
-<span class="sourceLineNo">1548</span>        throw new IOException(msg);<a name="line.1548"></a>
-<span class="sourceLineNo">1549</span>      }<a name="line.1549"></a>
-<span class="sourceLineNo">1550</span><a name="line.1550"></a>
-<span class="sourceLineNo">1551</span>      // If there is a checksum mismatch earlier, then retry with<a name="line.1551"></a>
-<span class="sourceLineNo">1552</span>      // HBase checksums switched off and use HDFS checksum verification.<a name="line.1552"></a>
-<span class="sourceLineNo">1553</span>      // This triggers HDFS to detect and fix corrupt replicas. The<a name="line.1553"></a>
-<span class="sourceLineNo">1554</span>      // next checksumOffCount read requests will use HDFS checksums.<a name="line.1554"></a>
-<span class="sourceLineNo">1555</span>      // The decrementing of this.checksumOffCount is not thread-safe,<a name="line.1555"></a>
-<span class="sourceLineNo">1556</span>      // but it is harmless because eventually checksumOffCount will be<a name="line.1556"></a>
-<span class="sourceLineNo">1557</span>      // a negative number.<a name="line.1557"></a>
-<span class="sourceLineNo">1558</span>      streamWrapper.checksumOk();<a name="line.1558"></a>
-<span class="sourceLineNo">1559</span>      return blk;<a name="line.1559"></a>
-<span class="sourceLineNo">1560</span>    }<a name="line.1560"></a>
-<span class="sourceLineNo">1561</span><a name="line.1561"></a>
-<span class="sourceLineNo">1562</span>    /**<a name="line.1562"></a>
-<span class="sourceLineNo">1563</span>     * Reads a version 2 block.<a name="line.1563"></a>
-<span class="sourceLineNo">1564</span>     *<a name="line.1564"></a>
-<span class="sourceLineNo">1565</span>     * @param offset the offset in the stream to read at<a name="line.1565"></a>
-<span class="sourceLineNo">1566</span>     * @param onDiskSizeWithHeaderL the on-disk size of the block, including<a name="line.1566"></a>
-<span class="sourceLineNo">1567</span>     *          the header, or -1 if unknown<a name="line.1567"></a>
-<span class="sourceLineNo">1568</span>     * @param uncompressedSize the uncompressed size of the the block. Always<a name="line.1568"></a>
-<span class="sourceLineNo">1569</span>     *          expected to be -1. This parameter is only used in version 1.<a name="line.1569"></a>
-<span class="sourceLineNo">1570</span>     * @param pread whether to use a positional read<a name="line.1570"></a>
-<span class="sourceLineNo">1571</span>     * @param verifyChecksum Whether to use HBase checksums.<a name="line.1571"></a>
-<span class="sourceLineNo">1572</span>     *        If HBase checksum is switched off, then use HDFS checksum.<a name="line.1572"></a>
-<span class="sourceLineNo">1573</span>     * @return the HFileBlock or null if there is a HBase checksum mismatch<a name="line.1573"></a>
-<span class="sourceLineNo">1574</span>     */<a name="line.1574"></a>
-<span class="sourceLineNo">1575</span>    private HFileBlock readBlockDataInternal(FSDataInputStream is, long offset,<a name="line.1575"></a>
-<span class="sourceLineNo">1576</span>        long onDiskSizeWithHeaderL, int uncompressedSize, boolean pread,<a name="line.1576"></a>
-<span class="sourceLineNo">1577</span>        boolean verifyChecksum)<a name="line.1577"></a>
-<span class="sourceLineNo">1578</span>    throws IOException {<a name="line.1578"></a>
-<span class="sourceLineNo">1579</span>      if (offset &lt; 0) {<a name="line.1579"></a>
-<span class="sourceLineNo">1580</span>        throw new IOException("Invalid offset=" + offset + " trying to read "<a name="line.1580"></a>
-<span class="sourceLineNo">1581</span>            + "block (onDiskSize=" + onDiskSizeWithHeaderL<a name="line.1581"></a>
-<span class="sourceLineNo">1582</span>            + ", uncompressedSize=" + uncompressedSize + ")");<a name="line.1582"></a>
-<span class="sourceLineNo">1583</span>      }<a name="line.1583"></a>
-<span class="sourceLineNo">1584</span><a name="line.1584"></a>
-<span class="sourceLineNo">1585</span>      if (uncompressedSize != -1) {<a name="line.1585"></a>
-<span class="sourceLineNo">1586</span>        throw new IOException("Version 2 block reader API does not need " +<a name="line.1586"></a>
-<span class="sourceLineNo">1587</span>            "the uncompressed size parameter");<a name="line.1587"></a>
-<span class="sourceLineNo">1588</span>      }<a name="line.1588"></a>
-<span class="sourceLineNo">1589</span><a name="line.1589"></a>
-<span class="sourceLineNo">1590</span>      if ((onDiskSizeWithHeaderL &lt; hdrSize &amp;&amp; onDiskSizeWithHeaderL != -1)<a name="line.1590"></a>
-<span class="sourceLineNo">1591</span>          || onDiskSizeWithHeaderL &gt;= Integer.MAX_VALUE) {<a name="line.1591"></a>
-<span class="sourceLineNo">1592</span>        throw new IOException("Invalid onDisksize=" + onDiskSizeWithHeaderL<a name="line.1592"></a>
-<span class="sourceLineNo">1593</span>            + ": expected to be at least " + hdrSize<a name="line.1593"></a>
-<span class="sourceLineNo">1594</span>            + " and at most " + Integer.MAX_VALUE + ", or -1 (offset="<a name="line.1594"></a>
-<span class="sourceLineNo">1595</span>            + offset + ", uncompressedSize=" + uncompressedSize + ")");<a name="line.1595"></a>
-<span class="sourceLineNo">1596</span>      }<a name="line.1596"></a>
-<span class="sourceLineNo">1597</span><a name="line.1597"></a>
-<span class="sourceLineNo">1598</span>      int onDiskSizeWithHeader = (int) onDiskSizeWithHeaderL;<a name="line.1598"></a>
-<span class="sourceLineNo">1599</span>      // See if we can avoid reading the header. This is desirable, because<a name="line.1599"></a>
-<span class="sourceLineNo">1600</span>      // we will not incur a backward seek operation if we have already<a name="line.1600"></a>
-<span class="sourceLineNo">1601</span>      // read this block's header as part of the previous read's look-ahead.<a name="line.1601"></a>
-<span class="sourceLineNo">1602</span>      // And we also want to skip reading the header again if it has already<a name="line.1602"></a>
-<span class="sourceLineNo">1603</span>      // been read.<a name="line.1603"></a>
-<span class="sourceLineNo">1604</span>      // TODO: How often does this optimization fire? Has to be same thread so the thread local<a name="line.1604"></a>
-<span class="sourceLineNo">1605</span>      // is pertinent and we have to be reading next block as in a big scan.<a name="line.1605"></a>
-<span class="sourceLineNo">1606</span>      PrefetchedHeader prefetchedHeader = prefetchedHeaderForThread.get();<a name="line.1606"></a>
-<span class="sourceLineNo">1607</span>      ByteBuffer headerBuf = prefetchedHeader.offset == offset? prefetchedHeader.buf: null;<a name="line.1607"></a>
-<span class="sourceLineNo">1608</span><a name="line.1608"></a>
-<span class="sourceLineNo">1609</span>      // Allocate enough space to fit the next block's header too.<a name="line.1609"></a>
-<span class="sourceLineNo">1610</span>      int nextBlockOnDiskSize = 0;<a name="line.1610"></a>
-<span class="sourceLineNo">1611</span>      byte[] onDiskBlock = null;<a name="line.1611"></a>
-<span class="sourceLineNo">1612</span><a name="line.1612"></a>
-<span class="sourceLineNo">1613</span>      HFileBlock b = null;<a name="line.1613"></a>
-<span class="sourceLineNo">1614</span>      if (onDiskSizeWithHeader &gt; 0) {<a name="line.1614"></a>
-<span class="sourceLineNo">1615</span>        // We know the total on-disk size. Read the entire block into memory,<a name="line.1615"></a>
-<span class="sourceLineNo">1616</span>        // then parse the header. This code path is used when<a name="line.1616"></a>
-<span class="sourceLineNo">1617</span>        // doing a random read operation relying on the block index, as well as<a name="line.1617"></a>
-<span class="sourceLineNo">1618</span>        // when the client knows the on-disk size from peeking into the next<a name="line.1618"></a>
-<span class="sourceLineNo">1619</span>        // block's header (e.g. this block's header) when reading the previous<a name="line.1619"></a>
-<span class="sourceLineNo">1620</span>        // block. This is the faster and more preferable case.<a name="line.1620"></a>
-<span class="sourceLineNo">1621</span><a name="line.1621"></a>
-<span class="sourceLineNo">1622</span>        // Size that we have to skip in case we have already read the header.<a name="line.1622"></a>
-<span class="sourceLineNo">1623</span>        int preReadHeaderSize = headerBuf == null ? 0 : hdrSize;<a name="line.1623"></a>
-<span class="sourceLineNo">1624</span>        onDiskBlock = new byte[onDiskSizeWithHeader + hdrSize]; // room for this block plus the<a name="line.1624"></a>
-<span class="sourceLineNo">1625</span>                                                                // next block's header<a name="line.1625"></a>
-<span class="sourceLineNo">1626</span>        nextBlockOnDiskSize = readAtOffset(is, onDiskBlock,<a name="line.1626"></a>
-<span class="sourceLineNo">1627</span>            preReadHeaderSize, onDiskSizeWithHeader - preReadHeaderSize,<a name="line.1627"></a>
-<span class="sourceLineNo">1628</span>            true, offset + preReadHeaderSize, pread);<a name="line.1628"></a>
-<span class="sourceLineNo">1629</span>        if (headerBuf != null) {<a name="line.1629"></a>
-<span class="sourceLineNo">1630</span>          // the header has been read when reading the previous block, copy<a name="line.1630"></a>
-<span class="sourceLineNo">1631</span>          // to this block's header<a name="line.1631"></a>
-<span class="sourceLineNo">1632</span>          // headerBuf is HBB<a name="line.1632"></a>
-<span class="sourceLineNo">1633</span>          assert headerBuf.hasArray();<a name="line.1633"></a>
-<span class="sourceLineNo">1634</span>          System.arraycopy(headerBuf.array(),<a name="line.1634"></a>
-<span class="sourceLineNo">1635</span>              headerBuf.arrayOffset(), onDiskBlock, 0, hdrSize);<a name="line.1635"></a>
-<span class="sourceLineNo">1636</span>        } else {<a name="line.1636"></a>
-<span class="sourceLineNo">1637</span>          headerBuf = ByteBuffer.wrap(onDiskBlock, 0, hdrSize);<a name="line.1637"></a>
-<span class="sourceLineNo">1638</span>        }<a name="line.1638"></a>
-<span class="sourceLineNo">1639</span>        // We know the total on-disk size but not the uncompressed size. Parse the header.<a name="line.1639"></a>
-<span class="sourceLineNo">1640</span>        try {<a name="line.1640"></a>
-<span class="sourceLineNo">1641</span>          // TODO: FIX!!! Expensive parse just to get a length<a name="line.1641"></a>
-<span class="sourceLineNo">1642</span>          b = new HFileBlock(headerBuf, fileContext.isUseHBaseChecksum());<a name="line.1642"></a>
-<span class="sourceLineNo">1643</span>        } catch (IOException ex) {<a name="line.1643"></a>
-<span class="sourceLineNo">1644</span>          // Seen in load testing. Provide comprehensive debug info.<a name="line.1644"></a>
-<span class="sourceLineNo">1645</span>          throw new IOException("Failed to read compressed block at "<a name="line.1645"></a>
-<span class="sourceLineNo">1646</span>              + offset<a name="line.1646"></a>
-<span class="sourceLineNo">1647</span>              + ", onDiskSizeWithoutHeader="<a name="line.1647"></a>
-<span class="sourceLineNo">1648</span>              + onDiskSizeWithHeader<a name="line.1648"></a>
-<span class="sourceLineNo">1649</span>              + ", preReadHeaderSize="<a name="line.1649"></a>
-<span class="sourceLineNo">1650</span>              + hdrSize<a name="line.1650"></a>
-<span class="sourceLineNo">1651</span>              + ", header.length="<a name="line.1651"></a>
-<span class="sourceLineNo">1652</span>              + prefetchedHeader.header.length<a name="line.1652"></a>
-<span class="sourceLineNo">1653</span>              + ", header bytes: "<a name="line.1653"></a>
-<span class="sourceLineNo">1654</span>              + Bytes.toStringBinary(prefetchedHeader.header, 0,<a name="line.1654"></a>
-<span class="sourceLineNo">1655</span>                  hdrSize), ex);<a name="line.1655"></a>
-<span class="sourceLineNo">1656</span>        }<a name="line.1656"></a>
-<span class="sourceLineNo">1657</span>        // if the caller specifies a onDiskSizeWithHeader, validate it.<a name="line.1657"></a>
-<span class="sourceLineNo">1658</span>        int onDiskSizeWithoutHeader = onDiskSizeWithHeader - hdrSize;<a name="line.1658"></a>
-<span class="sourceLineNo">1659</span>        assert onDiskSizeWithoutHeader &gt;= 0;<a name="line.1659"></a>
-<span class="sourceLineNo">1660</span>        b.validateOnDiskSizeWithoutHeader(onDiskSizeWithoutHeader);<a name="line.1660"></a>
-<span class="sourceLineNo">1661</span>      } else {<a name="line.1661"></a>
-<span class="sourceLineNo">1662</span>        // Check headerBuf to see if we have read this block's header as part of<a name="line.1662"></a>
-<span class="sourceLineNo">1663</span>        // reading the previous block. This is an optimization of peeking into<a name="line.1663"></a>
-<span class="sourceLineNo">1664</span>        // the next block's header (e.g.this block's header) when reading the<a name="line.1664"></a>
-<span class="sourceLineNo">1665</span>        // previous block. This is the faster and more preferable case. If the<a name="line.1665"></a>
-<span class="sourceLineNo">1666</span>        // header is already there, don't read the header again.<a name="line.1666"></a>
-<span class="sourceLineNo">1667</span><a name="line.1667"></a>
-<span class="sourceLineNo">1668</span>        // Unfortunately, we still have to do a separate read operation to<a name="line.1668"></a>
-<span class="sourceLineNo">1669</span>        // read the header.<a name="line.1669"></a>
-<span class="sourceLineNo">1670</span>        if (headerBuf == null) {<a name="line.1670"></a>
-<span class="sourceLineNo">1671</span>          // From the header, determine the on-disk size of the given hfile<a name="line.1671"></a>
-<span class="sourceLineNo">1672</span>          // block, and read the remaining data, thereby incurring two read<a name="line.1672"></a>
-<span class="sourceLineNo">1673</span>          // operations. This might happen when we are doing the first read<a name="line.1673"></a>
-<span class="sourceLineNo">1674</span>          // in a series of reads or a random read, and we don't have access<a name="line.1674"></a>
-<span class="sourceLineNo">1675</span>          // to the block index. This is costly and should happen very rarely.<a name="line.1675"></a>
-<span class="sourceLineNo">1676</span>          headerBuf = ByteBuffer.allocate(hdrSize);<a name="line.1676"></a>
-<span class="sourceLineNo">1677</span>          // headerBuf is HBB<a name="line.1677"></a>
-<span class="sourceLineNo">1678</span>          readAtOffset(is, headerBuf.array(), headerBuf.arrayOffset(),<a name="line.1678"></a>
-<span class="sourceLineNo">1679</span>              hdrSize, false, offset, pread);<a name="line.1679"></a>
-<span class="sourceLineNo">1680</span>        }<a name="line.1680"></a>
-<span class="sourceLineNo">1681</span>        // TODO: FIX!!! Expensive parse just to get a length<a name="line.1681"></a>
-<span class="sourceLineNo">1682</span>        b = new HFileBlock(headerBuf, fileContext.isUseHBaseChecksum());<a name="line.1682"></a>
-<span class="sourceLineNo">1683</span>        onDiskBlock = new byte[b.getOnDiskSizeWithHeader() + hdrSize];<a name="line.1683"></a>
-<span class="sourceLineNo">1684</span>        // headerBuf is HBB<a name="line.1684"></a>
-<span class="sourceLineNo">1685</span>        System.arraycopy(headerBuf.array(), headerBuf.arrayOffset(), onDiskBlock, 0, hdrSize);<a name="line.1685"></a>
-<span class="sourceLineNo">1686</span>        nextBlockOnDiskSize =<a name="line.1686"></a>
-<span class="sourceLineNo">1687</span>          readAtOffset(is, onDiskBlock, hdrSize, b.getOnDiskSizeWithHeader()<a name="line.1687"></a>
-<span class="sourceLineNo">1688</span>              - hdrSize, true, offset + hdrSize, pread);<a name="line.1688"></a>
-<span class="sourceLineNo">1689</span>        onDiskSizeWithHeader = b.onDiskSizeWithoutHeader + hdrSize;<a name="line.1689"></a>
-<span class="sourceLineNo">1690</span>      }<a name="line.1690"></a>
-<span class="sourceLineNo">1691</span><a name="line.1691"></a>
-<span class="sourceLineNo">1692</span>      if (!fileContext.isCompressedOrEncrypted()) {<a name="line.1692"></a>
-<span class="sourceLineNo">1693</span>        b.assumeUncompressed();<a name="line.1693"></a>
-<span class="sourceLineNo">1694</span>      }<a name="line.1694"></a>
-<span class="sourceLineNo">1695</span><a name="line.1695"></a>
-<span class="sourceLineNo">1696</span>      if (verifyChecksum &amp;&amp; !validateBlockChecksum(b, onDiskBlock, hdrSize)) {<a name="line.1696"></a>
-<span class="sourceLineNo">1697</span>        return null;             // checksum mismatch<a name="line.1697"></a>
-<span class="sourceLineNo">1698</span>      }<a name="line.1698"></a>
-<span class="sourceLineNo">1699</span><a name="line.1699"></a>
-<span class="sourceLineNo">1700</span>      // The onDiskBlock will become the headerAndDataBuffer for this block.<a name="line.1700"></a>
-<span class="sourceLineNo">1701</span>      // If nextBlockOnDiskSizeWithHeader is not zero, the onDiskBlock already<a name="line.1701"></a>
-<span class="sourceLineNo">1702</span>      // contains the header of next block, so no need to set next<a name="line.1702"></a>
-<span class="sourceLineNo">1703</span>      // block's header in it.<a name="line.1703"></a>
-<span class="sourceLineNo">1704</span>      b = new HFileBlock(ByteBuffer.wrap(onDiskBlock, 0, onDiskSizeWithHeader),<a name="line.1704"></a>
-<span class="sourceLineNo">1705</span>        this.fileContext.isUseHBaseChecksum());<a name="line.1705"></a>
-<span class="sourceLineNo">1706</span><a name="line.1706"></a>
-<span class="sourceLineNo">1707</span>      b.nextBlockOnDiskSizeWithHeader = nextBlockOnDiskSize;<a name="line.1707"></a>
-<span class="sourceLineNo">1708</span><a name="line.1708"></a>
-<span class="sourceLineNo">1709</span>      // Set prefetched header<a name="line.1709"></a>
-<span class="sourceLineNo">1710</span>      if (b.hasNextBlockHeader()) {<a name="line.1710"></a>
-<span class="sourceLineNo">1711</span>        prefetchedHeader.offset = offset + b.getOnDiskSizeWithHeader();<a name="line.1711"></a>
-<span class="sourceLineNo">1712</span>        System.arraycopy(onDiskBlock, onDiskSizeWithHeader, prefetchedHeader.header, 0, hdrSize);<a name="line.1712"></a>
-<span class="sourceLineNo">1713</span>      }<a name="line.1713"></a>
-<span class="sourceLineNo">1714</span><a name="line.1714"></a>
-<span class="sourceLineNo">1715</span>      b.offset = offset;<a name="line.1715"></a>
-<span class="sourceLineNo">1716</span>      b.fileContext.setIncludesTags(this.fileContext.isIncludesTags());<a name="line.1716"></a>
-<span class="sourceLineNo">1717</span>      b.fileContext.setIncludesMvcc(this.fileContext.isIncludesMvcc());<a name="line.1717"></a>
-<span class="sourceLineNo">1718</span>      return b;<a name="line.1718"></a>
-<span class="sourceLineNo">1719</span>    }<a name="line.1719"></a>
-<span class="sourceLineNo">1720</span><a name="line.1720"></a>
-<span class="sourceLineNo">1721</span>    public void setIncludesMemstoreTS(boolean includesMemstoreTS) {<a name="line.1721"></a>
-<span class="sourceLineNo">1722</span>      this.fileContext.setIncludesMvcc(includesMemstoreTS);<a name="line.1722"></a>
-<span class="sourceLineNo">1723</span>    }<a name="line.1723"></a>
-<span class="sourceLineNo">1724</span><a name="line.1724"></a>
-<span class="sourceLineNo">1725</span>    public void setDataBlockEncoder(HFileDataBlockEncoder encoder) {<a name="line.1725"></a>
-<span class="sourceLineNo">1726</span>      encodedBlockDecodingCtx = encoder.newDataBlockDecodingContext(this.fileContext);<a name="line.1726"></a>
-<span class="sourceLineNo">1727</span>    }<a name="line.1727"></a>
-<span class="sourceLineNo">1728</span><a name="line.1728"></a>
-<span class="sourceLineNo">1729</span>    @Override<a name="line.1729"></a>
-<span class="sourceLineNo">1730</span>    public HFileBlockDecodingContext getBlockDecodingContext() {<a name="line.1730"></a>
-<span class="sourceLineNo">1731</span>      return this.encodedBlockDecodingCtx;<a name="line.1731"></a>
-<span class="sourceLineNo">1732</span>    }<a name="line.1732"></a>
-<span class="sourceLineNo">1733</span><a name="line.1733"></a>
-<span class="sourceLineNo">1734</span>    @Override<a name="line.1734"></a>
-<span class="sourceLineNo">1735</span>    public HFileBlockDecodingContext getDefaultBlockDecodingContext() {<a name="line.1735"></a>
-<span class="sourceLineNo">1736</span>      return this.defaultDecodingCtx;<a name="line.1736"></a>
-<span class="sourceLineNo">1737</span>    }<a name="line.1737"></a>
-<span class="sourceLineNo">1738</span><a name="line.1738"></a>
-<span class="sourceLineNo">1739</span>    /**<a name="line.1739"></a>
-<span class="sourceLineNo">1740</span>     * Generates the checksum for the header as well as the data and<a name="line.1740"></a>
-<span class="sourceLineNo">1741</span>     * then validates that it matches the value stored in the header.<a name="line.1741"></a>
-<span class="sourceLineNo">1742</span>     * If there is a checksum mismatch, then return false. Otherwise<a name="line.1742"></a>
-<span class="sourceLineNo">1743</span>     * return true.<a name="line.1743"></a>
-<span class="sourceLineNo">1744</span>     */<a name="line.1744"></a>
-<span class="sourceLineNo">1745</span>    protected boolean validateBlockChecksum(HFileBlock block,  byte[] data, int hdrSize)<a name="line.1745"></a>
-<span class="sourceLineNo">1746</span>        throws IOException {<a name="line.1746"></a>
-<span class="sourceLineNo">1747</span>      return ChecksumUtil.validateBlockChecksum(path, block, data, hdrSize);<a name="line.1747"></a>
-<span class="sourceLineNo">1748</span>    }<a name="line.1748"></a>
-<span class="sourceLineNo">1749</span><a name="line.1749"></a>
-<span class="sourceLineNo">1750</span>    @Override<a name="line.1750"></a>
-<span class="sourceLineNo">1751</span>    public void closeStreams() throws IOException {<a name="line.1751"></a>
-<span class="sourceLineNo">1752</span>      streamWrapper.close();<a name="line.1752"></a>
-<span class="sourceLineNo">1753</span>    }<a name="line.1753"></a>
-<span class="sourceLineNo">1754</span><a name="line.1754"></a>
-<span class="sourceLineNo">1755</span>    @Override<a name="line.1755"></a>
-<span class="sourceLineNo">1756</span>    public String toString() {<a name="line.1756"></a>
-<span class="sourceLineNo">1757</span>      return "hfs=" + hfs + ", path=" + path + ", fileContext=" + fileContext;<a name="line.1757"></a>
-<span class="sourceLineNo">1758</span>    }<a name="line.1758"></a>
-<span class="sourceLineNo">1759</span>  }<a name="line.1759"></a>
-<span class="sourceLineNo">1760</span><a name="line.1760"></a>
-<span class="sourceLineNo">1761</span>  @Override<a name="line.1761"></a>
-<span class="sourceLineNo">1762</span>  public int getSerializedLength() {<a name="line.1762"></a>
-<span class="sourceLineNo">1763</span>    if (buf != null) {<a name="line.1763"></a>
-<span class="sourceLineNo">1764</span>      // include extra bytes for the next header when it's available.<a name="line.1764"></a>
-<span class="sourceLineNo">1765</span>      int extraSpace = hasNextBlockHeader() ? headerSize() : 0;<a name="line.1765"></a>
-<span class="sourceLineNo">1766</span>      return this.buf.limit() + extraSpace + HFileBlock.EXTRA_SERIALIZATION_SPACE;<a name="line.1766"></a>
-<span class="sourceLineNo">1767</span>    }<a name="line.1767"></a>
-<span class="sourceLineNo">1768</span>    return 0;<a name="line.1768"></a>
-<span class="sourceLineNo">1769</span>  }<a name="line.1769"></a>
-<span class="sourceLineNo">1770</span><a name="line.1770"></a>
-<span class="sourceLineNo">1771</span>  @Override<a name="line.1771"></a>
-<span class="sourceLineNo">1772</span>  public void serialize(ByteBuffer destination) {<a name="line.1772"></a>
-<span class="sourceLineNo">1773</span>    this.buf.get(destination, 0, getSerializedLength()<a name="line.1773"></a>
-<span class="sourceLineNo">1774</span>        - EXTRA_SERIALIZATION_SPACE);<a name="line.1774"></a>
-<span class="sourceLineNo">1775</span>    serializeExtraInfo(destination);<a name="line.1775"></a>
-<span class="sourceLineNo">1776</span>  }<a name="line.1776"></a>
-<span class="sourceLineNo">1777</span><a name="line.1777"></a>
-<span class="sourceLineNo">1778</span>  public void serializeExtraInfo(ByteBuffer destination) {<a name="line.1778"></a>
-<span class="sourceLineNo">1779</span>    destination.put(this.fileContext.isUseHBaseChecksum() ? (byte) 1 : (byte) 0);<a name="line.1779"></a>
-<span class="sourceLineNo">1780</span>    destination.putLong(this.offset);<a name="line.1780"></a>
-<span class="sourceLineNo">1781</span>    destination.putInt(this.nextBlockOnDiskSizeWithHeader);<a name="line.1781"></a>
-<span class="sourceLineNo">1782</span>    destination.rewind();<a name="line.1782"></a>
-<span class="sourceLineNo">1783</span>  }<a name="line.1783"></a>
-<span class="sourceLineNo">1784</span><a name="line.1784"></a>
-<span class="sourceLineNo">1785</span>  @Override<a name="line.1785"></a>
-<span class="sourceLineNo">1786</span>  public CacheableDeserializer&lt;Cacheable&gt; getDeserializer() {<a name="line.1786"></a>
-<span class="sourceLineNo">1787</span>    return HFileBlock.blockDeserializer;<a name="line.1787"></a>
-<span class="sourceLineNo">1788</span>  }<a name="line.1788"></a>
-<span class="sourceLineNo">1789</span><a name="line.1789"></a>
-<span class="sourceLineNo">1790</span>  @Override<a name="line.1790"></a>
-<span class="sourceLineNo">1791</span>  public int hashCode() {<a name="line.1791"></a>
-<span class="sourceLineNo">1792</span>    int result = 1;<a name="line.1792"></a>
-<span class="sourceLineNo">1793</span>    result = result * 31 + blockType.hashCode();<a name="line.1793"></a>
-<span class="sourceLineNo">1794</span>    result = result * 31 + nextBlockOnDiskSizeWithHeader;<a name="line.1794"></a>
-<span class="sourceLineNo">1795</span>    result = result * 31 + (int) (offset ^ (offset &gt;&gt;&gt; 32));<a name="line.1795"></a>
-<span class="sourceLineNo">1796</span>    result = result * 31 + onDiskSizeWithoutHeader;<a name="line.1796"></a>
-<span class="sourceLineNo">1797</span>    result = result * 31 + (int) (prevBlockOffset ^ (prevBlockOffset &gt;&gt;&gt; 32));<a name="line.1797"></a>
-<span class="sourceLineNo">1798</span>    result = result * 31 + uncompressedSizeWithoutHeader;<a name="line.1798"></a>
-<span class="sourceLineNo">1799</span>    result = result * 31 + buf.hashCode();<a name="line.1799"></a>
-<span class="sourceLineNo">1800</span>    return result;<a name="line.1800"></a>
-<span class="sourceLineNo">1801</span>  }<a name="line.1801"></a>
-<span class="sourceLineNo">1802</span><a name="line.1802"></a>
-<span class="sourceLineNo">1803</span>  @Override<a name="line.1803"></a>
-<span class="sourceLineNo">1804</span>  public boolean equals(Object comparison) {<a name="line.1804"></a>
-<span class="sourceLineNo">1805</span>    if (this == comparison) {<a name="line.1805"></a>
-<span class="sourceLineNo">1806</span>      return true;<a name="line.1806"></a>
-<span class="sourceLineNo">1807</span>    }<a name="line.1807"></a>
-<span class="sourceLineNo">1808</span>    if (comparison == null) {<a name="line.1808"></a>
-<span class="sourceLineNo">1809</span>      return false;<a name="line.1809"></a>
-<span class="sourceLineNo">1810</span>    }<a name="line.1810"></a>
-<span class="sourceLineNo">1811</span>    if (comparison.getClass() != this.getClass()) {<a name="line.1811"></a>
-<span class="sourceLineNo">1812</span>      return false;<a name="line.1812"></a>
-<span class="sourceLineNo">1813</span>    }<a name="line.1813"></a>
-<span class="sourceLineNo">1814</span><a name="line.1814"></a>
-<span class="sourceLineNo">1815</span>    HFileBlock castedComparison = (HFileBlock) comparison;<a name="line.1815"></a>
-<span class="sourceLineNo">1816</span><a name="line.1816"></a>
-<span class="sourceLineNo">1817</span>    if (castedComparison.blockType != this.blockType) {<a name="line.1817"></a>
-<span class="sourceLineNo">1818</span>      return false;<a name="line.1818"></a>
-<span class="sourceLineNo">1819</span>    }<a name="line.1819"></a>
-<span class="sourceLineNo">1820</span>    if (castedComparison.nextBlockOnDiskSizeWithHeader != this.nextBlockOnDiskSizeWithHeader) {<a name="line.1820"></a>
-<span class="sourceLineNo">1821</span>      return false;<a name="line.1821"></a>
-<span class="sourceLineNo">1822</span>    }<a name="line.1822"></a>
-<span class="sourceLineNo">1823</span>    if (castedComparison.offset != this.offset) {<a name="line.1823"></a>
-<span class="sourceLineNo">1824</span>      return false;<a name="line.1824"></a>
-<span class="sourceLineNo">1825</span>    }<a name="line.1825"></a>
-<span class="sourceLineNo">1826</span>    if (castedComparison.onDiskSizeWithoutHeader != this.onDiskSizeWithoutHeader) {<a name="line.1826"></a>
-<span class="sourceLineNo">1827</span>      return false;<a name="line.1827"></a>
-<span class="sourceLineNo">1828</span>    }<a name="line.1828"></a>
-<span class="sourceLineNo">1829</span>    if (castedComparison.prevBlockOffset != this.prevBlockOffset) {<a name="line.1829"></a>
-<span class="sourceLineNo">1830</span>      return false;<a name="line.1830"></a>
-<span class="sourceLineNo">1831</span>    }<a name="line.1831"></a>
-<span class="sourceLineNo">1832</span>    if (castedComparison.uncompressedSizeWithoutHeader != this.uncompressedSizeWithoutHeader) {<a name="line.1832"></a>
-<span class="sourceLineNo">1833</span>      return false;<a name="line.1833"></a>
-<span class="sourceLineNo">1834</span>    }<a name="line.1834"></a>
-<span class="sourceLineNo">1835</span>    if (ByteBuff.compareTo(this.buf, 0, this.buf.limit(), castedComparison.buf, 0,<a name="line.1835"></a>
-<span class="sourceLineNo">1836</span>        castedComparison.buf.limit()) != 0) {<a name="line.1836"></a>
-<span class="sourceLineNo">1837</span>      return false;<a name="line.1837"></a>
-<span class="sourceLineNo">1838</span>    }<a name="line.1838"></a>
-<span class="sourceLineNo">1839</span>    return true;<a name="line.1839"></a>
-<span class="sourceLineNo">1840</span>  }<a name="line.1840"></a>
-<span class="sourceLineNo">1841</span><a name="line.1841"></a>
-<span class="sourceLineNo">1842</span>  public DataBlockEncoding getDataBlockEncoding() {<a name="line.1842"></a>
-<span class="sourceLineNo">1843</span>    if (blockType == BlockType.ENCODED_DATA) {<a name="line.1843"></a>
-<span class="sourceLineNo">1844</span>      return DataBlockEncoding.getEncodingById(getDataBlockEncodingId());<a name="line.1844"></a>
-<span class="sourceLineNo">1845</span>    }<a name="line.1845"></a>
-<span class="sourceLineNo">1846</span>    return DataBlockEncoding.NONE;<a name="line.1846"></a>
-<span class="sourceLineNo">1847</span>  }<a name="line.1847"></a>
-<span class="sourceLineNo">1848</span><a name="line.1848"></a>
-<span class="sourceLineNo">1849</span>  byte getChecksumType() {<a name="line.1849"></a>
-<span class="sourceLineNo">1850</span>    return this.fileContext.getChecksumType().getCode();<a name="line.1850"></a>
-<span class="sourceLineNo">1851</span>  }<a name="line.1851"></a>
-<span class="sourceLineNo">1852</span><a name="line.1852"></a>
-<span class="sourceLineNo">1853</span>  int getBytesPerChecksum() {<a name="line.1853"></a>
-<span class="sourceLineNo">1854</span>    return this.fileContext.getBytesPerChecksum();<a name="line.1854"></a>
-<span class="sourceLineNo">1855</span>  }<a name="line.1855"></a>
-<span class="sourceLineNo">1856</span><a name="line.1856"></a>
-<span class="sourceLineNo">1857</span>  /** @return the size of data on disk + header. Excludes checksum. */<a name="line.1857"></a>
-<span class="sourceLineNo">1858</span>  int getOnDiskDataSizeWithHeader() {<a name="line.1858"></a>
-<span class="sourceLineNo">1859</span>    return this.onDiskDataSizeWithHeader;<a name="line.1859"></a>
-<span class="sourceLineNo">1860</span>  }<a name="line.1860"></a>
-<span class="sourceLineNo">1861</span><a name="line.1861"></a>
-<span class="sourceLineNo">1862</span>  /**<a name="line.1862"></a>
-<span class="sourceLineNo">1863</span>   * Calcuate the number of bytes required to store all the checksums<a name="line.1863"></a>
-<span class="sourceLineNo">1864</span>   * for this block. Each checksum value is a 4 byte integer.<a name="line.1864"></a>
-<span class="sourceLineNo">1865</span>   */<a name="line.1865"></a>
-<span class="sourceLineNo">1866</span>  int totalChecksumBytes() {<a name="line.1866"></a>
-<span class="sourceLineNo">1867</span>    // If the hfile block has minorVersion 0, then there are no checksum<a name="line.1867"></a>
-<span class="sourceLineNo">1868</span>    // data to validate. Similarly, a zero value in this.bytesPerChecksum<a name="line.1868"></a>
-<span class="sourceLineNo">1869</span>    // indicates that cached blocks do not have checksum data because<a name="line.1869"></a>
-<span class="sourceLineNo">1870</span>    // checksums were already validated when the block was read from disk.<a name="line.1870"></a>
-<span class="sourceLineNo">1871</span>    if (!fileContext.isUseHBaseChecksum() || this.fileContext.getBytesPerChecksum() == 0) {<a name="line.1871"></a>
-<span class="sourceLineNo">1872</span>      return 0;<a name="line.1872"></a>
-<span class="sourceLineNo">1873</span>    }<a name="line.1873"></a>
-<span class="sourceLineNo">1874</span>    return (int) ChecksumUtil.numBytes(onDiskDataSizeWithHeader,<a name="line.1874"></a>
-<span class="sourceLineNo">1875</span>        this.fileContext.getBytesPerChecksum());<a name="line.1875"></a>
-<span class="sourceLineNo">1876</span>  }<a name="line.1876"></a>
-<span class="sourceLineNo">1877</span><a name="line.1877"></a>
-<span class="sourceLineNo">1878</span>  /**<a name="line.1878"></a>
-<span class="sourceLineNo">1879</span>   * Returns the size of this block header.<a name="line.1879"></a>
-<span class="sourceLineNo">1880</span>   */<a name="line.1880"></a>
-<span class="sourceLineNo">1881</span>  public int headerSize() {<a name="line.1881"></a>
-<span class="sourceLineNo">1882</span>    return headerSize(this.fileContext.isUseHBaseChecksum());<a name="line.1882"></a>
-<span class="sourceLineNo">1883</span>  }<a name="line.1883"></a>
-<span class="sourceLineNo">1884</span><a name="line.1884"></a>
-<span class="sourceLineNo">1885</span>  /**<a name="line.1885"></a>
-<span class="sourceLineNo">1886</span>   * Maps a minor version to the size of the header.<a name="line.1886"></a>
-<span class="sourceLineNo">1887</span>   */<a name="line.1887"></a>
-<span class="sourceLineNo">1888</span>  public static int headerSize(boolean usesHBaseChecksum) {<a name="line.1888"></a>
-<span class="sourceLineNo">1889</span>    if (usesHBaseChecksum) {<a name="line.1889"></a>
-<span class="sourceLineNo">1890</span>      return HConstants.HFILEBLOCK_HEADER_SIZE;<a name="line.1890"></a>
-<span class="sourceLineNo">1891</span>    }<a name="line.1891"></a>
-<span class="sourceLineNo">1892</span>    return HConstants.HFILEBLOCK_HEADER_SIZE_NO_CHECKSUM;<a name="line.1892"></a>
-<span class="sourceLineNo">1893</span>  }<a name="line.1893"></a>
-<span class="sourceLineNo">1894</span><a name="line.1894"></a>
-<span class="sourceLineNo">1895</span>  /**<a name="line.1895"></a>
-<span class="sourceLineNo">1896</span>   * Return the appropriate DUMMY_HEADER for the minor version<a name="line.1896"></a>
-<span class="sourceLineNo">1897</span>   */<a name="line.1897"></a>
-<span class="sourceLineNo">1898</span>  public byte[] getDummyHeaderForVersion() {<a name="line.1898"></a>
-<span class="sourceLineNo">1899</span>    return getDummyHeaderForVersion(this.fileContext.isUseHBaseChecksum());<a name="line.1899"></a>
-<span class="sourceLineNo">1900</span>  }<a name="line.1900"></a>
-<span class="sourceLineNo">1901</span><a name="line.1901"></a>
-<span class="sourceLineNo">1902</span>  /**<a name="line.1902"></a>
-<span class="sourceLineNo">1903</span>   * Return the appropriate DUMMY_HEADER for the minor version<a name="line.1903"></a>
-<span class="sourceLineNo">1904</span>   */<a name="line.1904"></a>
-<span class="sourceLineNo">1905</span>  static private byte[] getDummyHeaderForVersion(boolean usesHBaseChecksum) {<a name="line.1905"></a>
-<span class="sourceLineNo">1906</span>    if (usesHBaseChecksum) {<a name="line.1906"></a>
-<span class="sourceLineNo">1907</span>      return HConstants.HFILEBLOCK_DUMMY_HEADER;<a name="line.1907"></a>
-<span class="sourceLineNo">1908</span>    }<a name="line.1908"></a>
-<span class="sourceLineNo">1909</span>    return DUMMY_HEADER_NO_CHECKSUM;<a name="line.1909"></a>
-<span class="sourceLineNo">1910</span>  }<a name="line.1910"></a>
-<span class="sourceLineNo">1911</span><a name="line.1911"></a>
-<span class="sourceLineNo">1912</span>  /**<a name="line.1912"></a>
-<span class="sourceLineNo">1913</span>   * @return the HFileContext used to create this HFileBlock. Not necessary the<a name="line.1913"></a>
-<span class="sourceLineNo">1914</span>   * fileContext for the file from which this block's data was originally read.<a name="line.1914"></a>
-<span class="sourceLineNo">1915</span>   */<a name="line.1915"></a>
-<span class="sourceLineNo">1916</span>  public HFileContext getHFileContext() {<a name="line.1916"></a>
-<span class="sourceLineNo">1917</span>    return this.fileContext;<a name="line.1917"></a>
-<span class="sourceLineNo">1918</span>  }<a name="line.1918"></a>
-<span class="sourceLineNo">1919</span><a name="line.1919"></a>
-<span class="sourceLineNo">1920</span>  @Override<a name="line.1920"></a>
-<span class="sourceLineNo">1921</span>  public MemoryType getMemoryType() {<a name="line.1921"></a>
-<span class="sourceLineNo">1922</span>    return this.memType;<a name="line.1922"></a>
-<span class="sourceLineNo">1923</span>  }<a name="line.1923"></a>
-<span class="sourceLineNo">1924</span><a name="line.1924"></a>
-<span class="sourceLineNo">1925</span>  /**<a name="line.1925"></a>
-<span class="sourceLineNo">1926</span>   * @return true if this block is backed by a shared memory area(such as that of a BucketCache).<a name="line.1926"></a>
-<span class="sourceLineNo">1927</span>   */<a name="line.1927"></a>
-<span class="sourceLineNo">1928</span>  public boolean usesSharedMemory() {<a name="line.1928"></a>
-<span class="sourceLineNo">1929</span>    return this.memType == MemoryType.SHARED;<a name="line.1929"></a>
-<span class="sourceLineNo">1930</span>  }<a name="line.1930"></a>
-<span class="sourceLineNo">1931</span><a name="line.1931"></a>
-<span class="sourceLineNo">1932</span>  /**<a name="line.1932"></a>
-<span class="sourceLineNo">1933</span>   * Convert the contents of the block header into a human readable string.<a name="line.1933"></a>
-<span class="sourceLineNo">1934</span>   * This is mostly helpful for debugging. This assumes that the block<a name="line.1934"></a>
-<span class="sourceLineNo">1935</span>   * has minor version &gt; 0.<a name="line.1935"></a>
-<span class="sourceLineNo">1936</span>   */<a name="line.1936"></a>
-<span class="sourceLineNo">1937</span>  static String toStringHeader(ByteBuff buf) throws IOException {<a name="line.1937"></a>
-<span class="sourceLineNo">1938</span>    byte[] magicBuf = new byte[Math.min(buf.limit() - buf.position(), BlockType.MAGIC_LENGTH)];<a name="line.1938"></a>
-<span class="sourceLineNo">1939</span>    buf.get(magicBuf);<a name="line.1939"></a>
-<span class="sourceLineNo">1940</span>    BlockType bt = BlockType.parse(magicBuf, 0, BlockType.MAGIC_LENGTH);<a name="line.1940"></a>
-<span class="sourceLineNo">1941</span>    int compressedBlockSizeNoHeader = buf.getInt();<a name="line.1941"></a>
-<span class="sourceLineNo">1942</span>    int uncompressedBlockSizeNoHeader = buf.getInt();<a name="line.1942"></a>
-<span class="sourceLineNo">1943</span>    long prevBlockOffset = buf.getLong();<a name="line.1943"></a>
-<span class="sourceLineNo">1944</span>    byte cksumtype = buf.get();<a name="line.1944"></a>
-<span class="sourceLineNo">1945</span>    long bytesPerChecksum = buf.getInt();<a name="line.1945"></a>
-<span class="sourceLineNo">1946</span>    long onDiskDataSizeWithHeader = buf.getInt();<a name="line.1946"></a>
-<span class="sourceLineNo">1947</span>    return " Header dump: magic: " + Bytes.toString(magicBuf) +<a name="line.1947"></a>
-<span class="sourceLineNo">1948</span>                   " blockType " + bt +<a name="line.1948"></a>
-<span class="sourceLineNo">1949</span>                   " compressedBlockSizeNoHeader " +<a name="line.1949"></a>
-<span class="sourceLineNo">1950</span>                   compressedBlockSizeNoHeader +<a name="line.1950"></a>
-<span class="sourceLineNo">1951</span>                   " uncompressedBlockSizeNoHeader " +<a name="line.1951"></a>
-<span class="sourceLineNo">1952</span>                   uncompressedBlockSizeNoHeader +<a name="line.1952"></a>
-<span class="sourceLineNo">1953</span>                   " prevBlockOffset " + prevBlockOffset +<a name="line.1953"></a>
-<span class="sourceLineNo">1954</span>                   " checksumType " + ChecksumType.codeToType(cksumtype) +<a name="line.1954"></a>
-<span class="sourceLineNo">1955</span>                   " bytesPerChecksum " + bytesPerChecksum +<a name="line.1955"></a>
-<span class="sourceLineNo">1956</span>                   " onDiskDataSizeWithHeader " + onDiskDataSizeWithHeader;<a name="line.1956"></a>
-<span class="sourceLineNo">1957</span>  }<a name="line.1957"></a>
-<span class="sourceLineNo">1958</span>}<a name="line.1958"></a>
+<span class="sourceLineNo">1361</span>    protected HFileContext fileContext;<a name="line.1361"></a>
+<span class="sourceLineNo">1362</span>    // Cache the fileName<a name="line.1362"></a>
+<span class="sourceLineNo">1363</span>    protected String pathName;<a name="line.1363"></a>
+<span class="sourceLineNo">1364</span><a name="line.1364"></a>
+<span class="sourceLineNo">1365</span>    public FSReaderImpl(FSDataInputStreamWrapper stream, long fileSize, HFileSystem hfs, Path path,<a name="line.1365"></a>
+<span class="sourceLineNo">1366</span>        HFileContext fileContext) throws IOException {<a name="line.1366"></a>
+<span class="sourceLineNo">1367</span>      this.fileSize = fileSize;<a name="line.1367"></a>
+<span class="sourceLineNo">1368</span>      this.hfs = hfs;<a name="line.1368"></a>
+<span class="sourceLineNo">1369</span>      if (path != null) {<a name="line.1369"></a>
+<span class="sourceLineNo">1370</span>        this.pathName = path.toString();<a name="line.1370"></a>
+<span class="sourceLineNo">1371</span>      }<a name="line.1371"></a>
+<span class="sourceLineNo">1372</span>      this.fileContext = fileContext;<a name="line.1372"></a>
+<span class="sourceLineNo">1373</span>      this.hdrSize = headerSize(fileContext.isUseHBaseChecksum());<a name="line.1373"></a>
+<span class="sourceLineNo">1374</span><a name="line.1374"></a>
+<span class="sourceLineNo">1375</span>      this.streamWrapper = stream;<a name="line.1375"></a>
+<span class="sourceLineNo">1376</span>      // Older versions of HBase didn't support checksum.<a name="line.1376"></a>
+<span class="sourceLineNo">1377</span>      this.streamWrapper.prepareForBlockReader(!fileContext.isUseHBaseChecksum());<a name="line.1377"></a>
+<span class="sourceLineNo">1378</span>      defaultDecodingCtx = new HFileBlockDefaultDecodingContext(fileContext);<a name="line.1378"></a>
+<span class="sourceLineNo">1379</span>      encodedBlockDecodingCtx = defaultDecodingCtx;<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>    /**<a name="line.1382"></a>
+<span class="sourceLineNo">1383</span>     * A constructor that reads files with the latest minor version.<a name="line.1383"></a>
+<span class="sourceLineNo">1384</span>     * This is used by unit tests only.<a name="line.1384"></a>
+<span class="sourceLineNo">1385</span>     */<a name="line.1385"></a>
+<span class="sourceLineNo">1386</span>    FSReaderImpl(FSDataInputStream istream, long fileSize, HFileContext fileContext)<a name="line.1386"></a>
+<span class="sourceLineNo">1387</span>    throws IOException {<a name="line.1387"></a>
+<span class="sourceLineNo">1388</span>      this(new FSDataInputStreamWrapper(istream), fileSize, null, null, fileContext);<a name="line.1388"></a>
+<span class="sourceLineNo">1389</span>    }<a name="line.1389"></a>
+<span class="sourceLineNo">1390</span><a name="line.1390"></a>
+<span class="sourceLineNo">1391</span>    public BlockIterator blockRange(final long startOffset, final long endOffset) {<a name="line.1391"></a>
+<span class="sourceLineNo">1392</span>      final FSReader owner = this; // handle for inner class<a name="line.1392"></a>
+<span class="sourceLineNo">1393</span>      return new BlockIterator() {<a name="line.1393"></a>
+<span class="sourceLineNo">1394</span>        private long offset = startOffset;<a name="line.1394"></a>
+<span class="sourceLineNo">1395</span><a name="line.1395"></a>
+<span class="sourceLineNo">1396</span>        @Override<a name="line.1396"></a>
+<span class="sourceLineNo">1397</span>        public HFileBlock nextBlock() throws IOException {<a name="line.1397"></a>
+<span class="sourceLineNo">1398</span>          if (offset &gt;= endOffset)<a name="line.1398"></a>
+<span class="sourceLineNo">1399</span>            return null;<a name="line.1399"></a>
+<span class="sourceLineNo">1400</span>          HFileBlock b = readBlockData(offset, -1, -1, false);<a name="line.1400"></a>
+<span class="sourceLineNo">1401</span>          offset += b.getOnDiskSizeWithHeader();<a name="line.1401"></a>
+<span class="sourceLineNo">1402</span>          return b.unpack(fileContext, owner);<a name="line.1402"></a>
+<span class="sourceLineNo">1403</span>        }<a name="line.1403"></a>
+<span class="sourceLineNo">1404</span><a name="line.1404"></a>
+<span class="sourceLineNo">1405</span>        @Override<a name="line.1405"></a>
+<span class="sourceLineNo">1406</span>        public HFileBlock nextBlockWithBlockType(BlockType blockType)<a name="line.1406"></a>
+<span class="sourceLineNo">1407</span>            throws IOException {<a name="line.1407"></a>
+<span class="sourceLineNo">1408</span>          HFileBlock blk = nextBlock();<a name="line.1408"></a>
+<span class="sourceLineNo">1409</span>          if (blk.getBlockType() != blockType) {<a name="line.1409"></a>
+<span class="sourceLineNo">1410</span>            throw new IOException("Expected block of type " + blockType<a name="line.1410"></a>
+<span class="sourceLineNo">1411</span>                + " but found " + blk.getBlockType());<a name="line.1411"></a>
+<span class="sourceLineNo">1412</span>          }<a name="line.1412"></a>
+<span class="sourceLineNo">1413</span>          return blk;<a name="line.1413"></a>
+<span class="sourceLineNo">1414</span>        }<a name="line.1414"></a>
+<span class="sourceLineNo">1415</span>      };<a name="line.1415"></a>
+<span class="sourceLineNo">1416</span>    }<a name="line.1416"></a>
+<span class="sourceLineNo">1417</span><a name="line.1417"></a>
+<span class="sourceLineNo">1418</span>    /**<a name="line.1418"></a>
+<span class="sourceLineNo">1419</span>     * Does a positional read or a seek and read into the given buffer. Returns<a name="line.1419"></a>
+<span class="sourceLineNo">1420</span>     * the on-disk size of the next block, or -1 if it could not be determined.<a name="line.1420"></a>
+<span class="sourceLineNo">1421</span>     *<a name="line.1421"></a>
+<span class="sourceLineNo">1422</span>     * @param dest destination buffer<a name="line.1422"></a>
+<span class="sourceLineNo">1423</span>     * @param destOffset offset in the destination buffer<a name="line.1423"></a>
+<span class="sourceLineNo">1424</span>     * @param size size of the block to be read<a name="line.1424"></a>
+<span class="sourceLineNo">1425</span>     * @param peekIntoNextBlock whether to read the next block's on-disk size<a name="line.1425"></a>
+<span class="sourceLineNo">1426</span>     * @param fileOffset position in the stream to read at<a name="line.1426"></a>
+<span class="sourceLineNo">1427</span>     * @param pread whether we should do a positional read<a name="line.1427"></a>
+<span class="sourceLineNo">1428</span>     * @param istream The input source of data<a name="line.1428"></a>
+<span class="sourceLineNo">1429</span>     * @return the on-disk size of the next block with header size included, or<a name="line.1429"></a>
+<span class="sourceLineNo">1430</span>     *         -1 if it could not be determined<a name="line.1430"></a>
+<span class="sourceLineNo">1431</span>     * @throws IOException<a name="line.1431"></a>
+<span class="sourceLineNo">1432</span>     */<a name="line.1432"></a>
+<span class="sourceLineNo">1433</span>    protected int readAtOffset(FSDataInputStream istream,<a name="line.1433"></a>
+<span class="sourceLineNo">1434</span>        byte[] dest, int destOffset, int size,<a name="line.1434"></a>
+<span class="sourceLineNo">1435</span>        boolean peekIntoNextBlock, long fileOffset, boolean pread)<a name="line.1435"></a>
+<span class="sourceLineNo">1436</span>        throws IOException {<a name="line.1436"></a>
+<span class="sourceLineNo">1437</span>      if (peekIntoNextBlock &amp;&amp;<a name="line.1437"></a>
+<span class="sourceLineNo">1438</span>          destOffset + size + hdrSize &gt; dest.length) {<a name="line.1438"></a>
+<span class="sourceLineNo">1439</span>        // We are asked to read the next block's header as well, but there is<a name="line.1439"></a>
+<span class="sourceLineNo">1440</span>        // not enough room in the array.<a name="line.1440"></a>
+<span class="sourceLineNo">1441</span>        throw new IOException("Attempted to read " + size + " bytes and " +<a name="line.1441"></a>
+<span class="sourceLineNo">1442</span>            hdrSize + " bytes of next header into a " + dest.length +<a name="line.1442"></a>
+<span class="sourceLineNo">1443</span>            "-byte array at offset " + destOffset);<a name="line.1443"></a>
+<span class="sourceLineNo">1444</span>      }<a name="line.1444"></a>
+<span class="sourceLineNo">1445</span><a name="line.1445"></a>
+<span class="sourceLineNo">1446</span>      if (!pread &amp;&amp; streamLock.tryLock()) {<a name="line.1446"></a>
+<span class="sourceLineNo">1447</span>        // Seek + read. Better for scanning.<a name="line.1447"></a>
+<span class="sourceLineNo">1448</span>        try {<a name="line.1448"></a>
+<span class="sourceLineNo">1449</span>          istream.seek(fileOffset);<a name="line.1449"></a>
+<span class="sourceLineNo">1450</span><a name="line.1450"></a>
+<span class="sourceLineNo">1451</span>          long realOffset = istream.getPos();<a name="line.1451"></a>
+<span class="sourceLineNo">1452</span>          if (realOffset != fileOffset) {<a name="line.1452"></a>
+<span class="sourceLineNo">1453</span>            throw new IOException("Tried to seek to " + fileOffset + " to "<a name="line.1453"></a>
+<span class="sourceLineNo">1454</span>                + "read " + size + " bytes, but pos=" + realOffset<a name="line.1454"></a>
+<span class="sourceLineNo">1455</span>                + " after seek");<a name="line.1455"></a>
+<span class="sourceLineNo">1456</span>          }<a name="line.1456"></a>
+<span class="sourceLineNo">1457</span><a name="line.1457"></a>
+<span class="sourceLineNo">1458</span>          if (!peekIntoNextBlock) {<a name="line.1458"></a>
+<span class="sourceLineNo">1459</span>            IOUtils.readFully(istream, dest, destOffset, size);<a name="line.1459"></a>
+<span class="sourceLineNo">1460</span>            return -1;<a name="line.1460"></a>
+<span class="sourceLineNo">1461</span>          }<a name="line.1461"></a>
+<span class="sourceLineNo">1462</span><a name="line.1462"></a>
+<span class="sourceLineNo">1463</span>          // Try to read the next block header.<a name="line.1463"></a>
+<span class="sourceLineNo">1464</span>          if (!readWithExtra(istream, dest, destOffset, size, hdrSize))<a name="line.1464"></a>
+<span class="sourceLineNo">1465</span>            return -1;<a name="line.1465"></a>
+<span class="sourceLineNo">1466</span>        } finally {<a name="line.1466"></a>
+<span class="sourceLineNo">1467</span>          streamLock.unlock();<a name="line.1467"></a>
+<span class="sourceLineNo">1468</span>        }<a name="line.1468"></a>
+<span class="sourceLineNo">1469</span>      } else {<a name="line.1469"></a>
+<span class="sourceLineNo">1470</span>        // Positional read. Better for random reads; or when the streamLock is already locked.<a name="line.1470"></a>
+<span class="sourceLineNo">1471</span>        int extraSize = peekIntoNextBlock ? hdrSize : 0;<a name="line.1471"></a>
+<span class="sourceLineNo">1472</span>        if (!positionalReadWithExtra(istream, fileOffset, dest, destOffset,<a name="line.1472"></a>
+<span class="sourceLineNo">1473</span>            size, extraSize)) {<a name="line.1473"></a>
+<span class="sourceLineNo">1474</span>          return -1;<a name="line.1474"></a>
+<span class="sourceLineNo">1475</span>        }<a name="line.1475"></a>
+<span class="sourceLineNo">1476</span>      }<a name="line.1476"></a>
+<span class="sourceLineNo">1477</span><a name="line.1477"></a>
+<span class="sourceLineNo">1478</span>      assert peekIntoNextBlock;<a name="line.1478"></a>
+<span class="sourceLineNo">1479</span>      return Bytes.toInt(dest, destOffset + size + BlockType.MAGIC_LENGTH) + hdrSize;<a name="line.1479"></a>
+<span class="sourceLineNo">1480</span>    }<a name="line.1480"></a>
+<span class="sourceLineNo">1481</span><a name="line.1481"></a>
+<span class="sourceLineNo">1482</span>    /**<a name="line.1482"></a>
+<span class="sourceLineNo">1483</span>     * Reads a version 2 block (version 1 blocks not supported and not expected). Tries to do as<a name="line.1483"></a>
+<span class="sourceLineNo">1484</span>     * little memory allocation as possible, using the provided on-disk size.<a name="line.1484"></a>
+<span class="sourceLineNo">1485</span>     *<a name="line.1485"></a>
+<span class="sourceLineNo">1486</span>     * @param offset the offset in the stream to read at<a name="line.1486"></a>
+<span class="sourceLineNo">1487</span>     * @param onDiskSizeWithHeaderL the on-disk size of the block, including<a name="line.1487"></a>
+<span class="sourceLineNo">1488</span>     *          the header, or -1 if unknown<a name="line.1488"></a>
+<span class="sourceLineNo">1489</span>     * @param uncompressedSize the uncompressed size of the the block. Always<a name="line.1489"></a>
+<span class="sourceLineNo">1490</span>     *          expected to be -1. This parameter is only used in version 1.<a name="line.1490"></a>
+<span class="sourceLineNo">1491</span>     * @param pread whether to use a positional read<a name="line.1491"></a>
+<span class="sourceLineNo">1492</span>     */<a name="line.1492"></a>
+<span class="sourceLineNo">1493</span>    @Override<a name="line.1493"></a>
+<span class="sourceLineNo">1494</span>    public HFileBlock readBlockData(long offset, long onDiskSizeWithHeaderL,<a name="line.1494"></a>
+<span class="sourceLineNo">1495</span>        int uncompressedSize, boolean pread)<a name="line.1495"></a>
+<span class="sourceLineNo">1496</span>    throws IOException {<a name="line.1496"></a>
+<span class="sourceLineNo">1497</span><a name="line.1497"></a>
+<span class="sourceLineNo">1498</span>      // get a copy of the current state of whether to validate<a name="line.1498"></a>
+<span class="sourceLineNo">1499</span>      // hbase checksums or not for this read call. This is not<a name="line.1499"></a>
+<span class="sourceLineNo">1500</span>      // thread-safe but the one constaint is that if we decide<a name="line.1500"></a>
+<span class="sourceLineNo">1501</span>      // to skip hbase checksum verification then we are<a name="line.1501"></a>
+<span class="sourceLineNo">1502</span>      // guaranteed to use hdfs checksum verification.<a name="line.1502"></a>
+<span class="sourceLineNo">1503</span>      boolean doVerificationThruHBaseChecksum = streamWrapper.shouldUseHBaseChecksum();<a name="line.1503"></a>
+<span class="sourceLineNo">1504</span>      FSDataInputStream is = streamWrapper.getStream(doVerificationThruHBaseChecksum);<a name="line.1504"></a>
+<span class="sourceLineNo">1505</span><a name="line.1505"></a>
+<span class="sourceLineNo">1506</span>      HFileBlock blk = readBlockDataInternal(is, offset,<a name="line.1506"></a>
+<span class="sourceLineNo">1507</span>                         onDiskSizeWithHeaderL,<a name="line.1507"></a>
+<span class="sourceLineNo">1508</span>                         uncompressedSize, pread,<a name="line.1508"></a>
+<span class="sourceLineNo">1509</span>                         doVerificationThruHBaseChecksum);<a name="line.1509"></a>
+<span class="sourceLineNo">1510</span>      if (blk == null) {<a name="line.1510"></a>
+<span class="sourceLineNo">1511</span>        HFile.LOG.warn("HBase checksum verification failed for file " +<a name="line.1511"></a>
+<span class="sourceLineNo">1512</span>                       pathName + " at offset " +<a name="line.1512"></a>
+<span class="sourceLineNo">1513</span>                       offset + " filesize " + fileSize +<a name="line.1513"></a>
+<span class="sourceLineNo">1514</span>                       ". Retrying read with HDFS checksums turned on...");<a name="line.1514"></a>
+<span class="sourceLineNo">1515</span><a name="line.1515"></a>
+<span class="sourceLineNo">1516</span>        if (!doVerificationThruHBaseChecksum) {<a name="line.1516"></a>
+<span class="sourceLineNo">1517</span>          String msg = "HBase checksum verification failed for file " +<a name="line.1517"></a>
+<span class="sourceLineNo">1518</span>                       pathName + " at offset " +<a name="line.1518"></a>
+<span class="sourceLineNo">1519</span>                       offset + " filesize " + fileSize +<a name="line.1519"></a>
+<span class="sourceLineNo">1520</span>                       " but this cannot happen because doVerify is " +<a name="line.1520"></a>
+<span class="sourceLineNo">1521</span>                       doVerificationThruHBaseChecksum;<a name="line.1521"></a>
+<span class="sourceLineNo">1522</span>          HFile.LOG.warn(msg);<a name="line.1522"></a>
+<span class="sourceLineNo">1523</span>          throw new IOException(msg); // cannot happen case here<a name="line.1523"></a>
+<span class="sourceLineNo">1524</span>        }<a name="line.1524"></a>
+<span class="sourceLineNo">1525</span>        HFile.checksumFailures.incrementAndGet(); // update metrics<a name="line.1525"></a>
+<span class="sourceLineNo">1526</span><a name="line.1526"></a>
+<span class="sourceLineNo">1527</span>        // If we have a checksum failure, we fall back into a mode where<a name="line.1527"></a>
+<span class="sourceLineNo">1528</span>        // the next few reads use HDFS level checksums. We aim to make the<a name="line.1528"></a>
+<span class="sourceLineNo">1529</span>        // next CHECKSUM_VERIFICATION_NUM_IO_THRESHOLD reads avoid<a name="line.1529"></a>
+<span class="sourceLineNo">1530</span>        // hbase checksum verification, but since this value is set without<a name="line.1530"></a>
+<span class="sourceLineNo">1531</span>        // holding any locks, it can so happen that we might actually do<a name="line.1531"></a>
+<span class="sourceLineNo">1532</span>        // a few more than precisely this number.<a name="line.1532"></a>
+<span class="sourceLineNo">1533</span>        is = this.streamWrapper.fallbackToFsChecksum(CHECKSUM_VERIFICATION_NUM_IO_THRESHOLD);<a name="line.1533"></a>
+<span class="sourceLineNo">1534</span>        doVerificationThruHBaseChecksum = false;<a name="line.1534"></a>
+<span class="sourceLineNo">1535</span>        blk = readBlockDataInternal(is, offset, onDiskSizeWithHeaderL,<a name="line.1535"></a>
+<span class="sourceLineNo">1536</span>                                    uncompressedSize, pread,<a name="line.1536"></a>
+<span class="sourceLineNo">1537</span>                                    doVerificationThruHBaseChecksum);<a name="line.1537"></a>
+<span class="sourceLineNo">1538</span>        if (blk != null) {<a name="line.1538"></a>
+<span class="sourceLineNo">1539</span>          HFile.LOG.warn("HDFS checksum verification suceeded for file " +<a name="line.1539"></a>
+<span class="sourceLineNo">1540</span>                         pathName + " at offset " +<a name="line.1540"></a>
+<span class="sourceLineNo">1541</span>                         offset + " filesize " + fileSize);<a name="line.1541"></a>
+<span class="sourceLineNo">1542</span>        }<a name="line.1542"></a>
+<span class="sourceLineNo">1543</span>      }<a name="line.1543"></a>
+<span class="sourceLineNo">1544</span>      if (blk == null &amp;&amp; !doVerificationThruHBaseChecksum) {<a name="line.1544"></a>
+<span class="sourceLineNo">1545</span>        String msg = "readBlockData failed, possibly due to " +<a name="line.1545"></a>
+<span class="sourceLineNo">1546</span>                     "checksum verification failed for file " + pathName +<a name="line.1546"></a>
+<span class="sourceLineNo">1547</span>                     " at offset " + offset + " filesize " + fileSize;<a name="line.1547"></a>
+<span class="sourceLineNo">1548</span>        HFile.LOG.warn(msg);<a name="line.1548"></a>
+<span class="sourceLineNo">1549</span>        throw new IOException(msg);<a name="line.1549"></a>
+<span class="sourceLineNo">1550</span>      }<a name="line.1550"></a>
+<span class="sourceLineNo">1551</span><a name="line.1551"></a>
+<span class="sourceLineNo">1552</span>      // If there is a checksum mismatch earlier, then retry with<a name="line.1552"></a>
+<span class="sourceLineNo">1553</span>      // HBase checksums switched off and use HDFS checksum verification.<a name="line.1553"></a>
+<span class="sourceLineNo">1554</span>      // This triggers HDFS to detect and fix corrupt replicas. The<a name="line.1554"></a>
+<span class="sourceLineNo">1555</span>      // next checksumOffCount read requests will use HDFS checksums.<a name="line.1555"></a>
+<span class="sourceLineNo">1556</span>      // The decrementing of this.checksumOffCount is not thread-safe,<a name="line.1556"></a>
+<span class="sourceLineNo">1557</span>      // but it is harmless because eventually checksumOffCount will be<a name="line.1557"></a>
+<span class="sourceLineNo">1558</span>      // a negative number.<a name="line.1558"></a>
+<span class="sourceLineNo">1559</span>      streamWrapper.checksumOk();<a name="line.1559"></a>
+<span class="sourceLineNo">1560</span>      return blk;<a name="line.1560"></a>
+<span class="sourceLineNo">1561</span>    }<a name="line.1561"></a>
+<span class="sourceLineNo">1562</span><a name="line.1562"></a>
+<span class="sourceLineNo">1563</span>    /**<a name="line.1563"></a>
+<span class="sourceLineNo">1564</span>     * Reads a version 2 block.<a name="line.1564"></a>
+<span class="sourceLineNo">1565</span>     *<a name="line.1565"></a>
+<span class="sourceLineNo">1566</span>     * @param offset the offset in the stream to read at<a name="line.1566"></a>
+<span class="sourceLineNo">1567</span>     * @param onDiskSizeWithHeaderL the on-disk size of the block, including<a name="line.1567"></a>
+<span class="sourceLineNo">1568</span>     *          the header, or -1 if unknown<a name="line.1568"></a>
+<span class="sourceLineNo">1569</span>     * @param uncompressedSize the uncompressed size of the the block. Always<a name="line.1569"></a>
+<span class="sourceLineNo">1570</span>     *          expected to be -1. This parameter is only used in version 1.<a name="line.1570"></a>
+<span class="sourceLineNo">1571</span>     * @param pread whether to use a positional read<a name="line.1571"></a>
+<span class="sourceLineNo">1572</span>     * @param verifyChecksum Whether to use HBase checksums.<a name="line.1572"></a>
+<span class="sourceLineNo">1573</span>     *        If HBase checksum is switched off, then use HDFS checksum.<a name="line.1573"></a>
+<span class="sourceLineNo">1574</span>     * @return the HFileBlock or null if there is a HBase checksum mismatch<a name="line.1574"></a>
+<span class="sourceLineNo">1575</span>     */<a name="line.1575"></a>
+<span class="sourceLineNo">1576</span>    private HFileBlock readBlockDataInternal(FSDataInputStream is, long offset,<a name="line.1576"></a>
+<span class="sourceLineNo">1577</span>        long onDiskSizeWithHeaderL, int uncompressedSize, boolean pread,<a name="line.1577"></a>
+<span class="sourceLineNo">1578</span>        boolean verifyChecksum)<a name="line.1578"></a>
+<span class="sourceLineNo">1579</span>    throws IOException {<a name="line.1579"></a>
+<span class="sourceLineNo">1580</span>      if (offset &lt; 0) {<a name="line.1580"></a>
+<span class="sourceLineNo">1581</span>        throw new IOException("Invalid offset=" + offset + " trying to read "<a name="line.1581"></a>
+<span class="sourceLineNo">1582</span>            + "block (onDiskSize=" + onDiskSizeWithHeaderL<a name="line.1582"></a>
+<span class="sourceLineNo">1583</span>            + ", uncompressedSize=" + uncompressedSize + ")");<a name="line.1583"></a>
+<span class="sourceLineNo">1584</span>      }<a name="line.1584"></a>
+<span class="sourceLineNo">1585</span><a name="line.1585"></a>
+<span class="sourceLineNo">1586</span>      if (uncompressedSize != -1) {<a name="line.1586"></a>
+<span class="sourceLineNo">1587</span>        throw new IOException("Version 2 block reader API does not need " +<a name="line.1587"></a>
+<span class="sourceLineNo">1588</span>            "the uncompressed size parameter");<a name="line.1588"></a>
+<span class="sourceLineNo">1589</span>      }<a name="line.1589"></a>
+<span class="sourceLineNo">1590</span><a name="line.1590"></a>
+<span class="sourceLineNo">1591</span>      if ((onDiskSizeWithHeaderL &lt; hdrSize &amp;&amp; onDiskSizeWithHeaderL != -1)<a name="line.1591"></a>
+<span class="sourceLineNo">1592</span>          || onDiskSizeWithHeaderL &gt;= Integer.MAX_VALUE) {<a name="line.1592"></a>
+<span class="sourceLineNo">1593</span>        throw new IOException("Invalid onDisksize=" + onDiskSizeWithHeaderL<a name="line.1593"></a>
+<span class="sourceLineNo">1594</span>            + ": expected to be at least " + hdrSize<a name="line.1594"></a>
+<span class="sourceLineNo">1595</span>            + " and at most " + Integer.MAX_VALUE + ", or -1 (offset="<a name="line.1595"></a>
+<span class="sourceLineNo">1596</span>            + offset + ", uncompressedSize=" + uncompressedSize + ")");<a name="line.1596"></a>
+<span class="sourceLineNo">1597</span>      }<a name="line.1597"></a>
+<span class="sourceLineNo">1598</span><a name="line.1598"></a>
+<span class="sourceLineNo">1599</span>      int onDiskSizeWithHeader = (int) onDiskSizeWithHeaderL;<a name="line.1599"></a>
+<span class="sourceLineNo">1600</span>      // See if we can avoid reading the header. This is desirable, because<a name="line.1600"></a>
+<span class="

<TRUNCATED>

Mime
View raw message