Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ public long getIOHitsPerSecond() {
public double getIOTimePerHit() {
long time = ioHitTime.sum() / NANO_TIME;
long count = ioHitCount.sum();
return ((float) time / (float) count);
return count == 0 ? 0.0 : (double) time / count;
}

public void reset() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,15 @@

import java.io.File;
import java.io.IOException;
import java.lang.reflect.Field;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.ThreadLocalRandom;
import java.util.concurrent.atomic.LongAdder;
import java.util.concurrent.locks.ReentrantReadWriteLock;
import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
Expand All @@ -44,6 +46,7 @@
import org.apache.hadoop.hbase.io.ByteBuffAllocator;
import org.apache.hadoop.hbase.io.hfile.BlockCacheKey;
import org.apache.hadoop.hbase.io.hfile.BlockType;
import org.apache.hadoop.hbase.io.hfile.CacheStats;
import org.apache.hadoop.hbase.io.hfile.CacheTestUtils;
import org.apache.hadoop.hbase.io.hfile.CacheTestUtils.HFileBlockPair;
import org.apache.hadoop.hbase.io.hfile.Cacheable;
Expand Down Expand Up @@ -770,4 +773,20 @@ public void testBlockAdditionWaitWhenCache() throws Exception {
HBASE_TESTING_UTILITY.cleanupTestDir();
}
}

@Test
public void testIOTimePerHitReturnsZeroWhenNoHits()
throws NoSuchFieldException, IllegalAccessException {
CacheStats cacheStats = cache.getStats();
assertTrue(cacheStats instanceof BucketCacheStats);
BucketCacheStats bucketCacheStats = (BucketCacheStats) cacheStats;

Field field = BucketCacheStats.class.getDeclaredField("ioHitCount");
field.setAccessible(true);
LongAdder ioHitCount = (LongAdder) field.get(bucketCacheStats);

assertEquals(0, ioHitCount.sum());
double ioTimePerHit = bucketCacheStats.getIOTimePerHit();
assertEquals(0, ioTimePerHit, 0.0);
}
}