@InterfaceAudience.Private public final class BucketAllocator extends Object
Modifier and Type | Class and Description |
---|---|
static class |
BucketAllocator.Bucket |
(package private) class |
BucketAllocator.BucketSizeInfo |
(package private) static class |
BucketAllocator.IndexStatistics |
Modifier and Type | Field and Description |
---|---|
private int |
bigItemSize |
private long |
bucketCapacity |
private BucketAllocator.Bucket[] |
buckets |
private BucketAllocator.BucketSizeInfo[] |
bucketSizeInfos |
private int[] |
bucketSizes |
private static int[] |
DEFAULT_BUCKET_SIZES |
static int |
FEWEST_ITEMS_IN_BUCKET |
private static org.apache.commons.logging.Log |
LOG |
private long |
totalSize |
private long |
usedSize |
Constructor and Description |
---|
BucketAllocator(long availableSpace,
int[] bucketSizes) |
BucketAllocator(long availableSpace,
int[] bucketSizes,
Map<BlockCacheKey,BucketCache.BucketEntry> map,
AtomicLong realCacheSize)
Rebuild the allocator's data structures from a persisted map.
|
Modifier and Type | Method and Description |
---|---|
long |
allocateBlock(int blockSize)
Allocate a block with specified size.
|
int |
freeBlock(long offset)
Free a block with the offset
|
long |
freeBlock(long[] freeList) |
int |
getBucketIndex(long offset) |
BucketAllocator.Bucket[] |
getBuckets() |
long |
getFreeSize() |
(package private) BucketAllocator.IndexStatistics[] |
getIndexStatistics() |
(package private) BucketAllocator.IndexStatistics[] |
getIndexStatistics(BucketAllocator.IndexStatistics grandTotal) |
Set<Integer> |
getLeastFilledBuckets(Set<Integer> excludedBuckets,
int bucketCount)
Returns a set of indices of the buckets that are least filled
excluding the offsets, we also the fully free buckets for the
BucketSizes where everything is empty and they only have one
completely free bucket as a reserved
|
long |
getTotalSize() |
long |
getUsedSize() |
private BucketAllocator.Bucket |
grabGlobalCompletelyFreeBucket() |
(package private) void |
logStatistics() |
BucketAllocator.BucketSizeInfo |
roundUpToBucketSizeInfo(int blockSize)
Round up the given block size to bucket size, and get the corresponding
BucketSizeInfo
|
int |
sizeIndexOfAllocation(long offset) |
int |
sizeOfAllocation(long offset) |
String |
toString() |
private static final org.apache.commons.logging.Log LOG
private static final int[] DEFAULT_BUCKET_SIZES
public static final int FEWEST_ITEMS_IN_BUCKET
private final int[] bucketSizes
private final int bigItemSize
private final long bucketCapacity
private BucketAllocator.Bucket[] buckets
private BucketAllocator.BucketSizeInfo[] bucketSizeInfos
private final long totalSize
private long usedSize
BucketAllocator(long availableSpace, int[] bucketSizes) throws BucketAllocatorException
BucketAllocatorException
BucketAllocator(long availableSpace, int[] bucketSizes, Map<BlockCacheKey,BucketCache.BucketEntry> map, AtomicLong realCacheSize) throws BucketAllocatorException
availableSpace
- capacity of cachemap
- A map stores the block key and BucketEntry(block's meta data
like offset, length)realCacheSize
- cached data size statistics for bucket cacheBucketAllocatorException
public BucketAllocator.BucketSizeInfo roundUpToBucketSizeInfo(int blockSize)
public long getUsedSize()
public long getFreeSize()
public long getTotalSize()
public long allocateBlock(int blockSize) throws CacheFullException, BucketAllocatorException
blockSize
- size of blockBucketAllocatorException
CacheFullException
private BucketAllocator.Bucket grabGlobalCompletelyFreeBucket()
public int freeBlock(long offset)
offset
- block's offsetpublic int sizeIndexOfAllocation(long offset)
public int sizeOfAllocation(long offset)
public BucketAllocator.Bucket[] getBuckets()
void logStatistics()
BucketAllocator.IndexStatistics[] getIndexStatistics(BucketAllocator.IndexStatistics grandTotal)
BucketAllocator.IndexStatistics[] getIndexStatistics()
public long freeBlock(long[] freeList)
public int getBucketIndex(long offset)
public Set<Integer> getLeastFilledBuckets(Set<Integer> excludedBuckets, int bucketCount)
excludedBuckets
- the buckets that need to be excluded due to
currently being in usedbucketCount
- max Number of buckets to returnCopyright © 2007–2019 The Apache Software Foundation. All rights reserved.