IndexStatistics[] getIndexStatistics(IndexStatistics grandTotal) { IndexStatistics[] stats = getIndexStatistics(); long totalfree = 0, totalused = 0; for (IndexStatistics stat : stats) { totalfree += stat.freeBytes(); totalused += stat.usedBytes(); } grandTotal.setTo(totalfree, totalused, 1); return stats; }
/** * Free a block with the offset * @param offset block's offset * @return size freed */ public synchronized int freeBlock(long offset) { int bucketNo = (int) (offset / bucketCapacity); assert bucketNo >= 0 && bucketNo < buckets.length; Bucket targetBucket = buckets[bucketNo]; bucketSizeInfos[targetBucket.sizeIndex()].freeBlock(targetBucket, offset); usedSize -= targetBucket.getItemAllocationSize(); return targetBucket.getItemAllocationSize(); }
/** * Only used in test * @throws InterruptedException */ void stopWriterThreads() throws InterruptedException { for (WriterThread writerThread : writerThreads) { writerThread.disableWriter(); writerThread.interrupt(); writerThread.join(); } }
void logStatistics() { IndexStatistics total = new IndexStatistics(); IndexStatistics[] stats = getIndexStatistics(total); LOG.info("Bucket allocator statistics follow:\n"); LOG.info(" Free bytes=" + total.freeBytes() + "+; used bytes=" + total.usedBytes() + "; total bytes=" + total.totalBytes()); for (IndexStatistics s : stats) { LOG.info(" Object size " + s.itemSize() + " used=" + s.usedCount() + "; free=" + s.freeCount() + "; total=" + s.totalCount()); } }
public synchronized IndexStatistics statistics() { long free = 0, used = 0; for (Object obj : bucketList.keySet()) { Bucket b = (Bucket) obj; free += b.freeCount(); used += b.usedCount(); } return new IndexStatistics(free, used, bucketSizes[sizeIndex]); }
private void cacheAndWaitUntilFlushedToBucket(BucketCache cache, BlockCacheKey cacheKey, Cacheable block) throws InterruptedException { cache.cacheBlock(cacheKey, block); waitUntilFlushedToBucket(cache, cacheKey); }
/** * Test non-error case just works. * @throws FileNotFoundException * @throws IOException * @throws InterruptedException */ @Test public void testNonErrorCase() throws IOException, InterruptedException { bc.cacheBlock(this.plainKey, this.plainCacheable); doDrainOfOneEntry(this.bc, this.wt, this.q); }
/** * Cache the block with the specified name and buffer. * @param cacheKey block's cache key * @param buf block buffer */ @Override public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf) { cacheBlock(cacheKey, buf, false); }
public long freeBlock(long freeList[]) { long sz = 0; for (int i = 0; i < freeList.length; ++i) sz += freeBlock(freeList[i]); return sz; }
IndexStatistics[] getIndexStatistics() { IndexStatistics[] stats = new IndexStatistics[bucketSizes.length]; for (int i = 0; i < stats.length; ++i) stats[i] = bucketSizeInfos[i].statistics(); return stats; }
@Override public void run() { bucketCache.logStats(); } }
BucketEntry(long offset, int length, long accessCounter, boolean inMemory) { setOffset(offset); this.length = length; this.accessCounter = accessCounter; if (inMemory) { this.priority = BlockPriority.MEMORY; } else { this.priority = BlockPriority.SINGLE; } }
public int sizeIndexOfAllocation(long offset) { int bucketNo = (int) (offset / bucketCapacity); assert bucketNo >= 0 && bucketNo < buckets.length; Bucket targetBucket = buckets[bucketNo]; return targetBucket.sizeIndex(); }
public int sizeOfAllocation(long offset) { int bucketNo = (int) (offset / bucketCapacity); assert bucketNo >= 0 && bucketNo < buckets.length; Bucket targetBucket = buckets[bucketNo]; return targetBucket.getItemAllocationSize(); }
public StatisticsThread(BucketCache bucketCache) { super("BucketCacheStatsThread"); setDaemon(true); this.bucketCache = bucketCache; }
public BucketEntryGroup(long bytesToFree, long blockSize, long bucketSize) { this.bucketSize = bucketSize; queue = new CachedEntryQueue(bytesToFree, blockSize); totalSize = 0; }
private void free(long offset) { offset -= baseOffset; assert offset >= 0; assert offset < itemCount * itemAllocationSize; assert offset % itemAllocationSize == 0; assert usedCount > 0; assert freeCount < itemCount; // Else duplicate free int item = (int) (offset / (long) itemAllocationSize); assert !freeListContains(item); --usedCount; freeList[freeCount++] = item; }
private Bucket grabGlobalCompletelyFreeBucket() { for (BucketSizeInfo bsi : bucketSizeInfos) { Bucket b = bsi.findAndRemoveCompletelyFreeBucket(); if (b != null) return b; } return null; }
/** * Cache the block with the specified name and buffer. * @param cacheKey block's cache key * @param cachedItem block buffer * @param inMemory if block is in-memory */ @Override public void cacheBlock(BlockCacheKey cacheKey, Cacheable cachedItem, boolean inMemory) { cacheBlockWithWait(cacheKey, cachedItem, inMemory, wait_when_cache); }
@Override public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf) { super.cacheBlock(cacheKey, buf); } }