diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java index 25f9727..2ed134d 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CacheConfig.java @@ -527,6 +527,12 @@ public class CacheConfig { if (blockCacheDisabled) return null; MemoryUsage mu = ManagementFactory.getMemoryMXBean().getHeapMemoryUsage(); LruBlockCache l1 = getL1(conf, mu); + // Allow an option where we run with CombinedBlockCache only the L2 is empty. META blocks + // go into L1. Data blocks not cached (other than by fscache). + if (conf.getBoolean("hbase.combinedblockcache.l2.null", false)) { + GLOBAL_BLOCK_CACHE_INSTANCE = new CombinedBlockCache(l1, null); + return GLOBAL_BLOCK_CACHE_INSTANCE; + } BucketCache l2 = getL2(conf, mu); if (l2 == null) { GLOBAL_BLOCK_CACHE_INSTANCE = l1; diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CombinedBlockCache.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CombinedBlockCache.java index c89073d..97646df 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CombinedBlockCache.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/io/hfile/CombinedBlockCache.java @@ -39,18 +39,18 @@ import org.apache.hadoop.hbase.io.hfile.bucket.BucketCache; public class CombinedBlockCache implements BlockCache, HeapSize { private final LruBlockCache lruCache; private final BucketCache bucketCache; - private final CombinedCacheStats combinedCacheStats; + private final CacheStats combinedCacheStats; public CombinedBlockCache(LruBlockCache lruCache, BucketCache bucketCache) { this.lruCache = lruCache; this.bucketCache = bucketCache; - this.combinedCacheStats = new CombinedCacheStats(lruCache.getStats(), - bucketCache.getStats()); + this.combinedCacheStats = this.bucketCache == null? this.lruCache.getStats(): + new CombinedCacheStats(lruCache.getStats(), this.bucketCache.getStats()); } @Override public long heapSize() { - return lruCache.heapSize() + bucketCache.heapSize(); + return lruCache.heapSize() + (this.bucketCache == null? 0: this.bucketCache.heapSize()); } @Override @@ -60,7 +60,9 @@ public class CombinedBlockCache implements BlockCache, HeapSize { if (isMetaBlock || cacheDataInL1) { lruCache.cacheBlock(cacheKey, buf, inMemory, cacheDataInL1); } else { - bucketCache.cacheBlock(cacheKey, buf, inMemory, cacheDataInL1); + if (this.bucketCache != null) { + this.bucketCache.cacheBlock(cacheKey, buf, inMemory, cacheDataInL1); + } } } @@ -77,18 +79,20 @@ public class CombinedBlockCache implements BlockCache, HeapSize { if (lruCache.containsBlock(cacheKey)) { return lruCache.getBlock(cacheKey, caching, repeat, updateCacheMetrics); } - return bucketCache.getBlock(cacheKey, caching, repeat, updateCacheMetrics); + return this.bucketCache == null? null: + this.bucketCache.getBlock(cacheKey, caching, repeat, updateCacheMetrics); } @Override public boolean evictBlock(BlockCacheKey cacheKey) { - return lruCache.evictBlock(cacheKey) || bucketCache.evictBlock(cacheKey); + return lruCache.evictBlock(cacheKey) || + this.bucketCache == null? false: this.bucketCache.evictBlock(cacheKey); } @Override public int evictBlocksByHfileName(String hfileName) { return lruCache.evictBlocksByHfileName(hfileName) - + bucketCache.evictBlocksByHfileName(hfileName); + + (this.bucketCache == null? 0: this.bucketCache.evictBlocksByHfileName(hfileName)); } @Override @@ -99,27 +103,27 @@ public class CombinedBlockCache implements BlockCache, HeapSize { @Override public void shutdown() { lruCache.shutdown(); - bucketCache.shutdown(); + if (this.bucketCache != null) this.bucketCache.shutdown(); } @Override public long size() { - return lruCache.size() + bucketCache.size(); + return lruCache.size() + (this.bucketCache == null? 0: bucketCache.size()); } @Override public long getFreeSize() { - return lruCache.getFreeSize() + bucketCache.getFreeSize(); + return lruCache.getFreeSize() + (this.bucketCache == null? 0: bucketCache.getFreeSize()); } @Override public long getCurrentSize() { - return lruCache.getCurrentSize() + bucketCache.getCurrentSize(); + return lruCache.getCurrentSize() + (this.bucketCache == null? 0: bucketCache.getCurrentSize()); } @Override public long getBlockCount() { - return lruCache.getBlockCount() + bucketCache.getBlockCount(); + return lruCache.getBlockCount() + (this.bucketCache == null? 0: bucketCache.getBlockCount()); } private static class CombinedCacheStats extends CacheStats { @@ -205,6 +209,7 @@ public class CombinedBlockCache implements BlockCache, HeapSize { @Override public BlockCache[] getBlockCaches() { - return new BlockCache [] {this.lruCache, this.bucketCache}; + return this.bucketCache == null? new BlockCache [] {this.lruCache}: + new BlockCache [] {this.lruCache, this.bucketCache}; } } \ No newline at end of file