@Override public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory) { boolean metaBlock = buf.getBlockType().getCategory() != BlockCategory.DATA; if (metaBlock) { onHeapCache.cacheBlock(cacheKey, buf, inMemory); } else { l2Cache.cacheBlock(cacheKey, buf, inMemory); } }
public CombinedBlockCache(LruBlockCache onHeapCache, BlockCache l2Cache) { this.onHeapCache = onHeapCache; this.l2Cache = l2Cache; this.combinedCacheStats = new CombinedCacheStats(onHeapCache.getStats(), l2Cache.getStats()); }
/** * If we make sure the block could not be cached, we will not acquire the lock * otherwise we will acquire lock */ public boolean shouldLockOnCacheMiss(BlockType blockType) { if (blockType == null) { return true; } return shouldCacheBlockOnRead(blockType.getCategory()); }
@Override void setUp() throws Exception { reader = HFile.createReader(this.fs, this.mf, new CacheConfig(this.conf), true, this.conf); this.reader.loadFileInfo(); }
@Override public String toString() { AgeSnapshot snapshot = getAgeAtEvictionSnapshot(); return "hitCount=" + getHitCount() + ", hitCachingCount=" + getHitCachingCount() + ", missCount=" + getMissCount() + ", missCachingCount=" + getMissCachingCount() + ", evictionCount=" + getEvictionCount() + ", evictedBlockCount=" + getEvictedCount() + ", primaryMissCount=" + getPrimaryMissCount() + ", primaryHitCount=" + getPrimaryHitCount() + ", evictedAgeMean=" + snapshot.getMean(); }
private void readStoreFile(Path storeFilePath) throws Exception { // Open the file reader with block cache disabled. HFile.Reader reader = HFile.createReader(fs, storeFilePath, conf); long offset = 0; while (offset < reader.getTrailer().getLoadOnOpenDataOffset()) { HFileBlock block = reader.readBlock(offset, -1, false, true, false, true, null, null); offset += block.getOnDiskSizeWithHeader(); } }
@Override public void returnBlock(HFileBlock block) { if (block != null) { this.cacheConf.getBlockCache().ifPresent(blockCache -> { BlockCacheKey cacheKey = new BlockCacheKey(this.getFileContext().getHFileName(), block.getOffset(), this.isPrimaryReplicaReader(), block.getBlockType()); blockCache.returnBlock(cacheKey, block); }); } }
/** * Caches the last written HFile block. * @param offset the offset of the block we want to cache. Used to determine * the cache key. */ private void doCacheOnWrite(long offset) { cacheConf.getBlockCache().ifPresent(cache -> { HFileBlock cacheFormatBlock = blockWriter.getBlockForCaching(cacheConf); cache.cacheBlock(new BlockCacheKey(name, offset, true, cacheFormatBlock.getBlockType()), cacheFormatBlock); }); }
private int getCurCellSerializedSize() { int curCellSize = KEY_VALUE_LEN_SIZE + currKeyLen + currValueLen + currMemstoreTSLen; if (this.reader.getFileContext().isIncludesTags()) { curCellSize += Bytes.SIZEOF_SHORT + currTagsLen; } return curCellSize; }
@Override public HFileBlock nextBlock() throws IOException { if (offset >= endOffset) { return null; } HFileBlock b = readBlockData(offset, length, false, false); offset += b.getOnDiskSizeWithHeader(); length = b.getNextBlockOnDiskSize(); return b.unpack(fileContext, owner); }
@Override public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics) { // TODO: is there a hole here, or just awkwardness since in the lruCache getBlock // we end up calling l2Cache.getBlock. // We are not in a position to exactly look at LRU cache or BC as BlockType may not be getting // passed always. return onHeapCache.containsBlock(cacheKey)? onHeapCache.getBlock(cacheKey, caching, repeat, updateCacheMetrics): l2Cache.getBlock(cacheKey, caching, repeat, updateCacheMetrics); }
@Override public int evictBlocksByHfileName(String hfileName) { return onHeapCache.evictBlocksByHfileName(hfileName) + l2Cache.evictBlocksByHfileName(hfileName); }
/** * Returns the size of this block header. */ public int headerSize() { return headerSize(this.fileContext.isUseHBaseChecksum()); }
@Override public boolean evictBlock(BlockCacheKey cacheKey) { boolean l1Result = this.onHeapCache.evictBlock(cacheKey); boolean l2Result = this.l2Cache.evictBlock(cacheKey); return l1Result || l2Result; } }
/** * @param cb * @return The block content as String. */ public static String toString(final CachedBlock cb, final long now) { return "filename=" + cb.getFilename() + ", " + toStringMinusFileName(cb, now); }
/** * @return the total heap size of data and meta block indexes in bytes. Does * not take into account non-root blocks of a multilevel data index. */ @Override public long indexSize() { return (dataBlockIndexReader != null ? dataBlockIndexReader.heapSize() : 0) + ((metaBlockIndexReader != null) ? metaBlockIndexReader.heapSize() : 0); }
@Override public void close() { if (!pread) { // For seek + pread stream socket should be closed when the scanner is closed. HBASE-9393 reader.unbufferStream(); } this.returnBlocks(true); }