Skip to content

Commit

Permalink
HBASE-22531 The HFileReaderImpl#shouldUseHeap return the incorrect tr…
Browse files Browse the repository at this point in the history
…ue when disabled BlockCache (#304)
  • Loading branch information
openinx authored Jun 14, 2019
1 parent e4a9147 commit 7840613
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -1419,7 +1419,7 @@ public HFileBlock getMetaBlock(String metaBlockName, boolean cacheBlock)
* boolean, boolean)
*/
private boolean shouldUseHeap(BlockType expectedBlockType) {
if (cacheConf.getBlockCache() == null) {
if (!cacheConf.getBlockCache().isPresent()) {
return false;
} else if (!cacheConf.isCombinedBlockCache()) {
// Block to cache in LruBlockCache must be an heap one. So just allocate block memory from
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@

import static org.apache.hadoop.hbase.HConstants.BUCKET_CACHE_IOENGINE_KEY;
import static org.apache.hadoop.hbase.HConstants.BUCKET_CACHE_SIZE_KEY;
import static org.apache.hadoop.hbase.HConstants.HFILE_BLOCK_CACHE_SIZE_KEY;
import static org.apache.hadoop.hbase.io.ByteBuffAllocator.BUFFER_SIZE_KEY;
import static org.apache.hadoop.hbase.io.ByteBuffAllocator.MAX_BUFFER_COUNT_KEY;
import static org.apache.hadoop.hbase.io.ByteBuffAllocator.MIN_ALLOCATE_SIZE_KEY;
Expand Down Expand Up @@ -422,4 +423,28 @@ public void testWithLruBlockCache() throws Exception {
Assert.assertNull(scanner.curBlock);
Assert.assertTrue(scanner.prevBlocks.isEmpty());
}

@Test
public void testDisabledBlockCache() throws Exception {
writeHFile(conf, fs, hfilePath, Algorithm.NONE, DataBlockEncoding.NONE, CELL_COUNT);
// Set LruBlockCache
conf.setFloat(HFILE_BLOCK_CACHE_SIZE_KEY, 0.0f);
BlockCache defaultBC = BlockCacheFactory.createBlockCache(conf);
Assert.assertNull(defaultBC);
CacheConfig cacheConfig = new CacheConfig(conf, null, defaultBC, allocator);
Assert.assertFalse(cacheConfig.isCombinedBlockCache()); // Must be LruBlockCache.
HFile.Reader reader = HFile.createReader(fs, hfilePath, cacheConfig, true, conf);
Assert.assertTrue(reader instanceof HFileReaderImpl);
// We've build a HFile tree with index = 16.
Assert.assertEquals(16, reader.getTrailer().getNumDataIndexLevels());

HFileBlock block1 = reader.getDataBlockIndexReader()
.loadDataBlockWithScanInfo(firstCell, null, true, true, false, DataBlockEncoding.NONE)
.getHFileBlock();

Assert.assertTrue(block1.isSharedMem());
Assert.assertTrue(block1 instanceof SharedMemHFileBlock);
Assert.assertEquals(1, block1.refCnt());
Assert.assertTrue(block1.release());
}
}

0 comments on commit 7840613

Please sign in to comment.