Class BucketAllocator
java.lang.Object
org.apache.hadoop.hbase.io.hfile.bucket.BucketAllocator
This class is used to allocate a block with specified size and free the block when evicting. It
manages an array of buckets, each bucket is associated with a size and caches elements up to this
size. For a completely empty bucket, this size could be re-specified dynamically.
This class is not thread safe.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic final class
(package private) final class
(package private) static class
Statistics to give a glimpse into the distribution of BucketCache objects. -
Field Summary
Modifier and TypeFieldDescriptionprivate final int
private final long
private BucketAllocator.Bucket[]
private BucketAllocator.BucketSizeInfo[]
private final int[]
private static final int[]
static final int
So, what is the minimum amount of items we'll tolerate in a single bucket?private static final org.slf4j.Logger
private final long
private long
-
Constructor Summary
ConstructorDescriptionBucketAllocator
(long availableSpace, int[] bucketSizes) BucketAllocator
(long availableSpace, int[] bucketSizes, Map<BlockCacheKey, BucketEntry> map, LongAdder realCacheSize) Rebuild the allocator's data structures from a persisted map. -
Method Summary
Modifier and TypeMethodDescriptionlong
allocateBlock
(int blockSize) Allocate a block with specified size.int
freeBlock
(long offset, int length) Free a block with the offsetint
getBucketIndex
(long offset) long
(package private) BucketAllocator.IndexStatistics[]
(package private) BucketAllocator.IndexStatistics[]
getIndexStatistics
(BucketAllocator.IndexStatistics grandTotal) 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 reservedlong
long
private BucketAllocator.Bucket
(package private) void
roundUpToBucketSizeInfo
(int blockSize) Round up the given block size to bucket size, and get the corresponding BucketSizeInfoint
sizeIndexOfAllocation
(long offset) int
sizeOfAllocation
(long offset) toString()
-
Field Details
-
LOG
-
DEFAULT_BUCKET_SIZES
-
FEWEST_ITEMS_IN_BUCKET
So, what is the minimum amount of items we'll tolerate in a single bucket?- See Also:
-
bucketSizes
-
bigItemSize
-
bucketCapacity
-
buckets
-
bucketSizeInfos
-
totalSize
-
usedSize
-
-
Constructor Details
-
BucketAllocator
BucketAllocator(long availableSpace, int[] bucketSizes) throws BucketAllocatorException - Throws:
BucketAllocatorException
-
BucketAllocator
BucketAllocator(long availableSpace, int[] bucketSizes, Map<BlockCacheKey, BucketEntry> map, LongAdder realCacheSize) throws BucketAllocatorExceptionRebuild the allocator's data structures from a persisted map.- Parameters:
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 cache- Throws:
BucketAllocatorException
-
-
Method Details
-
roundUpToBucketSizeInfo
Round up the given block size to bucket size, and get the corresponding BucketSizeInfo -
toString
-
getUsedSize
-
getFreeSize
-
getTotalSize
-
allocateBlock
Allocate a block with specified size. Return the offset- Parameters:
blockSize
- size of block- Returns:
- the offset in the IOEngine
- Throws:
CacheFullException
BucketAllocatorException
-
grabGlobalCompletelyFreeBucket
-
freeBlock
Free a block with the offset- Parameters:
offset
- block's offset- Returns:
- size freed
-
sizeIndexOfAllocation
-
sizeOfAllocation
-
getBuckets
-
logDebugStatistics
void logDebugStatistics() -
getIndexStatistics
-
getIndexStatistics
-
getBucketIndex
-
getLeastFilledBuckets
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- Parameters:
excludedBuckets
- the buckets that need to be excluded due to currently being in usedbucketCount
- max Number of buckets to return- Returns:
- set of bucket indices which could be used for eviction
-