diff --git a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetricsConnection.java b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetricsConnection.java index dd3e571a8b7a..66cdfb3183f8 100644 --- a/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetricsConnection.java +++ b/hbase-client/src/main/java/org/apache/hadoop/hbase/client/MetricsConnection.java @@ -552,6 +552,10 @@ public void incrMetaCacheHit() { metaCacheHits.inc(); } + public long getMetaCacheHits() { + return metaCacheHits.getCount(); + } + /** Increment the number of meta cache misses. */ public void incrMetaCacheMiss() { metaCacheMisses.inc(); diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMetaCache.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMetaCache.java index ce52918bfe42..f8f853e758e1 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMetaCache.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/client/TestMetaCache.java @@ -241,6 +241,8 @@ public void testPreserveMetaCacheOnException() throws Exception { Exception exp; boolean success; + long initialMetaCacheHits = metrics.getMetaCacheHits(); + long initialMetaCacheMisses = metrics.getMetaCacheMisses(); for (int i = 0; i < 50; i++) { exp = null; success = false; @@ -253,6 +255,12 @@ public void testPreserveMetaCacheOnException() throws Exception { table.increment(increment); table.delete(delete); table.mutateRow(mutations); + // The value of the metaCacheHits counter is incremented by 6 in each round of the loop, + // for 0th iteration there will be 5 hits + 1 cache miss. + assertEquals(initialMetaCacheHits + 6 * i + 5, metrics.getMetaCacheHits()); + // We will get a cache miss only on the first request, so the value will always be + // initialMetaCacheMisses + 1 + assertEquals(initialMetaCacheMisses + 1, metrics.getMetaCacheMisses()); } catch (IOException ex) { // Only keep track of the last exception that updated the meta cache if (ClientExceptionsUtil.isMetaClearingException(ex) || success) {