public void add(LruCachedBlock block) { totalSize += block.heapSize(); queue.add(block); }
/** * Attempt to add the specified cached block to this queue. * * <p>If the queue is smaller than the max size, or if the specified element * is ordered before the smallest element in the queue, the element will be * added to the queue. Otherwise, there is no side effect of this call. * @param cb block to try to add to the queue */ public void add(LruCachedBlock cb) { if(heapSize < maxSize) { queue.add(cb); heapSize += cb.heapSize(); } else { LruCachedBlock head = queue.peek(); if(cb.compareTo(head) > 0) { heapSize += cb.heapSize(); heapSize -= head.heapSize(); if(heapSize > maxSize) { queue.poll(); } else { heapSize += head.heapSize(); } queue.add(cb); } } }
/** * Helper function that updates the local size counter and also updates any * per-cf or per-blocktype metrics it can discern from given * {@link LruCachedBlock} */ private long updateSizeMetrics(LruCachedBlock cb, boolean evict) { long heapsize = cb.heapSize(); BlockType bt = cb.getBuffer().getBlockType(); if (evict) { heapsize *= -1; } if (bt != null && bt.isData()) { dataBlockSize.add(heapsize); } return size.addAndGet(heapsize); }
return block.heapSize();
/** * Helper function that updates the local size counter and also updates any * per-cf or per-blocktype metrics it can discern from given * {@link LruCachedBlock} * * @param cb * @param evict */ protected long updateSizeMetrics(LruCachedBlock cb, boolean evict) { long heapsize = cb.heapSize(); if (evict) { heapsize *= -1; } return size.addAndGet(heapsize); }
public void add(LruCachedBlock block) { totalSize += block.heapSize(); queue.add(block); }
/** * Attempt to add the specified cached block to this queue. * * <p>If the queue is smaller than the max size, or if the specified element * is ordered before the smallest element in the queue, the element will be * added to the queue. Otherwise, there is no side effect of this call. * @param cb block to try to add to the queue */ public void add(LruCachedBlock cb) { if(heapSize < maxSize) { queue.add(cb); heapSize += cb.heapSize(); } else { LruCachedBlock head = queue.peek(); if(cb.compareTo(head) > 0) { heapSize += cb.heapSize(); heapSize -= head.heapSize(); if(heapSize > maxSize) { queue.poll(); } else { heapSize += head.heapSize(); } queue.add(cb); } } }
/** * Evict the block, and it will be cached by the victim handler if exists && * block may be read again later * @param block * @param evictedByEvictionProcess true if the given block is evicted by * EvictionThread * @return the heap size of evicted block */ protected long evictBlock(LruCachedBlock block, boolean evictedByEvictionProcess) { map.remove(block.getCacheKey()); updateSizeMetrics(block, true); long val = elements.decrementAndGet(); if (LOG.isTraceEnabled()) { long size = map.size(); assertCounterSanity(size, val); } stats.evicted(block.getCachedTime(), block.getCacheKey().isPrimary()); if (evictedByEvictionProcess && victimHandler != null) { if (victimHandler instanceof BucketCache) { boolean wait = getCurrentSize() < acceptableSize(); boolean inMemory = block.getPriority() == BlockPriority.MEMORY; ((BucketCache)victimHandler).cacheBlockWithWait(block.getCacheKey(), block.getBuffer(), inMemory, wait); } else { victimHandler.cacheBlock(block.getCacheKey(), block.getBuffer()); } } return block.heapSize(); }