diff --git a/src/main/java/org/apache/hadoop/hbase/io/hfile/DoubleBlockCache.java b/src/main/java/org/apache/hadoop/hbase/io/hfile/DoubleBlockCache.java index a2aa183..6bf01bb 100644 --- a/src/main/java/org/apache/hadoop/hbase/io/hfile/DoubleBlockCache.java +++ b/src/main/java/org/apache/hadoop/hbase/io/hfile/DoubleBlockCache.java @@ -166,4 +166,12 @@ public class DoubleBlockCache implements BlockCache, HeapSize { return onHeapCache.getBlockCacheColumnFamilySummaries(conf); } + public BlockCache getOnHeapCache(){ + return onHeapCache; + } + + public BlockCache getOffHeapCache(){ + return offHeapCache; + } + } diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java index cd809ba..c7fc247 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java @@ -100,7 +100,9 @@ import org.apache.hadoop.hbase.filter.WritableByteArrayComparable; import org.apache.hadoop.hbase.io.hfile.BlockCache; import org.apache.hadoop.hbase.io.hfile.BlockCacheColumnFamilySummary; import org.apache.hadoop.hbase.io.hfile.CacheStats; +import org.apache.hadoop.hbase.io.hfile.DoubleBlockCache; import org.apache.hadoop.hbase.io.hfile.LruBlockCache; +import org.apache.hadoop.hbase.io.hfile.slab.SlabCache; import org.apache.hadoop.hbase.ipc.CoprocessorProtocol; import org.apache.hadoop.hbase.ipc.HBaseRPC; import org.apache.hadoop.hbase.ipc.HBaseRPCErrorHandler; @@ -1270,6 +1272,10 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, this.metrics.blockCacheHitCount.set(cacheStats.getHitCount()); this.metrics.blockCacheMissCount.set(cacheStats.getMissCount()); this.metrics.blockCacheEvictedCount.set(blockCache.getEvictedCount()); + + this.metrics.blockCacheCount.set(blockCache.size()); + this.metrics.blockCacheFree.set(blockCache.getFreeSize()); + this.metrics.blockCacheSize.set(blockCache.getCurrentSize()); double ratio = blockCache.getStats().getHitRatio(); int percent = (int) (ratio * 100); this.metrics.blockCacheHitRatio.set(percent); @@ -1277,6 +1283,27 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, percent = (int) (ratio * 100); this.metrics.blockCacheHitCachingRatio.set(percent); } + /*if the off heap cache is enabled */ + if(blockCache.getClass() == DoubleBlockCache.class){ + DoubleBlockCache castedCache = (DoubleBlockCache) blockCache; + this.metrics.offHeapCacheCount.set(castedCache.getOffHeapCache().size()); + this.metrics.offHeapCacheFree.set(castedCache.getOffHeapCache().getFreeSize()); + this.metrics.offHeapCacheSize.set(castedCache.getOffHeapCache().getCurrentSize()); + CacheStats cacheStats = castedCache.getOffHeapCache().getStats(); + this.metrics.offHeapCacheHitCount.set(cacheStats.getHitCount()); + this.metrics.offHeapCacheMissCount.set(cacheStats.getMissCount()); + this.metrics.offHeapCacheEvictedCount.set(castedCache.getOffHeapCache().getEvictedCount()); + + this.metrics.offHeapCacheCount.set(castedCache.getOffHeapCache().size()); + this.metrics.offHeapCacheFree.set(castedCache.getOffHeapCache().getFreeSize()); + this.metrics.offHeapCacheSize.set(castedCache.getOffHeapCache().getCurrentSize()); + double ratio = castedCache.getOffHeapCache().getStats().getHitRatio(); + int percent = (int) (ratio * 100); + this.metrics.offHeapCacheHitRatio.set(percent); + ratio = castedCache.getOffHeapCache().getStats().getHitCachingRatio(); + percent = (int) (ratio * 100); + this.metrics.offHeapCacheHitCachingRatio.set(percent); + } float localityIndex = hdfsBlocksDistribution.getBlockLocalityIndex( getServerName().getHostname()); int percent = (int) (localityIndex * 100); @@ -2404,7 +2431,7 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, } return closeRegion(region, false, zk); } - + @Override @QosPriority(priority=HIGH_QOS) public boolean closeRegion(byte[] encodedRegionName, boolean zk) throws IOException { @@ -2438,7 +2465,7 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, this.service.submit(crh); return true; } - + /** * @param encodedRegionName * encodedregionName to close @@ -3025,7 +3052,7 @@ public class HRegionServer implements HRegionInterface, HBaseRPCErrorHandler, public Set getRegionsInTransitionInRS() { return this.regionsInTransitionInRS; } - + public ExecutorService getExecutorService() { return service; } diff --git a/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java b/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java index cbf6da4..9268c41 100644 --- a/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java +++ b/src/main/java/org/apache/hadoop/hbase/regionserver/metrics/RegionServerMetrics.java @@ -113,6 +113,49 @@ public class RegionServerMetrics implements Updater { */ public final MetricsIntValue blockCacheHitCachingRatio = new MetricsIntValue("blockCacheHitCachingRatio", registry); + + /** + * Off-heap cache size. + */ + public final MetricsLongValue offHeapCacheSize = new MetricsLongValue("offHeapCacheSize", registry); + + /** + * Off-heap cache free size. + */ + public final MetricsLongValue offHeapCacheFree = new MetricsLongValue("offHeapCacheFree", registry); + + /** + * Off-heap cache item count. + */ + public final MetricsLongValue offHeapCacheCount = new MetricsLongValue("offHeapCacheCount", registry); + + /** + * Off-heap cache hit count. + */ + public final MetricsLongValue offHeapCacheHitCount = new MetricsLongValue("offHeapCacheHitCount", registry); + + /** + * Off-heap cache miss count. + */ + public final MetricsLongValue offHeapCacheMissCount = new MetricsLongValue("offHeapCacheMissCount", registry); + + /** + * Off-heap cache evict count. + */ + public final MetricsLongValue offHeapCacheEvictedCount = new MetricsLongValue("offHeapCacheEvictedCount", registry); + + /** + * Off-heap hit ratio. + */ + public final MetricsIntValue offHeapCacheHitRatio = new MetricsIntValue("offHeapCacheHitRatio", registry); + + /** + * Off-heap hit caching ratio. This only includes the requests to the offHeap + * cache where caching was turned on. See HBASE-2253. + */ + public final MetricsIntValue offHeapCacheHitCachingRatio = new MetricsIntValue("offHeapCacheHitCachingRatio", registry); + + /* * Count of requests to the regionservers since last call to metrics update */ @@ -160,7 +203,7 @@ public class RegionServerMetrics implements Updater { */ public final MetricsIntValue hdfsBlocksLocalityIndex = new MetricsIntValue("hdfsBlocksLocalityIndex", registry); - + /** * Sum of all the memstore sizes in this regionserver in MB */ @@ -172,7 +215,7 @@ public class RegionServerMetrics implements Updater { */ public final MetricsIntValue compactionQueueSize = new MetricsIntValue("compactionQueueSize", registry); - + /** * Size of the flush queue. */ @@ -288,6 +331,14 @@ public class RegionServerMetrics implements Updater { this.blockCacheEvictedCount.pushMetric(this.metricsRecord); this.blockCacheHitRatio.pushMetric(this.metricsRecord); this.blockCacheHitCachingRatio.pushMetric(this.metricsRecord); + this.offHeapCacheSize.pushMetric(this.metricsRecord); + this.offHeapCacheFree.pushMetric(this.metricsRecord); + this.offHeapCacheCount.pushMetric(this.metricsRecord); + this.offHeapCacheHitCount.pushMetric(this.metricsRecord); + this.offHeapCacheMissCount.pushMetric(this.metricsRecord); + this.offHeapCacheEvictedCount.pushMetric(this.metricsRecord); + this.offHeapCacheHitRatio.pushMetric(this.metricsRecord); + this.offHeapCacheHitCachingRatio.pushMetric(this.metricsRecord); this.hdfsBlocksLocalityIndex.pushMetric(this.metricsRecord); // Mix in HFile and HLog metrics