Search in sources :

Example 1 with BlockType

use of org.apache.hadoop.hbase.io.hfile.BlockType in project hbase by apache.

the class TestCacheOnWriteInSchema method readStoreFile.

private void readStoreFile(Path path) throws IOException {
    CacheConfig cacheConf = store.getCacheConfig();
    BlockCache cache = cacheConf.getBlockCache().get();
    HStoreFile sf = new HStoreFile(fs, path, conf, cacheConf, BloomType.ROWCOL, true);
    sf.initReader();
    HFile.Reader reader = sf.getReader().getHFileReader();
    try {
        // Open a scanner with (on read) caching disabled
        HFileScanner scanner = reader.getScanner(conf, false, false);
        assertTrue(testDescription, scanner.seekTo());
        // Cribbed from io.hfile.TestCacheOnWrite
        long offset = 0;
        while (offset < reader.getTrailer().getLoadOnOpenDataOffset()) {
            // Flags: don't cache the block, use pread, this is not a compaction.
            // Also, pass null for expected block type to avoid checking it.
            HFileBlock block = reader.readBlock(offset, -1, false, true, false, true, null, DataBlockEncoding.NONE);
            BlockCacheKey blockCacheKey = new BlockCacheKey(reader.getName(), offset);
            boolean isCached = cache.getBlock(blockCacheKey, true, false, true) != null;
            boolean shouldBeCached = cowType.shouldBeCached(block.getBlockType());
            final BlockType blockType = block.getBlockType();
            if (shouldBeCached != isCached && (cowType.blockType1.equals(blockType) || cowType.blockType2.equals(blockType))) {
                throw new AssertionError("shouldBeCached: " + shouldBeCached + "\n" + "isCached: " + isCached + "\n" + "Test description: " + testDescription + "\n" + "block: " + block + "\n" + "blockCacheKey: " + blockCacheKey);
            }
            offset += block.getOnDiskSizeWithHeader();
        }
    } finally {
        reader.close();
    }
}
Also used : HFileBlock(org.apache.hadoop.hbase.io.hfile.HFileBlock) BlockType(org.apache.hadoop.hbase.io.hfile.BlockType) BlockCache(org.apache.hadoop.hbase.io.hfile.BlockCache) HFileScanner(org.apache.hadoop.hbase.io.hfile.HFileScanner) HFile(org.apache.hadoop.hbase.io.hfile.HFile) CacheConfig(org.apache.hadoop.hbase.io.hfile.CacheConfig) BlockCacheKey(org.apache.hadoop.hbase.io.hfile.BlockCacheKey)

Aggregations

BlockCache (org.apache.hadoop.hbase.io.hfile.BlockCache)1 BlockCacheKey (org.apache.hadoop.hbase.io.hfile.BlockCacheKey)1 BlockType (org.apache.hadoop.hbase.io.hfile.BlockType)1 CacheConfig (org.apache.hadoop.hbase.io.hfile.CacheConfig)1 HFile (org.apache.hadoop.hbase.io.hfile.HFile)1 HFileBlock (org.apache.hadoop.hbase.io.hfile.HFileBlock)1 HFileScanner (org.apache.hadoop.hbase.io.hfile.HFileScanner)1