From ebf55aa2d1f77a2e93f897cbb36159d12da79191 Mon Sep 17 00:00:00 2001
From: Xuesen Liang
Date: Wed, 27 Apr 2022 20:35:04 +0800
Subject: [PATCH 1/3] HBASE-26982 Add index and bloom filter statistics of
LruBlockCache on rs web UI
---
.../hadoop/hbase/io/hfile/BlockType.java | 13 +++++
.../tmpl/regionserver/BlockCacheTmpl.jamon | 29 +++++++++-
.../hadoop/hbase/io/hfile/LruBlockCache.java | 57 ++++++++++++++++---
3 files changed, 90 insertions(+), 9 deletions(-)
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockType.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockType.java
index 4753813d30ef..c3571b43cd96 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockType.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockType.java
@@ -219,4 +219,17 @@ public final boolean isData() {
return this == DATA || this == ENCODED_DATA;
}
+ /**
+ * @return whether this block category is index
+ */
+ public final boolean isIndex() {
+ return this.getCategory() == BlockCategory.INDEX;
+ }
+
+ /**
+ * @return whether this block category is bloom filter
+ */
+ public final boolean isBloom() {
+ return this.getCategory() == BlockCategory.BLOOM;
+ }
}
diff --git a/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/BlockCacheTmpl.jamon b/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/BlockCacheTmpl.jamon
index a18e6d4cfc4c..cf9f36b7cdcb 100644
--- a/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/BlockCacheTmpl.jamon
+++ b/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/BlockCacheTmpl.jamon
@@ -36,6 +36,7 @@ org.apache.hadoop.hbase.io.hfile.CachedBlock;
org.apache.hadoop.conf.Configuration;
org.apache.hadoop.hbase.io.hfile.CacheConfig;
org.apache.hadoop.hbase.io.hfile.BlockCache;
+org.apache.hadoop.hbase.io.hfile.LruBlockCache;
org.apache.hadoop.hbase.io.hfile.bucket.BucketCacheStats;
org.apache.hadoop.hbase.io.hfile.bucket.BucketCache;
org.apache.hadoop.hbase.io.hfile.bucket.BucketAllocator;
@@ -285,6 +286,8 @@ are combined counts. Request count is sum of hits and misses.
org.apache.hadoop.hbase.io.hfile.BlockCacheUtil.getLoadedCachedBlocksByFile(config, bc);
AgeSnapshot cbsbfSnapshot = cbsbf.getAgeInCacheSnapshot();
+ boolean lru = bc instanceof LruBlockCache;
+
boolean bucketCache = bc.getClass().getSimpleName().equals("BucketCache");
BucketCacheStats bucketCacheStats = null;
BucketAllocator bucketAllocator = null;
@@ -336,7 +339,19 @@ are combined counts. Request count is sum of hits and misses.
Count of DATA Blocks |
%if>
+<%if lru %>
+
+ Index Block Count |
+ <% String.format("%,d", ((LruBlockCache)bc).getIndexBlockCount()) %> |
+ Count of INDEX Blocks |
+
+ Bloom Block Count |
+ <% String.format("%,d", ((LruBlockCache)bc).getBloomBlockCount()) %> |
+ Count of BLOOM Blocks |
+
+%if>
+
Size of Blocks |
<% TraditionalBinaryPrefix.long2String(bc.getCurrentSize(), "B", 1) %> |
Size of Blocks |
@@ -348,7 +363,19 @@ are combined counts. Request count is sum of hits and misses.
Size of DATA Blocks |
%if>
-<& evictions_tmpl; bc = bc; &>
+<%if lru %>
+
+ Size of Index Blocks |
+ <% String.format("%,d", ((LruBlockCache)bc).getCurrentIndexSize()) %> |
+ Size of INDEX Blocks |
+
+
+ Size of Bloom Blocks |
+ <% String.format("%,d", ((LruBlockCache)bc).getCurrentBloomSize()) %> |
+ Size of BLOOM Blocks |
+
+%if>
+ <& evictions_tmpl; bc = bc; &>
<& hits_tmpl; bc = bc; &>
<%if bucketCache %>
diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java
index 3e5ba1d19c56..9019832bb060 100644
--- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java
+++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/LruBlockCache.java
@@ -174,13 +174,25 @@ public class LruBlockCache implements FirstLevelBlockCache {
private final AtomicLong size;
/** Current size of data blocks */
- private final LongAdder dataBlockSize;
+ private final LongAdder dataBlockSize = new LongAdder();
+
+ /** Current size of index blocks */
+ private final LongAdder indexBlockSize = new LongAdder();
+
+ /** Current size of bloom blocks */
+ private final LongAdder bloomBlockSize = new LongAdder();
/** Current number of cached elements */
private final AtomicLong elements;
/** Current number of cached data block elements */
- private final LongAdder dataBlockElements;
+ private final LongAdder dataBlockElements = new LongAdder();
+
+ /** Current number of cached index block elements */
+ private final LongAdder indexBlockElements = new LongAdder();
+
+ /** Current number of cached bloom block elements */
+ private final LongAdder bloomBlockElements = new LongAdder();
/** Cache access count (sequential ID) */
private final AtomicLong count;
@@ -319,8 +331,6 @@ public LruBlockCache(long maxSize, long blockSize, boolean evictionThread,
this.stats = new CacheStats(this.getClass().getSimpleName());
this.count = new AtomicLong(0);
this.elements = new AtomicLong(0);
- this.dataBlockElements = new LongAdder();
- this.dataBlockSize = new LongAdder();
this.overhead = calculateOverhead(maxSize, blockSize, mapConcurrencyLevel);
this.size = new AtomicLong(this.overhead);
this.hardCapacityLimitFactor = hardLimitFactor;
@@ -432,7 +442,11 @@ public void cacheBlock(BlockCacheKey cacheKey, Cacheable buf, boolean inMemory)
long newSize = updateSizeMetrics(cb, false);
map.put(cacheKey, cb);
long val = elements.incrementAndGet();
- if (buf.getBlockType().isData()) {
+ if (buf.getBlockType().isBloom()) {
+ bloomBlockElements.increment();
+ } else if (buf.getBlockType().isIndex()) {
+ indexBlockElements.increment();
+ } else if (buf.getBlockType().isData()) {
dataBlockElements.increment();
}
if (LOG.isTraceEnabled()) {
@@ -489,8 +503,14 @@ private long updateSizeMetrics(LruCachedBlock cb, boolean evict) {
if (evict) {
heapsize *= -1;
}
- if (bt != null && bt.isData()) {
- dataBlockSize.add(heapsize);
+ if (bt != null) {
+ if (bt.isBloom()) {
+ bloomBlockSize.add(heapsize);
+ } else if (bt.isIndex()) {
+ indexBlockSize.add(heapsize);
+ } else if (bt.isData()) {
+ dataBlockSize.add(heapsize);
+ }
}
return size.addAndGet(heapsize);
}
@@ -606,7 +626,12 @@ protected long evictBlock(LruCachedBlock block, boolean evictedByEvictionProcess
long size = map.size();
assertCounterSanity(size, val);
}
- if (block.getBuffer().getBlockType().isData()) {
+ BlockType bt = block.getBuffer().getBlockType();
+ if (bt.isBloom()) {
+ bloomBlockElements.decrement();
+ } else if (bt.isIndex()) {
+ indexBlockElements.decrement();
+ } else if (bt.isData()) {
dataBlockElements.decrement();
}
if (evictedByEvictionProcess) {
@@ -885,6 +910,14 @@ public long getCurrentDataSize() {
return this.dataBlockSize.sum();
}
+ public long getCurrentIndexSize() {
+ return this.indexBlockSize.sum();
+ }
+
+ public long getCurrentBloomSize() {
+ return this.bloomBlockSize.sum();
+ }
+
@Override
public long getFreeSize() {
return getMaxSize() - getCurrentSize();
@@ -905,6 +938,14 @@ public long getDataBlockCount() {
return this.dataBlockElements.sum();
}
+ public long getIndexBlockCount() {
+ return this.indexBlockElements.sum();
+ }
+
+ public long getBloomBlockCount() {
+ return this.bloomBlockElements.sum();
+ }
+
EvictionThread getEvictionThread() {
return this.evictionThread;
}
From 1a7c0ed4ef388d83dcc263a022a27b1dcdef620f Mon Sep 17 00:00:00 2001
From: Xuesen Liang
Date: Thu, 14 Jul 2022 20:34:25 +0800
Subject: [PATCH 2/3] modify_format
---
.../hadoop/hbase/tmpl/regionserver/BlockCacheTmpl.jamon | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/BlockCacheTmpl.jamon b/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/BlockCacheTmpl.jamon
index cf9f36b7cdcb..e81e50cef6c4 100644
--- a/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/BlockCacheTmpl.jamon
+++ b/hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/BlockCacheTmpl.jamon
@@ -366,12 +366,12 @@ are combined counts. Request count is sum of hits and misses.
<%if lru %>
Size of Index Blocks |
- <% String.format("%,d", ((LruBlockCache)bc).getCurrentIndexSize()) %> |
+ <% TraditionalBinaryPrefix.long2String(((LruBlockCache)bc).getCurrentIndexSize(), "B", 1) %> |
Size of INDEX Blocks |
Size of Bloom Blocks |
- <% String.format("%,d", ((LruBlockCache)bc).getCurrentBloomSize()) %> |
+ <% TraditionalBinaryPrefix.long2String(((LruBlockCache)bc).getCurrentBloomSize(), "B", 1) %> |
Size of BLOOM Blocks |
%if>
From 040632134c94f32720ef6d30f076349d5ee0a5ee Mon Sep 17 00:00:00 2001
From: Xuesen Liang
Date: Mon, 15 Aug 2022 15:13:15 +0800
Subject: [PATCH 3/3] fix spotless
---
.../java/org/apache/hadoop/hbase/io/hfile/BlockType.java | 8 ++------
1 file changed, 2 insertions(+), 6 deletions(-)
diff --git a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockType.java b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockType.java
index 0d166fe750c2..9b8a6bbfe2c5 100644
--- a/hbase-common/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockType.java
+++ b/hbase-common/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockType.java
@@ -215,16 +215,12 @@ public final boolean isData() {
return this == DATA || this == ENCODED_DATA;
}
- /**
- * @return whether this block category is index
- */
+ /** Returns whether this block category is index */
public final boolean isIndex() {
return this.getCategory() == BlockCategory.INDEX;
}
- /**
- * @return whether this block category is bloom filter
- */
+ /** Returns whether this block category is bloom filter */
public final boolean isBloom() {
return this.getCategory() == BlockCategory.BLOOM;
}