HBASE-14314 Metrics for block cache should take region replicas into account
This commit is contained in:
parent
ec4d719f19
commit
b7a67c6382
|
@ -207,12 +207,20 @@ public interface MetricsRegionServerSource extends BaseSource {
|
|||
String BLOCK_CACHE_SIZE_DESC = "Size of the block cache.";
|
||||
String BLOCK_CACHE_HIT_COUNT = "blockCacheHitCount";
|
||||
String BLOCK_CACHE_HIT_COUNT_DESC = "Count of the hit on the block cache.";
|
||||
String BLOCK_CACHE_PRIMARY_HIT_COUNT = "blockCacheHitCountPrimary";
|
||||
String BLOCK_CACHE_PRIMARY_HIT_COUNT_DESC = "Count of hit on primary replica in the block cache.";
|
||||
String BLOCK_CACHE_MISS_COUNT = "blockCacheMissCount";
|
||||
String BLOCK_COUNT_MISS_COUNT_DESC =
|
||||
"Number of requests for a block that missed the block cache.";
|
||||
String BLOCK_CACHE_PRIMARY_MISS_COUNT = "blockCacheMissCountPrimary";
|
||||
String BLOCK_COUNT_PRIMARY_MISS_COUNT_DESC =
|
||||
"Number of requests for a block of primary replica that missed the block cache.";
|
||||
String BLOCK_CACHE_EVICTION_COUNT = "blockCacheEvictionCount";
|
||||
String BLOCK_CACHE_EVICTION_COUNT_DESC =
|
||||
"Count of the number of blocks evicted from the block cache.";
|
||||
String BLOCK_CACHE_PRIMARY_EVICTION_COUNT = "blockCacheEvictionCountPrimary";
|
||||
String BLOCK_CACHE_PRIMARY_EVICTION_COUNT_DESC =
|
||||
"Count of the number of blocks evicted from primary replica in the block cache.";
|
||||
String BLOCK_CACHE_HIT_PERCENT = "blockCacheCountHitPercent";
|
||||
String BLOCK_CACHE_HIT_PERCENT_DESC =
|
||||
"Percent of block cache requests that are hits";
|
||||
|
|
|
@ -197,16 +197,32 @@ public interface MetricsRegionServerWrapper {
|
|||
*/
|
||||
long getBlockCacheHitCount();
|
||||
|
||||
/**
|
||||
* Get the count of hits to primary replica in the block cache
|
||||
*/
|
||||
long getBlockCachePrimaryHitCount();
|
||||
|
||||
/**
|
||||
* Get the count of misses to the block cache.
|
||||
*/
|
||||
long getBlockCacheMissCount();
|
||||
|
||||
/**
|
||||
* Get the count of misses to primary replica in the block cache.
|
||||
*/
|
||||
long getBlockCachePrimaryMissCount();
|
||||
|
||||
/**
|
||||
* Get the number of items evicted from the block cache.
|
||||
*/
|
||||
long getBlockCacheEvictedCount();
|
||||
|
||||
/**
|
||||
* Get the number of items evicted from primary replica in the block cache.
|
||||
*/
|
||||
long getBlockCachePrimaryEvictedCount();
|
||||
|
||||
|
||||
/**
|
||||
* Get the percent of all requests that hit the block cache.
|
||||
*/
|
||||
|
|
|
@ -236,10 +236,16 @@ public class MetricsRegionServerSourceImpl
|
|||
rsWrap.getBlockCacheSize())
|
||||
.addCounter(Interns.info(BLOCK_CACHE_HIT_COUNT, BLOCK_CACHE_HIT_COUNT_DESC),
|
||||
rsWrap.getBlockCacheHitCount())
|
||||
.addCounter(Interns.info(BLOCK_CACHE_PRIMARY_HIT_COUNT,
|
||||
BLOCK_CACHE_PRIMARY_HIT_COUNT_DESC), rsWrap.getBlockCachePrimaryHitCount())
|
||||
.addCounter(Interns.info(BLOCK_CACHE_MISS_COUNT, BLOCK_COUNT_MISS_COUNT_DESC),
|
||||
rsWrap.getBlockCacheMissCount())
|
||||
.addCounter(Interns.info(BLOCK_CACHE_PRIMARY_MISS_COUNT,
|
||||
BLOCK_COUNT_PRIMARY_MISS_COUNT_DESC), rsWrap.getBlockCachePrimaryMissCount())
|
||||
.addCounter(Interns.info(BLOCK_CACHE_EVICTION_COUNT, BLOCK_CACHE_EVICTION_COUNT_DESC),
|
||||
rsWrap.getBlockCacheEvictedCount())
|
||||
.addCounter(Interns.info(BLOCK_CACHE_PRIMARY_EVICTION_COUNT,
|
||||
BLOCK_CACHE_PRIMARY_EVICTION_COUNT_DESC), rsWrap.getBlockCachePrimaryEvictedCount())
|
||||
.addGauge(Interns.info(BLOCK_CACHE_HIT_PERCENT, BLOCK_CACHE_HIT_PERCENT_DESC),
|
||||
rsWrap.getBlockCacheHitPercent())
|
||||
.addGauge(Interns.info(BLOCK_CACHE_EXPRESS_HIT_PERCENT,
|
||||
|
|
|
@ -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 boolean isPrimaryReplicaBlock;
|
||||
|
||||
/**
|
||||
* Construct a new BlockCacheKey
|
||||
|
@ -37,6 +38,11 @@ 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);
|
||||
}
|
||||
|
||||
public BlockCacheKey(String hfileName, long offset, boolean isPrimaryReplica) {
|
||||
this.isPrimaryReplicaBlock = isPrimaryReplica;
|
||||
this.hfileName = hfileName;
|
||||
this.offset = offset;
|
||||
}
|
||||
|
@ -63,7 +69,7 @@ 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 +
|
||||
public static final long FIXED_OVERHEAD = ClassSize.align(ClassSize.OBJECT +Bytes.SIZEOF_BOOLEAN +
|
||||
ClassSize.REFERENCE + // this.hfileName
|
||||
Bytes.SIZEOF_LONG); // this.offset
|
||||
|
||||
|
@ -85,6 +91,10 @@ public class BlockCacheKey implements HeapSize, java.io.Serializable {
|
|||
return hfileName;
|
||||
}
|
||||
|
||||
public boolean isPrimary() {
|
||||
return isPrimaryReplicaBlock;
|
||||
}
|
||||
|
||||
public long getOffset() {
|
||||
return offset;
|
||||
}
|
||||
|
|
|
@ -43,6 +43,9 @@ public class CacheStats {
|
|||
/** The number of getBlock requests that were cache hits */
|
||||
private final AtomicLong hitCount = new AtomicLong(0);
|
||||
|
||||
/** The number of getBlock requests that were cache hits from primary replica */
|
||||
private final AtomicLong primaryHitCount = new AtomicLong(0);
|
||||
|
||||
/**
|
||||
* The number of getBlock requests that were cache hits, but only from
|
||||
* requests that were set to use the block cache. This is because all reads
|
||||
|
@ -54,6 +57,8 @@ public class CacheStats {
|
|||
/** The number of getBlock requests that were cache misses */
|
||||
private final AtomicLong missCount = new AtomicLong(0);
|
||||
|
||||
/** The number of getBlock requests for primary replica that were cache misses */
|
||||
private final AtomicLong primaryMissCount = new AtomicLong(0);
|
||||
/**
|
||||
* The number of getBlock requests that were cache misses, but only from
|
||||
* requests that were set to use the block cache.
|
||||
|
@ -66,6 +71,9 @@ public class CacheStats {
|
|||
/** The total number of blocks that have been evicted */
|
||||
private final AtomicLong evictedBlockCount = new AtomicLong(0);
|
||||
|
||||
/** The total number of blocks for primary replica that have been evicted */
|
||||
private final AtomicLong primaryEvictedBlockCount = new AtomicLong(0);
|
||||
|
||||
/** The number of metrics periods to include in window */
|
||||
private final int numPeriodsInWindow;
|
||||
/** Hit counts for each period in window */
|
||||
|
@ -112,17 +120,25 @@ public class CacheStats {
|
|||
", missCount=" + getMissCount() + ", missCachingCount=" + getMissCachingCount() +
|
||||
", evictionCount=" + getEvictionCount() +
|
||||
", evictedBlockCount=" + getEvictedCount() +
|
||||
", primaryMissCount=" + getPrimaryMissCount() +
|
||||
", primaryHitCount=" + getPrimaryHitCount() +
|
||||
", evictedAgeMean=" + snapshot.getMean() +
|
||||
", evictedAgeStdDev=" + snapshot.getStdDev();
|
||||
}
|
||||
|
||||
public void miss(boolean caching) {
|
||||
public void miss(boolean caching, boolean primary) {
|
||||
missCount.incrementAndGet();
|
||||
if (primary) primaryMissCount.incrementAndGet();
|
||||
if (caching) missCachingCount.incrementAndGet();
|
||||
}
|
||||
|
||||
public void hit(boolean caching) {
|
||||
hit(caching, true);
|
||||
}
|
||||
|
||||
public void hit(boolean caching, boolean primary) {
|
||||
hitCount.incrementAndGet();
|
||||
if (primary) primaryHitCount.incrementAndGet();
|
||||
if (caching) hitCachingCount.incrementAndGet();
|
||||
}
|
||||
|
||||
|
@ -130,9 +146,12 @@ public class CacheStats {
|
|||
evictionCount.incrementAndGet();
|
||||
}
|
||||
|
||||
public void evicted(final long t) {
|
||||
public void evicted(final long t, boolean primary) {
|
||||
if (t > this.startTime) this.ageAtEviction.update(t - this.startTime);
|
||||
this.evictedBlockCount.incrementAndGet();
|
||||
if (primary) {
|
||||
primaryEvictedBlockCount.incrementAndGet();
|
||||
}
|
||||
}
|
||||
|
||||
public long getRequestCount() {
|
||||
|
@ -147,6 +166,10 @@ public class CacheStats {
|
|||
return missCount.get();
|
||||
}
|
||||
|
||||
public long getPrimaryMissCount() {
|
||||
return primaryMissCount.get();
|
||||
}
|
||||
|
||||
public long getMissCachingCount() {
|
||||
return missCachingCount.get();
|
||||
}
|
||||
|
@ -155,6 +178,10 @@ public class CacheStats {
|
|||
return hitCount.get();
|
||||
}
|
||||
|
||||
public long getPrimaryHitCount() {
|
||||
return primaryHitCount.get();
|
||||
}
|
||||
|
||||
public long getHitCachingCount() {
|
||||
return hitCachingCount.get();
|
||||
}
|
||||
|
@ -167,6 +194,10 @@ public class CacheStats {
|
|||
return this.evictedBlockCount.get();
|
||||
}
|
||||
|
||||
public long getPrimaryEvictedCount() {
|
||||
return primaryEvictedBlockCount.get();
|
||||
}
|
||||
|
||||
public double getHitRatio() {
|
||||
return ((float)getHitCount()/(float)getRequestCount());
|
||||
}
|
||||
|
|
|
@ -131,7 +131,7 @@ public class CombinedBlockCache implements ResizableBlockCache, HeapSize {
|
|||
return lruCache.getBlockCount() + l2Cache.getBlockCount();
|
||||
}
|
||||
|
||||
private static class CombinedCacheStats extends CacheStats {
|
||||
public static class CombinedCacheStats extends CacheStats {
|
||||
private final CacheStats lruCacheStats;
|
||||
private final CacheStats bucketCacheStats;
|
||||
|
||||
|
@ -158,6 +158,11 @@ public class CombinedBlockCache implements ResizableBlockCache, HeapSize {
|
|||
return lruCacheStats.getMissCount() + bucketCacheStats.getMissCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPrimaryMissCount() {
|
||||
return lruCacheStats.getPrimaryMissCount() + bucketCacheStats.getPrimaryMissCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getMissCachingCount() {
|
||||
return lruCacheStats.getMissCachingCount()
|
||||
|
@ -169,6 +174,10 @@ public class CombinedBlockCache implements ResizableBlockCache, HeapSize {
|
|||
return lruCacheStats.getHitCount() + bucketCacheStats.getHitCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPrimaryHitCount() {
|
||||
return lruCacheStats.getPrimaryHitCount() + bucketCacheStats.getPrimaryHitCount();
|
||||
}
|
||||
@Override
|
||||
public long getHitCachingCount() {
|
||||
return lruCacheStats.getHitCachingCount()
|
||||
|
@ -187,6 +196,12 @@ public class CombinedBlockCache implements ResizableBlockCache, HeapSize {
|
|||
+ bucketCacheStats.getEvictedCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getPrimaryEvictedCount() {
|
||||
return lruCacheStats.getPrimaryEvictedCount()
|
||||
+ bucketCacheStats.getPrimaryEvictedCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getHitRatioPastNPeriods() {
|
||||
double ratio = ((double) (lruCacheStats.getSumHitCountsPastNPeriods() + bucketCacheStats
|
||||
|
|
|
@ -463,6 +463,10 @@ public class HFile {
|
|||
*/
|
||||
HFileContext getFileContext();
|
||||
|
||||
boolean isPrimaryReplicaReader();
|
||||
|
||||
void setPrimaryReplicaReader(boolean isPrimaryReplicaReader);
|
||||
|
||||
boolean shouldIncludeMemstoreTS();
|
||||
|
||||
boolean isDecodeMemstoreTS();
|
||||
|
|
|
@ -87,6 +87,8 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
|
|||
/** Filled when we read in the trailer. */
|
||||
private final Compression.Algorithm compressAlgo;
|
||||
|
||||
private boolean isPrimaryReplicaReader;
|
||||
|
||||
/**
|
||||
* What kind of data block encoding should be used while reading, writing,
|
||||
* and handling cache.
|
||||
|
@ -352,7 +354,7 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
|
|||
BlockCache blockCache = this.cacheConf.getBlockCache();
|
||||
if (blockCache != null && block != null) {
|
||||
BlockCacheKey cacheKey = new BlockCacheKey(this.getFileContext().getHFileName(),
|
||||
block.getOffset());
|
||||
block.getOffset(), this.isPrimaryReplicaReader());
|
||||
blockCache.returnBlock(cacheKey, block);
|
||||
}
|
||||
}
|
||||
|
@ -438,6 +440,16 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
|
|||
return trailer;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrimaryReplicaReader() {
|
||||
return isPrimaryReplicaReader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setPrimaryReplicaReader(boolean isPrimaryReplicaReader) {
|
||||
this.isPrimaryReplicaReader = isPrimaryReplicaReader;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FileInfo loadFileInfo() throws IOException {
|
||||
return fileInfo;
|
||||
|
@ -1374,7 +1386,8 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
|
|||
.getRootBlockKey(block)) {
|
||||
// Check cache for block. If found return.
|
||||
long metaBlockOffset = metaBlockIndexReader.getRootBlockOffset(block);
|
||||
BlockCacheKey cacheKey = new BlockCacheKey(name, metaBlockOffset);
|
||||
BlockCacheKey cacheKey = new BlockCacheKey(name, metaBlockOffset,
|
||||
this.isPrimaryReplicaReader());
|
||||
|
||||
cacheBlock &= cacheConf.shouldCacheDataOnRead();
|
||||
if (cacheConf.isBlockCacheEnabled()) {
|
||||
|
@ -1421,7 +1434,8 @@ public class HFileReaderImpl implements HFile.Reader, Configurable {
|
|||
// the other choice is to duplicate work (which the cache would prevent you
|
||||
// from doing).
|
||||
|
||||
BlockCacheKey cacheKey = new BlockCacheKey(name, dataBlockOffset);
|
||||
BlockCacheKey cacheKey = new BlockCacheKey(name, dataBlockOffset,
|
||||
this.isPrimaryReplicaReader());
|
||||
|
||||
boolean useLock = false;
|
||||
IdLock.Entry lockEntry = null;
|
||||
|
|
|
@ -417,7 +417,7 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize {
|
|||
boolean updateCacheMetrics) {
|
||||
LruCachedBlock cb = map.get(cacheKey);
|
||||
if (cb == null) {
|
||||
if (!repeat && updateCacheMetrics) stats.miss(caching);
|
||||
if (!repeat && updateCacheMetrics) stats.miss(caching, cacheKey.isPrimary());
|
||||
// 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.
|
||||
|
@ -432,7 +432,7 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize {
|
|||
}
|
||||
return null;
|
||||
}
|
||||
if (updateCacheMetrics) stats.hit(caching);
|
||||
if (updateCacheMetrics) stats.hit(caching, cacheKey.isPrimary());
|
||||
cb.access(count.incrementAndGet());
|
||||
return cb.getBuffer();
|
||||
}
|
||||
|
@ -495,7 +495,7 @@ public class LruBlockCache implements ResizableBlockCache, HeapSize {
|
|||
long size = map.size();
|
||||
assertCounterSanity(size, val);
|
||||
}
|
||||
stats.evicted(block.getCachedTime());
|
||||
stats.evicted(block.getCachedTime(), block.getCacheKey().isPrimary());
|
||||
if (evictedByEvictionProcess && victimHandler != null) {
|
||||
if (victimHandler instanceof BucketCache) {
|
||||
boolean wait = getCurrentSize() < acceptableSize();
|
||||
|
|
|
@ -149,9 +149,9 @@ 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);
|
||||
cacheStats.miss(caching, cacheKey.isPrimary());
|
||||
} else {
|
||||
cacheStats.hit(caching);
|
||||
cacheStats.hit(caching, cacheKey.isPrimary());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -404,7 +404,7 @@ public class BucketCache implements BlockCache, HeapSize {
|
|||
RAMQueueEntry re = ramCache.get(key);
|
||||
if (re != null) {
|
||||
if (updateCacheMetrics) {
|
||||
cacheStats.hit(caching);
|
||||
cacheStats.hit(caching, key.isPrimary());
|
||||
}
|
||||
re.access(accessCount.incrementAndGet());
|
||||
return re.getData();
|
||||
|
@ -426,7 +426,7 @@ public class BucketCache implements BlockCache, HeapSize {
|
|||
bucketEntry.deserializerReference(this.deserialiserMap));
|
||||
long timeTaken = System.nanoTime() - start;
|
||||
if (updateCacheMetrics) {
|
||||
cacheStats.hit(caching);
|
||||
cacheStats.hit(caching, key.isPrimary());
|
||||
cacheStats.ioHit(timeTaken);
|
||||
}
|
||||
if (cachedBlock.getMemoryType() == MemoryType.SHARED) {
|
||||
|
@ -448,7 +448,7 @@ public class BucketCache implements BlockCache, HeapSize {
|
|||
}
|
||||
}
|
||||
if (!repeat && updateCacheMetrics) {
|
||||
cacheStats.miss(caching);
|
||||
cacheStats.miss(caching, key.isPrimary());
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
@ -478,7 +478,7 @@ public class BucketCache implements BlockCache, HeapSize {
|
|||
BucketEntry bucketEntry = backingMap.get(cacheKey);
|
||||
if (bucketEntry == null) {
|
||||
if (removedBlock != null) {
|
||||
cacheStats.evicted(0);
|
||||
cacheStats.evicted(0, cacheKey.isPrimary());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -500,7 +500,7 @@ public class BucketCache implements BlockCache, HeapSize {
|
|||
offsetLock.releaseLockEntry(lockEntry);
|
||||
}
|
||||
}
|
||||
cacheStats.evicted(bucketEntry.getCachedTime());
|
||||
cacheStats.evicted(bucketEntry.getCachedTime(), cacheKey.isPrimary());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -521,7 +521,7 @@ public class BucketCache implements BlockCache, HeapSize {
|
|||
BucketEntry bucketEntry = backingMap.get(cacheKey);
|
||||
if (bucketEntry == null) {
|
||||
if (removedBlock != null) {
|
||||
cacheStats.evicted(0);
|
||||
cacheStats.evicted(0, cacheKey.isPrimary());
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
|
@ -561,7 +561,7 @@ public class BucketCache implements BlockCache, HeapSize {
|
|||
offsetLock.releaseLockEntry(lockEntry);
|
||||
}
|
||||
}
|
||||
cacheStats.evicted(bucketEntry.getCachedTime());
|
||||
cacheStats.evicted(bucketEntry.getCachedTime(), cacheKey.isPrimary());
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -619,7 +619,8 @@ public class HStore implements Store {
|
|||
|
||||
if (newFiles == null) newFiles = new ArrayList<StoreFileInfo>(0);
|
||||
|
||||
HashMap<StoreFileInfo, StoreFile> currentFilesSet = new HashMap<StoreFileInfo, StoreFile>(currentFiles.size());
|
||||
HashMap<StoreFileInfo, StoreFile> currentFilesSet =
|
||||
new HashMap<StoreFileInfo, StoreFile>(currentFiles.size());
|
||||
for (StoreFile sf : currentFiles) {
|
||||
currentFilesSet.put(sf.getFileInfo(), sf);
|
||||
}
|
||||
|
@ -667,7 +668,8 @@ public class HStore implements Store {
|
|||
info.setRegionCoprocessorHost(this.region.getCoprocessorHost());
|
||||
StoreFile storeFile = new StoreFile(this.getFileSystem(), info, this.conf, this.cacheConf,
|
||||
this.family.getBloomFilterType());
|
||||
storeFile.createReader();
|
||||
StoreFile.Reader r = storeFile.createReader();
|
||||
r.setReplicaStoreFile(isPrimaryReplicaStore());
|
||||
return storeFile;
|
||||
}
|
||||
|
||||
|
@ -1134,7 +1136,7 @@ public class HStore implements Store {
|
|||
// but now we get them in ascending order, which I think is
|
||||
// actually more correct, since memstore get put at the end.
|
||||
List<StoreFileScanner> sfScanners = StoreFileScanner.getScannersForStoreFiles(storeFilesToScan,
|
||||
cacheBlocks, usePread, isCompaction, false, matcher, readPt);
|
||||
cacheBlocks, usePread, isCompaction, false, matcher, readPt, isPrimaryReplicaStore());
|
||||
List<KeyValueScanner> scanners =
|
||||
new ArrayList<KeyValueScanner>(sfScanners.size()+1);
|
||||
scanners.addAll(sfScanners);
|
||||
|
@ -2280,4 +2282,9 @@ public class HStore implements Store {
|
|||
public double getCompactionPressure() {
|
||||
return storeEngine.getStoreFileManager().getCompactionPressure();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isPrimaryReplicaStore() {
|
||||
return getRegionInfo().getReplicaId() == HRegionInfo.DEFAULT_REPLICA_ID;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -286,6 +286,14 @@ class MetricsRegionServerWrapperImpl
|
|||
return this.cacheStats.getHitCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBlockCachePrimaryHitCount() {
|
||||
if (this.cacheStats == null) {
|
||||
return 0;
|
||||
}
|
||||
return this.cacheStats.getPrimaryHitCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBlockCacheMissCount() {
|
||||
if (this.cacheStats == null) {
|
||||
|
@ -294,6 +302,14 @@ class MetricsRegionServerWrapperImpl
|
|||
return this.cacheStats.getMissCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBlockCachePrimaryMissCount() {
|
||||
if (this.cacheStats == null) {
|
||||
return 0;
|
||||
}
|
||||
return this.cacheStats.getPrimaryMissCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBlockCacheEvictedCount() {
|
||||
if (this.cacheStats == null) {
|
||||
|
@ -302,6 +318,14 @@ class MetricsRegionServerWrapperImpl
|
|||
return this.cacheStats.getEvictedCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBlockCachePrimaryEvictedCount() {
|
||||
if (this.cacheStats == null) {
|
||||
return 0;
|
||||
}
|
||||
return this.cacheStats.getPrimaryEvictedCount();
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBlockCacheHitPercent() {
|
||||
if (this.cacheStats == null) {
|
||||
|
|
|
@ -450,4 +450,6 @@ public interface Store extends HeapSize, StoreConfigInformation, PropagatingConf
|
|||
void refreshStoreFiles(Collection<String> newFiles) throws IOException;
|
||||
|
||||
void bulkLoadHFile(StoreFileInfo fileInfo) throws IOException;
|
||||
|
||||
boolean isPrimaryReplicaStore();
|
||||
}
|
||||
|
|
|
@ -1118,6 +1118,13 @@ public class StoreFile {
|
|||
bloomFilterType = BloomType.NONE;
|
||||
}
|
||||
|
||||
public void setReplicaStoreFile(boolean isPrimaryReplicaStoreFile) {
|
||||
reader.setPrimaryReplicaReader(isPrimaryReplicaStoreFile);
|
||||
}
|
||||
public boolean isPrimaryReplicaReader() {
|
||||
return reader.isPrimaryReplicaReader();
|
||||
}
|
||||
|
||||
/**
|
||||
* ONLY USE DEFAULT CONSTRUCTOR FOR UNIT TESTS
|
||||
*/
|
||||
|
|
|
@ -78,6 +78,10 @@ public class StoreFileScanner implements KeyValueScanner {
|
|||
this.hasMVCCInfo = hasMVCC;
|
||||
}
|
||||
|
||||
boolean isPrimaryReplica() {
|
||||
return reader.isPrimaryReplicaReader();
|
||||
}
|
||||
|
||||
/**
|
||||
* Return an array of scanners corresponding to the given
|
||||
* set of store files.
|
||||
|
@ -108,11 +112,12 @@ public class StoreFileScanner implements KeyValueScanner {
|
|||
public static List<StoreFileScanner> getScannersForStoreFiles(
|
||||
Collection<StoreFile> files, boolean cacheBlocks, boolean usePread,
|
||||
boolean isCompaction, boolean canUseDrop,
|
||||
ScanQueryMatcher matcher, long readPt) throws IOException {
|
||||
ScanQueryMatcher matcher, long readPt, boolean isPrimaryReplica) throws IOException {
|
||||
List<StoreFileScanner> scanners = new ArrayList<StoreFileScanner>(
|
||||
files.size());
|
||||
for (StoreFile file : files) {
|
||||
StoreFile.Reader r = file.createReader(canUseDrop);
|
||||
r.setReplicaStoreFile(isPrimaryReplica);
|
||||
StoreFileScanner scanner = r.getStoreFileScanner(cacheBlocks, usePread,
|
||||
isCompaction, readPt);
|
||||
scanner.setScanQueryMatcher(matcher);
|
||||
|
@ -121,6 +126,14 @@ public class StoreFileScanner implements KeyValueScanner {
|
|||
return scanners;
|
||||
}
|
||||
|
||||
public static List<StoreFileScanner> getScannersForStoreFiles(
|
||||
Collection<StoreFile> files, boolean cacheBlocks, boolean usePread,
|
||||
boolean isCompaction, boolean canUseDrop,
|
||||
ScanQueryMatcher matcher, long readPt) throws IOException {
|
||||
return getScannersForStoreFiles(files, cacheBlocks, usePread, isCompaction, canUseDrop,
|
||||
matcher, readPt, true);
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "StoreFileScanner[" + hfs.toString() + ", cur=" + cur + "]";
|
||||
}
|
||||
|
|
|
@ -619,18 +619,18 @@ public class TestLruBlockCache {
|
|||
// should be (2/4)=0.5 and (1/1)=1
|
||||
stats.hit(false);
|
||||
stats.hit(true);
|
||||
stats.miss(false);
|
||||
stats.miss(false);
|
||||
stats.miss(false, false);
|
||||
stats.miss(false, false);
|
||||
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);
|
||||
stats.miss(false);
|
||||
stats.miss(false);
|
||||
stats.miss(false);
|
||||
stats.miss(true, false);
|
||||
stats.miss(false, false);
|
||||
stats.miss(false, false);
|
||||
stats.miss(false, false);
|
||||
stats.rollMetricsPeriod();
|
||||
assertEquals(0.25, stats.getHitRatioPastNPeriods(), delta);
|
||||
assertEquals(0.5, stats.getHitCachingRatioPastNPeriods(), delta);
|
||||
|
@ -647,16 +647,16 @@ public class TestLruBlockCache {
|
|||
|
||||
// period 4, evict period 1, two caching misses
|
||||
// should be (4/10)=0.4 and (2/5)=0.4
|
||||
stats.miss(true);
|
||||
stats.miss(true);
|
||||
stats.miss(true, false);
|
||||
stats.miss(true, false);
|
||||
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);
|
||||
stats.miss(true);
|
||||
stats.miss(true, false);
|
||||
stats.miss(true, false);
|
||||
stats.hit(false);
|
||||
stats.hit(false);
|
||||
stats.rollMetricsPeriod();
|
||||
|
@ -683,8 +683,8 @@ public class TestLruBlockCache {
|
|||
|
||||
// period 9, one of each
|
||||
// should be (2/4)=0.5 and (1/2)=0.5
|
||||
stats.miss(true);
|
||||
stats.miss(false);
|
||||
stats.miss(true, false);
|
||||
stats.miss(false, false);
|
||||
stats.hit(true);
|
||||
stats.hit(false);
|
||||
stats.rollMetricsPeriod();
|
||||
|
|
|
@ -175,16 +175,31 @@ public class MetricsRegionServerWrapperStub implements MetricsRegionServerWrappe
|
|||
return 416;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBlockCachePrimaryHitCount() {
|
||||
return 422;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBlockCacheMissCount() {
|
||||
return 417;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBlockCachePrimaryMissCount() {
|
||||
return 421;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBlockCacheEvictedCount() {
|
||||
return 418;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long getBlockCachePrimaryEvictedCount() {
|
||||
return 420;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getBlockCacheHitPercent() {
|
||||
return 98;
|
||||
|
|
|
@ -524,13 +524,13 @@ public class TestHeapMemoryManager {
|
|||
|
||||
@Override
|
||||
public boolean evictBlock(BlockCacheKey cacheKey) {
|
||||
stats.evicted(0);
|
||||
stats.evicted(0, cacheKey != null ? cacheKey.isPrimary() : true);
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int evictBlocksByHfileName(String hfileName) {
|
||||
stats.evicted(0); // Just assuming only one block for file here.
|
||||
stats.evicted(0, true); // Just assuming only one block for file here.
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue