Package org.apache.hadoop.hbase.io.util
Class MemorySizeUtil
java.lang.Object
org.apache.hadoop.hbase.io.util.MemorySizeUtil
Util class to calculate memory size for memstore(on heap, off heap), block cache(L1, L2) of RS.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final float
static final float
static final String
Configuration key for the absolute amount of heap memory that must remain free for a RegionServer to startprivate static final String
private static final org.slf4j.Logger
static final String
static final String
static final String
static final String
static final String
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic float
getBlockCacheHeapPercent
(org.apache.hadoop.conf.Configuration conf) Retrieve configured size for on heap block cache as percentage of total heap.static long
getBlockCacheSizeInBytes
(org.apache.hadoop.conf.Configuration conf) Retrieve an explicit block cache size in bytes in the configuration.static long
getBucketCacheSize
(org.apache.hadoop.conf.Configuration conf) static float
getGlobalMemStoreHeapLowerMark
(org.apache.hadoop.conf.Configuration conf, boolean honorOldConfig) Retrieve configured size for global memstore lower water mark as fraction of global memstore size.static float
getGlobalMemStoreHeapPercent
(org.apache.hadoop.conf.Configuration c, boolean logInvalid) Retrieve global memstore configured size as percentage of total heap.static Pair<Long,
MemoryType> getGlobalMemStoreSize
(org.apache.hadoop.conf.Configuration conf) Returns Pair of global memstore size and memory type(ie.static long
getOnHeapCacheSize
(org.apache.hadoop.conf.Configuration conf) static long
getOnheapGlobalMemStoreSize
(org.apache.hadoop.conf.Configuration conf) Returns the onheap global memstore limit based on the config 'hbase.regionserver.global.memstore.size'.static float
getRegionServerMinFreeHeapFraction
(org.apache.hadoop.conf.Configuration conf) Returns the minimum required free heap as a fraction of total heap.private static long
getRegionServerMinFreeHeapInBytes
(org.apache.hadoop.conf.Configuration conf) Retrieve an explicit minimum required free heap size in bytes in the configuration.static MemoryUsage
Return JVM memory statistics while properly handling runtime exceptions from the JVM.static void
validateRegionServerHeapMemoryAllocation
(org.apache.hadoop.conf.Configuration conf) Validates that heap allocations for MemStore and block cache do not exceed the allowed limit, ensuring enough free heap remains for other RegionServer tasks.
-
Field Details
-
MEMSTORE_SIZE_KEY
- See Also:
-
MEMSTORE_SIZE_OLD_KEY
- See Also:
-
MEMSTORE_SIZE_LOWER_LIMIT_KEY
- See Also:
-
MEMSTORE_SIZE_LOWER_LIMIT_OLD_KEY
- See Also:
-
OFFHEAP_MEMSTORE_SIZE_KEY
- See Also:
-
DEFAULT_MEMSTORE_SIZE
- See Also:
-
DEFAULT_MEMSTORE_SIZE_LOWER_LIMIT
- See Also:
-
HBASE_REGION_SERVER_FREE_HEAP_MIN_MEMORY_SIZE_KEY
Configuration key for the absolute amount of heap memory that must remain free for a RegionServer to start- See Also:
-
LOG
-
JVM_HEAP_EXCEPTION
- See Also:
-
-
Constructor Details
-
MemorySizeUtil
public MemorySizeUtil()
-
-
Method Details
-
safeGetHeapMemoryUsage
Return JVM memory statistics while properly handling runtime exceptions from the JVM.- Returns:
- a memory usage object, null if there was a runtime exception. (n.b. you could also get -1 values back from the JVM)
- See Also:
-
validateRegionServerHeapMemoryAllocation
public static void validateRegionServerHeapMemoryAllocation(org.apache.hadoop.conf.Configuration conf) Validates that heap allocations for MemStore and block cache do not exceed the allowed limit, ensuring enough free heap remains for other RegionServer tasks.- Parameters:
conf
- the configuration to validate- Throws:
RuntimeException
- if the combined allocation exceeds the threshold
-
getRegionServerMinFreeHeapInBytes
Retrieve an explicit minimum required free heap size in bytes in the configuration.- Parameters:
conf
- used to read configs- Returns:
- the minimum required free heap size in bytes, or a negative value if not configured.
- Throws:
IllegalArgumentException
- if HBASE_REGION_SERVER_FREE_HEAP_MIN_MEMORY_SIZE_KEY format is invalid
-
getRegionServerMinFreeHeapFraction
Returns the minimum required free heap as a fraction of total heap. -
getGlobalMemStoreHeapPercent
public static float getGlobalMemStoreHeapPercent(org.apache.hadoop.conf.Configuration c, boolean logInvalid) Retrieve global memstore configured size as percentage of total heap. -
getGlobalMemStoreHeapLowerMark
public static float getGlobalMemStoreHeapLowerMark(org.apache.hadoop.conf.Configuration conf, boolean honorOldConfig) Retrieve configured size for global memstore lower water mark as fraction of global memstore size. -
getGlobalMemStoreSize
public static Pair<Long,MemoryType> getGlobalMemStoreSize(org.apache.hadoop.conf.Configuration conf) Returns Pair of global memstore size and memory type(ie. on heap or off heap). -
getOnheapGlobalMemStoreSize
Returns the onheap global memstore limit based on the config 'hbase.regionserver.global.memstore.size'.- Returns:
- the onheap global memstore limt
-
getBlockCacheHeapPercent
Retrieve configured size for on heap block cache as percentage of total heap. -
getBlockCacheSizeInBytes
Retrieve an explicit block cache size in bytes in the configuration.- Parameters:
conf
- used to read cache configs- Returns:
- the number of bytes to use for LRU, negative if disabled.
- Throws:
IllegalArgumentException
- if HFILE_BLOCK_CACHE_MEMORY_SIZE_KEY format is invalid
-
getOnHeapCacheSize
- Parameters:
conf
- used to read cache configs- Returns:
- the number of bytes to use for LRU, negative if disabled.
- Throws:
IllegalArgumentException
- if HFILE_BLOCK_CACHE_SIZE_KEY is > 1.0
-
getBucketCacheSize
- Parameters:
conf
- used to read config for bucket cache size.- Returns:
- the number of bytes to use for bucket cache, negative if disabled.
-