HBASE-14983 Create metrics for per block type hit/miss ratios

Summary: Missing a root index block is worse than missing a data block. We should know the difference

Test Plan: Tested on a local instance. All numbers looked reasonable.

Differential Revision: https://reviews.facebook.net/D55563
This commit is contained in:
Elliott Clark 2015-12-15 15:35:16 -08:00
parent fee0212da0
commit 75d46e4697
16 changed files with 711 additions and 54 deletions

View File

@ -145,14 +145,13 @@ public class MemcachedBlockCache implements BlockCache {
// Update stats if this request doesn't have it turned off 100% of the time
if (updateCacheMetrics) {
if (result == null) {
cacheStats.miss(caching, cacheKey.isPrimary());
cacheStats.miss(caching, cacheKey.isPrimary(), cacheKey.getBlockType());
} else {
cacheStats.hit(caching, cacheKey.isPrimary());
cacheStats.hit(caching, cacheKey.isPrimary(), cacheKey.getBlockType());
}
}
}
return result;
}

View File

@ -294,6 +294,29 @@ public interface MetricsRegionServerSource extends BaseSource {
String BLOCK_CACHE_FAILED_INSERTION_COUNT = "blockCacheFailedInsertionCount";
String BLOCK_CACHE_FAILED_INSERTION_COUNT_DESC = "Number of times that a block cache " +
"insertion failed. Usually due to size restrictions.";
String BLOCK_CACHE_DATA_MISS_COUNT = "blockCacheDataMissCount";
String BLOCK_CACHE_ENCODED_DATA_MISS_COUNT = "blockCacheEncodedDataMissCount";
String BLOCK_CACHE_LEAF_INDEX_MISS_COUNT = "blockCacheLeafIndexMissCount";
String BLOCK_CACHE_BLOOM_CHUNK_MISS_COUNT = "blockCacheBloomChunkMissCount";
String BLOCK_CACHE_META_MISS_COUNT = "blockCacheMetaMissCount";
String BLOCK_CACHE_ROOT_INDEX_MISS_COUNT = "blockCacheRootIndexMissCount";
String BLOCK_CACHE_INTERMEDIATE_INDEX_MISS_COUNT = "blockCacheIntermediateIndexMissCount";
String BLOCK_CACHE_FILE_INFO_MISS_COUNT = "blockCacheFileInfoMissCount";
String BLOCK_CACHE_GENERAL_BLOOM_META_MISS_COUNT = "blockCacheGeneralBloomMetaMissCount";
String BLOCK_CACHE_DELETE_FAMILY_BLOOM_MISS_COUNT = "blockCacheDeleteFamilyBloomMissCount";
String BLOCK_CACHE_TRAILER_MISS_COUNT = "blockCacheTrailerMissCount";
String BLOCK_CACHE_DATA_HIT_COUNT = "blockCacheDataHitCount";
String BLOCK_CACHE_ENCODED_DATA_HIT_COUNT = "blockCacheEncodedDataHitCount";
String BLOCK_CACHE_LEAF_INDEX_HIT_COUNT = "blockCacheLeafIndexHitCount";
String BLOCK_CACHE_BLOOM_CHUNK_HIT_COUNT = "blockCacheBloomChunkHitCount";
String BLOCK_CACHE_META_HIT_COUNT = "blockCacheMetaHitCount";
String BLOCK_CACHE_ROOT_INDEX_HIT_COUNT = "blockCacheRootIndexHitCount";
String BLOCK_CACHE_INTERMEDIATE_INDEX_HIT_COUNT = "blockCacheIntermediateIndexHitCount";
String BLOCK_CACHE_FILE_INFO_HIT_COUNT = "blockCacheFileInfoHitCount";
String BLOCK_CACHE_GENERAL_BLOOM_META_HIT_COUNT = "blockCacheGeneralBloomMetaHitCount";
String BLOCK_CACHE_DELETE_FAMILY_BLOOM_HIT_COUNT = "blockCacheDeleteFamilyBloomHitCount";
String BLOCK_CACHE_TRAILER_HIT_COUNT = "blockCacheTrailerHitCount";
String RS_START_TIME_NAME = "regionServerStartTime";
String ZOOKEEPER_QUORUM_NAME = "zookeeperQuorum";
String SERVER_NAME_NAME = "serverName";

View File

@ -327,4 +327,44 @@ public interface MetricsRegionServerWrapper {
* Get the average region size to this region server.
*/
long getAverageRegionSize();
long getDataMissCount();
long getLeafIndexMissCount();
long getBloomChunkMissCount();
long getMetaMissCount();
long getRootIndexMissCount();
long getIntermediateIndexMissCount();
long getFileInfoMissCount();
long getGeneralBloomMetaMissCount();
long getDeleteFamilyBloomMissCount();
long getTrailerMissCount();
long getDataHitCount();
long getLeafIndexHitCount();
long getBloomChunkHitCount();
long getMetaHitCount();
long getRootIndexHitCount();
long getIntermediateIndexHitCount();
long getFileInfoHitCount();
long getGeneralBloomMetaHitCount();
long getDeleteFamilyBloomHitCount();
long getTrailerHitCount();
}

View File

@ -375,6 +375,7 @@ public class MetricsRegionServerSourceImpl
rsWrap.getCompactionQueueSize())
.addGauge(Interns.info(FLUSH_QUEUE_LENGTH, FLUSH_QUEUE_LENGTH_DESC),
rsWrap.getFlushQueueSize())
.addGauge(Interns.info(BLOCK_CACHE_FREE_SIZE, BLOCK_CACHE_FREE_DESC),
rsWrap.getBlockCacheFreeSize())
.addGauge(Interns.info(BLOCK_CACHE_COUNT, BLOCK_CACHE_COUNT_DESC),
@ -399,6 +400,41 @@ public class MetricsRegionServerSourceImpl
BLOCK_CACHE_EXPRESS_HIT_PERCENT_DESC), rsWrap.getBlockCacheHitCachingPercent())
.addCounter(Interns.info(BLOCK_CACHE_FAILED_INSERTION_COUNT,
BLOCK_CACHE_FAILED_INSERTION_COUNT_DESC),rsWrap.getBlockCacheFailedInsertions())
.addCounter(Interns.info(BLOCK_CACHE_DATA_MISS_COUNT, ""), rsWrap.getDataMissCount())
.addCounter(Interns.info(BLOCK_CACHE_LEAF_INDEX_MISS_COUNT, ""),
rsWrap.getLeafIndexMissCount())
.addCounter(Interns.info(BLOCK_CACHE_BLOOM_CHUNK_MISS_COUNT, ""),
rsWrap.getBloomChunkMissCount())
.addCounter(Interns.info(BLOCK_CACHE_META_MISS_COUNT, ""), rsWrap.getMetaMissCount())
.addCounter(Interns.info(BLOCK_CACHE_ROOT_INDEX_MISS_COUNT, ""),
rsWrap.getRootIndexMissCount())
.addCounter(Interns.info(BLOCK_CACHE_INTERMEDIATE_INDEX_MISS_COUNT, ""),
rsWrap.getIntermediateIndexMissCount())
.addCounter(Interns.info(BLOCK_CACHE_FILE_INFO_MISS_COUNT, ""),
rsWrap.getFileInfoMissCount())
.addCounter(Interns.info(BLOCK_CACHE_GENERAL_BLOOM_META_MISS_COUNT, ""),
rsWrap.getGeneralBloomMetaMissCount())
.addCounter(Interns.info(BLOCK_CACHE_DELETE_FAMILY_BLOOM_MISS_COUNT, ""),
rsWrap.getDeleteFamilyBloomMissCount())
.addCounter(Interns.info(BLOCK_CACHE_TRAILER_MISS_COUNT, ""),
rsWrap.getTrailerMissCount())
.addCounter(Interns.info(BLOCK_CACHE_DATA_HIT_COUNT, ""), rsWrap.getDataHitCount())
.addCounter(Interns.info(BLOCK_CACHE_LEAF_INDEX_HIT_COUNT, ""),
rsWrap.getLeafIndexHitCount())
.addCounter(Interns.info(BLOCK_CACHE_BLOOM_CHUNK_HIT_COUNT, ""),
rsWrap.getBloomChunkHitCount())
.addCounter(Interns.info(BLOCK_CACHE_META_HIT_COUNT, ""), rsWrap.getMetaHitCount())
.addCounter(Interns.info(BLOCK_CACHE_ROOT_INDEX_HIT_COUNT, ""),
rsWrap.getRootIndexHitCount())
.addCounter(Interns.info(BLOCK_CACHE_INTERMEDIATE_INDEX_HIT_COUNT, ""),
rsWrap.getIntermediateIndexHitCount())
.addCounter(Interns.info(BLOCK_CACHE_FILE_INFO_HIT_COUNT, ""),
rsWrap.getFileInfoHitCount())
.addCounter(Interns.info(BLOCK_CACHE_GENERAL_BLOOM_META_HIT_COUNT, ""),
rsWrap.getGeneralBloomMetaHitCount())
.addCounter(Interns.info(BLOCK_CACHE_DELETE_FAMILY_BLOOM_HIT_COUNT, ""),
rsWrap.getDeleteFamilyBloomHitCount())
.addCounter(Interns.info(BLOCK_CACHE_TRAILER_HIT_COUNT, ""), rsWrap.getTrailerHitCount())
.addCounter(Interns.info(UPDATES_BLOCKED_TIME, UPDATES_BLOCKED_DESC),
rsWrap.getUpdatesBlockedTime())
.addCounter(Interns.info(FLUSHED_CELLS, FLUSHED_CELLS_DESC),
@ -415,7 +451,6 @@ public class MetricsRegionServerSourceImpl
rsWrap.getMajorCompactedCellsSize())
.addCounter(Interns.info(BLOCKED_REQUESTS_COUNT, BLOCKED_REQUESTS_COUNT_DESC),
rsWrap.getBlockedRequestsCount())
.tag(Interns.info(ZOOKEEPER_QUORUM_NAME, ZOOKEEPER_QUORUM_DESC),
rsWrap.getZookeeperQuorum())
.tag(Interns.info(SERVER_NAME_NAME, SERVER_NAME_DESC), rsWrap.getServerName())

View File

@ -30,6 +30,7 @@ public class BlockCacheKey implements HeapSize, java.io.Serializable {
private static final long serialVersionUID = -5199992013113130534L;
private final String hfileName;
private final long offset;
private final BlockType blockType;
private final boolean isPrimaryReplicaBlock;
/**
@ -38,13 +39,14 @@ public class BlockCacheKey implements HeapSize, java.io.Serializable {
* @param offset Offset of the block into the file
*/
public BlockCacheKey(String hfileName, long offset) {
this(hfileName, offset, true);
this(hfileName, offset, true, BlockType.DATA);
}
public BlockCacheKey(String hfileName, long offset, boolean isPrimaryReplica) {
public BlockCacheKey(String hfileName, long offset, boolean isPrimaryReplica, BlockType blockType) {
this.isPrimaryReplicaBlock = isPrimaryReplica;
this.hfileName = hfileName;
this.offset = offset;
this.blockType = blockType;
}
@Override
@ -69,9 +71,12 @@ public class BlockCacheKey implements HeapSize, java.io.Serializable {
return String.format("%s_%d", hfileName, offset);
}
public static final long FIXED_OVERHEAD = ClassSize.align(ClassSize.OBJECT +Bytes.SIZEOF_BOOLEAN +
ClassSize.REFERENCE + // this.hfileName
Bytes.SIZEOF_LONG); // this.offset
public static final long FIXED_OVERHEAD = ClassSize.align(
ClassSize.OBJECT +
Bytes.SIZEOF_BOOLEAN +
ClassSize.REFERENCE + // this.hfileName
ClassSize.REFERENCE + // this.blockType
Bytes.SIZEOF_LONG); // this.offset
/**
* Strings have two bytes per character due to default Java Unicode encoding
@ -98,4 +103,8 @@ public class BlockCacheKey implements HeapSize, java.io.Serializable {
public long getOffset() {
return offset;
}
public BlockType getBlockType() {
return blockType;
}
}

View File

@ -73,6 +73,29 @@ public class CacheStats {
/** The total number of blocks that were not inserted. */
private final AtomicLong failedInserts = new AtomicLong(0);
/** Per Block Type Counts */
private final Counter dataMissCount = new Counter(0);
private final Counter leafIndexMissCount = new Counter(0);
private final Counter bloomChunkMissCount = new Counter(0);
private final Counter metaMissCount = new Counter(0);
private final Counter rootIndexMissCount = new Counter(0);
private final Counter intermediateIndexMissCount = new Counter(0);
private final Counter fileInfoMissCount = new Counter(0);
private final Counter generalBloomMetaMissCount = new Counter(0);
private final Counter deleteFamilyBloomMissCount = new Counter(0);
private final Counter trailerMissCount = new Counter(0);
private final Counter dataHitCount = new Counter(0);
private final Counter leafIndexHitCount = new Counter(0);
private final Counter bloomChunkHitCount = new Counter(0);
private final Counter metaHitCount = new Counter(0);
private final Counter rootIndexHitCount = new Counter(0);
private final Counter intermediateIndexHitCount = new Counter(0);
private final Counter fileInfoHitCount = new Counter(0);
private final Counter generalBloomMetaHitCount = new Counter(0);
private final Counter deleteFamilyBloomHitCount = new Counter(0);
private final Counter trailerHitCount = new Counter(0);
/** The number of metrics periods to include in window */
private final int numPeriodsInWindow;
/** Hit counts for each period in window */
@ -124,20 +147,99 @@ public class CacheStats {
", evictedAgeMean=" + snapshot.getMean();
}
public void miss(boolean caching, boolean primary) {
public void miss(boolean caching, boolean primary, BlockType type) {
missCount.increment();
if (primary) primaryMissCount.increment();
if (caching) missCachingCount.increment();
if (type == null) {
return;
}
switch (type) {
case DATA:
case ENCODED_DATA:
dataMissCount.increment();
break;
case LEAF_INDEX:
leafIndexMissCount.increment();
break;
case BLOOM_CHUNK:
bloomChunkMissCount.increment();
break;
case META:
metaMissCount.increment();
break;
case INTERMEDIATE_INDEX:
intermediateIndexMissCount.increment();
break;
case ROOT_INDEX:
rootIndexMissCount.increment();
break;
case FILE_INFO:
fileInfoMissCount.increment();
break;
case GENERAL_BLOOM_META:
generalBloomMetaMissCount.increment();
break;
case DELETE_FAMILY_BLOOM_META:
deleteFamilyBloomMissCount.increment();
break;
case TRAILER:
trailerMissCount.increment();
break;
default:
// If there's a new type that's fine
// Ignore it for now. This is metrics don't exception.
break;
}
}
public void hit(boolean caching) {
hit(caching, true);
}
public void hit(boolean caching, boolean primary) {
public void hit(boolean caching, boolean primary, BlockType type) {
hitCount.increment();
if (primary) primaryHitCount.increment();
if (caching) hitCachingCount.increment();
if (type == null) {
return;
}
switch (type) {
case DATA:
case ENCODED_DATA:
dataHitCount.increment();
break;
case LEAF_INDEX:
leafIndexHitCount.increment();
break;
case BLOOM_CHUNK:
bloomChunkHitCount.increment();
break;
case META:
metaHitCount.increment();
break;
case INTERMEDIATE_INDEX:
intermediateIndexHitCount.increment();
break;
case ROOT_INDEX:
rootIndexHitCount.increment();
break;
case FILE_INFO:
fileInfoHitCount.increment();
break;
case GENERAL_BLOOM_META:
generalBloomMetaHitCount.increment();
break;
case DELETE_FAMILY_BLOOM_META:
deleteFamilyBloomHitCount.increment();
break;
case TRAILER:
trailerHitCount.increment();
break;
default:
// If there's a new type that's fine
// Ignore it for now. This is metrics don't exception.
break;
}
}
public void evict() {
@ -156,6 +258,88 @@ public class CacheStats {
return failedInserts.incrementAndGet();
}
// All of the counts of misses and hits.
public long getDataMissCount() {
return dataMissCount.get();
}
public long getLeafIndexMissCount() {
return leafIndexMissCount.get();
}
public long getBloomChunkMissCount() {
return bloomChunkMissCount.get();
}
public long getMetaMissCount() {
return metaMissCount.get();
}
public long getRootIndexMissCount() {
return rootIndexMissCount.get();
}
public long getIntermediateIndexMissCount() {
return intermediateIndexMissCount.get();
}
public long getFileInfoMissCount() {
return fileInfoMissCount.get();
}
public long getGeneralBloomMetaMissCount() {
return generalBloomMetaMissCount.get();
}
public long getDeleteFamilyBloomMissCount() {
return deleteFamilyBloomMissCount.get();
}
public long getTrailerMissCount() {
return trailerMissCount.get();
}
public long getDataHitCount() {
return dataHitCount.get();
}
public long getLeafIndexHitCount() {
return leafIndexHitCount.get();
}
public long getBloomChunkHitCount() {
return bloomChunkHitCount.get();
}
public long getMetaHitCount() {
return metaHitCount.get();
}
public long getRootIndexHitCount() {
return rootIndexHitCount.get();
}
public long getIntermediateIndexHitCount() {
return intermediateIndexHitCount.get();
}
public long getFileInfoHitCount() {
return fileInfoHitCount.get();
}
public long getGeneralBloomMetaHitCount() {
return generalBloomMetaHitCount.get();
}
public long getDeleteFamilyBloomHitCount() {
return deleteFamilyBloomHitCount.get();
}
public long getTrailerHitCount() {
return trailerHitCount.get();
}
public long getRequestCount() {
return getHitCount() + getMissCount();
}

View File

@ -139,6 +139,112 @@ public class CombinedBlockCache implements ResizableBlockCache, HeapSize {
this.bucketCacheStats = fcStats;
}
@Override
public long getDataMissCount() {
return lruCacheStats.getDataMissCount() + bucketCacheStats.getDataMissCount();
}
@Override
public long getLeafIndexMissCount() {
return lruCacheStats.getLeafIndexMissCount() + bucketCacheStats.getLeafIndexMissCount();
}
@Override
public long getBloomChunkMissCount() {
return lruCacheStats.getBloomChunkMissCount() + bucketCacheStats.getBloomChunkMissCount();
}
@Override
public long getMetaMissCount() {
return lruCacheStats.getMetaMissCount() + bucketCacheStats.getMetaMissCount();
}
@Override
public long getRootIndexMissCount() {
return lruCacheStats.getRootIndexMissCount() + bucketCacheStats.getRootIndexMissCount();
}
@Override
public long getIntermediateIndexMissCount() {
return lruCacheStats.getIntermediateIndexMissCount() +
bucketCacheStats.getIntermediateIndexMissCount();
}
@Override
public long getFileInfoMissCount() {
return lruCacheStats.getFileInfoMissCount() + bucketCacheStats.getFileInfoMissCount();
}
@Override
public long getGeneralBloomMetaMissCount() {
return lruCacheStats.getGeneralBloomMetaMissCount() +
bucketCacheStats.getGeneralBloomMetaMissCount();
}
@Override
public long getDeleteFamilyBloomMissCount() {
return lruCacheStats.getDeleteFamilyBloomMissCount() +
bucketCacheStats.getDeleteFamilyBloomMissCount();
}
@Override
public long getTrailerMissCount() {
return lruCacheStats.getTrailerMissCount() + bucketCacheStats.getTrailerMissCount();
}
@Override
public long getDataHitCount() {
return lruCacheStats.getDataHitCount() + bucketCacheStats.getDataHitCount();
}
@Override
public long getLeafIndexHitCount() {
return lruCacheStats.getLeafIndexHitCount() + bucketCacheStats.getLeafIndexHitCount();
}
@Override
public long getBloomChunkHitCount() {
return lruCacheStats.getBloomChunkHitCount() + bucketCacheStats.getBloomChunkHitCount();
}
@Override
public long getMetaHitCount() {
return lruCacheStats.getMetaHitCount() + bucketCacheStats.getMetaHitCount();
}
@Override
public long getRootIndexHitCount() {
return lruCacheStats.getRootIndexHitCount() + bucketCacheStats.getRootIndexHitCount();
}
@Override
public long getIntermediateIndexHitCount() {
return lruCacheStats.getIntermediateIndexHitCount() +
bucketCacheStats.getIntermediateIndexHitCount();
}
@Override
public long getFileInfoHitCount() {
return lruCacheStats.getFileInfoHitCount() + bucketCacheStats.getFileInfoHitCount();
}
@Override
public long getGeneralBloomMetaHitCount() {
return lruCacheStats.getGeneralBloomMetaHitCount() +
bucketCacheStats.getGeneralBloomMetaHitCount();
}
@Override
public long getDeleteFamilyBloomHitCount() {
return lruCacheStats.getDeleteFamilyBloomHitCount() +
bucketCacheStats.getDeleteFamilyBloomHitCount();
}
@Override
public long getTrailerHitCount() {
return lruCacheStats.getTrailerHitCount() + bucketCacheStats.getTrailerHitCount();
}
@Override
public long getRequestCount() {
return lruCacheStats.getRequestCount()

View File

@ -981,7 +981,7 @@ public class HFileBlockIndex {
if (cacheConf != null) {
HFileBlock blockForCaching = blockWriter.getBlockForCaching(cacheConf);
cacheConf.getBlockCache().cacheBlock(new BlockCacheKey(nameForCaching,
beginOffset), blockForCaching);
beginOffset, true, blockForCaching.getBlockType()), blockForCaching);
}
// Add intermediate index block size

View File

@ -347,7 +347,7 @@ public class HFileReaderV2 extends AbstractHFileReader {
// Check cache for block. If found return.
long metaBlockOffset = metaBlockIndexReader.getRootBlockOffset(block);
BlockCacheKey cacheKey = new BlockCacheKey(name, metaBlockOffset,
this.isPrimaryReplicaReader());
this.isPrimaryReplicaReader(), BlockType.META);
cacheBlock &= cacheConf.shouldCacheDataOnRead();
if (cacheConf.isBlockCacheEnabled()) {
@ -395,7 +395,8 @@ public class HFileReaderV2 extends AbstractHFileReader {
// Without a cache, this synchronizing is needless overhead, but really
// the other choice is to duplicate work (which the cache would prevent you
// from doing).
BlockCacheKey cacheKey = new BlockCacheKey(name, dataBlockOffset,this.isPrimaryReplicaReader());
BlockCacheKey cacheKey =
new BlockCacheKey(name, dataBlockOffset, this.isPrimaryReplicaReader(), expectedBlockType);
boolean useLock = false;
IdLock.Entry lockEntry = null;
TraceScope traceScope = Trace.startSpan("HFileReaderV2.readBlock");

View File

@ -200,7 +200,7 @@ public class HFileWriterV2 extends AbstractHFileWriter {
private void doCacheOnWrite(long offset) {
HFileBlock cacheFormatBlock = fsBlockWriter.getBlockForCaching(cacheConf);
cacheConf.getBlockCache().cacheBlock(
new BlockCacheKey(name, offset), cacheFormatBlock);
new BlockCacheKey(name, offset, true, cacheFormatBlock.getBlockType()), cacheFormatBlock);
}
/**

View File

@ -440,7 +440,9 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize {
boolean updateCacheMetrics) {
LruCachedBlock cb = map.get(cacheKey);
if (cb == null) {
if (!repeat && updateCacheMetrics) stats.miss(caching, cacheKey.isPrimary());
if (!repeat && updateCacheMetrics) {
stats.miss(caching, cacheKey.isPrimary(), cacheKey.getBlockType());
}
// If there is another block cache then try and read there.
// However if this is a retry ( second time in double checked locking )
// And it's already a miss then the l2 will also be a miss.
@ -455,7 +457,7 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize {
}
return null;
}
if (updateCacheMetrics) stats.hit(caching, cacheKey.isPrimary());
if (updateCacheMetrics) stats.hit(caching, cacheKey.isPrimary(), cacheKey.getBlockType());
cb.access(count.incrementAndGet());
return cb.getBuffer();
}

View File

@ -398,7 +398,7 @@ public class BucketCache implements BlockCache, HeapSize {
RAMQueueEntry re = ramCache.get(key);
if (re != null) {
if (updateCacheMetrics) {
cacheStats.hit(caching, key.isPrimary());
cacheStats.hit(caching, key.isPrimary(), key.getBlockType());
}
re.access(accessCount.incrementAndGet());
return re.getData();
@ -424,7 +424,7 @@ public class BucketCache implements BlockCache, HeapSize {
Cacheable cachedBlock = deserializer.deserialize(bb, true);
long timeTaken = System.nanoTime() - start;
if (updateCacheMetrics) {
cacheStats.hit(caching, key.isPrimary());
cacheStats.hit(caching, key.isPrimary(), key.getBlockType());
cacheStats.ioHit(timeTaken);
}
bucketEntry.access(accessCount.incrementAndGet());
@ -441,7 +441,7 @@ public class BucketCache implements BlockCache, HeapSize {
}
}
if (!repeat && updateCacheMetrics) {
cacheStats.miss(caching, key.isPrimary());
cacheStats.miss(caching, key.isPrimary(), key.getBlockType());
}
return null;
}

View File

@ -676,4 +676,162 @@ class MetricsRegionServerWrapperImpl
return averageRegionSize;
}
public long getDataMissCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getDataMissCount();
}
@Override
public long getLeafIndexMissCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getLeafIndexMissCount();
}
@Override
public long getBloomChunkMissCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getBloomChunkMissCount();
}
@Override
public long getMetaMissCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getMetaMissCount();
}
@Override
public long getRootIndexMissCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getRootIndexMissCount();
}
@Override
public long getIntermediateIndexMissCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getIntermediateIndexMissCount();
}
@Override
public long getFileInfoMissCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getFileInfoMissCount();
}
@Override
public long getGeneralBloomMetaMissCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getGeneralBloomMetaMissCount();
}
@Override
public long getDeleteFamilyBloomMissCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getDeleteFamilyBloomMissCount();
}
@Override
public long getTrailerMissCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getTrailerMissCount();
}
@Override
public long getDataHitCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getDataHitCount();
}
@Override
public long getLeafIndexHitCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getLeafIndexHitCount();
}
@Override
public long getBloomChunkHitCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getBloomChunkHitCount();
}
@Override
public long getMetaHitCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getMetaHitCount();
}
@Override
public long getRootIndexHitCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getRootIndexHitCount();
}
@Override
public long getIntermediateIndexHitCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getIntermediateIndexHitCount();
}
@Override
public long getFileInfoHitCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getFileInfoHitCount();
}
@Override
public long getGeneralBloomMetaHitCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getGeneralBloomMetaHitCount();
}
@Override
public long getDeleteFamilyBloomHitCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getDeleteFamilyBloomHitCount();
}
@Override
public long getTrailerHitCount() {
if (this.cacheStats == null) {
return 0;
}
return cacheStats.getTrailerHitCount();
}
}

View File

@ -38,11 +38,11 @@ public class TestCombinedBlockCache {
// period 1:
// lru cache: 1 hit caching, 1 miss caching
// bucket cache: 2 hit non-caching,1 miss non-caching/primary,1 fail insert
lruCacheStats.hit(true);
lruCacheStats.miss(true, false);
bucketCacheStats.hit(false);
bucketCacheStats.hit(false);
bucketCacheStats.miss(false, true);
lruCacheStats.hit(true, true, BlockType.DATA);
lruCacheStats.miss(true, false, BlockType.DATA);
bucketCacheStats.hit(false,true, BlockType.DATA);
bucketCacheStats.hit(false,true, BlockType.DATA);
bucketCacheStats.miss(false, true, BlockType.DATA);
assertEquals(5, stats.getRequestCount());
assertEquals(2, stats.getRequestCachingCount());
@ -84,9 +84,9 @@ public class TestCombinedBlockCache {
// period 2:
// lru cache: 3 hit caching
lruCacheStats.hit(true);
lruCacheStats.hit(true);
lruCacheStats.hit(true);
lruCacheStats.hit(true, true, BlockType.DATA);
lruCacheStats.hit(true, true, BlockType.DATA);
lruCacheStats.hit(true, true, BlockType.DATA);
stats.rollMetricsPeriod();
assertEquals(6, stats.getSumHitCountsPastNPeriods());
assertEquals(8, stats.getSumRequestCountsPastNPeriods());

View File

@ -659,48 +659,48 @@ public class TestLruBlockCache {
// period 1, 1 hit caching, 1 hit non-caching, 2 miss non-caching
// should be (2/4)=0.5 and (1/1)=1
stats.hit(false);
stats.hit(true);
stats.miss(false, false);
stats.miss(false, false);
stats.hit(false, true, BlockType.DATA);
stats.hit(true, true, BlockType.DATA);
stats.miss(false, false, BlockType.DATA);
stats.miss(false, false, BlockType.DATA);
stats.rollMetricsPeriod();
assertEquals(0.5, stats.getHitRatioPastNPeriods(), delta);
assertEquals(1.0, stats.getHitCachingRatioPastNPeriods(), delta);
// period 2, 1 miss caching, 3 miss non-caching
// should be (2/8)=0.25 and (1/2)=0.5
stats.miss(true, false);
stats.miss(false, false);
stats.miss(false, false);
stats.miss(false, false);
stats.miss(true, false, BlockType.DATA);
stats.miss(false, false, BlockType.DATA);
stats.miss(false, false, BlockType.DATA);
stats.miss(false, false, BlockType.DATA);
stats.rollMetricsPeriod();
assertEquals(0.25, stats.getHitRatioPastNPeriods(), delta);
assertEquals(0.5, stats.getHitCachingRatioPastNPeriods(), delta);
// period 3, 2 hits of each type
// should be (6/12)=0.5 and (3/4)=0.75
stats.hit(false);
stats.hit(true);
stats.hit(false);
stats.hit(true);
stats.hit(false, true, BlockType.DATA);
stats.hit(true, true, BlockType.DATA);
stats.hit(false, true, BlockType.DATA);
stats.hit(true, true, BlockType.DATA);
stats.rollMetricsPeriod();
assertEquals(0.5, stats.getHitRatioPastNPeriods(), delta);
assertEquals(0.75, stats.getHitCachingRatioPastNPeriods(), delta);
// period 4, evict period 1, two caching misses
// should be (4/10)=0.4 and (2/5)=0.4
stats.miss(true, false);
stats.miss(true, false);
stats.miss(true, false, BlockType.DATA);
stats.miss(true, false, BlockType.DATA);
stats.rollMetricsPeriod();
assertEquals(0.4, stats.getHitRatioPastNPeriods(), delta);
assertEquals(0.4, stats.getHitCachingRatioPastNPeriods(), delta);
// period 5, evict period 2, 2 caching misses, 2 non-caching hit
// should be (6/10)=0.6 and (2/6)=1/3
stats.miss(true, false);
stats.miss(true, false);
stats.hit(false);
stats.hit(false);
stats.miss(true, false, BlockType.DATA);
stats.miss(true, false, BlockType.DATA);
stats.hit(false, true, BlockType.DATA);
stats.hit(false, true, BlockType.DATA);
stats.rollMetricsPeriod();
assertEquals(0.6, stats.getHitRatioPastNPeriods(), delta);
assertEquals((double)1/3, stats.getHitCachingRatioPastNPeriods(), delta);
@ -725,10 +725,10 @@ public class TestLruBlockCache {
// period 9, one of each
// should be (2/4)=0.5 and (1/2)=0.5
stats.miss(true, false);
stats.miss(false, false);
stats.hit(true);
stats.hit(false);
stats.miss(true, false, BlockType.DATA);
stats.miss(false, false, BlockType.DATA);
stats.hit(true, true, BlockType.DATA);
stats.hit(false, true, BlockType.DATA);
stats.rollMetricsPeriod();
assertEquals(0.5, stats.getHitRatioPastNPeriods(), delta);
assertEquals(0.5, stats.getHitCachingRatioPastNPeriods(), delta);

View File

@ -310,6 +310,106 @@ public class MetricsRegionServerWrapperStub implements MetricsRegionServerWrappe
return 0;
}
@Override
public long getDataMissCount() {
return 0;
}
@Override
public long getLeafIndexMissCount() {
return 0;
}
@Override
public long getBloomChunkMissCount() {
return 0;
}
@Override
public long getMetaMissCount() {
return 0;
}
@Override
public long getRootIndexMissCount() {
return 0;
}
@Override
public long getIntermediateIndexMissCount() {
return 0;
}
@Override
public long getFileInfoMissCount() {
return 0;
}
@Override
public long getGeneralBloomMetaMissCount() {
return 0;
}
@Override
public long getDeleteFamilyBloomMissCount() {
return 0;
}
@Override
public long getTrailerMissCount() {
return 0;
}
@Override
public long getDataHitCount() {
return 0;
}
@Override
public long getLeafIndexHitCount() {
return 0;
}
@Override
public long getBloomChunkHitCount() {
return 0;
}
@Override
public long getMetaHitCount() {
return 0;
}
@Override
public long getRootIndexHitCount() {
return 0;
}
@Override
public long getIntermediateIndexHitCount() {
return 0;
}
@Override
public long getFileInfoHitCount() {
return 0;
}
@Override
public long getGeneralBloomMetaHitCount() {
return 0;
}
@Override
public long getDeleteFamilyBloomHitCount() {
return 0;
}
@Override
public long getTrailerHitCount() {
return 0;
}
@Override
public int getSplitQueueSize() {
return 0;