@Override public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics) { // Assume that nothing is the block cache HFileBlock result = null; try (TraceScope traceScope = TraceUtil.createTrace("MemcachedBlockCache.getBlock")) { result = client.get(cacheKey.toString(), tc); } catch (Exception e) { // Catch a pretty broad set of exceptions to limit any changes in the memecache client // and how it handles failures from leaking into the read path. if (LOG.isDebugEnabled()) { LOG.debug("Exception pulling from memcached [ " + cacheKey.toString() + " ]. Treating as a miss.", e); } result = null; } finally { // Update stats if this request doesn't have it turned off 100% of the time if (updateCacheMetrics) { if (result == null) { cacheStats.miss(caching, cacheKey.isPrimary(), cacheKey.getBlockType()); } else { cacheStats.hit(caching, cacheKey.isPrimary(), cacheKey.getBlockType()); } } } return result; }
if (updateCacheMetrics) stats.hit(caching, cacheKey.isPrimary(), cacheKey.getBlockType()); cb.access(count.incrementAndGet()); return cb.getBuffer();
stats.hit(false, true, BlockType.DATA); stats.hit(true, true, BlockType.DATA); stats.miss(false, false, BlockType.DATA); stats.miss(false, false, BlockType.DATA); stats.hit(false, true, BlockType.DATA); stats.hit(true, true, BlockType.DATA); stats.hit(false, true, BlockType.DATA); stats.hit(true, true, BlockType.DATA); stats.rollMetricsPeriod(); assertEquals(0.5, stats.getHitRatioPastNPeriods(), delta); stats.hit(false, true, BlockType.DATA); stats.hit(false, true, BlockType.DATA); stats.rollMetricsPeriod(); assertEquals(0.6, stats.getHitRatioPastNPeriods(), delta); stats.hit(true, true, BlockType.DATA); stats.hit(false, true, BlockType.DATA); stats.rollMetricsPeriod(); assertEquals(0.5, stats.getHitRatioPastNPeriods(), delta);
lruCacheStats.hit(true, true, BlockType.DATA); lruCacheStats.miss(true, false, BlockType.DATA); bucketCacheStats.hit(false,true, BlockType.DATA); bucketCacheStats.hit(false,true, BlockType.DATA); bucketCacheStats.miss(false, true, BlockType.DATA); lruCacheStats.hit(true, true, BlockType.DATA); lruCacheStats.hit(true, true, BlockType.DATA); lruCacheStats.hit(true, true, BlockType.DATA); stats.rollMetricsPeriod(); assertEquals(6, stats.getSumHitCountsPastNPeriods());
public void hit(boolean caching) { hit(caching, true); }
@Override public Cacheable getBlock(BlockCacheKey key, boolean caching, boolean repeat) { CacheablePair contentBlock = backingMap.get(key); if (contentBlock == null) { if (!repeat) stats.miss(caching); return null; } stats.hit(caching); // If lock cannot be obtained, that means we're undergoing eviction. try { contentBlock.recentlyAccessed.set(System.nanoTime()); synchronized (contentBlock) { if (contentBlock.serializedData == null) { // concurrently evicted LOG.warn("Concurrent eviction of " + key); return null; } return contentBlock.deserializer .deserialize(contentBlock.serializedData.asReadOnlyBuffer()); } } catch (Throwable t) { LOG.error("Deserializer threw an exception. This may indicate a bug.", t); return null; } }
@Override public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat) { Cacheable cachedBlock; if ((cachedBlock = onHeapCache.getBlock(cacheKey, caching, repeat)) != null) { stats.hit(caching); return cachedBlock; } else if ((cachedBlock = offHeapCache.getBlock(cacheKey, caching, repeat)) != null) { if (caching) { onHeapCache.cacheBlock(cacheKey, cachedBlock); } stats.hit(caching); return cachedBlock; } if (!repeat) stats.miss(caching); return null; }
/** * Get the buffer of the block with the specified name. * @param cacheKey block's cache key * @param caching true if the caller caches blocks on cache misses * @param repeat Whether this is a repeat lookup for the same block * (used to avoid double counting cache misses when doing double-check locking) * {@see HFileReaderV2#readBlock(long, long, boolean, boolean, boolean, BlockType)} * @return buffer of specified cache key, or null if not in cache */ @Override public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat) { CachedBlock cb = map.get(cacheKey); if(cb == null) { if (!repeat) stats.miss(caching); return null; } stats.hit(caching); cb.access(count.incrementAndGet()); return cb.getBuffer(); }
/** * Get the buffer of the block with the specified name. * @param caching * @param key * @param repeat * * @return buffer of specified block name, or null if not in cache */ public Cacheable getBlock(BlockCacheKey key, boolean caching, boolean repeat) { SingleSizeCache cachedBlock = backingStore.get(key); if (cachedBlock == null) { if (!repeat) stats.miss(caching); return null; } Cacheable contentBlock = cachedBlock.getBlock(key, caching, false); if (contentBlock != null) { stats.hit(caching); } else { if (!repeat) stats.miss(caching); } return contentBlock; }
if (updateCacheMetrics) stats.hit(caching, cacheKey.isPrimary()); cb.access(count.incrementAndGet()); return cb.getBuffer();
@Override public Cacheable getBlock(BlockCacheKey cacheKey, boolean caching, boolean repeat, boolean updateCacheMetrics) { // Assume that nothing is the block cache HFileBlock result = null; try (TraceScope traceScope = TraceUtil.createTrace("MemcachedBlockCache.getBlock")) { result = client.get(cacheKey.toString(), tc); } catch (Exception e) { // Catch a pretty broad set of exceptions to limit any changes in the memecache client // and how it handles failures from leaking into the read path. if (LOG.isDebugEnabled()) { LOG.debug("Exception pulling from memcached [ " + cacheKey.toString() + " ]. Treating as a miss.", e); } result = null; } finally { // Update stats if this request doesn't have it turned off 100% of the time if (updateCacheMetrics) { if (result == null) { cacheStats.miss(caching, cacheKey.isPrimary(), cacheKey.getBlockType()); } else { cacheStats.hit(caching, cacheKey.isPrimary(), cacheKey.getBlockType()); } } } return result; }
stats.hit(false, true, BlockType.DATA); stats.hit(true, true, BlockType.DATA); stats.miss(false, false, BlockType.DATA); stats.miss(false, false, BlockType.DATA); stats.hit(false, true, BlockType.DATA); stats.hit(true, true, BlockType.DATA); stats.hit(false, true, BlockType.DATA); stats.hit(true, true, BlockType.DATA); stats.rollMetricsPeriod(); assertEquals(0.5, stats.getHitRatioPastNPeriods(), delta); stats.hit(false, true, BlockType.DATA); stats.hit(false, true, BlockType.DATA); stats.rollMetricsPeriod(); assertEquals(0.6, stats.getHitRatioPastNPeriods(), delta); stats.hit(true, true, BlockType.DATA); stats.hit(false, true, BlockType.DATA); stats.rollMetricsPeriod(); assertEquals(0.5, stats.getHitRatioPastNPeriods(), delta);
lruCacheStats.hit(true, true, BlockType.DATA); lruCacheStats.miss(true, false, BlockType.DATA); bucketCacheStats.hit(false,true, BlockType.DATA); bucketCacheStats.hit(false,true, BlockType.DATA); bucketCacheStats.miss(false, true, BlockType.DATA); lruCacheStats.hit(true, true, BlockType.DATA); lruCacheStats.hit(true, true, BlockType.DATA); lruCacheStats.hit(true, true, BlockType.DATA); stats.rollMetricsPeriod(); assertEquals(6, stats.getSumHitCountsPastNPeriods());