hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From git-site-r...@apache.org
Subject [03/51] [partial] hbase-site git commit: Published site at 82d554e3783372cc6b05489452c815b57c06f6cd.
Date Thu, 11 May 2017 14:59:19 GMT
http://git-wip-us.apache.org/repos/asf/hbase-site/blob/1241ee85/testdevapidocs/src-html/org/apache/hadoop/hbase/io/hfile/TestHFileBlock.BlockReaderThread.html
----------------------------------------------------------------------
diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/io/hfile/TestHFileBlock.BlockReaderThread.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/io/hfile/TestHFileBlock.BlockReaderThread.html
index b535394..1b4407c 100644
--- a/testdevapidocs/src-html/org/apache/hadoop/hbase/io/hfile/TestHFileBlock.BlockReaderThread.html
+++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/io/hfile/TestHFileBlock.BlockReaderThread.html
@@ -679,187 +679,188 @@
 <span class="sourceLineNo">671</span>      while (System.currentTimeMillis() &lt; endTime) {<a name="line.671"></a>
 <span class="sourceLineNo">672</span>        int blockId = rand.nextInt(NUM_TEST_BLOCKS);<a name="line.672"></a>
 <span class="sourceLineNo">673</span>        long offset = offsets.get(blockId);<a name="line.673"></a>
-<span class="sourceLineNo">674</span>        boolean pread = rand.nextBoolean();<a name="line.674"></a>
-<span class="sourceLineNo">675</span>        boolean withOnDiskSize = rand.nextBoolean();<a name="line.675"></a>
-<span class="sourceLineNo">676</span>        long expectedSize =<a name="line.676"></a>
-<span class="sourceLineNo">677</span>          (blockId == NUM_TEST_BLOCKS - 1 ? fileSize<a name="line.677"></a>
-<span class="sourceLineNo">678</span>              : offsets.get(blockId + 1)) - offset;<a name="line.678"></a>
-<span class="sourceLineNo">679</span><a name="line.679"></a>
-<span class="sourceLineNo">680</span>        HFileBlock b;<a name="line.680"></a>
-<span class="sourceLineNo">681</span>        try {<a name="line.681"></a>
-<span class="sourceLineNo">682</span>          long onDiskSizeArg = withOnDiskSize ? expectedSize : -1;<a name="line.682"></a>
-<span class="sourceLineNo">683</span>          b = hbr.readBlockData(offset, onDiskSizeArg, pread);<a name="line.683"></a>
-<span class="sourceLineNo">684</span>        } catch (IOException ex) {<a name="line.684"></a>
-<span class="sourceLineNo">685</span>          LOG.error("Error in client " + clientId + " trying to read block at "<a name="line.685"></a>
-<span class="sourceLineNo">686</span>              + offset + ", pread=" + pread + ", withOnDiskSize=" +<a name="line.686"></a>
-<span class="sourceLineNo">687</span>              withOnDiskSize, ex);<a name="line.687"></a>
-<span class="sourceLineNo">688</span>          return false;<a name="line.688"></a>
-<span class="sourceLineNo">689</span>        }<a name="line.689"></a>
-<span class="sourceLineNo">690</span><a name="line.690"></a>
-<span class="sourceLineNo">691</span>        assertEquals(types.get(blockId), b.getBlockType());<a name="line.691"></a>
-<span class="sourceLineNo">692</span>        assertEquals(expectedSize, b.getOnDiskSizeWithHeader());<a name="line.692"></a>
-<span class="sourceLineNo">693</span>        assertEquals(offset, b.getOffset());<a name="line.693"></a>
-<span class="sourceLineNo">694</span><a name="line.694"></a>
-<span class="sourceLineNo">695</span>        ++numBlocksRead;<a name="line.695"></a>
-<span class="sourceLineNo">696</span>        if (pread)<a name="line.696"></a>
-<span class="sourceLineNo">697</span>          ++numPositionalRead;<a name="line.697"></a>
-<span class="sourceLineNo">698</span>        if (withOnDiskSize)<a name="line.698"></a>
-<span class="sourceLineNo">699</span>          ++numWithOnDiskSize;<a name="line.699"></a>
-<span class="sourceLineNo">700</span>      }<a name="line.700"></a>
-<span class="sourceLineNo">701</span>      LOG.info("Client " + clientId + " successfully read " + numBlocksRead +<a name="line.701"></a>
-<span class="sourceLineNo">702</span>        " blocks (with pread: " + numPositionalRead + ", with onDiskSize " +<a name="line.702"></a>
-<span class="sourceLineNo">703</span>        "specified: " + numWithOnDiskSize + ")");<a name="line.703"></a>
-<span class="sourceLineNo">704</span><a name="line.704"></a>
-<span class="sourceLineNo">705</span>      return true;<a name="line.705"></a>
-<span class="sourceLineNo">706</span>    }<a name="line.706"></a>
-<span class="sourceLineNo">707</span><a name="line.707"></a>
-<span class="sourceLineNo">708</span>  }<a name="line.708"></a>
-<span class="sourceLineNo">709</span><a name="line.709"></a>
-<span class="sourceLineNo">710</span>  @Test<a name="line.710"></a>
-<span class="sourceLineNo">711</span>  public void testConcurrentReading() throws Exception {<a name="line.711"></a>
-<span class="sourceLineNo">712</span>    testConcurrentReadingInternals();<a name="line.712"></a>
-<span class="sourceLineNo">713</span>  }<a name="line.713"></a>
-<span class="sourceLineNo">714</span><a name="line.714"></a>
-<span class="sourceLineNo">715</span>  protected void testConcurrentReadingInternals() throws IOException,<a name="line.715"></a>
-<span class="sourceLineNo">716</span>      InterruptedException, ExecutionException {<a name="line.716"></a>
-<span class="sourceLineNo">717</span>    for (Compression.Algorithm compressAlgo : COMPRESSION_ALGORITHMS) {<a name="line.717"></a>
-<span class="sourceLineNo">718</span>      Path path = new Path(TEST_UTIL.getDataTestDir(), "concurrent_reading");<a name="line.718"></a>
-<span class="sourceLineNo">719</span>      Random rand = defaultRandom();<a name="line.719"></a>
-<span class="sourceLineNo">720</span>      List&lt;Long&gt; offsets = new ArrayList&lt;&gt;();<a name="line.720"></a>
-<span class="sourceLineNo">721</span>      List&lt;BlockType&gt; types = new ArrayList&lt;&gt;();<a name="line.721"></a>
-<span class="sourceLineNo">722</span>      writeBlocks(rand, compressAlgo, path, offsets, null, types, null);<a name="line.722"></a>
-<span class="sourceLineNo">723</span>      FSDataInputStream is = fs.open(path);<a name="line.723"></a>
-<span class="sourceLineNo">724</span>      long fileSize = fs.getFileStatus(path).getLen();<a name="line.724"></a>
-<span class="sourceLineNo">725</span>      HFileContext meta = new HFileContextBuilder()<a name="line.725"></a>
-<span class="sourceLineNo">726</span>                          .withHBaseCheckSum(true)<a name="line.726"></a>
-<span class="sourceLineNo">727</span>                          .withIncludesMvcc(includesMemstoreTS)<a name="line.727"></a>
-<span class="sourceLineNo">728</span>                          .withIncludesTags(includesTag)<a name="line.728"></a>
-<span class="sourceLineNo">729</span>                          .withCompression(compressAlgo)<a name="line.729"></a>
-<span class="sourceLineNo">730</span>                          .build();<a name="line.730"></a>
-<span class="sourceLineNo">731</span>      HFileBlock.FSReader hbr = new HFileBlock.FSReaderImpl(is, fileSize, meta);<a name="line.731"></a>
-<span class="sourceLineNo">732</span><a name="line.732"></a>
-<span class="sourceLineNo">733</span>      Executor exec = Executors.newFixedThreadPool(NUM_READER_THREADS);<a name="line.733"></a>
-<span class="sourceLineNo">734</span>      ExecutorCompletionService&lt;Boolean&gt; ecs = new ExecutorCompletionService&lt;&gt;(exec);<a name="line.734"></a>
-<span class="sourceLineNo">735</span><a name="line.735"></a>
-<span class="sourceLineNo">736</span>      for (int i = 0; i &lt; NUM_READER_THREADS; ++i) {<a name="line.736"></a>
-<span class="sourceLineNo">737</span>        ecs.submit(new BlockReaderThread("reader_" + (char) ('A' + i), hbr,<a name="line.737"></a>
-<span class="sourceLineNo">738</span>            offsets, types, fileSize));<a name="line.738"></a>
-<span class="sourceLineNo">739</span>      }<a name="line.739"></a>
-<span class="sourceLineNo">740</span><a name="line.740"></a>
-<span class="sourceLineNo">741</span>      for (int i = 0; i &lt; NUM_READER_THREADS; ++i) {<a name="line.741"></a>
-<span class="sourceLineNo">742</span>        Future&lt;Boolean&gt; result = ecs.take();<a name="line.742"></a>
-<span class="sourceLineNo">743</span>        assertTrue(result.get());<a name="line.743"></a>
-<span class="sourceLineNo">744</span>        if (detailedLogging) {<a name="line.744"></a>
-<span class="sourceLineNo">745</span>          LOG.info(String.valueOf(i + 1)<a name="line.745"></a>
-<span class="sourceLineNo">746</span>            + " reader threads finished successfully (algo=" + compressAlgo<a name="line.746"></a>
-<span class="sourceLineNo">747</span>            + ")");<a name="line.747"></a>
-<span class="sourceLineNo">748</span>        }<a name="line.748"></a>
-<span class="sourceLineNo">749</span>      }<a name="line.749"></a>
-<span class="sourceLineNo">750</span><a name="line.750"></a>
-<span class="sourceLineNo">751</span>      is.close();<a name="line.751"></a>
-<span class="sourceLineNo">752</span>    }<a name="line.752"></a>
-<span class="sourceLineNo">753</span>  }<a name="line.753"></a>
-<span class="sourceLineNo">754</span><a name="line.754"></a>
-<span class="sourceLineNo">755</span>  private long writeBlocks(Random rand, Compression.Algorithm compressAlgo,<a name="line.755"></a>
-<span class="sourceLineNo">756</span>      Path path, List&lt;Long&gt; expectedOffsets, List&lt;Long&gt; expectedPrevOffsets,<a name="line.756"></a>
-<span class="sourceLineNo">757</span>      List&lt;BlockType&gt; expectedTypes, List&lt;ByteBuffer&gt; expectedContents<a name="line.757"></a>
-<span class="sourceLineNo">758</span>  ) throws IOException {<a name="line.758"></a>
-<span class="sourceLineNo">759</span>    boolean cacheOnWrite = expectedContents != null;<a name="line.759"></a>
-<span class="sourceLineNo">760</span>    FSDataOutputStream os = fs.create(path);<a name="line.760"></a>
-<span class="sourceLineNo">761</span>    HFileContext meta = new HFileContextBuilder()<a name="line.761"></a>
-<span class="sourceLineNo">762</span>                        .withHBaseCheckSum(true)<a name="line.762"></a>
-<span class="sourceLineNo">763</span>                        .withIncludesMvcc(includesMemstoreTS)<a name="line.763"></a>
-<span class="sourceLineNo">764</span>                        .withIncludesTags(includesTag)<a name="line.764"></a>
-<span class="sourceLineNo">765</span>                        .withCompression(compressAlgo)<a name="line.765"></a>
-<span class="sourceLineNo">766</span>                        .withBytesPerCheckSum(HFile.DEFAULT_BYTES_PER_CHECKSUM)<a name="line.766"></a>
-<span class="sourceLineNo">767</span>                        .build();<a name="line.767"></a>
-<span class="sourceLineNo">768</span>    HFileBlock.Writer hbw = new HFileBlock.Writer(null, meta);<a name="line.768"></a>
-<span class="sourceLineNo">769</span>    Map&lt;BlockType, Long&gt; prevOffsetByType = new HashMap&lt;&gt;();<a name="line.769"></a>
-<span class="sourceLineNo">770</span>    long totalSize = 0;<a name="line.770"></a>
-<span class="sourceLineNo">771</span>    for (int i = 0; i &lt; NUM_TEST_BLOCKS; ++i) {<a name="line.771"></a>
-<span class="sourceLineNo">772</span>      long pos = os.getPos();<a name="line.772"></a>
-<span class="sourceLineNo">773</span>      int blockTypeOrdinal = rand.nextInt(BlockType.values().length);<a name="line.773"></a>
-<span class="sourceLineNo">774</span>      if (blockTypeOrdinal == BlockType.ENCODED_DATA.ordinal()) {<a name="line.774"></a>
-<span class="sourceLineNo">775</span>        blockTypeOrdinal = BlockType.DATA.ordinal();<a name="line.775"></a>
-<span class="sourceLineNo">776</span>      }<a name="line.776"></a>
-<span class="sourceLineNo">777</span>      BlockType bt = BlockType.values()[blockTypeOrdinal];<a name="line.777"></a>
-<span class="sourceLineNo">778</span>      DataOutputStream dos = hbw.startWriting(bt);<a name="line.778"></a>
-<span class="sourceLineNo">779</span>      int size = rand.nextInt(500);<a name="line.779"></a>
-<span class="sourceLineNo">780</span>      for (int j = 0; j &lt; size; ++j) {<a name="line.780"></a>
-<span class="sourceLineNo">781</span>        // This might compress well.<a name="line.781"></a>
-<span class="sourceLineNo">782</span>        dos.writeShort(i + 1);<a name="line.782"></a>
-<span class="sourceLineNo">783</span>        dos.writeInt(j + 1);<a name="line.783"></a>
-<span class="sourceLineNo">784</span>      }<a name="line.784"></a>
-<span class="sourceLineNo">785</span><a name="line.785"></a>
-<span class="sourceLineNo">786</span>      if (expectedOffsets != null)<a name="line.786"></a>
-<span class="sourceLineNo">787</span>        expectedOffsets.add(os.getPos());<a name="line.787"></a>
-<span class="sourceLineNo">788</span><a name="line.788"></a>
-<span class="sourceLineNo">789</span>      if (expectedPrevOffsets != null) {<a name="line.789"></a>
-<span class="sourceLineNo">790</span>        Long prevOffset = prevOffsetByType.get(bt);<a name="line.790"></a>
-<span class="sourceLineNo">791</span>        expectedPrevOffsets.add(prevOffset != null ? prevOffset : -1);<a name="line.791"></a>
-<span class="sourceLineNo">792</span>        prevOffsetByType.put(bt, os.getPos());<a name="line.792"></a>
-<span class="sourceLineNo">793</span>      }<a name="line.793"></a>
-<span class="sourceLineNo">794</span><a name="line.794"></a>
-<span class="sourceLineNo">795</span>      expectedTypes.add(bt);<a name="line.795"></a>
-<span class="sourceLineNo">796</span><a name="line.796"></a>
-<span class="sourceLineNo">797</span>      hbw.writeHeaderAndData(os);<a name="line.797"></a>
-<span class="sourceLineNo">798</span>      totalSize += hbw.getOnDiskSizeWithHeader();<a name="line.798"></a>
-<span class="sourceLineNo">799</span><a name="line.799"></a>
-<span class="sourceLineNo">800</span>      if (cacheOnWrite)<a name="line.800"></a>
-<span class="sourceLineNo">801</span>        expectedContents.add(hbw.cloneUncompressedBufferWithHeader());<a name="line.801"></a>
-<span class="sourceLineNo">802</span><a name="line.802"></a>
-<span class="sourceLineNo">803</span>      if (detailedLogging) {<a name="line.803"></a>
-<span class="sourceLineNo">804</span>        LOG.info("Written block #" + i + " of type " + bt<a name="line.804"></a>
-<span class="sourceLineNo">805</span>            + ", uncompressed size " + hbw.getUncompressedSizeWithoutHeader()<a name="line.805"></a>
-<span class="sourceLineNo">806</span>            + ", packed size " + hbw.getOnDiskSizeWithoutHeader()<a name="line.806"></a>
-<span class="sourceLineNo">807</span>            + " at offset " + pos);<a name="line.807"></a>
-<span class="sourceLineNo">808</span>      }<a name="line.808"></a>
-<span class="sourceLineNo">809</span>    }<a name="line.809"></a>
-<span class="sourceLineNo">810</span>    os.close();<a name="line.810"></a>
-<span class="sourceLineNo">811</span>    LOG.info("Created a temporary file at " + path + ", "<a name="line.811"></a>
-<span class="sourceLineNo">812</span>        + fs.getFileStatus(path).getLen() + " byte, compression=" +<a name="line.812"></a>
-<span class="sourceLineNo">813</span>        compressAlgo);<a name="line.813"></a>
-<span class="sourceLineNo">814</span>    return totalSize;<a name="line.814"></a>
-<span class="sourceLineNo">815</span>  }<a name="line.815"></a>
-<span class="sourceLineNo">816</span><a name="line.816"></a>
-<span class="sourceLineNo">817</span>  @Test<a name="line.817"></a>
-<span class="sourceLineNo">818</span>  public void testBlockHeapSize() {<a name="line.818"></a>
-<span class="sourceLineNo">819</span>    testBlockHeapSizeInternals();<a name="line.819"></a>
-<span class="sourceLineNo">820</span>  }<a name="line.820"></a>
-<span class="sourceLineNo">821</span><a name="line.821"></a>
-<span class="sourceLineNo">822</span>  protected void testBlockHeapSizeInternals() {<a name="line.822"></a>
-<span class="sourceLineNo">823</span>    if (ClassSize.is32BitJVM()) {<a name="line.823"></a>
-<span class="sourceLineNo">824</span>      assertEquals(64, HFileBlock.MULTI_BYTE_BUFFER_HEAP_SIZE);<a name="line.824"></a>
-<span class="sourceLineNo">825</span>    } else {<a name="line.825"></a>
-<span class="sourceLineNo">826</span>      assertEquals(72, HFileBlock.MULTI_BYTE_BUFFER_HEAP_SIZE);<a name="line.826"></a>
-<span class="sourceLineNo">827</span>    }<a name="line.827"></a>
-<span class="sourceLineNo">828</span><a name="line.828"></a>
-<span class="sourceLineNo">829</span>    for (int size : new int[] { 100, 256, 12345 }) {<a name="line.829"></a>
-<span class="sourceLineNo">830</span>      byte[] byteArr = new byte[HConstants.HFILEBLOCK_HEADER_SIZE + size];<a name="line.830"></a>
-<span class="sourceLineNo">831</span>      ByteBuffer buf = ByteBuffer.wrap(byteArr, 0, size);<a name="line.831"></a>
-<span class="sourceLineNo">832</span>      HFileContext meta = new HFileContextBuilder()<a name="line.832"></a>
-<span class="sourceLineNo">833</span>                          .withIncludesMvcc(includesMemstoreTS)<a name="line.833"></a>
-<span class="sourceLineNo">834</span>                          .withIncludesTags(includesTag)<a name="line.834"></a>
-<span class="sourceLineNo">835</span>                          .withHBaseCheckSum(false)<a name="line.835"></a>
-<span class="sourceLineNo">836</span>                          .withCompression(Algorithm.NONE)<a name="line.836"></a>
-<span class="sourceLineNo">837</span>                          .withBytesPerCheckSum(HFile.DEFAULT_BYTES_PER_CHECKSUM)<a name="line.837"></a>
-<span class="sourceLineNo">838</span>                          .withChecksumType(ChecksumType.NULL).build();<a name="line.838"></a>
-<span class="sourceLineNo">839</span>      HFileBlock block = new HFileBlock(BlockType.DATA, size, size, -1, buf,<a name="line.839"></a>
-<span class="sourceLineNo">840</span>          HFileBlock.FILL_HEADER, -1, 0, -1, meta);<a name="line.840"></a>
-<span class="sourceLineNo">841</span>      long byteBufferExpectedSize = ClassSize.align(ClassSize.estimateBase(<a name="line.841"></a>
-<span class="sourceLineNo">842</span>          new MultiByteBuff(buf).getClass(), true)<a name="line.842"></a>
-<span class="sourceLineNo">843</span>          + HConstants.HFILEBLOCK_HEADER_SIZE + size);<a name="line.843"></a>
-<span class="sourceLineNo">844</span>      long hfileMetaSize =  ClassSize.align(ClassSize.estimateBase(HFileContext.class, true));<a name="line.844"></a>
-<span class="sourceLineNo">845</span>      long hfileBlockExpectedSize =<a name="line.845"></a>
-<span class="sourceLineNo">846</span>          ClassSize.align(ClassSize.estimateBase(HFileBlock.class, true));<a name="line.846"></a>
-<span class="sourceLineNo">847</span>      long expected = hfileBlockExpectedSize + byteBufferExpectedSize + hfileMetaSize;<a name="line.847"></a>
-<span class="sourceLineNo">848</span>      assertEquals("Block data size: " + size + ", byte buffer expected " +<a name="line.848"></a>
-<span class="sourceLineNo">849</span>          "size: " + byteBufferExpectedSize + ", HFileBlock class expected " +<a name="line.849"></a>
-<span class="sourceLineNo">850</span>          "size: " + hfileBlockExpectedSize + ";", expected,<a name="line.850"></a>
-<span class="sourceLineNo">851</span>          block.heapSize());<a name="line.851"></a>
-<span class="sourceLineNo">852</span>    }<a name="line.852"></a>
-<span class="sourceLineNo">853</span>  }<a name="line.853"></a>
-<span class="sourceLineNo">854</span>}<a name="line.854"></a>
+<span class="sourceLineNo">674</span>        // now we only support concurrent read with pread = true<a name="line.674"></a>
+<span class="sourceLineNo">675</span>        boolean pread = true;<a name="line.675"></a>
+<span class="sourceLineNo">676</span>        boolean withOnDiskSize = rand.nextBoolean();<a name="line.676"></a>
+<span class="sourceLineNo">677</span>        long expectedSize =<a name="line.677"></a>
+<span class="sourceLineNo">678</span>          (blockId == NUM_TEST_BLOCKS - 1 ? fileSize<a name="line.678"></a>
+<span class="sourceLineNo">679</span>              : offsets.get(blockId + 1)) - offset;<a name="line.679"></a>
+<span class="sourceLineNo">680</span><a name="line.680"></a>
+<span class="sourceLineNo">681</span>        HFileBlock b;<a name="line.681"></a>
+<span class="sourceLineNo">682</span>        try {<a name="line.682"></a>
+<span class="sourceLineNo">683</span>          long onDiskSizeArg = withOnDiskSize ? expectedSize : -1;<a name="line.683"></a>
+<span class="sourceLineNo">684</span>          b = hbr.readBlockData(offset, onDiskSizeArg, pread);<a name="line.684"></a>
+<span class="sourceLineNo">685</span>        } catch (IOException ex) {<a name="line.685"></a>
+<span class="sourceLineNo">686</span>          LOG.error("Error in client " + clientId + " trying to read block at "<a name="line.686"></a>
+<span class="sourceLineNo">687</span>              + offset + ", pread=" + pread + ", withOnDiskSize=" +<a name="line.687"></a>
+<span class="sourceLineNo">688</span>              withOnDiskSize, ex);<a name="line.688"></a>
+<span class="sourceLineNo">689</span>          return false;<a name="line.689"></a>
+<span class="sourceLineNo">690</span>        }<a name="line.690"></a>
+<span class="sourceLineNo">691</span><a name="line.691"></a>
+<span class="sourceLineNo">692</span>        assertEquals(types.get(blockId), b.getBlockType());<a name="line.692"></a>
+<span class="sourceLineNo">693</span>        assertEquals(expectedSize, b.getOnDiskSizeWithHeader());<a name="line.693"></a>
+<span class="sourceLineNo">694</span>        assertEquals(offset, b.getOffset());<a name="line.694"></a>
+<span class="sourceLineNo">695</span><a name="line.695"></a>
+<span class="sourceLineNo">696</span>        ++numBlocksRead;<a name="line.696"></a>
+<span class="sourceLineNo">697</span>        if (pread)<a name="line.697"></a>
+<span class="sourceLineNo">698</span>          ++numPositionalRead;<a name="line.698"></a>
+<span class="sourceLineNo">699</span>        if (withOnDiskSize)<a name="line.699"></a>
+<span class="sourceLineNo">700</span>          ++numWithOnDiskSize;<a name="line.700"></a>
+<span class="sourceLineNo">701</span>      }<a name="line.701"></a>
+<span class="sourceLineNo">702</span>      LOG.info("Client " + clientId + " successfully read " + numBlocksRead +<a name="line.702"></a>
+<span class="sourceLineNo">703</span>        " blocks (with pread: " + numPositionalRead + ", with onDiskSize " +<a name="line.703"></a>
+<span class="sourceLineNo">704</span>        "specified: " + numWithOnDiskSize + ")");<a name="line.704"></a>
+<span class="sourceLineNo">705</span><a name="line.705"></a>
+<span class="sourceLineNo">706</span>      return true;<a name="line.706"></a>
+<span class="sourceLineNo">707</span>    }<a name="line.707"></a>
+<span class="sourceLineNo">708</span><a name="line.708"></a>
+<span class="sourceLineNo">709</span>  }<a name="line.709"></a>
+<span class="sourceLineNo">710</span><a name="line.710"></a>
+<span class="sourceLineNo">711</span>  @Test<a name="line.711"></a>
+<span class="sourceLineNo">712</span>  public void testConcurrentReading() throws Exception {<a name="line.712"></a>
+<span class="sourceLineNo">713</span>    testConcurrentReadingInternals();<a name="line.713"></a>
+<span class="sourceLineNo">714</span>  }<a name="line.714"></a>
+<span class="sourceLineNo">715</span><a name="line.715"></a>
+<span class="sourceLineNo">716</span>  protected void testConcurrentReadingInternals() throws IOException,<a name="line.716"></a>
+<span class="sourceLineNo">717</span>      InterruptedException, ExecutionException {<a name="line.717"></a>
+<span class="sourceLineNo">718</span>    for (Compression.Algorithm compressAlgo : COMPRESSION_ALGORITHMS) {<a name="line.718"></a>
+<span class="sourceLineNo">719</span>      Path path = new Path(TEST_UTIL.getDataTestDir(), "concurrent_reading");<a name="line.719"></a>
+<span class="sourceLineNo">720</span>      Random rand = defaultRandom();<a name="line.720"></a>
+<span class="sourceLineNo">721</span>      List&lt;Long&gt; offsets = new ArrayList&lt;&gt;();<a name="line.721"></a>
+<span class="sourceLineNo">722</span>      List&lt;BlockType&gt; types = new ArrayList&lt;&gt;();<a name="line.722"></a>
+<span class="sourceLineNo">723</span>      writeBlocks(rand, compressAlgo, path, offsets, null, types, null);<a name="line.723"></a>
+<span class="sourceLineNo">724</span>      FSDataInputStream is = fs.open(path);<a name="line.724"></a>
+<span class="sourceLineNo">725</span>      long fileSize = fs.getFileStatus(path).getLen();<a name="line.725"></a>
+<span class="sourceLineNo">726</span>      HFileContext meta = new HFileContextBuilder()<a name="line.726"></a>
+<span class="sourceLineNo">727</span>                          .withHBaseCheckSum(true)<a name="line.727"></a>
+<span class="sourceLineNo">728</span>                          .withIncludesMvcc(includesMemstoreTS)<a name="line.728"></a>
+<span class="sourceLineNo">729</span>                          .withIncludesTags(includesTag)<a name="line.729"></a>
+<span class="sourceLineNo">730</span>                          .withCompression(compressAlgo)<a name="line.730"></a>
+<span class="sourceLineNo">731</span>                          .build();<a name="line.731"></a>
+<span class="sourceLineNo">732</span>      HFileBlock.FSReader hbr = new HFileBlock.FSReaderImpl(is, fileSize, meta);<a name="line.732"></a>
+<span class="sourceLineNo">733</span><a name="line.733"></a>
+<span class="sourceLineNo">734</span>      Executor exec = Executors.newFixedThreadPool(NUM_READER_THREADS);<a name="line.734"></a>
+<span class="sourceLineNo">735</span>      ExecutorCompletionService&lt;Boolean&gt; ecs = new ExecutorCompletionService&lt;&gt;(exec);<a name="line.735"></a>
+<span class="sourceLineNo">736</span><a name="line.736"></a>
+<span class="sourceLineNo">737</span>      for (int i = 0; i &lt; NUM_READER_THREADS; ++i) {<a name="line.737"></a>
+<span class="sourceLineNo">738</span>        ecs.submit(new BlockReaderThread("reader_" + (char) ('A' + i), hbr,<a name="line.738"></a>
+<span class="sourceLineNo">739</span>            offsets, types, fileSize));<a name="line.739"></a>
+<span class="sourceLineNo">740</span>      }<a name="line.740"></a>
+<span class="sourceLineNo">741</span><a name="line.741"></a>
+<span class="sourceLineNo">742</span>      for (int i = 0; i &lt; NUM_READER_THREADS; ++i) {<a name="line.742"></a>
+<span class="sourceLineNo">743</span>        Future&lt;Boolean&gt; result = ecs.take();<a name="line.743"></a>
+<span class="sourceLineNo">744</span>        assertTrue(result.get());<a name="line.744"></a>
+<span class="sourceLineNo">745</span>        if (detailedLogging) {<a name="line.745"></a>
+<span class="sourceLineNo">746</span>          LOG.info(String.valueOf(i + 1)<a name="line.746"></a>
+<span class="sourceLineNo">747</span>            + " reader threads finished successfully (algo=" + compressAlgo<a name="line.747"></a>
+<span class="sourceLineNo">748</span>            + ")");<a name="line.748"></a>
+<span class="sourceLineNo">749</span>        }<a name="line.749"></a>
+<span class="sourceLineNo">750</span>      }<a name="line.750"></a>
+<span class="sourceLineNo">751</span><a name="line.751"></a>
+<span class="sourceLineNo">752</span>      is.close();<a name="line.752"></a>
+<span class="sourceLineNo">753</span>    }<a name="line.753"></a>
+<span class="sourceLineNo">754</span>  }<a name="line.754"></a>
+<span class="sourceLineNo">755</span><a name="line.755"></a>
+<span class="sourceLineNo">756</span>  private long writeBlocks(Random rand, Compression.Algorithm compressAlgo,<a name="line.756"></a>
+<span class="sourceLineNo">757</span>      Path path, List&lt;Long&gt; expectedOffsets, List&lt;Long&gt; expectedPrevOffsets,<a name="line.757"></a>
+<span class="sourceLineNo">758</span>      List&lt;BlockType&gt; expectedTypes, List&lt;ByteBuffer&gt; expectedContents<a name="line.758"></a>
+<span class="sourceLineNo">759</span>  ) throws IOException {<a name="line.759"></a>
+<span class="sourceLineNo">760</span>    boolean cacheOnWrite = expectedContents != null;<a name="line.760"></a>
+<span class="sourceLineNo">761</span>    FSDataOutputStream os = fs.create(path);<a name="line.761"></a>
+<span class="sourceLineNo">762</span>    HFileContext meta = new HFileContextBuilder()<a name="line.762"></a>
+<span class="sourceLineNo">763</span>                        .withHBaseCheckSum(true)<a name="line.763"></a>
+<span class="sourceLineNo">764</span>                        .withIncludesMvcc(includesMemstoreTS)<a name="line.764"></a>
+<span class="sourceLineNo">765</span>                        .withIncludesTags(includesTag)<a name="line.765"></a>
+<span class="sourceLineNo">766</span>                        .withCompression(compressAlgo)<a name="line.766"></a>
+<span class="sourceLineNo">767</span>                        .withBytesPerCheckSum(HFile.DEFAULT_BYTES_PER_CHECKSUM)<a name="line.767"></a>
+<span class="sourceLineNo">768</span>                        .build();<a name="line.768"></a>
+<span class="sourceLineNo">769</span>    HFileBlock.Writer hbw = new HFileBlock.Writer(null, meta);<a name="line.769"></a>
+<span class="sourceLineNo">770</span>    Map&lt;BlockType, Long&gt; prevOffsetByType = new HashMap&lt;&gt;();<a name="line.770"></a>
+<span class="sourceLineNo">771</span>    long totalSize = 0;<a name="line.771"></a>
+<span class="sourceLineNo">772</span>    for (int i = 0; i &lt; NUM_TEST_BLOCKS; ++i) {<a name="line.772"></a>
+<span class="sourceLineNo">773</span>      long pos = os.getPos();<a name="line.773"></a>
+<span class="sourceLineNo">774</span>      int blockTypeOrdinal = rand.nextInt(BlockType.values().length);<a name="line.774"></a>
+<span class="sourceLineNo">775</span>      if (blockTypeOrdinal == BlockType.ENCODED_DATA.ordinal()) {<a name="line.775"></a>
+<span class="sourceLineNo">776</span>        blockTypeOrdinal = BlockType.DATA.ordinal();<a name="line.776"></a>
+<span class="sourceLineNo">777</span>      }<a name="line.777"></a>
+<span class="sourceLineNo">778</span>      BlockType bt = BlockType.values()[blockTypeOrdinal];<a name="line.778"></a>
+<span class="sourceLineNo">779</span>      DataOutputStream dos = hbw.startWriting(bt);<a name="line.779"></a>
+<span class="sourceLineNo">780</span>      int size = rand.nextInt(500);<a name="line.780"></a>
+<span class="sourceLineNo">781</span>      for (int j = 0; j &lt; size; ++j) {<a name="line.781"></a>
+<span class="sourceLineNo">782</span>        // This might compress well.<a name="line.782"></a>
+<span class="sourceLineNo">783</span>        dos.writeShort(i + 1);<a name="line.783"></a>
+<span class="sourceLineNo">784</span>        dos.writeInt(j + 1);<a name="line.784"></a>
+<span class="sourceLineNo">785</span>      }<a name="line.785"></a>
+<span class="sourceLineNo">786</span><a name="line.786"></a>
+<span class="sourceLineNo">787</span>      if (expectedOffsets != null)<a name="line.787"></a>
+<span class="sourceLineNo">788</span>        expectedOffsets.add(os.getPos());<a name="line.788"></a>
+<span class="sourceLineNo">789</span><a name="line.789"></a>
+<span class="sourceLineNo">790</span>      if (expectedPrevOffsets != null) {<a name="line.790"></a>
+<span class="sourceLineNo">791</span>        Long prevOffset = prevOffsetByType.get(bt);<a name="line.791"></a>
+<span class="sourceLineNo">792</span>        expectedPrevOffsets.add(prevOffset != null ? prevOffset : -1);<a name="line.792"></a>
+<span class="sourceLineNo">793</span>        prevOffsetByType.put(bt, os.getPos());<a name="line.793"></a>
+<span class="sourceLineNo">794</span>      }<a name="line.794"></a>
+<span class="sourceLineNo">795</span><a name="line.795"></a>
+<span class="sourceLineNo">796</span>      expectedTypes.add(bt);<a name="line.796"></a>
+<span class="sourceLineNo">797</span><a name="line.797"></a>
+<span class="sourceLineNo">798</span>      hbw.writeHeaderAndData(os);<a name="line.798"></a>
+<span class="sourceLineNo">799</span>      totalSize += hbw.getOnDiskSizeWithHeader();<a name="line.799"></a>
+<span class="sourceLineNo">800</span><a name="line.800"></a>
+<span class="sourceLineNo">801</span>      if (cacheOnWrite)<a name="line.801"></a>
+<span class="sourceLineNo">802</span>        expectedContents.add(hbw.cloneUncompressedBufferWithHeader());<a name="line.802"></a>
+<span class="sourceLineNo">803</span><a name="line.803"></a>
+<span class="sourceLineNo">804</span>      if (detailedLogging) {<a name="line.804"></a>
+<span class="sourceLineNo">805</span>        LOG.info("Written block #" + i + " of type " + bt<a name="line.805"></a>
+<span class="sourceLineNo">806</span>            + ", uncompressed size " + hbw.getUncompressedSizeWithoutHeader()<a name="line.806"></a>
+<span class="sourceLineNo">807</span>            + ", packed size " + hbw.getOnDiskSizeWithoutHeader()<a name="line.807"></a>
+<span class="sourceLineNo">808</span>            + " at offset " + pos);<a name="line.808"></a>
+<span class="sourceLineNo">809</span>      }<a name="line.809"></a>
+<span class="sourceLineNo">810</span>    }<a name="line.810"></a>
+<span class="sourceLineNo">811</span>    os.close();<a name="line.811"></a>
+<span class="sourceLineNo">812</span>    LOG.info("Created a temporary file at " + path + ", "<a name="line.812"></a>
+<span class="sourceLineNo">813</span>        + fs.getFileStatus(path).getLen() + " byte, compression=" +<a name="line.813"></a>
+<span class="sourceLineNo">814</span>        compressAlgo);<a name="line.814"></a>
+<span class="sourceLineNo">815</span>    return totalSize;<a name="line.815"></a>
+<span class="sourceLineNo">816</span>  }<a name="line.816"></a>
+<span class="sourceLineNo">817</span><a name="line.817"></a>
+<span class="sourceLineNo">818</span>  @Test<a name="line.818"></a>
+<span class="sourceLineNo">819</span>  public void testBlockHeapSize() {<a name="line.819"></a>
+<span class="sourceLineNo">820</span>    testBlockHeapSizeInternals();<a name="line.820"></a>
+<span class="sourceLineNo">821</span>  }<a name="line.821"></a>
+<span class="sourceLineNo">822</span><a name="line.822"></a>
+<span class="sourceLineNo">823</span>  protected void testBlockHeapSizeInternals() {<a name="line.823"></a>
+<span class="sourceLineNo">824</span>    if (ClassSize.is32BitJVM()) {<a name="line.824"></a>
+<span class="sourceLineNo">825</span>      assertEquals(64, HFileBlock.MULTI_BYTE_BUFFER_HEAP_SIZE);<a name="line.825"></a>
+<span class="sourceLineNo">826</span>    } else {<a name="line.826"></a>
+<span class="sourceLineNo">827</span>      assertEquals(72, HFileBlock.MULTI_BYTE_BUFFER_HEAP_SIZE);<a name="line.827"></a>
+<span class="sourceLineNo">828</span>    }<a name="line.828"></a>
+<span class="sourceLineNo">829</span><a name="line.829"></a>
+<span class="sourceLineNo">830</span>    for (int size : new int[] { 100, 256, 12345 }) {<a name="line.830"></a>
+<span class="sourceLineNo">831</span>      byte[] byteArr = new byte[HConstants.HFILEBLOCK_HEADER_SIZE + size];<a name="line.831"></a>
+<span class="sourceLineNo">832</span>      ByteBuffer buf = ByteBuffer.wrap(byteArr, 0, size);<a name="line.832"></a>
+<span class="sourceLineNo">833</span>      HFileContext meta = new HFileContextBuilder()<a name="line.833"></a>
+<span class="sourceLineNo">834</span>                          .withIncludesMvcc(includesMemstoreTS)<a name="line.834"></a>
+<span class="sourceLineNo">835</span>                          .withIncludesTags(includesTag)<a name="line.835"></a>
+<span class="sourceLineNo">836</span>                          .withHBaseCheckSum(false)<a name="line.836"></a>
+<span class="sourceLineNo">837</span>                          .withCompression(Algorithm.NONE)<a name="line.837"></a>
+<span class="sourceLineNo">838</span>                          .withBytesPerCheckSum(HFile.DEFAULT_BYTES_PER_CHECKSUM)<a name="line.838"></a>
+<span class="sourceLineNo">839</span>                          .withChecksumType(ChecksumType.NULL).build();<a name="line.839"></a>
+<span class="sourceLineNo">840</span>      HFileBlock block = new HFileBlock(BlockType.DATA, size, size, -1, buf,<a name="line.840"></a>
+<span class="sourceLineNo">841</span>          HFileBlock.FILL_HEADER, -1, 0, -1, meta);<a name="line.841"></a>
+<span class="sourceLineNo">842</span>      long byteBufferExpectedSize = ClassSize.align(ClassSize.estimateBase(<a name="line.842"></a>
+<span class="sourceLineNo">843</span>          new MultiByteBuff(buf).getClass(), true)<a name="line.843"></a>
+<span class="sourceLineNo">844</span>          + HConstants.HFILEBLOCK_HEADER_SIZE + size);<a name="line.844"></a>
+<span class="sourceLineNo">845</span>      long hfileMetaSize =  ClassSize.align(ClassSize.estimateBase(HFileContext.class, true));<a name="line.845"></a>
+<span class="sourceLineNo">846</span>      long hfileBlockExpectedSize =<a name="line.846"></a>
+<span class="sourceLineNo">847</span>          ClassSize.align(ClassSize.estimateBase(HFileBlock.class, true));<a name="line.847"></a>
+<span class="sourceLineNo">848</span>      long expected = hfileBlockExpectedSize + byteBufferExpectedSize + hfileMetaSize;<a name="line.848"></a>
+<span class="sourceLineNo">849</span>      assertEquals("Block data size: " + size + ", byte buffer expected " +<a name="line.849"></a>
+<span class="sourceLineNo">850</span>          "size: " + byteBufferExpectedSize + ", HFileBlock class expected " +<a name="line.850"></a>
+<span class="sourceLineNo">851</span>          "size: " + hfileBlockExpectedSize + ";", expected,<a name="line.851"></a>
+<span class="sourceLineNo">852</span>          block.heapSize());<a name="line.852"></a>
+<span class="sourceLineNo">853</span>    }<a name="line.853"></a>
+<span class="sourceLineNo">854</span>  }<a name="line.854"></a>
+<span class="sourceLineNo">855</span>}<a name="line.855"></a>
 
 
 

http://git-wip-us.apache.org/repos/asf/hbase-site/blob/1241ee85/testdevapidocs/src-html/org/apache/hadoop/hbase/io/hfile/TestHFileBlock.html
----------------------------------------------------------------------
diff --git a/testdevapidocs/src-html/org/apache/hadoop/hbase/io/hfile/TestHFileBlock.html b/testdevapidocs/src-html/org/apache/hadoop/hbase/io/hfile/TestHFileBlock.html
index b535394..1b4407c 100644
--- a/testdevapidocs/src-html/org/apache/hadoop/hbase/io/hfile/TestHFileBlock.html
+++ b/testdevapidocs/src-html/org/apache/hadoop/hbase/io/hfile/TestHFileBlock.html
@@ -679,187 +679,188 @@
 <span class="sourceLineNo">671</span>      while (System.currentTimeMillis() &lt; endTime) {<a name="line.671"></a>
 <span class="sourceLineNo">672</span>        int blockId = rand.nextInt(NUM_TEST_BLOCKS);<a name="line.672"></a>
 <span class="sourceLineNo">673</span>        long offset = offsets.get(blockId);<a name="line.673"></a>
-<span class="sourceLineNo">674</span>        boolean pread = rand.nextBoolean();<a name="line.674"></a>
-<span class="sourceLineNo">675</span>        boolean withOnDiskSize = rand.nextBoolean();<a name="line.675"></a>
-<span class="sourceLineNo">676</span>        long expectedSize =<a name="line.676"></a>
-<span class="sourceLineNo">677</span>          (blockId == NUM_TEST_BLOCKS - 1 ? fileSize<a name="line.677"></a>
-<span class="sourceLineNo">678</span>              : offsets.get(blockId + 1)) - offset;<a name="line.678"></a>
-<span class="sourceLineNo">679</span><a name="line.679"></a>
-<span class="sourceLineNo">680</span>        HFileBlock b;<a name="line.680"></a>
-<span class="sourceLineNo">681</span>        try {<a name="line.681"></a>
-<span class="sourceLineNo">682</span>          long onDiskSizeArg = withOnDiskSize ? expectedSize : -1;<a name="line.682"></a>
-<span class="sourceLineNo">683</span>          b = hbr.readBlockData(offset, onDiskSizeArg, pread);<a name="line.683"></a>
-<span class="sourceLineNo">684</span>        } catch (IOException ex) {<a name="line.684"></a>
-<span class="sourceLineNo">685</span>          LOG.error("Error in client " + clientId + " trying to read block at "<a name="line.685"></a>
-<span class="sourceLineNo">686</span>              + offset + ", pread=" + pread + ", withOnDiskSize=" +<a name="line.686"></a>
-<span class="sourceLineNo">687</span>              withOnDiskSize, ex);<a name="line.687"></a>
-<span class="sourceLineNo">688</span>          return false;<a name="line.688"></a>
-<span class="sourceLineNo">689</span>        }<a name="line.689"></a>
-<span class="sourceLineNo">690</span><a name="line.690"></a>
-<span class="sourceLineNo">691</span>        assertEquals(types.get(blockId), b.getBlockType());<a name="line.691"></a>
-<span class="sourceLineNo">692</span>        assertEquals(expectedSize, b.getOnDiskSizeWithHeader());<a name="line.692"></a>
-<span class="sourceLineNo">693</span>        assertEquals(offset, b.getOffset());<a name="line.693"></a>
-<span class="sourceLineNo">694</span><a name="line.694"></a>
-<span class="sourceLineNo">695</span>        ++numBlocksRead;<a name="line.695"></a>
-<span class="sourceLineNo">696</span>        if (pread)<a name="line.696"></a>
-<span class="sourceLineNo">697</span>          ++numPositionalRead;<a name="line.697"></a>
-<span class="sourceLineNo">698</span>        if (withOnDiskSize)<a name="line.698"></a>
-<span class="sourceLineNo">699</span>          ++numWithOnDiskSize;<a name="line.699"></a>
-<span class="sourceLineNo">700</span>      }<a name="line.700"></a>
-<span class="sourceLineNo">701</span>      LOG.info("Client " + clientId + " successfully read " + numBlocksRead +<a name="line.701"></a>
-<span class="sourceLineNo">702</span>        " blocks (with pread: " + numPositionalRead + ", with onDiskSize " +<a name="line.702"></a>
-<span class="sourceLineNo">703</span>        "specified: " + numWithOnDiskSize + ")");<a name="line.703"></a>
-<span class="sourceLineNo">704</span><a name="line.704"></a>
-<span class="sourceLineNo">705</span>      return true;<a name="line.705"></a>
-<span class="sourceLineNo">706</span>    }<a name="line.706"></a>
-<span class="sourceLineNo">707</span><a name="line.707"></a>
-<span class="sourceLineNo">708</span>  }<a name="line.708"></a>
-<span class="sourceLineNo">709</span><a name="line.709"></a>
-<span class="sourceLineNo">710</span>  @Test<a name="line.710"></a>
-<span class="sourceLineNo">711</span>  public void testConcurrentReading() throws Exception {<a name="line.711"></a>
-<span class="sourceLineNo">712</span>    testConcurrentReadingInternals();<a name="line.712"></a>
-<span class="sourceLineNo">713</span>  }<a name="line.713"></a>
-<span class="sourceLineNo">714</span><a name="line.714"></a>
-<span class="sourceLineNo">715</span>  protected void testConcurrentReadingInternals() throws IOException,<a name="line.715"></a>
-<span class="sourceLineNo">716</span>      InterruptedException, ExecutionException {<a name="line.716"></a>
-<span class="sourceLineNo">717</span>    for (Compression.Algorithm compressAlgo : COMPRESSION_ALGORITHMS) {<a name="line.717"></a>
-<span class="sourceLineNo">718</span>      Path path = new Path(TEST_UTIL.getDataTestDir(), "concurrent_reading");<a name="line.718"></a>
-<span class="sourceLineNo">719</span>      Random rand = defaultRandom();<a name="line.719"></a>
-<span class="sourceLineNo">720</span>      List&lt;Long&gt; offsets = new ArrayList&lt;&gt;();<a name="line.720"></a>
-<span class="sourceLineNo">721</span>      List&lt;BlockType&gt; types = new ArrayList&lt;&gt;();<a name="line.721"></a>
-<span class="sourceLineNo">722</span>      writeBlocks(rand, compressAlgo, path, offsets, null, types, null);<a name="line.722"></a>
-<span class="sourceLineNo">723</span>      FSDataInputStream is = fs.open(path);<a name="line.723"></a>
-<span class="sourceLineNo">724</span>      long fileSize = fs.getFileStatus(path).getLen();<a name="line.724"></a>
-<span class="sourceLineNo">725</span>      HFileContext meta = new HFileContextBuilder()<a name="line.725"></a>
-<span class="sourceLineNo">726</span>                          .withHBaseCheckSum(true)<a name="line.726"></a>
-<span class="sourceLineNo">727</span>                          .withIncludesMvcc(includesMemstoreTS)<a name="line.727"></a>
-<span class="sourceLineNo">728</span>                          .withIncludesTags(includesTag)<a name="line.728"></a>
-<span class="sourceLineNo">729</span>                          .withCompression(compressAlgo)<a name="line.729"></a>
-<span class="sourceLineNo">730</span>                          .build();<a name="line.730"></a>
-<span class="sourceLineNo">731</span>      HFileBlock.FSReader hbr = new HFileBlock.FSReaderImpl(is, fileSize, meta);<a name="line.731"></a>
-<span class="sourceLineNo">732</span><a name="line.732"></a>
-<span class="sourceLineNo">733</span>      Executor exec = Executors.newFixedThreadPool(NUM_READER_THREADS);<a name="line.733"></a>
-<span class="sourceLineNo">734</span>      ExecutorCompletionService&lt;Boolean&gt; ecs = new ExecutorCompletionService&lt;&gt;(exec);<a name="line.734"></a>
-<span class="sourceLineNo">735</span><a name="line.735"></a>
-<span class="sourceLineNo">736</span>      for (int i = 0; i &lt; NUM_READER_THREADS; ++i) {<a name="line.736"></a>
-<span class="sourceLineNo">737</span>        ecs.submit(new BlockReaderThread("reader_" + (char) ('A' + i), hbr,<a name="line.737"></a>
-<span class="sourceLineNo">738</span>            offsets, types, fileSize));<a name="line.738"></a>
-<span class="sourceLineNo">739</span>      }<a name="line.739"></a>
-<span class="sourceLineNo">740</span><a name="line.740"></a>
-<span class="sourceLineNo">741</span>      for (int i = 0; i &lt; NUM_READER_THREADS; ++i) {<a name="line.741"></a>
-<span class="sourceLineNo">742</span>        Future&lt;Boolean&gt; result = ecs.take();<a name="line.742"></a>
-<span class="sourceLineNo">743</span>        assertTrue(result.get());<a name="line.743"></a>
-<span class="sourceLineNo">744</span>        if (detailedLogging) {<a name="line.744"></a>
-<span class="sourceLineNo">745</span>          LOG.info(String.valueOf(i + 1)<a name="line.745"></a>
-<span class="sourceLineNo">746</span>            + " reader threads finished successfully (algo=" + compressAlgo<a name="line.746"></a>
-<span class="sourceLineNo">747</span>            + ")");<a name="line.747"></a>
-<span class="sourceLineNo">748</span>        }<a name="line.748"></a>
-<span class="sourceLineNo">749</span>      }<a name="line.749"></a>
-<span class="sourceLineNo">750</span><a name="line.750"></a>
-<span class="sourceLineNo">751</span>      is.close();<a name="line.751"></a>
-<span class="sourceLineNo">752</span>    }<a name="line.752"></a>
-<span class="sourceLineNo">753</span>  }<a name="line.753"></a>
-<span class="sourceLineNo">754</span><a name="line.754"></a>
-<span class="sourceLineNo">755</span>  private long writeBlocks(Random rand, Compression.Algorithm compressAlgo,<a name="line.755"></a>
-<span class="sourceLineNo">756</span>      Path path, List&lt;Long&gt; expectedOffsets, List&lt;Long&gt; expectedPrevOffsets,<a name="line.756"></a>
-<span class="sourceLineNo">757</span>      List&lt;BlockType&gt; expectedTypes, List&lt;ByteBuffer&gt; expectedContents<a name="line.757"></a>
-<span class="sourceLineNo">758</span>  ) throws IOException {<a name="line.758"></a>
-<span class="sourceLineNo">759</span>    boolean cacheOnWrite = expectedContents != null;<a name="line.759"></a>
-<span class="sourceLineNo">760</span>    FSDataOutputStream os = fs.create(path);<a name="line.760"></a>
-<span class="sourceLineNo">761</span>    HFileContext meta = new HFileContextBuilder()<a name="line.761"></a>
-<span class="sourceLineNo">762</span>                        .withHBaseCheckSum(true)<a name="line.762"></a>
-<span class="sourceLineNo">763</span>                        .withIncludesMvcc(includesMemstoreTS)<a name="line.763"></a>
-<span class="sourceLineNo">764</span>                        .withIncludesTags(includesTag)<a name="line.764"></a>
-<span class="sourceLineNo">765</span>                        .withCompression(compressAlgo)<a name="line.765"></a>
-<span class="sourceLineNo">766</span>                        .withBytesPerCheckSum(HFile.DEFAULT_BYTES_PER_CHECKSUM)<a name="line.766"></a>
-<span class="sourceLineNo">767</span>                        .build();<a name="line.767"></a>
-<span class="sourceLineNo">768</span>    HFileBlock.Writer hbw = new HFileBlock.Writer(null, meta);<a name="line.768"></a>
-<span class="sourceLineNo">769</span>    Map&lt;BlockType, Long&gt; prevOffsetByType = new HashMap&lt;&gt;();<a name="line.769"></a>
-<span class="sourceLineNo">770</span>    long totalSize = 0;<a name="line.770"></a>
-<span class="sourceLineNo">771</span>    for (int i = 0; i &lt; NUM_TEST_BLOCKS; ++i) {<a name="line.771"></a>
-<span class="sourceLineNo">772</span>      long pos = os.getPos();<a name="line.772"></a>
-<span class="sourceLineNo">773</span>      int blockTypeOrdinal = rand.nextInt(BlockType.values().length);<a name="line.773"></a>
-<span class="sourceLineNo">774</span>      if (blockTypeOrdinal == BlockType.ENCODED_DATA.ordinal()) {<a name="line.774"></a>
-<span class="sourceLineNo">775</span>        blockTypeOrdinal = BlockType.DATA.ordinal();<a name="line.775"></a>
-<span class="sourceLineNo">776</span>      }<a name="line.776"></a>
-<span class="sourceLineNo">777</span>      BlockType bt = BlockType.values()[blockTypeOrdinal];<a name="line.777"></a>
-<span class="sourceLineNo">778</span>      DataOutputStream dos = hbw.startWriting(bt);<a name="line.778"></a>
-<span class="sourceLineNo">779</span>      int size = rand.nextInt(500);<a name="line.779"></a>
-<span class="sourceLineNo">780</span>      for (int j = 0; j &lt; size; ++j) {<a name="line.780"></a>
-<span class="sourceLineNo">781</span>        // This might compress well.<a name="line.781"></a>
-<span class="sourceLineNo">782</span>        dos.writeShort(i + 1);<a name="line.782"></a>
-<span class="sourceLineNo">783</span>        dos.writeInt(j + 1);<a name="line.783"></a>
-<span class="sourceLineNo">784</span>      }<a name="line.784"></a>
-<span class="sourceLineNo">785</span><a name="line.785"></a>
-<span class="sourceLineNo">786</span>      if (expectedOffsets != null)<a name="line.786"></a>
-<span class="sourceLineNo">787</span>        expectedOffsets.add(os.getPos());<a name="line.787"></a>
-<span class="sourceLineNo">788</span><a name="line.788"></a>
-<span class="sourceLineNo">789</span>      if (expectedPrevOffsets != null) {<a name="line.789"></a>
-<span class="sourceLineNo">790</span>        Long prevOffset = prevOffsetByType.get(bt);<a name="line.790"></a>
-<span class="sourceLineNo">791</span>        expectedPrevOffsets.add(prevOffset != null ? prevOffset : -1);<a name="line.791"></a>
-<span class="sourceLineNo">792</span>        prevOffsetByType.put(bt, os.getPos());<a name="line.792"></a>
-<span class="sourceLineNo">793</span>      }<a name="line.793"></a>
-<span class="sourceLineNo">794</span><a name="line.794"></a>
-<span class="sourceLineNo">795</span>      expectedTypes.add(bt);<a name="line.795"></a>
-<span class="sourceLineNo">796</span><a name="line.796"></a>
-<span class="sourceLineNo">797</span>      hbw.writeHeaderAndData(os);<a name="line.797"></a>
-<span class="sourceLineNo">798</span>      totalSize += hbw.getOnDiskSizeWithHeader();<a name="line.798"></a>
-<span class="sourceLineNo">799</span><a name="line.799"></a>
-<span class="sourceLineNo">800</span>      if (cacheOnWrite)<a name="line.800"></a>
-<span class="sourceLineNo">801</span>        expectedContents.add(hbw.cloneUncompressedBufferWithHeader());<a name="line.801"></a>
-<span class="sourceLineNo">802</span><a name="line.802"></a>
-<span class="sourceLineNo">803</span>      if (detailedLogging) {<a name="line.803"></a>
-<span class="sourceLineNo">804</span>        LOG.info("Written block #" + i + " of type " + bt<a name="line.804"></a>
-<span class="sourceLineNo">805</span>            + ", uncompressed size " + hbw.getUncompressedSizeWithoutHeader()<a name="line.805"></a>
-<span class="sourceLineNo">806</span>            + ", packed size " + hbw.getOnDiskSizeWithoutHeader()<a name="line.806"></a>
-<span class="sourceLineNo">807</span>            + " at offset " + pos);<a name="line.807"></a>
-<span class="sourceLineNo">808</span>      }<a name="line.808"></a>
-<span class="sourceLineNo">809</span>    }<a name="line.809"></a>
-<span class="sourceLineNo">810</span>    os.close();<a name="line.810"></a>
-<span class="sourceLineNo">811</span>    LOG.info("Created a temporary file at " + path + ", "<a name="line.811"></a>
-<span class="sourceLineNo">812</span>        + fs.getFileStatus(path).getLen() + " byte, compression=" +<a name="line.812"></a>
-<span class="sourceLineNo">813</span>        compressAlgo);<a name="line.813"></a>
-<span class="sourceLineNo">814</span>    return totalSize;<a name="line.814"></a>
-<span class="sourceLineNo">815</span>  }<a name="line.815"></a>
-<span class="sourceLineNo">816</span><a name="line.816"></a>
-<span class="sourceLineNo">817</span>  @Test<a name="line.817"></a>
-<span class="sourceLineNo">818</span>  public void testBlockHeapSize() {<a name="line.818"></a>
-<span class="sourceLineNo">819</span>    testBlockHeapSizeInternals();<a name="line.819"></a>
-<span class="sourceLineNo">820</span>  }<a name="line.820"></a>
-<span class="sourceLineNo">821</span><a name="line.821"></a>
-<span class="sourceLineNo">822</span>  protected void testBlockHeapSizeInternals() {<a name="line.822"></a>
-<span class="sourceLineNo">823</span>    if (ClassSize.is32BitJVM()) {<a name="line.823"></a>
-<span class="sourceLineNo">824</span>      assertEquals(64, HFileBlock.MULTI_BYTE_BUFFER_HEAP_SIZE);<a name="line.824"></a>
-<span class="sourceLineNo">825</span>    } else {<a name="line.825"></a>
-<span class="sourceLineNo">826</span>      assertEquals(72, HFileBlock.MULTI_BYTE_BUFFER_HEAP_SIZE);<a name="line.826"></a>
-<span class="sourceLineNo">827</span>    }<a name="line.827"></a>
-<span class="sourceLineNo">828</span><a name="line.828"></a>
-<span class="sourceLineNo">829</span>    for (int size : new int[] { 100, 256, 12345 }) {<a name="line.829"></a>
-<span class="sourceLineNo">830</span>      byte[] byteArr = new byte[HConstants.HFILEBLOCK_HEADER_SIZE + size];<a name="line.830"></a>
-<span class="sourceLineNo">831</span>      ByteBuffer buf = ByteBuffer.wrap(byteArr, 0, size);<a name="line.831"></a>
-<span class="sourceLineNo">832</span>      HFileContext meta = new HFileContextBuilder()<a name="line.832"></a>
-<span class="sourceLineNo">833</span>                          .withIncludesMvcc(includesMemstoreTS)<a name="line.833"></a>
-<span class="sourceLineNo">834</span>                          .withIncludesTags(includesTag)<a name="line.834"></a>
-<span class="sourceLineNo">835</span>                          .withHBaseCheckSum(false)<a name="line.835"></a>
-<span class="sourceLineNo">836</span>                          .withCompression(Algorithm.NONE)<a name="line.836"></a>
-<span class="sourceLineNo">837</span>                          .withBytesPerCheckSum(HFile.DEFAULT_BYTES_PER_CHECKSUM)<a name="line.837"></a>
-<span class="sourceLineNo">838</span>                          .withChecksumType(ChecksumType.NULL).build();<a name="line.838"></a>
-<span class="sourceLineNo">839</span>      HFileBlock block = new HFileBlock(BlockType.DATA, size, size, -1, buf,<a name="line.839"></a>
-<span class="sourceLineNo">840</span>          HFileBlock.FILL_HEADER, -1, 0, -1, meta);<a name="line.840"></a>
-<span class="sourceLineNo">841</span>      long byteBufferExpectedSize = ClassSize.align(ClassSize.estimateBase(<a name="line.841"></a>
-<span class="sourceLineNo">842</span>          new MultiByteBuff(buf).getClass(), true)<a name="line.842"></a>
-<span class="sourceLineNo">843</span>          + HConstants.HFILEBLOCK_HEADER_SIZE + size);<a name="line.843"></a>
-<span class="sourceLineNo">844</span>      long hfileMetaSize =  ClassSize.align(ClassSize.estimateBase(HFileContext.class, true));<a name="line.844"></a>
-<span class="sourceLineNo">845</span>      long hfileBlockExpectedSize =<a name="line.845"></a>
-<span class="sourceLineNo">846</span>          ClassSize.align(ClassSize.estimateBase(HFileBlock.class, true));<a name="line.846"></a>
-<span class="sourceLineNo">847</span>      long expected = hfileBlockExpectedSize + byteBufferExpectedSize + hfileMetaSize;<a name="line.847"></a>
-<span class="sourceLineNo">848</span>      assertEquals("Block data size: " + size + ", byte buffer expected " +<a name="line.848"></a>
-<span class="sourceLineNo">849</span>          "size: " + byteBufferExpectedSize + ", HFileBlock class expected " +<a name="line.849"></a>
-<span class="sourceLineNo">850</span>          "size: " + hfileBlockExpectedSize + ";", expected,<a name="line.850"></a>
-<span class="sourceLineNo">851</span>          block.heapSize());<a name="line.851"></a>
-<span class="sourceLineNo">852</span>    }<a name="line.852"></a>
-<span class="sourceLineNo">853</span>  }<a name="line.853"></a>
-<span class="sourceLineNo">854</span>}<a name="line.854"></a>
+<span class="sourceLineNo">674</span>        // now we only support concurrent read with pread = true<a name="line.674"></a>
+<span class="sourceLineNo">675</span>        boolean pread = true;<a name="line.675"></a>
+<span class="sourceLineNo">676</span>        boolean withOnDiskSize = rand.nextBoolean();<a name="line.676"></a>
+<span class="sourceLineNo">677</span>        long expectedSize =<a name="line.677"></a>
+<span class="sourceLineNo">678</span>          (blockId == NUM_TEST_BLOCKS - 1 ? fileSize<a name="line.678"></a>
+<span class="sourceLineNo">679</span>              : offsets.get(blockId + 1)) - offset;<a name="line.679"></a>
+<span class="sourceLineNo">680</span><a name="line.680"></a>
+<span class="sourceLineNo">681</span>        HFileBlock b;<a name="line.681"></a>
+<span class="sourceLineNo">682</span>        try {<a name="line.682"></a>
+<span class="sourceLineNo">683</span>          long onDiskSizeArg = withOnDiskSize ? expectedSize : -1;<a name="line.683"></a>
+<span class="sourceLineNo">684</span>          b = hbr.readBlockData(offset, onDiskSizeArg, pread);<a name="line.684"></a>
+<span class="sourceLineNo">685</span>        } catch (IOException ex) {<a name="line.685"></a>
+<span class="sourceLineNo">686</span>          LOG.error("Error in client " + clientId + " trying to read block at "<a name="line.686"></a>
+<span class="sourceLineNo">687</span>              + offset + ", pread=" + pread + ", withOnDiskSize=" +<a name="line.687"></a>
+<span class="sourceLineNo">688</span>              withOnDiskSize, ex);<a name="line.688"></a>
+<span class="sourceLineNo">689</span>          return false;<a name="line.689"></a>
+<span class="sourceLineNo">690</span>        }<a name="line.690"></a>
+<span class="sourceLineNo">691</span><a name="line.691"></a>
+<span class="sourceLineNo">692</span>        assertEquals(types.get(blockId), b.getBlockType());<a name="line.692"></a>
+<span class="sourceLineNo">693</span>        assertEquals(expectedSize, b.getOnDiskSizeWithHeader());<a name="line.693"></a>
+<span class="sourceLineNo">694</span>        assertEquals(offset, b.getOffset());<a name="line.694"></a>
+<span class="sourceLineNo">695</span><a name="line.695"></a>
+<span class="sourceLineNo">696</span>        ++numBlocksRead;<a name="line.696"></a>
+<span class="sourceLineNo">697</span>        if (pread)<a name="line.697"></a>
+<span class="sourceLineNo">698</span>          ++numPositionalRead;<a name="line.698"></a>
+<span class="sourceLineNo">699</span>        if (withOnDiskSize)<a name="line.699"></a>
+<span class="sourceLineNo">700</span>          ++numWithOnDiskSize;<a name="line.700"></a>
+<span class="sourceLineNo">701</span>      }<a name="line.701"></a>
+<span class="sourceLineNo">702</span>      LOG.info("Client " + clientId + " successfully read " + numBlocksRead +<a name="line.702"></a>
+<span class="sourceLineNo">703</span>        " blocks (with pread: " + numPositionalRead + ", with onDiskSize " +<a name="line.703"></a>
+<span class="sourceLineNo">704</span>        "specified: " + numWithOnDiskSize + ")");<a name="line.704"></a>
+<span class="sourceLineNo">705</span><a name="line.705"></a>
+<span class="sourceLineNo">706</span>      return true;<a name="line.706"></a>
+<span class="sourceLineNo">707</span>    }<a name="line.707"></a>
+<span class="sourceLineNo">708</span><a name="line.708"></a>
+<span class="sourceLineNo">709</span>  }<a name="line.709"></a>
+<span class="sourceLineNo">710</span><a name="line.710"></a>
+<span class="sourceLineNo">711</span>  @Test<a name="line.711"></a>
+<span class="sourceLineNo">712</span>  public void testConcurrentReading() throws Exception {<a name="line.712"></a>
+<span class="sourceLineNo">713</span>    testConcurrentReadingInternals();<a name="line.713"></a>
+<span class="sourceLineNo">714</span>  }<a name="line.714"></a>
+<span class="sourceLineNo">715</span><a name="line.715"></a>
+<span class="sourceLineNo">716</span>  protected void testConcurrentReadingInternals() throws IOException,<a name="line.716"></a>
+<span class="sourceLineNo">717</span>      InterruptedException, ExecutionException {<a name="line.717"></a>
+<span class="sourceLineNo">718</span>    for (Compression.Algorithm compressAlgo : COMPRESSION_ALGORITHMS) {<a name="line.718"></a>
+<span class="sourceLineNo">719</span>      Path path = new Path(TEST_UTIL.getDataTestDir(), "concurrent_reading");<a name="line.719"></a>
+<span class="sourceLineNo">720</span>      Random rand = defaultRandom();<a name="line.720"></a>
+<span class="sourceLineNo">721</span>      List&lt;Long&gt; offsets = new ArrayList&lt;&gt;();<a name="line.721"></a>
+<span class="sourceLineNo">722</span>      List&lt;BlockType&gt; types = new ArrayList&lt;&gt;();<a name="line.722"></a>
+<span class="sourceLineNo">723</span>      writeBlocks(rand, compressAlgo, path, offsets, null, types, null);<a name="line.723"></a>
+<span class="sourceLineNo">724</span>      FSDataInputStream is = fs.open(path);<a name="line.724"></a>
+<span class="sourceLineNo">725</span>      long fileSize = fs.getFileStatus(path).getLen();<a name="line.725"></a>
+<span class="sourceLineNo">726</span>      HFileContext meta = new HFileContextBuilder()<a name="line.726"></a>
+<span class="sourceLineNo">727</span>                          .withHBaseCheckSum(true)<a name="line.727"></a>
+<span class="sourceLineNo">728</span>                          .withIncludesMvcc(includesMemstoreTS)<a name="line.728"></a>
+<span class="sourceLineNo">729</span>                          .withIncludesTags(includesTag)<a name="line.729"></a>
+<span class="sourceLineNo">730</span>                          .withCompression(compressAlgo)<a name="line.730"></a>
+<span class="sourceLineNo">731</span>                          .build();<a name="line.731"></a>
+<span class="sourceLineNo">732</span>      HFileBlock.FSReader hbr = new HFileBlock.FSReaderImpl(is, fileSize, meta);<a name="line.732"></a>
+<span class="sourceLineNo">733</span><a name="line.733"></a>
+<span class="sourceLineNo">734</span>      Executor exec = Executors.newFixedThreadPool(NUM_READER_THREADS);<a name="line.734"></a>
+<span class="sourceLineNo">735</span>      ExecutorCompletionService&lt;Boolean&gt; ecs = new ExecutorCompletionService&lt;&gt;(exec);<a name="line.735"></a>
+<span class="sourceLineNo">736</span><a name="line.736"></a>
+<span class="sourceLineNo">737</span>      for (int i = 0; i &lt; NUM_READER_THREADS; ++i) {<a name="line.737"></a>
+<span class="sourceLineNo">738</span>        ecs.submit(new BlockReaderThread("reader_" + (char) ('A' + i), hbr,<a name="line.738"></a>
+<span class="sourceLineNo">739</span>            offsets, types, fileSize));<a name="line.739"></a>
+<span class="sourceLineNo">740</span>      }<a name="line.740"></a>
+<span class="sourceLineNo">741</span><a name="line.741"></a>
+<span class="sourceLineNo">742</span>      for (int i = 0; i &lt; NUM_READER_THREADS; ++i) {<a name="line.742"></a>
+<span class="sourceLineNo">743</span>        Future&lt;Boolean&gt; result = ecs.take();<a name="line.743"></a>
+<span class="sourceLineNo">744</span>        assertTrue(result.get());<a name="line.744"></a>
+<span class="sourceLineNo">745</span>        if (detailedLogging) {<a name="line.745"></a>
+<span class="sourceLineNo">746</span>          LOG.info(String.valueOf(i + 1)<a name="line.746"></a>
+<span class="sourceLineNo">747</span>            + " reader threads finished successfully (algo=" + compressAlgo<a name="line.747"></a>
+<span class="sourceLineNo">748</span>            + ")");<a name="line.748"></a>
+<span class="sourceLineNo">749</span>        }<a name="line.749"></a>
+<span class="sourceLineNo">750</span>      }<a name="line.750"></a>
+<span class="sourceLineNo">751</span><a name="line.751"></a>
+<span class="sourceLineNo">752</span>      is.close();<a name="line.752"></a>
+<span class="sourceLineNo">753</span>    }<a name="line.753"></a>
+<span class="sourceLineNo">754</span>  }<a name="line.754"></a>
+<span class="sourceLineNo">755</span><a name="line.755"></a>
+<span class="sourceLineNo">756</span>  private long writeBlocks(Random rand, Compression.Algorithm compressAlgo,<a name="line.756"></a>
+<span class="sourceLineNo">757</span>      Path path, List&lt;Long&gt; expectedOffsets, List&lt;Long&gt; expectedPrevOffsets,<a name="line.757"></a>
+<span class="sourceLineNo">758</span>      List&lt;BlockType&gt; expectedTypes, List&lt;ByteBuffer&gt; expectedContents<a name="line.758"></a>
+<span class="sourceLineNo">759</span>  ) throws IOException {<a name="line.759"></a>
+<span class="sourceLineNo">760</span>    boolean cacheOnWrite = expectedContents != null;<a name="line.760"></a>
+<span class="sourceLineNo">761</span>    FSDataOutputStream os = fs.create(path);<a name="line.761"></a>
+<span class="sourceLineNo">762</span>    HFileContext meta = new HFileContextBuilder()<a name="line.762"></a>
+<span class="sourceLineNo">763</span>                        .withHBaseCheckSum(true)<a name="line.763"></a>
+<span class="sourceLineNo">764</span>                        .withIncludesMvcc(includesMemstoreTS)<a name="line.764"></a>
+<span class="sourceLineNo">765</span>                        .withIncludesTags(includesTag)<a name="line.765"></a>
+<span class="sourceLineNo">766</span>                        .withCompression(compressAlgo)<a name="line.766"></a>
+<span class="sourceLineNo">767</span>                        .withBytesPerCheckSum(HFile.DEFAULT_BYTES_PER_CHECKSUM)<a name="line.767"></a>
+<span class="sourceLineNo">768</span>                        .build();<a name="line.768"></a>
+<span class="sourceLineNo">769</span>    HFileBlock.Writer hbw = new HFileBlock.Writer(null, meta);<a name="line.769"></a>
+<span class="sourceLineNo">770</span>    Map&lt;BlockType, Long&gt; prevOffsetByType = new HashMap&lt;&gt;();<a name="line.770"></a>
+<span class="sourceLineNo">771</span>    long totalSize = 0;<a name="line.771"></a>
+<span class="sourceLineNo">772</span>    for (int i = 0; i &lt; NUM_TEST_BLOCKS; ++i) {<a name="line.772"></a>
+<span class="sourceLineNo">773</span>      long pos = os.getPos();<a name="line.773"></a>
+<span class="sourceLineNo">774</span>      int blockTypeOrdinal = rand.nextInt(BlockType.values().length);<a name="line.774"></a>
+<span class="sourceLineNo">775</span>      if (blockTypeOrdinal == BlockType.ENCODED_DATA.ordinal()) {<a name="line.775"></a>
+<span class="sourceLineNo">776</span>        blockTypeOrdinal = BlockType.DATA.ordinal();<a name="line.776"></a>
+<span class="sourceLineNo">777</span>      }<a name="line.777"></a>
+<span class="sourceLineNo">778</span>      BlockType bt = BlockType.values()[blockTypeOrdinal];<a name="line.778"></a>
+<span class="sourceLineNo">779</span>      DataOutputStream dos = hbw.startWriting(bt);<a name="line.779"></a>
+<span class="sourceLineNo">780</span>      int size = rand.nextInt(500);<a name="line.780"></a>
+<span class="sourceLineNo">781</span>      for (int j = 0; j &lt; size; ++j) {<a name="line.781"></a>
+<span class="sourceLineNo">782</span>        // This might compress well.<a name="line.782"></a>
+<span class="sourceLineNo">783</span>        dos.writeShort(i + 1);<a name="line.783"></a>
+<span class="sourceLineNo">784</span>        dos.writeInt(j + 1);<a name="line.784"></a>
+<span class="sourceLineNo">785</span>      }<a name="line.785"></a>
+<span class="sourceLineNo">786</span><a name="line.786"></a>
+<span class="sourceLineNo">787</span>      if (expectedOffsets != null)<a name="line.787"></a>
+<span class="sourceLineNo">788</span>        expectedOffsets.add(os.getPos());<a name="line.788"></a>
+<span class="sourceLineNo">789</span><a name="line.789"></a>
+<span class="sourceLineNo">790</span>      if (expectedPrevOffsets != null) {<a name="line.790"></a>
+<span class="sourceLineNo">791</span>        Long prevOffset = prevOffsetByType.get(bt);<a name="line.791"></a>
+<span class="sourceLineNo">792</span>        expectedPrevOffsets.add(prevOffset != null ? prevOffset : -1);<a name="line.792"></a>
+<span class="sourceLineNo">793</span>        prevOffsetByType.put(bt, os.getPos());<a name="line.793"></a>
+<span class="sourceLineNo">794</span>      }<a name="line.794"></a>
+<span class="sourceLineNo">795</span><a name="line.795"></a>
+<span class="sourceLineNo">796</span>      expectedTypes.add(bt);<a name="line.796"></a>
+<span class="sourceLineNo">797</span><a name="line.797"></a>
+<span class="sourceLineNo">798</span>      hbw.writeHeaderAndData(os);<a name="line.798"></a>
+<span class="sourceLineNo">799</span>      totalSize += hbw.getOnDiskSizeWithHeader();<a name="line.799"></a>
+<span class="sourceLineNo">800</span><a name="line.800"></a>
+<span class="sourceLineNo">801</span>      if (cacheOnWrite)<a name="line.801"></a>
+<span class="sourceLineNo">802</span>        expectedContents.add(hbw.cloneUncompressedBufferWithHeader());<a name="line.802"></a>
+<span class="sourceLineNo">803</span><a name="line.803"></a>
+<span class="sourceLineNo">804</span>      if (detailedLogging) {<a name="line.804"></a>
+<span class="sourceLineNo">805</span>        LOG.info("Written block #" + i + " of type " + bt<a name="line.805"></a>
+<span class="sourceLineNo">806</span>            + ", uncompressed size " + hbw.getUncompressedSizeWithoutHeader()<a name="line.806"></a>
+<span class="sourceLineNo">807</span>            + ", packed size " + hbw.getOnDiskSizeWithoutHeader()<a name="line.807"></a>
+<span class="sourceLineNo">808</span>            + " at offset " + pos);<a name="line.808"></a>
+<span class="sourceLineNo">809</span>      }<a name="line.809"></a>
+<span class="sourceLineNo">810</span>    }<a name="line.810"></a>
+<span class="sourceLineNo">811</span>    os.close();<a name="line.811"></a>
+<span class="sourceLineNo">812</span>    LOG.info("Created a temporary file at " + path + ", "<a name="line.812"></a>
+<span class="sourceLineNo">813</span>        + fs.getFileStatus(path).getLen() + " byte, compression=" +<a name="line.813"></a>
+<span class="sourceLineNo">814</span>        compressAlgo);<a name="line.814"></a>
+<span class="sourceLineNo">815</span>    return totalSize;<a name="line.815"></a>
+<span class="sourceLineNo">816</span>  }<a name="line.816"></a>
+<span class="sourceLineNo">817</span><a name="line.817"></a>
+<span class="sourceLineNo">818</span>  @Test<a name="line.818"></a>
+<span class="sourceLineNo">819</span>  public void testBlockHeapSize() {<a name="line.819"></a>
+<span class="sourceLineNo">820</span>    testBlockHeapSizeInternals();<a name="line.820"></a>
+<span class="sourceLineNo">821</span>  }<a name="line.821"></a>
+<span class="sourceLineNo">822</span><a name="line.822"></a>
+<span class="sourceLineNo">823</span>  protected void testBlockHeapSizeInternals() {<a name="line.823"></a>
+<span class="sourceLineNo">824</span>    if (ClassSize.is32BitJVM()) {<a name="line.824"></a>
+<span class="sourceLineNo">825</span>      assertEquals(64, HFileBlock.MULTI_BYTE_BUFFER_HEAP_SIZE);<a name="line.825"></a>
+<span class="sourceLineNo">826</span>    } else {<a name="line.826"></a>
+<span class="sourceLineNo">827</span>      assertEquals(72, HFileBlock.MULTI_BYTE_BUFFER_HEAP_SIZE);<a name="line.827"></a>
+<span class="sourceLineNo">828</span>    }<a name="line.828"></a>
+<span class="sourceLineNo">829</span><a name="line.829"></a>
+<span class="sourceLineNo">830</span>    for (int size : new int[] { 100, 256, 12345 }) {<a name="line.830"></a>
+<span class="sourceLineNo">831</span>      byte[] byteArr = new byte[HConstants.HFILEBLOCK_HEADER_SIZE + size];<a name="line.831"></a>
+<span class="sourceLineNo">832</span>      ByteBuffer buf = ByteBuffer.wrap(byteArr, 0, size);<a name="line.832"></a>
+<span class="sourceLineNo">833</span>      HFileContext meta = new HFileContextBuilder()<a name="line.833"></a>
+<span class="sourceLineNo">834</span>                          .withIncludesMvcc(includesMemstoreTS)<a name="line.834"></a>
+<span class="sourceLineNo">835</span>                          .withIncludesTags(includesTag)<a name="line.835"></a>
+<span class="sourceLineNo">836</span>                          .withHBaseCheckSum(false)<a name="line.836"></a>
+<span class="sourceLineNo">837</span>                          .withCompression(Algorithm.NONE)<a name="line.837"></a>
+<span class="sourceLineNo">838</span>                          .withBytesPerCheckSum(HFile.DEFAULT_BYTES_PER_CHECKSUM)<a name="line.838"></a>
+<span class="sourceLineNo">839</span>                          .withChecksumType(ChecksumType.NULL).build();<a name="line.839"></a>
+<span class="sourceLineNo">840</span>      HFileBlock block = new HFileBlock(BlockType.DATA, size, size, -1, buf,<a name="line.840"></a>
+<span class="sourceLineNo">841</span>          HFileBlock.FILL_HEADER, -1, 0, -1, meta);<a name="line.841"></a>
+<span class="sourceLineNo">842</span>      long byteBufferExpectedSize = ClassSize.align(ClassSize.estimateBase(<a name="line.842"></a>
+<span class="sourceLineNo">843</span>          new MultiByteBuff(buf).getClass(), true)<a name="line.843"></a>
+<span class="sourceLineNo">844</span>          + HConstants.HFILEBLOCK_HEADER_SIZE + size);<a name="line.844"></a>
+<span class="sourceLineNo">845</span>      long hfileMetaSize =  ClassSize.align(ClassSize.estimateBase(HFileContext.class, true));<a name="line.845"></a>
+<span class="sourceLineNo">846</span>      long hfileBlockExpectedSize =<a name="line.846"></a>
+<span class="sourceLineNo">847</span>          ClassSize.align(ClassSize.estimateBase(HFileBlock.class, true));<a name="line.847"></a>
+<span class="sourceLineNo">848</span>      long expected = hfileBlockExpectedSize + byteBufferExpectedSize + hfileMetaSize;<a name="line.848"></a>
+<span class="sourceLineNo">849</span>      assertEquals("Block data size: " + size + ", byte buffer expected " +<a name="line.849"></a>
+<span class="sourceLineNo">850</span>          "size: " + byteBufferExpectedSize + ", HFileBlock class expected " +<a name="line.850"></a>
+<span class="sourceLineNo">851</span>          "size: " + hfileBlockExpectedSize + ";", expected,<a name="line.851"></a>
+<span class="sourceLineNo">852</span>          block.heapSize());<a name="line.852"></a>
+<span class="sourceLineNo">853</span>    }<a name="line.853"></a>
+<span class="sourceLineNo">854</span>  }<a name="line.854"></a>
+<span class="sourceLineNo">855</span>}<a name="line.855"></a>
 
 
 


Mime
View raw message