Skip to content

Commit 5429771

Browse files
committed
Separate RowCache from BlockCache
- Implement RowCache - Initially considered modifying LruBlockCache, but the required changes were extensive. Instead, implemented RowCache using Caffeine cache. - Add row.cache.size configuration - Default is 0.0 (disabled); RowCache is enabled only if explicitly set to a value > 0. - The combined size of BlockCache + MemStore + RowCache must not exceed 80% of the heap. - Add Row Cache tab to RegionServer Block Cache UI - RowCache is not a BlockCache, but added here since there is no better place. - Add RowCache metrics - Metrics for size, count, eviction, hit, and miss are now exposed.
1 parent 80b728c commit 5429771

File tree

29 files changed

+559
-325
lines changed

29 files changed

+559
-325
lines changed

hbase-client/src/main/java/org/apache/hadoop/hbase/client/TableDescriptorBuilder.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -234,7 +234,7 @@ public class TableDescriptorBuilder {
234234
@InterfaceAudience.Private
235235
public static final String ROW_CACHE_ENABLED = "ROW_CACHE_ENABLED";
236236
private static final Bytes ROW_CACHE_ENABLED_KEY = new Bytes(Bytes.toBytes(ROW_CACHE_ENABLED));
237-
private static final boolean DEFAULT_ROW_CACHE_ENABLED = false;
237+
private static final boolean DEFAULT_ROW_CACHE_ENABLED = true;
238238

239239
static {
240240
DEFAULT_VALUES.put(MAX_FILESIZE, String.valueOf(HConstants.DEFAULT_MAX_FILE_SIZE));

hbase-common/src/main/java/org/apache/hadoop/hbase/HConstants.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1017,6 +1017,13 @@ public enum OperationStatusCode {
10171017

10181018
public static final float HFILE_BLOCK_CACHE_SIZE_DEFAULT = 0.4f;
10191019

1020+
/**
1021+
* Configuration key for the size of the row cache
1022+
*/
1023+
public static final String ROW_CACHE_SIZE_KEY = "row.cache.size";
1024+
1025+
public static final float ROW_CACHE_SIZE_DEFAULT = 0.0f;
1026+
10201027
/**
10211028
* Configuration key for the memory size of the block cache
10221029
*/

hbase-common/src/main/java/org/apache/hadoop/hbase/io/hfile/BlockType.java

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -80,14 +80,6 @@ public int getId() {
8080
/** Fixed file trailer, both versions (always just a magic string) */
8181
TRAILER("TRABLK\"$", BlockCategory.META),
8282

83-
// Pseudo block
84-
85-
/**
86-
* Cells of a row for row cache. This is a pseudo block type. It only exists to share the
87-
* BlockCache interface.
88-
*/
89-
ROW_CELLS("ROWCELLS", BlockCategory.ROW),
90-
9183
// Legacy blocks
9284

9385
/** Block index magic string in version 1 */
@@ -99,7 +91,6 @@ public enum BlockCategory {
9991
INDEX,
10092
BLOOM,
10193
ALL_CATEGORIES,
102-
ROW,
10394
UNKNOWN;
10495

10596
/**

hbase-common/src/main/resources/hbase-default.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1027,6 +1027,12 @@ possible configurations would overwhelm and obscure the important.
10271027
This configuration allows setting an absolute memory size instead of a percentage of the maximum heap.
10281028
Takes precedence over hfile.block.cache.size if both are specified.</description>
10291029
</property>
1030+
<property>
1031+
<name>row.cache.size</name>
1032+
<value>0.0</value>
1033+
<description>Percentage of maximum heap (-Xmx setting) to allocate to row cache.
1034+
Default of 0.0; it means the row cache is disabled.</description>
1035+
</property>
10301036
<property>
10311037
<name>hfile.block.index.cacheonwrite</name>
10321038
<value>false</value>

hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSource.java

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -386,7 +386,6 @@ public interface MetricsRegionServerSource extends BaseSource, JvmPauseMonitorSo
386386
String BLOCK_CACHE_GENERAL_BLOOM_META_MISS_COUNT = "blockCacheGeneralBloomMetaMissCount";
387387
String BLOCK_CACHE_DELETE_FAMILY_BLOOM_MISS_COUNT = "blockCacheDeleteFamilyBloomMissCount";
388388
String BLOCK_CACHE_TRAILER_MISS_COUNT = "blockCacheTrailerMissCount";
389-
String BLOCK_CACHE_ROW_MISS_COUNT = "blockCacheRowMissCount";
390389
String BLOCK_CACHE_DATA_HIT_COUNT = "blockCacheDataHitCount";
391390
String BLOCK_CACHE_ENCODED_DATA_HIT_COUNT = "blockCacheEncodedDataHitCount";
392391
String BLOCK_CACHE_LEAF_INDEX_HIT_COUNT = "blockCacheLeafIndexHitCount";
@@ -398,7 +397,6 @@ public interface MetricsRegionServerSource extends BaseSource, JvmPauseMonitorSo
398397
String BLOCK_CACHE_GENERAL_BLOOM_META_HIT_COUNT = "blockCacheGeneralBloomMetaHitCount";
399398
String BLOCK_CACHE_DELETE_FAMILY_BLOOM_HIT_COUNT = "blockCacheDeleteFamilyBloomHitCount";
400399
String BLOCK_CACHE_TRAILER_HIT_COUNT = "blockCacheTrailerHitCount";
401-
String BLOCK_CACHE_ROW_HIT_COUNT = "blockCacheRowHitCount";
402400
String L1_CACHE_FREE_SIZE = "l1CacheFreeSize";
403401
String L1_CACHE_FREE_SIZE_DESC = "Amount of free bytes in the L1 cache";
404402
String L1_CACHE_SIZE = "l1CacheSize";
@@ -432,6 +430,13 @@ public interface MetricsRegionServerSource extends BaseSource, JvmPauseMonitorSo
432430
String L2_CACHE_HIT_RATIO_DESC = "L2 cache hit ratio.";
433431
String L2_CACHE_MISS_RATIO = "l2CacheMissRatio";
434432
String L2_CACHE_MISS_RATIO_DESC = "L2 cache miss ratio.";
433+
434+
String ROW_CACHE_HIT_COUNT = "rowCacheHitCount";
435+
String ROW_CACHE_MISS_COUNT = "rowCacheMissCount";
436+
String ROW_CACHE_EVICTED_ROW_COUNT = "rowCacheEvictedRowCount";
437+
String ROW_CACHE_SIZE = "rowCacheSize";
438+
String ROW_CACHE_COUNT = "rowCacheCount";
439+
435440
String RS_START_TIME_NAME = "regionServerStartTime";
436441
String ZOOKEEPER_QUORUM_NAME = "zookeeperQuorum";
437442
String SERVER_NAME_NAME = "serverName";

hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerSourceImpl.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -436,7 +436,6 @@ public void getMetrics(MetricsCollector metricsCollector, boolean all) {
436436
.addCounter(Interns.info(BLOCK_CACHE_DELETE_FAMILY_BLOOM_MISS_COUNT, ""),
437437
rsWrap.getDeleteFamilyBloomMissCount())
438438
.addCounter(Interns.info(BLOCK_CACHE_TRAILER_MISS_COUNT, ""), rsWrap.getTrailerMissCount())
439-
.addCounter(Interns.info(BLOCK_CACHE_ROW_MISS_COUNT, ""), rsWrap.getRowMissCount())
440439
.addCounter(Interns.info(BLOCK_CACHE_DATA_HIT_COUNT, ""), rsWrap.getDataHitCount())
441440
.addCounter(Interns.info(BLOCK_CACHE_LEAF_INDEX_HIT_COUNT, ""),
442441
rsWrap.getLeafIndexHitCount())
@@ -453,7 +452,12 @@ public void getMetrics(MetricsCollector metricsCollector, boolean all) {
453452
.addCounter(Interns.info(BLOCK_CACHE_DELETE_FAMILY_BLOOM_HIT_COUNT, ""),
454453
rsWrap.getDeleteFamilyBloomHitCount())
455454
.addCounter(Interns.info(BLOCK_CACHE_TRAILER_HIT_COUNT, ""), rsWrap.getTrailerHitCount())
456-
.addCounter(Interns.info(BLOCK_CACHE_ROW_HIT_COUNT, ""), rsWrap.getRowHitCount())
455+
.addCounter(Interns.info(ROW_CACHE_HIT_COUNT, ""), rsWrap.getRowCacheHitCount())
456+
.addCounter(Interns.info(ROW_CACHE_MISS_COUNT, ""), rsWrap.getRowCacheMissCount())
457+
.addCounter(Interns.info(ROW_CACHE_EVICTED_ROW_COUNT, ""),
458+
rsWrap.getRowCacheEvictedRowCount())
459+
.addGauge(Interns.info(ROW_CACHE_SIZE, ""), rsWrap.getRowCacheSize())
460+
.addGauge(Interns.info(ROW_CACHE_COUNT, ""), rsWrap.getRowCacheCount())
457461
.addCounter(Interns.info(UPDATES_BLOCKED_TIME, UPDATES_BLOCKED_DESC),
458462
rsWrap.getUpdatesBlockedTime())
459463
.addCounter(Interns.info(FLUSHED_CELLS, FLUSHED_CELLS_DESC), rsWrap.getFlushedCellsCount())

hbase-hadoop-compat/src/main/java/org/apache/hadoop/hbase/regionserver/MetricsRegionServerWrapper.java

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -615,8 +615,6 @@ public interface MetricsRegionServerWrapper {
615615

616616
long getTrailerMissCount();
617617

618-
long getRowMissCount();
619-
620618
long getDataHitCount();
621619

622620
long getLeafIndexHitCount();
@@ -637,7 +635,15 @@ public interface MetricsRegionServerWrapper {
637635

638636
long getTrailerHitCount();
639637

640-
long getRowHitCount();
638+
long getRowCacheHitCount();
639+
640+
long getRowCacheMissCount();
641+
642+
long getRowCacheSize();
643+
644+
long getRowCacheCount();
645+
646+
long getRowCacheEvictedRowCount();
641647

642648
long getTotalRowActionRequestCount();
643649

hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/BlockCacheTmpl.jamon

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ Template for rendering Block Cache tabs in RegionServer Status page.
2121
CacheConfig cacheConfig;
2222
Configuration config;
2323
BlockCache bc;
24+
RowCache rowCache;
2425
</%args>
2526
<%java>
2627
String bcUrl = bc == null ? null : "http://hbase.apache.org/devapidocs/" + bc.getClass().getName().replaceAll("\\.", "/") + ".html";
@@ -42,6 +43,7 @@ org.apache.hadoop.hbase.io.hfile.bucket.BucketCacheStats;
4243
org.apache.hadoop.hbase.io.hfile.bucket.BucketCache;
4344
org.apache.hadoop.hbase.io.hfile.bucket.BucketAllocator;
4445
org.apache.hadoop.hbase.io.hfile.bucket.BucketAllocator.Bucket;
46+
org.apache.hadoop.hbase.regionserver.RowCache;
4547
org.apache.hadoop.util.StringUtils.TraditionalBinaryPrefix;
4648
</%import>
4749
<div class="tabbable">
@@ -51,6 +53,7 @@ org.apache.hadoop.util.StringUtils.TraditionalBinaryPrefix;
5153
<li class="nav-item"><a class="nav-link" href="#tab_bc_stats" data-bs-toggle="tab" role="tab">Stats</a></li>
5254
<li class="nav-item"><a class="nav-link" href="#tab_bc_l1" data-bs-toggle="tab" role="tab">L1</a></li>
5355
<li class="nav-item"><a class="nav-link" href="#tab_bc_l2" data-bs-toggle="tab" role="tab">L2</a></li>
56+
<li class="nav-item"><a class="nav-link" href="#tab_row_cache" data-bs-toggle="tab" role="tab">Row Cache</a></li>
5457
</ul>
5558
<div class="tab-content">
5659
<div class="tab-pane active" id="tab_bc_baseInfo" role="tabpanel">
@@ -68,6 +71,9 @@ org.apache.hadoop.util.StringUtils.TraditionalBinaryPrefix;
6871
<div class="tab-pane" id="tab_bc_l2" role="tabpanel">
6972
<& bc_l; bc = bcs == null? null: bcs.length <= 1? null: bcs[1]; name = "L2"; evictions = evictions; &>
7073
</div>
74+
<div class="tab-pane" id="tab_row_cache" role="tabpanel">
75+
<& row_cache_stats; rowCache = rowCache &>
76+
</div>
7177
</div>
7278
</div>
7379

@@ -562,3 +568,55 @@ Increase that value to get a complete picture.
562568
</p>
563569
</%def>
564570

571+
<%def row_cache_stats>
572+
<%args>
573+
RowCache rowCache;
574+
</%args>
575+
<%if rowCache == null %>
576+
<p>RowCache is null</p>
577+
<%else>
578+
<table class="table table-striped">
579+
<tr>
580+
<th>Attribute</th>
581+
<th>Value</th>
582+
<th>Description</th>
583+
</tr>
584+
<tr>
585+
<td>Size</td>
586+
<td><% TraditionalBinaryPrefix.long2String(rowCache.getSize(), "B", 1) %></td>
587+
<td>Current size of row cache in use</td>
588+
</tr>
589+
<tr>
590+
<td>Free</td>
591+
<td><% TraditionalBinaryPrefix.long2String(rowCache.getMaxSize() - rowCache.getSize(), "B", 1) %></td>
592+
<td>The total free memory currently available to store more cache entries</td>
593+
</tr>
594+
<tr>
595+
<td>Count</td>
596+
<td><% String.format("%,d", rowCache.getCount()) %></td>
597+
<td>The number of rows in row cache</td>
598+
</tr>
599+
<tr>
600+
<td>Evicted Rows</td>
601+
<td><% String.format("%,d", rowCache.getEvictedRowCount()) %></td>
602+
<td>The total number of rows evicted</td>
603+
</tr>
604+
<tr>
605+
<td>Hits</td>
606+
<td><% String.format("%,d", rowCache.getHitCount()) %></td>
607+
<td>The number requests that were cache hits</td>
608+
</tr>
609+
<tr>
610+
<td>Misses</td>
611+
<td><% String.format("%,d", rowCache.getMissCount()) %></td>
612+
<td>The number requests that were cache misses</td>
613+
</tr>
614+
<tr>
615+
<td>All Time Hit Ratio</td>
616+
<td><% String.format("%,.2f", rowCache.getHitCount() * 100.0 / (rowCache.getMissCount() + rowCache.getHitCount())) %><% "%" %></td>
617+
<td>Hit Count divided by total requests count</td>
618+
</tr>
619+
</table>
620+
<p>RowCache is a separate cache distinct from BlockCache. Since there is no more appropriate place to display RowCache information, it is shown here alongside BlockCache.</p>
621+
</%if>
622+
</%def>

hbase-server/src/main/jamon/org/apache/hadoop/hbase/tmpl/regionserver/RSStatusTmpl.jamon

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,12 @@ String bcv = "";
2626
<%import>
2727
java.util.*;
2828
org.apache.hadoop.hbase.regionserver.HRegionServer;
29+
org.apache.hadoop.hbase.regionserver.RowCacheService;
2930
org.apache.hadoop.hbase.client.RegionInfo;
3031
org.apache.hadoop.hbase.ServerName;
3132
org.apache.hadoop.hbase.HBaseConfiguration;
3233
org.apache.hadoop.hbase.io.hfile.CacheConfig;
34+
org.apache.hadoop.hbase.regionserver.RowCache;
3335
org.apache.hadoop.hbase.shaded.protobuf.ProtobufUtil;
3436
org.apache.hadoop.hbase.shaded.protobuf.generated.AdminProtos.ServerInfo;
3537
org.apache.hadoop.hbase.util.JvmVersion;
@@ -51,6 +53,8 @@ org.apache.hadoop.hbase.zookeeper.MasterAddressTracker;
5153
ServerName masterServerName = masterAddressTracker == null ? null
5254
: masterAddressTracker.getMasterAddress();
5355
int infoPort = masterAddressTracker == null ? 0 : masterAddressTracker.getMasterInfoPort();
56+
RowCacheService rowCacheService = regionServer.getRSRpcServices().getRowCacheService();
57+
RowCache rowCache = rowCacheService == null ? null : rowCacheService.getRowCache();
5458
</%java>
5559

5660
<%class>
@@ -149,7 +153,7 @@ org.apache.hadoop.hbase.zookeeper.MasterAddressTracker;
149153

150154
<section>
151155
<h2>Block Cache</h2>
152-
<& BlockCacheTmpl; cacheConfig = new CacheConfig(regionServer.getConfiguration()); config = regionServer.getConfiguration(); bc = regionServer.getBlockCache().orElse(null) &>
156+
<& BlockCacheTmpl; cacheConfig = new CacheConfig(regionServer.getConfiguration()); config = regionServer.getConfiguration(); bc = regionServer.getBlockCache().orElse(null); rowCache = rowCache &>
153157
</section>
154158

155159
<section>

hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheStats.java

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,6 @@ public class CacheStats {
9191
private final LongAdder generalBloomMetaMissCount = new LongAdder();
9292
private final LongAdder deleteFamilyBloomMissCount = new LongAdder();
9393
private final LongAdder trailerMissCount = new LongAdder();
94-
private final LongAdder rowMissCount = new LongAdder();
9594

9695
private final LongAdder dataHitCount = new LongAdder();
9796
private final LongAdder leafIndexHitCount = new LongAdder();
@@ -103,7 +102,6 @@ public class CacheStats {
103102
private final LongAdder generalBloomMetaHitCount = new LongAdder();
104103
private final LongAdder deleteFamilyBloomHitCount = new LongAdder();
105104
private final LongAdder trailerHitCount = new LongAdder();
106-
private final LongAdder rowHitCount = new LongAdder();
107105

108106
// Executor for periodic cache stats rolling
109107
private ScheduledExecutorService metricsRollerScheduler;
@@ -221,9 +219,6 @@ public void miss(boolean caching, boolean primary, BlockType type) {
221219
case TRAILER:
222220
trailerMissCount.increment();
223221
break;
224-
case ROW_CELLS:
225-
rowMissCount.increment();
226-
break;
227222
default:
228223
// If there's a new type that's fine
229224
// Ignore it for now. This is metrics don't exception.
@@ -271,9 +266,6 @@ public void hit(boolean caching, boolean primary, BlockType type) {
271266
case TRAILER:
272267
trailerHitCount.increment();
273268
break;
274-
case ROW_CELLS:
275-
rowHitCount.increment();
276-
break;
277269
default:
278270
// If there's a new type that's fine
279271
// Ignore it for now. This is metrics don't exception.
@@ -384,14 +376,6 @@ public long getTrailerHitCount() {
384376
return trailerHitCount.sum();
385377
}
386378

387-
public long getRowHitCount() {
388-
return rowHitCount.sum();
389-
}
390-
391-
public long getRowMissCount() {
392-
return rowMissCount.sum();
393-
}
394-
395379
public long getRequestCount() {
396380
return getHitCount() + getMissCount();
397381
}

0 commit comments

Comments
 (0)