From 48b2502a5fcd4d3cd954c3abf6703422da7cdc2f Mon Sep 17 00:00:00 2001 From: Jerry He Date: Thu, 6 Apr 2017 16:45:45 -0700 Subject: [PATCH] HBASE-17816 HRegion#mutateRowWithLocks should update writeRequestCount metric (Weizhan Zeng) --- .../hadoop/hbase/regionserver/HRegion.java | 1 + .../hbase/regionserver/TestHRegion.java | 24 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java index 7f889ce624c..a87b679ba56 100644 --- a/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java +++ b/hbase-server/src/main/java/org/apache/hadoop/hbase/regionserver/HRegion.java @@ -6966,6 +6966,7 @@ public class HRegion implements HeapSize, PropagatingConfigurationObserver, Regi @Override public void mutateRowsWithLocks(Collection mutations, Collection rowsToLock, long nonceGroup, long nonce) throws IOException { + writeRequestsCount.add(mutations.size()); MultiRowMutationProcessor proc = new MultiRowMutationProcessor(mutations, rowsToLock); processRowsWithLocks(proc, -1, nonceGroup, nonce); } diff --git a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java index eac3c77b463..d56d6ecf2ac 100644 --- a/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java +++ b/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestHRegion.java @@ -6391,4 +6391,28 @@ public class TestHRegion { this.region = null; } } + + @Test + public void testMutateRow_WriteRequestCount() throws Exception { + byte[] row1 = Bytes.toBytes("row1"); + byte[] fam1 = Bytes.toBytes("fam1"); + byte[] qf1 = Bytes.toBytes("qualifier"); + byte[] val1 = Bytes.toBytes("value1"); + + RowMutations rm = new RowMutations(row1); + Put put = new Put(row1); + put.addColumn(fam1, qf1, val1); + rm.add(put); + + this.region = initHRegion(tableName, method, CONF, fam1); + try { + long wrcBeforeMutate = this.region.writeRequestsCount.longValue(); + this.region.mutateRow(rm); + long wrcAfterMutate = this.region.writeRequestsCount.longValue(); + Assert.assertEquals(wrcBeforeMutate + rm.getMutations().size(), wrcAfterMutate); + } finally { + HBaseTestingUtility.closeRegionAndWAL(this.region); + this.region = null; + } + } }