hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [11/26] hbase-site git commit: Published site at 219625233c1e8ad9daf2c35bc2e3a0844e1b97ba.
Date Tue, 03 Apr 2018 14:47:56 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/21347dff/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileBlock.Writer.State.html
----------------------------------------------------------------------
diff --git a/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileBlock.Writer.State.html b/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileBlock.Writer.State.html
index 12d10e1..97ceefd 100644
--- a/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileBlock.Writer.State.html
+++ b/devapidocs/src-html/org/apache/hadoop/hbase/io/hfile/HFileBlock.Writer.State.html
@@ -1740,384 +1740,380 @@
 <span class="sourceLineNo">1732</span>      // and will save us having to seek the stream backwards to reread the header we<a name="line.1732"></a>
 <span class="sourceLineNo">1733</span>      // read the last time through here.<a name="line.1733"></a>
 <span class="sourceLineNo">1734</span>      ByteBuffer headerBuf = getCachedHeader(offset);<a name="line.1734"></a>
-<span class="sourceLineNo">1735</span>      if (LOG.isTraceEnabled()) {<a name="line.1735"></a>
-<span class="sourceLineNo">1736</span>        LOG.trace("Reading " + this.fileContext.getHFileName() + " at offset=" + offset +<a name="line.1736"></a>
-<span class="sourceLineNo">1737</span>          ", pread=" + pread + ", verifyChecksum=" + verifyChecksum + ", cachedHeader=" +<a name="line.1737"></a>
-<span class="sourceLineNo">1738</span>          headerBuf + ", onDiskSizeWithHeader=" + onDiskSizeWithHeader);<a name="line.1738"></a>
-<span class="sourceLineNo">1739</span>      }<a name="line.1739"></a>
-<span class="sourceLineNo">1740</span>      // This is NOT same as verifyChecksum. This latter is whether to do hbase<a name="line.1740"></a>
-<span class="sourceLineNo">1741</span>      // checksums. Can change with circumstances. The below flag is whether the<a name="line.1741"></a>
-<span class="sourceLineNo">1742</span>      // file has support for checksums (version 2+).<a name="line.1742"></a>
-<span class="sourceLineNo">1743</span>      boolean checksumSupport = this.fileContext.isUseHBaseChecksum();<a name="line.1743"></a>
-<span class="sourceLineNo">1744</span>      long startTime = System.currentTimeMillis();<a name="line.1744"></a>
-<span class="sourceLineNo">1745</span>      if (onDiskSizeWithHeader &lt;= 0) {<a name="line.1745"></a>
-<span class="sourceLineNo">1746</span>        // We were not passed the block size. Need to get it from the header. If header was<a name="line.1746"></a>
-<span class="sourceLineNo">1747</span>        // not cached (see getCachedHeader above), need to seek to pull it in. This is costly<a name="line.1747"></a>
-<span class="sourceLineNo">1748</span>        // and should happen very rarely. Currently happens on open of a hfile reader where we<a name="line.1748"></a>
-<span class="sourceLineNo">1749</span>        // read the trailer blocks to pull in the indices. Otherwise, we are reading block sizes<a name="line.1749"></a>
-<span class="sourceLineNo">1750</span>        // out of the hfile index. To check, enable TRACE in this file and you'll get an exception<a name="line.1750"></a>
-<span class="sourceLineNo">1751</span>        // in a LOG every time we seek. See HBASE-17072 for more detail.<a name="line.1751"></a>
-<span class="sourceLineNo">1752</span>        if (headerBuf == null) {<a name="line.1752"></a>
-<span class="sourceLineNo">1753</span>          if (LOG.isTraceEnabled()) {<a name="line.1753"></a>
-<span class="sourceLineNo">1754</span>            LOG.trace("Extra see to get block size!", new RuntimeException());<a name="line.1754"></a>
-<span class="sourceLineNo">1755</span>          }<a name="line.1755"></a>
-<span class="sourceLineNo">1756</span>          headerBuf = ByteBuffer.allocate(hdrSize);<a name="line.1756"></a>
-<span class="sourceLineNo">1757</span>          readAtOffset(is, headerBuf.array(), headerBuf.arrayOffset(), hdrSize, false,<a name="line.1757"></a>
-<span class="sourceLineNo">1758</span>              offset, pread);<a name="line.1758"></a>
-<span class="sourceLineNo">1759</span>        }<a name="line.1759"></a>
-<span class="sourceLineNo">1760</span>        onDiskSizeWithHeader = getOnDiskSizeWithHeader(headerBuf, checksumSupport);<a name="line.1760"></a>
-<span class="sourceLineNo">1761</span>      }<a name="line.1761"></a>
-<span class="sourceLineNo">1762</span>      int preReadHeaderSize = headerBuf == null? 0 : hdrSize;<a name="line.1762"></a>
-<span class="sourceLineNo">1763</span>      // Allocate enough space to fit the next block's header too; saves a seek next time through.<a name="line.1763"></a>
-<span class="sourceLineNo">1764</span>      // onDiskBlock is whole block + header + checksums then extra hdrSize to read next header;<a name="line.1764"></a>
-<span class="sourceLineNo">1765</span>      // onDiskSizeWithHeader is header, body, and any checksums if present. preReadHeaderSize<a name="line.1765"></a>
-<span class="sourceLineNo">1766</span>      // says where to start reading. If we have the header cached, then we don't need to read<a name="line.1766"></a>
-<span class="sourceLineNo">1767</span>      // it again and we can likely read from last place we left off w/o need to backup and reread<a name="line.1767"></a>
-<span class="sourceLineNo">1768</span>      // the header we read last time through here.<a name="line.1768"></a>
-<span class="sourceLineNo">1769</span>      // TODO: Make this ByteBuffer-based. Will make it easier to go to HDFS with BBPool (offheap).<a name="line.1769"></a>
-<span class="sourceLineNo">1770</span>      byte [] onDiskBlock = new byte[onDiskSizeWithHeader + hdrSize];<a name="line.1770"></a>
-<span class="sourceLineNo">1771</span>      int nextBlockOnDiskSize = readAtOffset(is, onDiskBlock, preReadHeaderSize,<a name="line.1771"></a>
-<span class="sourceLineNo">1772</span>          onDiskSizeWithHeader - preReadHeaderSize, true, offset + preReadHeaderSize, pread);<a name="line.1772"></a>
-<span class="sourceLineNo">1773</span>      if (headerBuf != null) {<a name="line.1773"></a>
-<span class="sourceLineNo">1774</span>        // The header has been read when reading the previous block OR in a distinct header-only<a name="line.1774"></a>
-<span class="sourceLineNo">1775</span>        // read. Copy to this block's header.<a name="line.1775"></a>
-<span class="sourceLineNo">1776</span>        System.arraycopy(headerBuf.array(), headerBuf.arrayOffset(), onDiskBlock, 0, hdrSize);<a name="line.1776"></a>
-<span class="sourceLineNo">1777</span>      } else {<a name="line.1777"></a>
-<span class="sourceLineNo">1778</span>        headerBuf = ByteBuffer.wrap(onDiskBlock, 0, hdrSize);<a name="line.1778"></a>
-<span class="sourceLineNo">1779</span>      }<a name="line.1779"></a>
-<span class="sourceLineNo">1780</span>      // Do a few checks before we go instantiate HFileBlock.<a name="line.1780"></a>
-<span class="sourceLineNo">1781</span>      assert onDiskSizeWithHeader &gt; this.hdrSize;<a name="line.1781"></a>
-<span class="sourceLineNo">1782</span>      verifyOnDiskSizeMatchesHeader(onDiskSizeWithHeader, headerBuf, offset, checksumSupport);<a name="line.1782"></a>
-<span class="sourceLineNo">1783</span>      ByteBuffer onDiskBlockByteBuffer = ByteBuffer.wrap(onDiskBlock, 0, onDiskSizeWithHeader);<a name="line.1783"></a>
-<span class="sourceLineNo">1784</span>      // Verify checksum of the data before using it for building HFileBlock.<a name="line.1784"></a>
-<span class="sourceLineNo">1785</span>      if (verifyChecksum &amp;&amp;<a name="line.1785"></a>
-<span class="sourceLineNo">1786</span>          !validateChecksum(offset, onDiskBlockByteBuffer, hdrSize)) {<a name="line.1786"></a>
-<span class="sourceLineNo">1787</span>        return null;<a name="line.1787"></a>
-<span class="sourceLineNo">1788</span>      }<a name="line.1788"></a>
-<span class="sourceLineNo">1789</span>      long duration = System.currentTimeMillis() - startTime;<a name="line.1789"></a>
-<span class="sourceLineNo">1790</span>      if (updateMetrics) {<a name="line.1790"></a>
-<span class="sourceLineNo">1791</span>        HFile.updateReadLatency(duration, pread);<a name="line.1791"></a>
-<span class="sourceLineNo">1792</span>      }<a name="line.1792"></a>
-<span class="sourceLineNo">1793</span>      // The onDiskBlock will become the headerAndDataBuffer for this block.<a name="line.1793"></a>
-<span class="sourceLineNo">1794</span>      // If nextBlockOnDiskSizeWithHeader is not zero, the onDiskBlock already<a name="line.1794"></a>
-<span class="sourceLineNo">1795</span>      // contains the header of next block, so no need to set next block's header in it.<a name="line.1795"></a>
-<span class="sourceLineNo">1796</span>      HFileBlock hFileBlock =<a name="line.1796"></a>
-<span class="sourceLineNo">1797</span>          new HFileBlock(new SingleByteBuff(onDiskBlockByteBuffer), checksumSupport,<a name="line.1797"></a>
-<span class="sourceLineNo">1798</span>              MemoryType.EXCLUSIVE, offset, nextBlockOnDiskSize, fileContext);<a name="line.1798"></a>
-<span class="sourceLineNo">1799</span>      // Run check on uncompressed sizings.<a name="line.1799"></a>
-<span class="sourceLineNo">1800</span>      if (!fileContext.isCompressedOrEncrypted()) {<a name="line.1800"></a>
-<span class="sourceLineNo">1801</span>        hFileBlock.sanityCheckUncompressed();<a name="line.1801"></a>
-<span class="sourceLineNo">1802</span>      }<a name="line.1802"></a>
-<span class="sourceLineNo">1803</span>      if (LOG.isTraceEnabled()) {<a name="line.1803"></a>
-<span class="sourceLineNo">1804</span>        LOG.trace("Read " + hFileBlock + " in " + duration + " ns");<a name="line.1804"></a>
-<span class="sourceLineNo">1805</span>      }<a name="line.1805"></a>
-<span class="sourceLineNo">1806</span>      // Cache next block header if we read it for the next time through here.<a name="line.1806"></a>
-<span class="sourceLineNo">1807</span>      if (nextBlockOnDiskSize != -1) {<a name="line.1807"></a>
-<span class="sourceLineNo">1808</span>        cacheNextBlockHeader(offset + hFileBlock.getOnDiskSizeWithHeader(),<a name="line.1808"></a>
-<span class="sourceLineNo">1809</span>            onDiskBlock, onDiskSizeWithHeader, hdrSize);<a name="line.1809"></a>
-<span class="sourceLineNo">1810</span>      }<a name="line.1810"></a>
-<span class="sourceLineNo">1811</span>      return hFileBlock;<a name="line.1811"></a>
-<span class="sourceLineNo">1812</span>    }<a name="line.1812"></a>
-<span class="sourceLineNo">1813</span><a name="line.1813"></a>
-<span class="sourceLineNo">1814</span>    @Override<a name="line.1814"></a>
-<span class="sourceLineNo">1815</span>    public void setIncludesMemStoreTS(boolean includesMemstoreTS) {<a name="line.1815"></a>
-<span class="sourceLineNo">1816</span>      this.fileContext.setIncludesMvcc(includesMemstoreTS);<a name="line.1816"></a>
-<span class="sourceLineNo">1817</span>    }<a name="line.1817"></a>
-<span class="sourceLineNo">1818</span><a name="line.1818"></a>
-<span class="sourceLineNo">1819</span>    @Override<a name="line.1819"></a>
-<span class="sourceLineNo">1820</span>    public void setDataBlockEncoder(HFileDataBlockEncoder encoder) {<a name="line.1820"></a>
-<span class="sourceLineNo">1821</span>      encodedBlockDecodingCtx = encoder.newDataBlockDecodingContext(this.fileContext);<a name="line.1821"></a>
-<span class="sourceLineNo">1822</span>    }<a name="line.1822"></a>
-<span class="sourceLineNo">1823</span><a name="line.1823"></a>
-<span class="sourceLineNo">1824</span>    @Override<a name="line.1824"></a>
-<span class="sourceLineNo">1825</span>    public HFileBlockDecodingContext getBlockDecodingContext() {<a name="line.1825"></a>
-<span class="sourceLineNo">1826</span>      return this.encodedBlockDecodingCtx;<a name="line.1826"></a>
-<span class="sourceLineNo">1827</span>    }<a name="line.1827"></a>
-<span class="sourceLineNo">1828</span><a name="line.1828"></a>
-<span class="sourceLineNo">1829</span>    @Override<a name="line.1829"></a>
-<span class="sourceLineNo">1830</span>    public HFileBlockDecodingContext getDefaultBlockDecodingContext() {<a name="line.1830"></a>
-<span class="sourceLineNo">1831</span>      return this.defaultDecodingCtx;<a name="line.1831"></a>
-<span class="sourceLineNo">1832</span>    }<a name="line.1832"></a>
-<span class="sourceLineNo">1833</span><a name="line.1833"></a>
-<span class="sourceLineNo">1834</span>    /**<a name="line.1834"></a>
-<span class="sourceLineNo">1835</span>     * Generates the checksum for the header as well as the data and then validates it.<a name="line.1835"></a>
-<span class="sourceLineNo">1836</span>     * If the block doesn't uses checksum, returns false.<a name="line.1836"></a>
-<span class="sourceLineNo">1837</span>     * @return True if checksum matches, else false.<a name="line.1837"></a>
-<span class="sourceLineNo">1838</span>     */<a name="line.1838"></a>
-<span class="sourceLineNo">1839</span>    private boolean validateChecksum(long offset, ByteBuffer data, int hdrSize)<a name="line.1839"></a>
-<span class="sourceLineNo">1840</span>        throws IOException {<a name="line.1840"></a>
-<span class="sourceLineNo">1841</span>      // If this is an older version of the block that does not have checksums, then return false<a name="line.1841"></a>
-<span class="sourceLineNo">1842</span>      // indicating that checksum verification did not succeed. Actually, this method should never<a name="line.1842"></a>
-<span class="sourceLineNo">1843</span>      // be called when the minorVersion is 0, thus this is a defensive check for a cannot-happen<a name="line.1843"></a>
-<span class="sourceLineNo">1844</span>      // case. Since this is a cannot-happen case, it is better to return false to indicate a<a name="line.1844"></a>
-<span class="sourceLineNo">1845</span>      // checksum validation failure.<a name="line.1845"></a>
-<span class="sourceLineNo">1846</span>      if (!fileContext.isUseHBaseChecksum()) {<a name="line.1846"></a>
-<span class="sourceLineNo">1847</span>        return false;<a name="line.1847"></a>
-<span class="sourceLineNo">1848</span>      }<a name="line.1848"></a>
-<span class="sourceLineNo">1849</span>      return ChecksumUtil.validateChecksum(data, pathName, offset, hdrSize);<a name="line.1849"></a>
-<span class="sourceLineNo">1850</span>    }<a name="line.1850"></a>
-<span class="sourceLineNo">1851</span><a name="line.1851"></a>
-<span class="sourceLineNo">1852</span>    @Override<a name="line.1852"></a>
-<span class="sourceLineNo">1853</span>    public void closeStreams() throws IOException {<a name="line.1853"></a>
-<span class="sourceLineNo">1854</span>      streamWrapper.close();<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>    @Override<a name="line.1857"></a>
-<span class="sourceLineNo">1858</span>    public void unbufferStream() {<a name="line.1858"></a>
-<span class="sourceLineNo">1859</span>      // To handle concurrent reads, ensure that no other client is accessing the streams while we<a name="line.1859"></a>
-<span class="sourceLineNo">1860</span>      // unbuffer it.<a name="line.1860"></a>
-<span class="sourceLineNo">1861</span>      if (streamLock.tryLock()) {<a name="line.1861"></a>
-<span class="sourceLineNo">1862</span>        try {<a name="line.1862"></a>
-<span class="sourceLineNo">1863</span>          this.streamWrapper.unbuffer();<a name="line.1863"></a>
-<span class="sourceLineNo">1864</span>        } finally {<a name="line.1864"></a>
-<span class="sourceLineNo">1865</span>          streamLock.unlock();<a name="line.1865"></a>
-<span class="sourceLineNo">1866</span>        }<a name="line.1866"></a>
-<span class="sourceLineNo">1867</span>      }<a name="line.1867"></a>
-<span class="sourceLineNo">1868</span>    }<a name="line.1868"></a>
-<span class="sourceLineNo">1869</span><a name="line.1869"></a>
-<span class="sourceLineNo">1870</span>    @Override<a name="line.1870"></a>
-<span class="sourceLineNo">1871</span>    public String toString() {<a name="line.1871"></a>
-<span class="sourceLineNo">1872</span>      return "hfs=" + hfs + ", path=" + pathName + ", fileContext=" + fileContext;<a name="line.1872"></a>
-<span class="sourceLineNo">1873</span>    }<a name="line.1873"></a>
-<span class="sourceLineNo">1874</span>  }<a name="line.1874"></a>
-<span class="sourceLineNo">1875</span><a name="line.1875"></a>
-<span class="sourceLineNo">1876</span>  /** An additional sanity-check in case no compression or encryption is being used. */<a name="line.1876"></a>
-<span class="sourceLineNo">1877</span>  @VisibleForTesting<a name="line.1877"></a>
-<span class="sourceLineNo">1878</span>  void sanityCheckUncompressed() throws IOException {<a name="line.1878"></a>
-<span class="sourceLineNo">1879</span>    if (onDiskSizeWithoutHeader != uncompressedSizeWithoutHeader +<a name="line.1879"></a>
-<span class="sourceLineNo">1880</span>        totalChecksumBytes()) {<a name="line.1880"></a>
-<span class="sourceLineNo">1881</span>      throw new IOException("Using no compression but "<a name="line.1881"></a>
-<span class="sourceLineNo">1882</span>          + "onDiskSizeWithoutHeader=" + onDiskSizeWithoutHeader + ", "<a name="line.1882"></a>
-<span class="sourceLineNo">1883</span>          + "uncompressedSizeWithoutHeader=" + uncompressedSizeWithoutHeader<a name="line.1883"></a>
-<span class="sourceLineNo">1884</span>          + ", numChecksumbytes=" + totalChecksumBytes());<a name="line.1884"></a>
-<span class="sourceLineNo">1885</span>    }<a name="line.1885"></a>
-<span class="sourceLineNo">1886</span>  }<a name="line.1886"></a>
-<span class="sourceLineNo">1887</span><a name="line.1887"></a>
-<span class="sourceLineNo">1888</span>  // Cacheable implementation<a name="line.1888"></a>
-<span class="sourceLineNo">1889</span>  @Override<a name="line.1889"></a>
-<span class="sourceLineNo">1890</span>  public int getSerializedLength() {<a name="line.1890"></a>
-<span class="sourceLineNo">1891</span>    if (buf != null) {<a name="line.1891"></a>
-<span class="sourceLineNo">1892</span>      // Include extra bytes for block metadata.<a name="line.1892"></a>
-<span class="sourceLineNo">1893</span>      return this.buf.limit() + BLOCK_METADATA_SPACE;<a name="line.1893"></a>
-<span class="sourceLineNo">1894</span>    }<a name="line.1894"></a>
-<span class="sourceLineNo">1895</span>    return 0;<a name="line.1895"></a>
-<span class="sourceLineNo">1896</span>  }<a name="line.1896"></a>
-<span class="sourceLineNo">1897</span><a name="line.1897"></a>
-<span class="sourceLineNo">1898</span>  // Cacheable implementation<a name="line.1898"></a>
-<span class="sourceLineNo">1899</span>  @Override<a name="line.1899"></a>
-<span class="sourceLineNo">1900</span>  public void serialize(ByteBuffer destination) {<a name="line.1900"></a>
-<span class="sourceLineNo">1901</span>    // BE CAREFUL!! There is a custom version of this serialization over in BucketCache#doDrain.<a name="line.1901"></a>
-<span class="sourceLineNo">1902</span>    // Make sure any changes in here are reflected over there.<a name="line.1902"></a>
-<span class="sourceLineNo">1903</span>    this.buf.get(destination, 0, getSerializedLength() - BLOCK_METADATA_SPACE);<a name="line.1903"></a>
-<span class="sourceLineNo">1904</span>    destination = addMetaData(destination);<a name="line.1904"></a>
-<span class="sourceLineNo">1905</span><a name="line.1905"></a>
-<span class="sourceLineNo">1906</span>    // Make it ready for reading. flip sets position to zero and limit to current position which<a name="line.1906"></a>
-<span class="sourceLineNo">1907</span>    // is what we want if we do not want to serialize the block plus checksums if present plus<a name="line.1907"></a>
-<span class="sourceLineNo">1908</span>    // metadata.<a name="line.1908"></a>
-<span class="sourceLineNo">1909</span>    destination.flip();<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>   * For use by bucketcache. This exposes internals.<a name="line.1913"></a>
-<span class="sourceLineNo">1914</span>   */<a name="line.1914"></a>
-<span class="sourceLineNo">1915</span>  public ByteBuffer getMetaData() {<a name="line.1915"></a>
-<span class="sourceLineNo">1916</span>    ByteBuffer bb = ByteBuffer.allocate(BLOCK_METADATA_SPACE);<a name="line.1916"></a>
-<span class="sourceLineNo">1917</span>    bb = addMetaData(bb);<a name="line.1917"></a>
-<span class="sourceLineNo">1918</span>    bb.flip();<a name="line.1918"></a>
-<span class="sourceLineNo">1919</span>    return bb;<a name="line.1919"></a>
-<span class="sourceLineNo">1920</span>  }<a name="line.1920"></a>
-<span class="sourceLineNo">1921</span><a name="line.1921"></a>
-<span class="sourceLineNo">1922</span>  /**<a name="line.1922"></a>
-<span class="sourceLineNo">1923</span>   * Adds metadata at current position (position is moved forward). Does not flip or reset.<a name="line.1923"></a>
-<span class="sourceLineNo">1924</span>   * @return The passed &lt;code&gt;destination&lt;/code&gt; with metadata added.<a name="line.1924"></a>
-<span class="sourceLineNo">1925</span>   */<a name="line.1925"></a>
-<span class="sourceLineNo">1926</span>  private ByteBuffer addMetaData(final ByteBuffer destination) {<a name="line.1926"></a>
-<span class="sourceLineNo">1927</span>    destination.put(this.fileContext.isUseHBaseChecksum() ? (byte) 1 : (byte) 0);<a name="line.1927"></a>
-<span class="sourceLineNo">1928</span>    destination.putLong(this.offset);<a name="line.1928"></a>
-<span class="sourceLineNo">1929</span>    destination.putInt(this.nextBlockOnDiskSize);<a name="line.1929"></a>
-<span class="sourceLineNo">1930</span>    return destination;<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>  // Cacheable implementation<a name="line.1933"></a>
-<span class="sourceLineNo">1934</span>  @Override<a name="line.1934"></a>
-<span class="sourceLineNo">1935</span>  public CacheableDeserializer&lt;Cacheable&gt; getDeserializer() {<a name="line.1935"></a>
-<span class="sourceLineNo">1936</span>    return HFileBlock.BLOCK_DESERIALIZER;<a name="line.1936"></a>
-<span class="sourceLineNo">1937</span>  }<a name="line.1937"></a>
-<span class="sourceLineNo">1938</span><a name="line.1938"></a>
-<span class="sourceLineNo">1939</span>  @Override<a name="line.1939"></a>
-<span class="sourceLineNo">1940</span>  public int hashCode() {<a name="line.1940"></a>
-<span class="sourceLineNo">1941</span>    int result = 1;<a name="line.1941"></a>
-<span class="sourceLineNo">1942</span>    result = result * 31 + blockType.hashCode();<a name="line.1942"></a>
-<span class="sourceLineNo">1943</span>    result = result * 31 + nextBlockOnDiskSize;<a name="line.1943"></a>
-<span class="sourceLineNo">1944</span>    result = result * 31 + (int) (offset ^ (offset &gt;&gt;&gt; 32));<a name="line.1944"></a>
-<span class="sourceLineNo">1945</span>    result = result * 31 + onDiskSizeWithoutHeader;<a name="line.1945"></a>
-<span class="sourceLineNo">1946</span>    result = result * 31 + (int) (prevBlockOffset ^ (prevBlockOffset &gt;&gt;&gt; 32));<a name="line.1946"></a>
-<span class="sourceLineNo">1947</span>    result = result * 31 + uncompressedSizeWithoutHeader;<a name="line.1947"></a>
-<span class="sourceLineNo">1948</span>    result = result * 31 + buf.hashCode();<a name="line.1948"></a>
-<span class="sourceLineNo">1949</span>    return result;<a name="line.1949"></a>
-<span class="sourceLineNo">1950</span>  }<a name="line.1950"></a>
-<span class="sourceLineNo">1951</span><a name="line.1951"></a>
-<span class="sourceLineNo">1952</span>  @Override<a name="line.1952"></a>
-<span class="sourceLineNo">1953</span>  public boolean equals(Object comparison) {<a name="line.1953"></a>
-<span class="sourceLineNo">1954</span>    if (this == comparison) {<a name="line.1954"></a>
-<span class="sourceLineNo">1955</span>      return true;<a name="line.1955"></a>
-<span class="sourceLineNo">1956</span>    }<a name="line.1956"></a>
-<span class="sourceLineNo">1957</span>    if (comparison == null) {<a name="line.1957"></a>
-<span class="sourceLineNo">1958</span>      return false;<a name="line.1958"></a>
-<span class="sourceLineNo">1959</span>    }<a name="line.1959"></a>
-<span class="sourceLineNo">1960</span>    if (comparison.getClass() != this.getClass()) {<a name="line.1960"></a>
-<span class="sourceLineNo">1961</span>      return false;<a name="line.1961"></a>
-<span class="sourceLineNo">1962</span>    }<a name="line.1962"></a>
-<span class="sourceLineNo">1963</span><a name="line.1963"></a>
-<span class="sourceLineNo">1964</span>    HFileBlock castedComparison = (HFileBlock) comparison;<a name="line.1964"></a>
-<span class="sourceLineNo">1965</span><a name="line.1965"></a>
-<span class="sourceLineNo">1966</span>    if (castedComparison.blockType != this.blockType) {<a name="line.1966"></a>
-<span class="sourceLineNo">1967</span>      return false;<a name="line.1967"></a>
-<span class="sourceLineNo">1968</span>    }<a name="line.1968"></a>
-<span class="sourceLineNo">1969</span>    if (castedComparison.nextBlockOnDiskSize != this.nextBlockOnDiskSize) {<a name="line.1969"></a>
+<span class="sourceLineNo">1735</span>      LOG.trace("Reading {} at offset={}, pread={}, verifyChecksum={}, cachedHeader={}, " +<a name="line.1735"></a>
+<span class="sourceLineNo">1736</span>          "onDiskSizeWithHeader={}", this.fileContext.getHFileName(), offset, pread,<a name="line.1736"></a>
+<span class="sourceLineNo">1737</span>          verifyChecksum, headerBuf, onDiskSizeWithHeader);<a name="line.1737"></a>
+<span class="sourceLineNo">1738</span>      // This is NOT same as verifyChecksum. This latter is whether to do hbase<a name="line.1738"></a>
+<span class="sourceLineNo">1739</span>      // checksums. Can change with circumstances. The below flag is whether the<a name="line.1739"></a>
+<span class="sourceLineNo">1740</span>      // file has support for checksums (version 2+).<a name="line.1740"></a>
+<span class="sourceLineNo">1741</span>      boolean checksumSupport = this.fileContext.isUseHBaseChecksum();<a name="line.1741"></a>
+<span class="sourceLineNo">1742</span>      long startTime = System.currentTimeMillis();<a name="line.1742"></a>
+<span class="sourceLineNo">1743</span>      if (onDiskSizeWithHeader &lt;= 0) {<a name="line.1743"></a>
+<span class="sourceLineNo">1744</span>        // We were not passed the block size. Need to get it from the header. If header was<a name="line.1744"></a>
+<span class="sourceLineNo">1745</span>        // not cached (see getCachedHeader above), need to seek to pull it in. This is costly<a name="line.1745"></a>
+<span class="sourceLineNo">1746</span>        // and should happen very rarely. Currently happens on open of a hfile reader where we<a name="line.1746"></a>
+<span class="sourceLineNo">1747</span>        // read the trailer blocks to pull in the indices. Otherwise, we are reading block sizes<a name="line.1747"></a>
+<span class="sourceLineNo">1748</span>        // out of the hfile index. To check, enable TRACE in this file and you'll get an exception<a name="line.1748"></a>
+<span class="sourceLineNo">1749</span>        // in a LOG every time we seek. See HBASE-17072 for more detail.<a name="line.1749"></a>
+<span class="sourceLineNo">1750</span>        if (headerBuf == null) {<a name="line.1750"></a>
+<span class="sourceLineNo">1751</span>          if (LOG.isTraceEnabled()) {<a name="line.1751"></a>
+<span class="sourceLineNo">1752</span>            LOG.trace("Extra see to get block size!", new RuntimeException());<a name="line.1752"></a>
+<span class="sourceLineNo">1753</span>          }<a name="line.1753"></a>
+<span class="sourceLineNo">1754</span>          headerBuf = ByteBuffer.allocate(hdrSize);<a name="line.1754"></a>
+<span class="sourceLineNo">1755</span>          readAtOffset(is, headerBuf.array(), headerBuf.arrayOffset(), hdrSize, false,<a name="line.1755"></a>
+<span class="sourceLineNo">1756</span>              offset, pread);<a name="line.1756"></a>
+<span class="sourceLineNo">1757</span>        }<a name="line.1757"></a>
+<span class="sourceLineNo">1758</span>        onDiskSizeWithHeader = getOnDiskSizeWithHeader(headerBuf, checksumSupport);<a name="line.1758"></a>
+<span class="sourceLineNo">1759</span>      }<a name="line.1759"></a>
+<span class="sourceLineNo">1760</span>      int preReadHeaderSize = headerBuf == null? 0 : hdrSize;<a name="line.1760"></a>
+<span class="sourceLineNo">1761</span>      // Allocate enough space to fit the next block's header too; saves a seek next time through.<a name="line.1761"></a>
+<span class="sourceLineNo">1762</span>      // onDiskBlock is whole block + header + checksums then extra hdrSize to read next header;<a name="line.1762"></a>
+<span class="sourceLineNo">1763</span>      // onDiskSizeWithHeader is header, body, and any checksums if present. preReadHeaderSize<a name="line.1763"></a>
+<span class="sourceLineNo">1764</span>      // says where to start reading. If we have the header cached, then we don't need to read<a name="line.1764"></a>
+<span class="sourceLineNo">1765</span>      // it again and we can likely read from last place we left off w/o need to backup and reread<a name="line.1765"></a>
+<span class="sourceLineNo">1766</span>      // the header we read last time through here.<a name="line.1766"></a>
+<span class="sourceLineNo">1767</span>      // TODO: Make this ByteBuffer-based. Will make it easier to go to HDFS with BBPool (offheap).<a name="line.1767"></a>
+<span class="sourceLineNo">1768</span>      byte [] onDiskBlock = new byte[onDiskSizeWithHeader + hdrSize];<a name="line.1768"></a>
+<span class="sourceLineNo">1769</span>      int nextBlockOnDiskSize = readAtOffset(is, onDiskBlock, preReadHeaderSize,<a name="line.1769"></a>
+<span class="sourceLineNo">1770</span>          onDiskSizeWithHeader - preReadHeaderSize, true, offset + preReadHeaderSize, pread);<a name="line.1770"></a>
+<span class="sourceLineNo">1771</span>      if (headerBuf != null) {<a name="line.1771"></a>
+<span class="sourceLineNo">1772</span>        // The header has been read when reading the previous block OR in a distinct header-only<a name="line.1772"></a>
+<span class="sourceLineNo">1773</span>        // read. Copy to this block's header.<a name="line.1773"></a>
+<span class="sourceLineNo">1774</span>        System.arraycopy(headerBuf.array(), headerBuf.arrayOffset(), onDiskBlock, 0, hdrSize);<a name="line.1774"></a>
+<span class="sourceLineNo">1775</span>      } else {<a name="line.1775"></a>
+<span class="sourceLineNo">1776</span>        headerBuf = ByteBuffer.wrap(onDiskBlock, 0, hdrSize);<a name="line.1776"></a>
+<span class="sourceLineNo">1777</span>      }<a name="line.1777"></a>
+<span class="sourceLineNo">1778</span>      // Do a few checks before we go instantiate HFileBlock.<a name="line.1778"></a>
+<span class="sourceLineNo">1779</span>      assert onDiskSizeWithHeader &gt; this.hdrSize;<a name="line.1779"></a>
+<span class="sourceLineNo">1780</span>      verifyOnDiskSizeMatchesHeader(onDiskSizeWithHeader, headerBuf, offset, checksumSupport);<a name="line.1780"></a>
+<span class="sourceLineNo">1781</span>      ByteBuffer onDiskBlockByteBuffer = ByteBuffer.wrap(onDiskBlock, 0, onDiskSizeWithHeader);<a name="line.1781"></a>
+<span class="sourceLineNo">1782</span>      // Verify checksum of the data before using it for building HFileBlock.<a name="line.1782"></a>
+<span class="sourceLineNo">1783</span>      if (verifyChecksum &amp;&amp;<a name="line.1783"></a>
+<span class="sourceLineNo">1784</span>          !validateChecksum(offset, onDiskBlockByteBuffer, hdrSize)) {<a name="line.1784"></a>
+<span class="sourceLineNo">1785</span>        return null;<a name="line.1785"></a>
+<span class="sourceLineNo">1786</span>      }<a name="line.1786"></a>
+<span class="sourceLineNo">1787</span>      long duration = System.currentTimeMillis() - startTime;<a name="line.1787"></a>
+<span class="sourceLineNo">1788</span>      if (updateMetrics) {<a name="line.1788"></a>
+<span class="sourceLineNo">1789</span>        HFile.updateReadLatency(duration, pread);<a name="line.1789"></a>
+<span class="sourceLineNo">1790</span>      }<a name="line.1790"></a>
+<span class="sourceLineNo">1791</span>      // The onDiskBlock will become the headerAndDataBuffer for this block.<a name="line.1791"></a>
+<span class="sourceLineNo">1792</span>      // If nextBlockOnDiskSizeWithHeader is not zero, the onDiskBlock already<a name="line.1792"></a>
+<span class="sourceLineNo">1793</span>      // contains the header of next block, so no need to set next block's header in it.<a name="line.1793"></a>
+<span class="sourceLineNo">1794</span>      HFileBlock hFileBlock =<a name="line.1794"></a>
+<span class="sourceLineNo">1795</span>          new HFileBlock(new SingleByteBuff(onDiskBlockByteBuffer), checksumSupport,<a name="line.1795"></a>
+<span class="sourceLineNo">1796</span>              MemoryType.EXCLUSIVE, offset, nextBlockOnDiskSize, fileContext);<a name="line.1796"></a>
+<span class="sourceLineNo">1797</span>      // Run check on uncompressed sizings.<a name="line.1797"></a>
+<span class="sourceLineNo">1798</span>      if (!fileContext.isCompressedOrEncrypted()) {<a name="line.1798"></a>
+<span class="sourceLineNo">1799</span>        hFileBlock.sanityCheckUncompressed();<a name="line.1799"></a>
+<span class="sourceLineNo">1800</span>      }<a name="line.1800"></a>
+<span class="sourceLineNo">1801</span>      LOG.trace("Read {} in {} ns", hFileBlock, duration);<a name="line.1801"></a>
+<span class="sourceLineNo">1802</span>      // Cache next block header if we read it for the next time through here.<a name="line.1802"></a>
+<span class="sourceLineNo">1803</span>      if (nextBlockOnDiskSize != -1) {<a name="line.1803"></a>
+<span class="sourceLineNo">1804</span>        cacheNextBlockHeader(offset + hFileBlock.getOnDiskSizeWithHeader(),<a name="line.1804"></a>
+<span class="sourceLineNo">1805</span>            onDiskBlock, onDiskSizeWithHeader, hdrSize);<a name="line.1805"></a>
+<span class="sourceLineNo">1806</span>      }<a name="line.1806"></a>
+<span class="sourceLineNo">1807</span>      return hFileBlock;<a name="line.1807"></a>
+<span class="sourceLineNo">1808</span>    }<a name="line.1808"></a>
+<span class="sourceLineNo">1809</span><a name="line.1809"></a>
+<span class="sourceLineNo">1810</span>    @Override<a name="line.1810"></a>
+<span class="sourceLineNo">1811</span>    public void setIncludesMemStoreTS(boolean includesMemstoreTS) {<a name="line.1811"></a>
+<span class="sourceLineNo">1812</span>      this.fileContext.setIncludesMvcc(includesMemstoreTS);<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>    @Override<a name="line.1815"></a>
+<span class="sourceLineNo">1816</span>    public void setDataBlockEncoder(HFileDataBlockEncoder encoder) {<a name="line.1816"></a>
+<span class="sourceLineNo">1817</span>      encodedBlockDecodingCtx = encoder.newDataBlockDecodingContext(this.fileContext);<a name="line.1817"></a>
+<span class="sourceLineNo">1818</span>    }<a name="line.1818"></a>
+<span class="sourceLineNo">1819</span><a name="line.1819"></a>
+<span class="sourceLineNo">1820</span>    @Override<a name="line.1820"></a>
+<span class="sourceLineNo">1821</span>    public HFileBlockDecodingContext getBlockDecodingContext() {<a name="line.1821"></a>
+<span class="sourceLineNo">1822</span>      return this.encodedBlockDecodingCtx;<a name="line.1822"></a>
+<span class="sourceLineNo">1823</span>    }<a name="line.1823"></a>
+<span class="sourceLineNo">1824</span><a name="line.1824"></a>
+<span class="sourceLineNo">1825</span>    @Override<a name="line.1825"></a>
+<span class="sourceLineNo">1826</span>    public HFileBlockDecodingContext getDefaultBlockDecodingContext() {<a name="line.1826"></a>
+<span class="sourceLineNo">1827</span>      return this.defaultDecodingCtx;<a name="line.1827"></a>
+<span class="sourceLineNo">1828</span>    }<a name="line.1828"></a>
+<span class="sourceLineNo">1829</span><a name="line.1829"></a>
+<span class="sourceLineNo">1830</span>    /**<a name="line.1830"></a>
+<span class="sourceLineNo">1831</span>     * Generates the checksum for the header as well as the data and then validates it.<a name="line.1831"></a>
+<span class="sourceLineNo">1832</span>     * If the block doesn't uses checksum, returns false.<a name="line.1832"></a>
+<span class="sourceLineNo">1833</span>     * @return True if checksum matches, else false.<a name="line.1833"></a>
+<span class="sourceLineNo">1834</span>     */<a name="line.1834"></a>
+<span class="sourceLineNo">1835</span>    private boolean validateChecksum(long offset, ByteBuffer data, int hdrSize)<a name="line.1835"></a>
+<span class="sourceLineNo">1836</span>        throws IOException {<a name="line.1836"></a>
+<span class="sourceLineNo">1837</span>      // If this is an older version of the block that does not have checksums, then return false<a name="line.1837"></a>
+<span class="sourceLineNo">1838</span>      // indicating that checksum verification did not succeed. Actually, this method should never<a name="line.1838"></a>
+<span class="sourceLineNo">1839</span>      // be called when the minorVersion is 0, thus this is a defensive check for a cannot-happen<a name="line.1839"></a>
+<span class="sourceLineNo">1840</span>      // case. Since this is a cannot-happen case, it is better to return false to indicate a<a name="line.1840"></a>
+<span class="sourceLineNo">1841</span>      // checksum validation failure.<a name="line.1841"></a>
+<span class="sourceLineNo">1842</span>      if (!fileContext.isUseHBaseChecksum()) {<a name="line.1842"></a>
+<span class="sourceLineNo">1843</span>        return false;<a name="line.1843"></a>
+<span class="sourceLineNo">1844</span>      }<a name="line.1844"></a>
+<span class="sourceLineNo">1845</span>      return ChecksumUtil.validateChecksum(data, pathName, offset, hdrSize);<a name="line.1845"></a>
+<span class="sourceLineNo">1846</span>    }<a name="line.1846"></a>
+<span class="sourceLineNo">1847</span><a name="line.1847"></a>
+<span class="sourceLineNo">1848</span>    @Override<a name="line.1848"></a>
+<span class="sourceLineNo">1849</span>    public void closeStreams() throws IOException {<a name="line.1849"></a>
+<span class="sourceLineNo">1850</span>      streamWrapper.close();<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>    @Override<a name="line.1853"></a>
+<span class="sourceLineNo">1854</span>    public void unbufferStream() {<a name="line.1854"></a>
+<span class="sourceLineNo">1855</span>      // To handle concurrent reads, ensure that no other client is accessing the streams while we<a name="line.1855"></a>
+<span class="sourceLineNo">1856</span>      // unbuffer it.<a name="line.1856"></a>
+<span class="sourceLineNo">1857</span>      if (streamLock.tryLock()) {<a name="line.1857"></a>
+<span class="sourceLineNo">1858</span>        try {<a name="line.1858"></a>
+<span class="sourceLineNo">1859</span>          this.streamWrapper.unbuffer();<a name="line.1859"></a>
+<span class="sourceLineNo">1860</span>        } finally {<a name="line.1860"></a>
+<span class="sourceLineNo">1861</span>          streamLock.unlock();<a name="line.1861"></a>
+<span class="sourceLineNo">1862</span>        }<a name="line.1862"></a>
+<span class="sourceLineNo">1863</span>      }<a name="line.1863"></a>
+<span class="sourceLineNo">1864</span>    }<a name="line.1864"></a>
+<span class="sourceLineNo">1865</span><a name="line.1865"></a>
+<span class="sourceLineNo">1866</span>    @Override<a name="line.1866"></a>
+<span class="sourceLineNo">1867</span>    public String toString() {<a name="line.1867"></a>
+<span class="sourceLineNo">1868</span>      return "hfs=" + hfs + ", path=" + pathName + ", fileContext=" + fileContext;<a name="line.1868"></a>
+<span class="sourceLineNo">1869</span>    }<a name="line.1869"></a>
+<span class="sourceLineNo">1870</span>  }<a name="line.1870"></a>
+<span class="sourceLineNo">1871</span><a name="line.1871"></a>
+<span class="sourceLineNo">1872</span>  /** An additional sanity-check in case no compression or encryption is being used. */<a name="line.1872"></a>
+<span class="sourceLineNo">1873</span>  @VisibleForTesting<a name="line.1873"></a>
+<span class="sourceLineNo">1874</span>  void sanityCheckUncompressed() throws IOException {<a name="line.1874"></a>
+<span class="sourceLineNo">1875</span>    if (onDiskSizeWithoutHeader != uncompressedSizeWithoutHeader +<a name="line.1875"></a>
+<span class="sourceLineNo">1876</span>        totalChecksumBytes()) {<a name="line.1876"></a>
+<span class="sourceLineNo">1877</span>      throw new IOException("Using no compression but "<a name="line.1877"></a>
+<span class="sourceLineNo">1878</span>          + "onDiskSizeWithoutHeader=" + onDiskSizeWithoutHeader + ", "<a name="line.1878"></a>
+<span class="sourceLineNo">1879</span>          + "uncompressedSizeWithoutHeader=" + uncompressedSizeWithoutHeader<a name="line.1879"></a>
+<span class="sourceLineNo">1880</span>          + ", numChecksumbytes=" + totalChecksumBytes());<a name="line.1880"></a>
+<span class="sourceLineNo">1881</span>    }<a name="line.1881"></a>
+<span class="sourceLineNo">1882</span>  }<a name="line.1882"></a>
+<span class="sourceLineNo">1883</span><a name="line.1883"></a>
+<span class="sourceLineNo">1884</span>  // Cacheable implementation<a name="line.1884"></a>
+<span class="sourceLineNo">1885</span>  @Override<a name="line.1885"></a>
+<span class="sourceLineNo">1886</span>  public int getSerializedLength() {<a name="line.1886"></a>
+<span class="sourceLineNo">1887</span>    if (buf != null) {<a name="line.1887"></a>
+<span class="sourceLineNo">1888</span>      // Include extra bytes for block metadata.<a name="line.1888"></a>
+<span class="sourceLineNo">1889</span>      return this.buf.limit() + BLOCK_METADATA_SPACE;<a name="line.1889"></a>
+<span class="sourceLineNo">1890</span>    }<a name="line.1890"></a>
+<span class="sourceLineNo">1891</span>    return 0;<a name="line.1891"></a>
+<span class="sourceLineNo">1892</span>  }<a name="line.1892"></a>
+<span class="sourceLineNo">1893</span><a name="line.1893"></a>
+<span class="sourceLineNo">1894</span>  // Cacheable implementation<a name="line.1894"></a>
+<span class="sourceLineNo">1895</span>  @Override<a name="line.1895"></a>
+<span class="sourceLineNo">1896</span>  public void serialize(ByteBuffer destination) {<a name="line.1896"></a>
+<span class="sourceLineNo">1897</span>    // BE CAREFUL!! There is a custom version of this serialization over in BucketCache#doDrain.<a name="line.1897"></a>
+<span class="sourceLineNo">1898</span>    // Make sure any changes in here are reflected over there.<a name="line.1898"></a>
+<span class="sourceLineNo">1899</span>    this.buf.get(destination, 0, getSerializedLength() - BLOCK_METADATA_SPACE);<a name="line.1899"></a>
+<span class="sourceLineNo">1900</span>    destination = addMetaData(destination);<a name="line.1900"></a>
+<span class="sourceLineNo">1901</span><a name="line.1901"></a>
+<span class="sourceLineNo">1902</span>    // Make it ready for reading. flip sets position to zero and limit to current position which<a name="line.1902"></a>
+<span class="sourceLineNo">1903</span>    // is what we want if we do not want to serialize the block plus checksums if present plus<a name="line.1903"></a>
+<span class="sourceLineNo">1904</span>    // metadata.<a name="line.1904"></a>
+<span class="sourceLineNo">1905</span>    destination.flip();<a name="line.1905"></a>
+<span class="sourceLineNo">1906</span>  }<a name="line.1906"></a>
+<span class="sourceLineNo">1907</span><a name="line.1907"></a>
+<span class="sourceLineNo">1908</span>  /**<a name="line.1908"></a>
+<span class="sourceLineNo">1909</span>   * For use by bucketcache. This exposes internals.<a name="line.1909"></a>
+<span class="sourceLineNo">1910</span>   */<a name="line.1910"></a>
+<span class="sourceLineNo">1911</span>  public ByteBuffer getMetaData() {<a name="line.1911"></a>
+<span class="sourceLineNo">1912</span>    ByteBuffer bb = ByteBuffer.allocate(BLOCK_METADATA_SPACE);<a name="line.1912"></a>
+<span class="sourceLineNo">1913</span>    bb = addMetaData(bb);<a name="line.1913"></a>
+<span class="sourceLineNo">1914</span>    bb.flip();<a name="line.1914"></a>
+<span class="sourceLineNo">1915</span>    return bb;<a name="line.1915"></a>
+<span class="sourceLineNo">1916</span>  }<a name="line.1916"></a>
+<span class="sourceLineNo">1917</span><a name="line.1917"></a>
+<span class="sourceLineNo">1918</span>  /**<a name="line.1918"></a>
+<span class="sourceLineNo">1919</span>   * Adds metadata at current position (position is moved forward). Does not flip or reset.<a name="line.1919"></a>
+<span class="sourceLineNo">1920</span>   * @return The passed &lt;code&gt;destination&lt;/code&gt; with metadata added.<a name="line.1920"></a>
+<span class="sourceLineNo">1921</span>   */<a name="line.1921"></a>
+<span class="sourceLineNo">1922</span>  private ByteBuffer addMetaData(final ByteBuffer destination) {<a name="line.1922"></a>
+<span class="sourceLineNo">1923</span>    destination.put(this.fileContext.isUseHBaseChecksum() ? (byte) 1 : (byte) 0);<a name="line.1923"></a>
+<span class="sourceLineNo">1924</span>    destination.putLong(this.offset);<a name="line.1924"></a>
+<span class="sourceLineNo">1925</span>    destination.putInt(this.nextBlockOnDiskSize);<a name="line.1925"></a>
+<span class="sourceLineNo">1926</span>    return destination;<a name="line.1926"></a>
+<span class="sourceLineNo">1927</span>  }<a name="line.1927"></a>
+<span class="sourceLineNo">1928</span><a name="line.1928"></a>
+<span class="sourceLineNo">1929</span>  // Cacheable implementation<a name="line.1929"></a>
+<span class="sourceLineNo">1930</span>  @Override<a name="line.1930"></a>
+<span class="sourceLineNo">1931</span>  public CacheableDeserializer&lt;Cacheable&gt; getDeserializer() {<a name="line.1931"></a>
+<span class="sourceLineNo">1932</span>    return HFileBlock.BLOCK_DESERIALIZER;<a name="line.1932"></a>
+<span class="sourceLineNo">1933</span>  }<a name="line.1933"></a>
+<span class="sourceLineNo">1934</span><a name="line.1934"></a>
+<span class="sourceLineNo">1935</span>  @Override<a name="line.1935"></a>
+<span class="sourceLineNo">1936</span>  public int hashCode() {<a name="line.1936"></a>
+<span class="sourceLineNo">1937</span>    int result = 1;<a name="line.1937"></a>
+<span class="sourceLineNo">1938</span>    result = result * 31 + blockType.hashCode();<a name="line.1938"></a>
+<span class="sourceLineNo">1939</span>    result = result * 31 + nextBlockOnDiskSize;<a name="line.1939"></a>
+<span class="sourceLineNo">1940</span>    result = result * 31 + (int) (offset ^ (offset &gt;&gt;&gt; 32));<a name="line.1940"></a>
+<span class="sourceLineNo">1941</span>    result = result * 31 + onDiskSizeWithoutHeader;<a name="line.1941"></a>
+<span class="sourceLineNo">1942</span>    result = result * 31 + (int) (prevBlockOffset ^ (prevBlockOffset &gt;&gt;&gt; 32));<a name="line.1942"></a>
+<span class="sourceLineNo">1943</span>    result = result * 31 + uncompressedSizeWithoutHeader;<a name="line.1943"></a>
+<span class="sourceLineNo">1944</span>    result = result * 31 + buf.hashCode();<a name="line.1944"></a>
+<span class="sourceLineNo">1945</span>    return result;<a name="line.1945"></a>
+<span class="sourceLineNo">1946</span>  }<a name="line.1946"></a>
+<span class="sourceLineNo">1947</span><a name="line.1947"></a>
+<span class="sourceLineNo">1948</span>  @Override<a name="line.1948"></a>
+<span class="sourceLineNo">1949</span>  public boolean equals(Object comparison) {<a name="line.1949"></a>
+<span class="sourceLineNo">1950</span>    if (this == comparison) {<a name="line.1950"></a>
+<span class="sourceLineNo">1951</span>      return true;<a name="line.1951"></a>
+<span class="sourceLineNo">1952</span>    }<a name="line.1952"></a>
+<span class="sourceLineNo">1953</span>    if (comparison == null) {<a name="line.1953"></a>
+<span class="sourceLineNo">1954</span>      return false;<a name="line.1954"></a>
+<span class="sourceLineNo">1955</span>    }<a name="line.1955"></a>
+<span class="sourceLineNo">1956</span>    if (comparison.getClass() != this.getClass()) {<a name="line.1956"></a>
+<span class="sourceLineNo">1957</span>      return false;<a name="line.1957"></a>
+<span class="sourceLineNo">1958</span>    }<a name="line.1958"></a>
+<span class="sourceLineNo">1959</span><a name="line.1959"></a>
+<span class="sourceLineNo">1960</span>    HFileBlock castedComparison = (HFileBlock) comparison;<a name="line.1960"></a>
+<span class="sourceLineNo">1961</span><a name="line.1961"></a>
+<span class="sourceLineNo">1962</span>    if (castedComparison.blockType != this.blockType) {<a name="line.1962"></a>
+<span class="sourceLineNo">1963</span>      return false;<a name="line.1963"></a>
+<span class="sourceLineNo">1964</span>    }<a name="line.1964"></a>
+<span class="sourceLineNo">1965</span>    if (castedComparison.nextBlockOnDiskSize != this.nextBlockOnDiskSize) {<a name="line.1965"></a>
+<span class="sourceLineNo">1966</span>      return false;<a name="line.1966"></a>
+<span class="sourceLineNo">1967</span>    }<a name="line.1967"></a>
+<span class="sourceLineNo">1968</span>    // Offset is important. Needed when we have to remake cachekey when block is returned to cache.<a name="line.1968"></a>
+<span class="sourceLineNo">1969</span>    if (castedComparison.offset != this.offset) {<a name="line.1969"></a>
 <span class="sourceLineNo">1970</span>      return false;<a name="line.1970"></a>
 <span class="sourceLineNo">1971</span>    }<a name="line.1971"></a>
-<span class="sourceLineNo">1972</span>    // Offset is important. Needed when we have to remake cachekey when block is returned to cache.<a name="line.1972"></a>
-<span class="sourceLineNo">1973</span>    if (castedComparison.offset != this.offset) {<a name="line.1973"></a>
-<span class="sourceLineNo">1974</span>      return false;<a name="line.1974"></a>
-<span class="sourceLineNo">1975</span>    }<a name="line.1975"></a>
-<span class="sourceLineNo">1976</span>    if (castedComparison.onDiskSizeWithoutHeader != this.onDiskSizeWithoutHeader) {<a name="line.1976"></a>
-<span class="sourceLineNo">1977</span>      return false;<a name="line.1977"></a>
-<span class="sourceLineNo">1978</span>    }<a name="line.1978"></a>
-<span class="sourceLineNo">1979</span>    if (castedComparison.prevBlockOffset != this.prevBlockOffset) {<a name="line.1979"></a>
-<span class="sourceLineNo">1980</span>      return false;<a name="line.1980"></a>
-<span class="sourceLineNo">1981</span>    }<a name="line.1981"></a>
-<span class="sourceLineNo">1982</span>    if (castedComparison.uncompressedSizeWithoutHeader != this.uncompressedSizeWithoutHeader) {<a name="line.1982"></a>
+<span class="sourceLineNo">1972</span>    if (castedComparison.onDiskSizeWithoutHeader != this.onDiskSizeWithoutHeader) {<a name="line.1972"></a>
+<span class="sourceLineNo">1973</span>      return false;<a name="line.1973"></a>
+<span class="sourceLineNo">1974</span>    }<a name="line.1974"></a>
+<span class="sourceLineNo">1975</span>    if (castedComparison.prevBlockOffset != this.prevBlockOffset) {<a name="line.1975"></a>
+<span class="sourceLineNo">1976</span>      return false;<a name="line.1976"></a>
+<span class="sourceLineNo">1977</span>    }<a name="line.1977"></a>
+<span class="sourceLineNo">1978</span>    if (castedComparison.uncompressedSizeWithoutHeader != this.uncompressedSizeWithoutHeader) {<a name="line.1978"></a>
+<span class="sourceLineNo">1979</span>      return false;<a name="line.1979"></a>
+<span class="sourceLineNo">1980</span>    }<a name="line.1980"></a>
+<span class="sourceLineNo">1981</span>    if (ByteBuff.compareTo(this.buf, 0, this.buf.limit(), castedComparison.buf, 0,<a name="line.1981"></a>
+<span class="sourceLineNo">1982</span>        castedComparison.buf.limit()) != 0) {<a name="line.1982"></a>
 <span class="sourceLineNo">1983</span>      return false;<a name="line.1983"></a>
 <span class="sourceLineNo">1984</span>    }<a name="line.1984"></a>
-<span class="sourceLineNo">1985</span>    if (ByteBuff.compareTo(this.buf, 0, this.buf.limit(), castedComparison.buf, 0,<a name="line.1985"></a>
-<span class="sourceLineNo">1986</span>        castedComparison.buf.limit()) != 0) {<a name="line.1986"></a>
-<span class="sourceLineNo">1987</span>      return false;<a name="line.1987"></a>
-<span class="sourceLineNo">1988</span>    }<a name="line.1988"></a>
-<span class="sourceLineNo">1989</span>    return true;<a name="line.1989"></a>
-<span class="sourceLineNo">1990</span>  }<a name="line.1990"></a>
-<span class="sourceLineNo">1991</span><a name="line.1991"></a>
-<span class="sourceLineNo">1992</span>  DataBlockEncoding getDataBlockEncoding() {<a name="line.1992"></a>
-<span class="sourceLineNo">1993</span>    if (blockType == BlockType.ENCODED_DATA) {<a name="line.1993"></a>
-<span class="sourceLineNo">1994</span>      return DataBlockEncoding.getEncodingById(getDataBlockEncodingId());<a name="line.1994"></a>
-<span class="sourceLineNo">1995</span>    }<a name="line.1995"></a>
-<span class="sourceLineNo">1996</span>    return DataBlockEncoding.NONE;<a name="line.1996"></a>
-<span class="sourceLineNo">1997</span>  }<a name="line.1997"></a>
-<span class="sourceLineNo">1998</span><a name="line.1998"></a>
-<span class="sourceLineNo">1999</span>  @VisibleForTesting<a name="line.1999"></a>
-<span class="sourceLineNo">2000</span>  byte getChecksumType() {<a name="line.2000"></a>
-<span class="sourceLineNo">2001</span>    return this.fileContext.getChecksumType().getCode();<a name="line.2001"></a>
+<span class="sourceLineNo">1985</span>    return true;<a name="line.1985"></a>
+<span class="sourceLineNo">1986</span>  }<a name="line.1986"></a>
+<span class="sourceLineNo">1987</span><a name="line.1987"></a>
+<span class="sourceLineNo">1988</span>  DataBlockEncoding getDataBlockEncoding() {<a name="line.1988"></a>
+<span class="sourceLineNo">1989</span>    if (blockType == BlockType.ENCODED_DATA) {<a name="line.1989"></a>
+<span class="sourceLineNo">1990</span>      return DataBlockEncoding.getEncodingById(getDataBlockEncodingId());<a name="line.1990"></a>
+<span class="sourceLineNo">1991</span>    }<a name="line.1991"></a>
+<span class="sourceLineNo">1992</span>    return DataBlockEncoding.NONE;<a name="line.1992"></a>
+<span class="sourceLineNo">1993</span>  }<a name="line.1993"></a>
+<span class="sourceLineNo">1994</span><a name="line.1994"></a>
+<span class="sourceLineNo">1995</span>  @VisibleForTesting<a name="line.1995"></a>
+<span class="sourceLineNo">1996</span>  byte getChecksumType() {<a name="line.1996"></a>
+<span class="sourceLineNo">1997</span>    return this.fileContext.getChecksumType().getCode();<a name="line.1997"></a>
+<span class="sourceLineNo">1998</span>  }<a name="line.1998"></a>
+<span class="sourceLineNo">1999</span><a name="line.1999"></a>
+<span class="sourceLineNo">2000</span>  int getBytesPerChecksum() {<a name="line.2000"></a>
+<span class="sourceLineNo">2001</span>    return this.fileContext.getBytesPerChecksum();<a name="line.2001"></a>
 <span class="sourceLineNo">2002</span>  }<a name="line.2002"></a>
 <span class="sourceLineNo">2003</span><a name="line.2003"></a>
-<span class="sourceLineNo">2004</span>  int getBytesPerChecksum() {<a name="line.2004"></a>
-<span class="sourceLineNo">2005</span>    return this.fileContext.getBytesPerChecksum();<a name="line.2005"></a>
-<span class="sourceLineNo">2006</span>  }<a name="line.2006"></a>
-<span class="sourceLineNo">2007</span><a name="line.2007"></a>
-<span class="sourceLineNo">2008</span>  /** @return the size of data on disk + header. Excludes checksum. */<a name="line.2008"></a>
-<span class="sourceLineNo">2009</span>  @VisibleForTesting<a name="line.2009"></a>
-<span class="sourceLineNo">2010</span>  int getOnDiskDataSizeWithHeader() {<a name="line.2010"></a>
-<span class="sourceLineNo">2011</span>    return this.onDiskDataSizeWithHeader;<a name="line.2011"></a>
-<span class="sourceLineNo">2012</span>  }<a name="line.2012"></a>
-<span class="sourceLineNo">2013</span><a name="line.2013"></a>
-<span class="sourceLineNo">2014</span>  /**<a name="line.2014"></a>
-<span class="sourceLineNo">2015</span>   * Calculate the number of bytes required to store all the checksums<a name="line.2015"></a>
-<span class="sourceLineNo">2016</span>   * for this block. Each checksum value is a 4 byte integer.<a name="line.2016"></a>
-<span class="sourceLineNo">2017</span>   */<a name="line.2017"></a>
-<span class="sourceLineNo">2018</span>  int totalChecksumBytes() {<a name="line.2018"></a>
-<span class="sourceLineNo">2019</span>    // If the hfile block has minorVersion 0, then there are no checksum<a name="line.2019"></a>
-<span class="sourceLineNo">2020</span>    // data to validate. Similarly, a zero value in this.bytesPerChecksum<a name="line.2020"></a>
-<span class="sourceLineNo">2021</span>    // indicates that cached blocks do not have checksum data because<a name="line.2021"></a>
-<span class="sourceLineNo">2022</span>    // checksums were already validated when the block was read from disk.<a name="line.2022"></a>
-<span class="sourceLineNo">2023</span>    if (!fileContext.isUseHBaseChecksum() || this.fileContext.getBytesPerChecksum() == 0) {<a name="line.2023"></a>
-<span class="sourceLineNo">2024</span>      return 0;<a name="line.2024"></a>
-<span class="sourceLineNo">2025</span>    }<a name="line.2025"></a>
-<span class="sourceLineNo">2026</span>    return (int) ChecksumUtil.numBytes(onDiskDataSizeWithHeader,<a name="line.2026"></a>
-<span class="sourceLineNo">2027</span>        this.fileContext.getBytesPerChecksum());<a name="line.2027"></a>
-<span class="sourceLineNo">2028</span>  }<a name="line.2028"></a>
-<span class="sourceLineNo">2029</span><a name="line.2029"></a>
-<span class="sourceLineNo">2030</span>  /**<a name="line.2030"></a>
-<span class="sourceLineNo">2031</span>   * Returns the size of this block header.<a name="line.2031"></a>
-<span class="sourceLineNo">2032</span>   */<a name="line.2032"></a>
-<span class="sourceLineNo">2033</span>  public int headerSize() {<a name="line.2033"></a>
-<span class="sourceLineNo">2034</span>    return headerSize(this.fileContext.isUseHBaseChecksum());<a name="line.2034"></a>
-<span class="sourceLineNo">2035</span>  }<a name="line.2035"></a>
-<span class="sourceLineNo">2036</span><a name="line.2036"></a>
-<span class="sourceLineNo">2037</span>  /**<a name="line.2037"></a>
-<span class="sourceLineNo">2038</span>   * Maps a minor version to the size of the header.<a name="line.2038"></a>
-<span class="sourceLineNo">2039</span>   */<a name="line.2039"></a>
-<span class="sourceLineNo">2040</span>  public static int headerSize(boolean usesHBaseChecksum) {<a name="line.2040"></a>
-<span class="sourceLineNo">2041</span>    return usesHBaseChecksum?<a name="line.2041"></a>
-<span class="sourceLineNo">2042</span>        HConstants.HFILEBLOCK_HEADER_SIZE: HConstants.HFILEBLOCK_HEADER_SIZE_NO_CHECKSUM;<a name="line.2042"></a>
-<span class="sourceLineNo">2043</span>  }<a name="line.2043"></a>
-<span class="sourceLineNo">2044</span><a name="line.2044"></a>
-<span class="sourceLineNo">2045</span>  /**<a name="line.2045"></a>
-<span class="sourceLineNo">2046</span>   * Return the appropriate DUMMY_HEADER for the minor version<a name="line.2046"></a>
-<span class="sourceLineNo">2047</span>   */<a name="line.2047"></a>
-<span class="sourceLineNo">2048</span>  @VisibleForTesting<a name="line.2048"></a>
-<span class="sourceLineNo">2049</span>  // TODO: Why is this in here?<a name="line.2049"></a>
-<span class="sourceLineNo">2050</span>  byte[] getDummyHeaderForVersion() {<a name="line.2050"></a>
-<span class="sourceLineNo">2051</span>    return getDummyHeaderForVersion(this.fileContext.isUseHBaseChecksum());<a name="line.2051"></a>
-<span class="sourceLineNo">2052</span>  }<a name="line.2052"></a>
-<span class="sourceLineNo">2053</span><a name="line.2053"></a>
-<span class="sourceLineNo">2054</span>  /**<a name="line.2054"></a>
-<span class="sourceLineNo">2055</span>   * Return the appropriate DUMMY_HEADER for the minor version<a name="line.2055"></a>
-<span class="sourceLineNo">2056</span>   */<a name="line.2056"></a>
-<span class="sourceLineNo">2057</span>  static private byte[] getDummyHeaderForVersion(boolean usesHBaseChecksum) {<a name="line.2057"></a>
-<span class="sourceLineNo">2058</span>    return usesHBaseChecksum? HConstants.HFILEBLOCK_DUMMY_HEADER: DUMMY_HEADER_NO_CHECKSUM;<a name="line.2058"></a>
-<span class="sourceLineNo">2059</span>  }<a name="line.2059"></a>
-<span class="sourceLineNo">2060</span><a name="line.2060"></a>
-<span class="sourceLineNo">2061</span>  /**<a name="line.2061"></a>
-<span class="sourceLineNo">2062</span>   * @return This HFileBlocks fileContext which will a derivative of the<a name="line.2062"></a>
-<span class="sourceLineNo">2063</span>   * fileContext for the file from which this block's data was originally read.<a name="line.2063"></a>
-<span class="sourceLineNo">2064</span>   */<a name="line.2064"></a>
-<span class="sourceLineNo">2065</span>  HFileContext getHFileContext() {<a name="line.2065"></a>
-<span class="sourceLineNo">2066</span>    return this.fileContext;<a name="line.2066"></a>
-<span class="sourceLineNo">2067</span>  }<a name="line.2067"></a>
-<span class="sourceLineNo">2068</span><a name="line.2068"></a>
-<span class="sourceLineNo">2069</span>  @Override<a name="line.2069"></a>
-<span class="sourceLineNo">2070</span>  public MemoryType getMemoryType() {<a name="line.2070"></a>
-<span class="sourceLineNo">2071</span>    return this.memType;<a name="line.2071"></a>
-<span class="sourceLineNo">2072</span>  }<a name="line.2072"></a>
-<span class="sourceLineNo">2073</span><a name="line.2073"></a>
-<span class="sourceLineNo">2074</span>  /**<a name="line.2074"></a>
-<span class="sourceLineNo">2075</span>   * @return true if this block is backed by a shared memory area(such as that of a BucketCache).<a name="line.2075"></a>
-<span class="sourceLineNo">2076</span>   */<a name="line.2076"></a>
-<span class="sourceLineNo">2077</span>  boolean usesSharedMemory() {<a name="line.2077"></a>
-<span class="sourceLineNo">2078</span>    return this.memType == MemoryType.SHARED;<a name="line.2078"></a>
-<span class="sourceLineNo">2079</span>  }<a name="line.2079"></a>
-<span class="sourceLineNo">2080</span><a name="line.2080"></a>
-<span class="sourceLineNo">2081</span>  /**<a name="line.2081"></a>
-<span class="sourceLineNo">2082</span>   * Convert the contents of the block header into a human readable string.<a name="line.2082"></a>
-<span class="sourceLineNo">2083</span>   * This is mostly helpful for debugging. This assumes that the block<a name="line.2083"></a>
-<span class="sourceLineNo">2084</span>   * has minor version &gt; 0.<a name="line.2084"></a>
-<span class="sourceLineNo">2085</span>   */<a name="line.2085"></a>
-<span class="sourceLineNo">2086</span>  @VisibleForTesting<a name="line.2086"></a>
-<span class="sourceLineNo">2087</span>  static String toStringHeader(ByteBuff buf) throws IOException {<a name="line.2087"></a>
-<span class="sourceLineNo">2088</span>    byte[] magicBuf = new byte[Math.min(buf.limit() - buf.position(), BlockType.MAGIC_LENGTH)];<a name="line.2088"></a>
-<span class="sourceLineNo">2089</span>    buf.get(magicBuf);<a name="line.2089"></a>
-<span class="sourceLineNo">2090</span>    BlockType bt = BlockType.parse(magicBuf, 0, BlockType.MAGIC_LENGTH);<a name="line.2090"></a>
-<span class="sourceLineNo">2091</span>    int compressedBlockSizeNoHeader = buf.getInt();<a name="line.2091"></a>
-<span class="sourceLineNo">2092</span>    int uncompressedBlockSizeNoHeader = buf.getInt();<a name="line.2092"></a>
-<span class="sourceLineNo">2093</span>    long prevBlockOffset = buf.getLong();<a name="line.2093"></a>
-<span class="sourceLineNo">2094</span>    byte cksumtype = buf.get();<a name="line.2094"></a>
-<span class="sourceLineNo">2095</span>    long bytesPerChecksum = buf.getInt();<a name="line.2095"></a>
-<span class="sourceLineNo">2096</span>    long onDiskDataSizeWithHeader = buf.getInt();<a name="line.2096"></a>
-<span class="sourceLineNo">2097</span>    return " Header dump: magic: " + Bytes.toString(magicBuf) +<a name="line.2097"></a>
-<span class="sourceLineNo">2098</span>                   " blockType " + bt +<a name="line.2098"></a>
-<span class="sourceLineNo">2099</span>                   " compressedBlockSizeNoHeader " +<a name="line.2099"></a>
-<span class="sourceLineNo">2100</span>                   compressedBlockSizeNoHeader +<a name="line.2100"></a>
-<span class="sourceLineNo">2101</span>                   " uncompressedBlockSizeNoHeader " +<a name="line.2101"></a>
-<span class="sourceLineNo">2102</span>                   uncompressedBlockSizeNoHeader +<a name="line.2102"></a>
-<span class="sourceLineNo">2103</span>                   " prevBlockOffset " + prevBlockOffset +<a name="line.2103"></a>
-<span class="sourceLineNo">2104</span>                   " checksumType " + ChecksumType.codeToType(cksumtype) +<a name="line.2104"></a>
-<span class="sourceLineNo">2105</span>                   " bytesPerChecksum " + bytesPerChecksum +<a name="line.2105"></a>
-<span class="sourceLineNo">2106</span>                   " onDiskDataSizeWithHeader " + onDiskDataSizeWithHeader;<a name="line.2106"></a>
+<span class="sourceLineNo">2004</span>  /** @return the size of data on disk + header. Excludes checksum. */<a name="line.2004"></a>
+<span class="sourceLineNo">2005</span>  @VisibleForTesting<a name="line.2005"></a>
+<span class="sourceLineNo">2006</span>  int getOnDiskDataSizeWithHeader() {<a name="line.2006"></a>
+<span class="sourceLineNo">2007</span>    return this.onDiskDataSizeWithHeader;<a name="line.2007"></a>
+<span class="sourceLineNo">2008</span>  }<a name="line.2008"></a>
+<span class="sourceLineNo">2009</span><a name="line.2009"></a>
+<span class="sourceLineNo">2010</span>  /**<a name="line.2010"></a>
+<span class="sourceLineNo">2011</span>   * Calculate the number of bytes required to store all the checksums<a name="line.2011"></a>
+<span class="sourceLineNo">2012</span>   * for this block. Each checksum value is a 4 byte integer.<a name="line.2012"></a>
+<span class="sourceLineNo">2013</span>   */<a name="line.2013"></a>
+<span class="sourceLineNo">2014</span>  int totalChecksumBytes() {<a name="line.2014"></a>
+<span class="sourceLineNo">2015</span>    // If the hfile block has minorVersion 0, then there are no checksum<a name="line.2015"></a>
+<span class="sourceLineNo">2016</span>    // data to validate. Similarly, a zero value in this.bytesPerChecksum<a name="line.2016"></a>
+<span class="sourceLineNo">2017</span>    // indicates that cached blocks do not have checksum data because<a name="line.2017"></a>
+<span class="sourceLineNo">2018</span>    // checksums were already validated when the block was read from disk.<a name="line.2018"></a>
+<span class="sourceLineNo">2019</span>    if (!fileContext.isUseHBaseChecksum() || this.fileContext.getBytesPerChecksum() == 0) {<a name="line.2019"></a>
+<span class="sourceLineNo">2020</span>      return 0;<a name="line.2020"></a>
+<span class="sourceLineNo">2021</span>    }<a name="line.2021"></a>
+<span class="sourceLineNo">2022</span>    return (int) ChecksumUtil.numBytes(onDiskDataSizeWithHeader,<a name="line.2022"></a>
+<span class="sourceLineNo">2023</span>        this.fileContext.getBytesPerChecksum());<a name="line.2023"></a>
+<span class="sourceLineNo">2024</span>  }<a name="line.2024"></a>
+<span class="sourceLineNo">2025</span><a name="line.2025"></a>
+<span class="sourceLineNo">2026</span>  /**<a name="line.2026"></a>
+<span class="sourceLineNo">2027</span>   * Returns the size of this block header.<a name="line.2027"></a>
+<span class="sourceLineNo">2028</span>   */<a name="line.2028"></a>
+<span class="sourceLineNo">2029</span>  public int headerSize() {<a name="line.2029"></a>
+<span class="sourceLineNo">2030</span>    return headerSize(this.fileContext.isUseHBaseChecksum());<a name="line.2030"></a>
+<span class="sourceLineNo">2031</span>  }<a name="line.2031"></a>
+<span class="sourceLineNo">2032</span><a name="line.2032"></a>
+<span class="sourceLineNo">2033</span>  /**<a name="line.2033"></a>
+<span class="sourceLineNo">2034</span>   * Maps a minor version to the size of the header.<a name="line.2034"></a>
+<span class="sourceLineNo">2035</span>   */<a name="line.2035"></a>
+<span class="sourceLineNo">2036</span>  public static int headerSize(boolean usesHBaseChecksum) {<a name="line.2036"></a>
+<span class="sourceLineNo">2037</span>    return usesHBaseChecksum?<a name="line.2037"></a>
+<span class="sourceLineNo">2038</span>        HConstants.HFILEBLOCK_HEADER_SIZE: HConstants.HFILEBLOCK_HEADER_SIZE_NO_CHECKSUM;<a name="line.2038"></a>
+<span class="sourceLineNo">2039</span>  }<a name="line.2039"></a>
+<span class="sourceLineNo">2040</span><a name="line.2040"></a>
+<span class="sourceLineNo">2041</span>  /**<a name="line.2041"></a>
+<span class="sourceLineNo">2042</span>   * Return the appropriate DUMMY_HEADER for the minor version<a name="line.2042"></a>
+<span class="sourceLineNo">2043</span>   */<a name="line.2043"></a>
+<span class="sourceLineNo">2044</span>  @VisibleForTesting<a name="line.2044"></a>
+<span class="sourceLineNo">2045</span>  // TODO: Why is this in here?<a name="line.2045"></a>
+<span class="sourceLineNo">2046</span>  byte[] getDummyHeaderForVersion() {<a name="line.2046"></a>
+<span class="sourceLineNo">2047</span>    return getDummyHeaderForVersion(this.fileContext.isUseHBaseChecksum());<a name="line.2047"></a>
+<span class="sourceLineNo">2048</span>  }<a name="line.2048"></a>
+<span class="sourceLineNo">2049</span><a name="line.2049"></a>
+<span class="sourceLineNo">2050</span>  /**<a name="line.2050"></a>
+<span class="sourceLineNo">2051</span>   * Return the appropriate DUMMY_HEADER for the minor version<a name="line.2051"></a>
+<span class="sourceLineNo">2052</span>   */<a name="line.2052"></a>
+<span class="sourceLineNo">2053</span>  static private byte[] getDummyHeaderForVersion(boolean usesHBaseChecksum) {<a name="line.2053"></a>
+<span class="sourceLineNo">2054</span>    return usesHBaseChecksum? HConstants.HFILEBLOCK_DUMMY_HEADER: DUMMY_HEADER_NO_CHECKSUM;<a name="line.2054"></a>
+<span class="sourceLineNo">2055</span>  }<a name="line.2055"></a>
+<span class="sourceLineNo">2056</span><a name="line.2056"></a>
+<span class="sourceLineNo">2057</span>  /**<a name="line.2057"></a>
+<span class="sourceLineNo">2058</span>   * @return This HFileBlocks fileContext which will a derivative of the<a name="line.2058"></a>
+<span class="sourceLineNo">2059</span>   * fileContext for the file from which this block's data was originally read.<a name="line.2059"></a>
+<span class="sourceLineNo">2060</span>   */<a name="line.2060"></a>
+<span class="sourceLineNo">2061</span>  HFileContext getHFileContext() {<a name="line.2061"></a>
+<span class="sourceLineNo">2062</span>    return this.fileContext;<a name="line.2062"></a>
+<span class="sourceLineNo">2063</span>  }<a name="line.2063"></a>
+<span class="sourceLineNo">2064</span><a name="line.2064"></a>
+<span class="sourceLineNo">2065</span>  @Override<a name="line.2065"></a>
+<span class="sourceLineNo">2066</span>  public MemoryType getMemoryType() {<a name="line.2066"></a>
+<span class="sourceLineNo">2067</span>    return this.memType;<a name="line.2067"></a>
+<span class="sourceLineNo">2068</span>  }<a name="line.2068"></a>
+<span class="sourceLineNo">2069</span><a name="line.2069"></a>
+<span class="sourceLineNo">2070</span>  /**<a name="line.2070"></a>
+<span class="sourceLineNo">2071</span>   * @return true if this block is backed by a shared memory area(such as that of a BucketCache).<a name="line.2071"></a>
+<span class="sourceLineNo">2072</span>   */<a name="line.2072"></a>
+<span class="sourceLineNo">2073</span>  boolean usesSharedMemory() {<a name="line.2073"></a>
+<span class="sourceLineNo">2074</span>    return this.memType == MemoryType.SHARED;<a name="line.2074"></a>
+<span class="sourceLineNo">2075</span>  }<a name="line.2075"></a>
+<span class="sourceLineNo">2076</span><a name="line.2076"></a>
+<span class="sourceLineNo">2077</span>  /**<a name="line.2077"></a>
+<span class="sourceLineNo">2078</span>   * Convert the contents of the block header into a human readable string.<a name="line.2078"></a>
+<span class="sourceLineNo">2079</span>   * This is mostly helpful for debugging. This assumes that the block<a name="line.2079"></a>
+<span class="sourceLineNo">2080</span>   * has minor version &gt; 0.<a name="line.2080"></a>
+<span class="sourceLineNo">2081</span>   */<a name="line.2081"></a>
+<span class="sourceLineNo">2082</span>  @VisibleForTesting<a name="line.2082"></a>
+<span class="sourceLineNo">2083</span>  static String toStringHeader(ByteBuff buf) throws IOException {<a name="line.2083"></a>
+<span class="sourceLineNo">2084</span>    byte[] magicBuf = new byte[Math.min(buf.limit() - buf.position(), BlockType.MAGIC_LENGTH)];<a name="line.2084"></a>
+<span class="sourceLineNo">2085</span>    buf.get(magicBuf);<a name="line.2085"></a>
+<span class="sourceLineNo">2086</span>    BlockType bt = BlockType.parse(magicBuf, 0, BlockType.MAGIC_LENGTH);<a name="line.2086"></a>
+<span class="sourceLineNo">2087</span>    int compressedBlockSizeNoHeader = buf.getInt();<a name="line.2087"></a>
+<span class="sourceLineNo">2088</span>    int uncompressedBlockSizeNoHeader = buf.getInt();<a name="line.2088"></a>
+<span class="sourceLineNo">2089</span>    long prevBlockOffset = buf.getLong();<a name="line.2089"></a>
+<span class="sourceLineNo">2090</span>    byte cksumtype = buf.get();<a name="line.2090"></a>
+<span class="sourceLineNo">2091</span>    long bytesPerChecksum = buf.getInt();<a name="line.2091"></a>
+<span class="sourceLineNo">2092</span>    long onDiskDataSizeWithHeader = buf.getInt();<a name="line.2092"></a>
+<span class="sourceLineNo">2093</span>    return " Header dump: magic: " + Bytes.toString(magicBuf) +<a name="line.2093"></a>
+<span class="sourceLineNo">2094</span>                   " blockType " + bt +<a name="line.2094"></a>
+<span class="sourceLineNo">2095</span>                   " compressedBlockSizeNoHeader " +<a name="line.2095"></a>
+<span class="sourceLineNo">2096</span>                   compressedBlockSizeNoHeader +<a name="line.2096"></a>
+<span class="sourceLineNo">2097</span>                   " uncompressedBlockSizeNoHeader " +<a name="line.2097"></a>
+<span class="sourceLineNo">2098</span>                   uncompressedBlockSizeNoHeader +<a name="line.2098"></a>
+<span class="sourceLineNo">2099</span>                   " prevBlockOffset " + prevBlockOffset +<a name="line.2099"></a>
+<span class="sourceLineNo">2100</span>                   " checksumType " + ChecksumType.codeToType(cksumtype) +<a name="line.2100"></a>
+<span class="sourceLineNo">2101</span>                   " bytesPerChecksum " + bytesPerChecksum +<a name="line.2101"></a>
+<span class="sourceLineNo">2102</span>                   " onDiskDataSizeWithHeader " + onDiskDataSizeWithHeader;<a name="line.2102"></a>
+<span class="sourceLineNo">2103</span>  }<a name="line.2103"></a>
+<span class="sourceLineNo">2104</span><a name="line.2104"></a>
+<span class="sourceLineNo">2105</span>  public HFileBlock deepClone() {<a name="line.2105"></a>
+<span class="sourceLineNo">2106</span>    return new HFileBlock(this, true);<a name="line.2106"></a>
 <span class="sourceLineNo">2107</span>  }<a name="line.2107"></a>
-<span class="sourceLineNo">2108</span><a name="line.2108"></a>
-<span class="sourceLineNo">2109</span>  public HFileBlock deepClone() {<a name="line.2109"></a>
-<span class="sourceLineNo">2110</span>    return new HFileBlock(this, true);<a name="line.2110"></a>
-<span class="sourceLineNo">2111</span>  }<a name="line.2111"></a>
-<span class="sourceLineNo">2112</span>}<a name="line.2112"></a>
+<span class="sourceLineNo">2108</span>}<a name="line.2108"></a>
 
 
 


Mime
View raw message