From d3d37b7c321f92f121856f2c54b112c4594fe5bc Mon Sep 17 00:00:00 2001 From: huiruan <876107431@qq.com> Date: Wed, 24 May 2023 22:30:04 +0800 Subject: [PATCH 1/4] HBASE-27885 expose metaCacheHits in MetricsConnection --- .../org/apache/hadoop/hbase/client/MetricsConnection.java | 4 ++++ 1 file changed, 4 insertions(+) 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(); From 986f754c96acdc15127ab6faf689c826402320ac Mon Sep 17 00:00:00 2001 From: huiruan <876107431@qq.com> Date: Fri, 26 May 2023 01:23:52 +0800 Subject: [PATCH 2/4] add a test case for getMetaCacheHits --- .../java/org/apache/hadoop/hbase/client/TestMetaCache.java | 3 +++ 1 file changed, 3 insertions(+) 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..f1f37a718154 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 @@ -253,6 +253,9 @@ 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, + // and the first request will not hit cache + assertEquals(6 * i + 5, metrics.getMetaCacheHits()); } catch (IOException ex) { // Only keep track of the last exception that updated the meta cache if (ClientExceptionsUtil.isMetaClearingException(ex) || success) { From 2ea8ebdbc801bde4d6fc43a0b5fa98531d79a225 Mon Sep 17 00:00:00 2001 From: huiruan <876107431@qq.com> Date: Fri, 26 May 2023 17:01:06 +0800 Subject: [PATCH 3/4] improve test case --- .../java/org/apache/hadoop/hbase/client/TestMetaCache.java | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) 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 f1f37a718154..b227dfaf077e 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,7 @@ public void testPreserveMetaCacheOnException() throws Exception { Exception exp; boolean success; + long initialMetaCacheHits = metrics.getMetaCacheHits(); for (int i = 0; i < 50; i++) { exp = null; success = false; @@ -254,8 +255,10 @@ public void testPreserveMetaCacheOnException() throws Exception { table.delete(delete); table.mutateRow(mutations); // The value of the metaCacheHits counter is incremented by 6 in each round of the loop, - // and the first request will not hit cache - assertEquals(6 * i + 5, metrics.getMetaCacheHits()); + // 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 1. + assertEquals(1, metrics.getMetaCacheMisses()); } catch (IOException ex) { // Only keep track of the last exception that updated the meta cache if (ClientExceptionsUtil.isMetaClearingException(ex) || success) { From a825eb02cfe441d249b0553e3f11dd1dce6d04af Mon Sep 17 00:00:00 2001 From: huiruan <876107431@qq.com> Date: Sat, 27 May 2023 13:24:21 +0800 Subject: [PATCH 4/4] improve test case --- .../java/org/apache/hadoop/hbase/client/TestMetaCache.java | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) 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 b227dfaf077e..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 @@ -242,6 +242,7 @@ 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; @@ -257,8 +258,9 @@ public void testPreserveMetaCacheOnException() throws Exception { // 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 1. - assertEquals(1, metrics.getMetaCacheMisses()); + // 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) {