hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mbau...@apache.org
Subject svn commit: r1393955 - in /hbase/branches/0.89-fb/src: main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java
Date Thu, 04 Oct 2012 08:41:25 GMT
Author: mbautin
Date: Thu Oct  4 08:41:25 2012
New Revision: 1393955

URL: http://svn.apache.org/viewvc?rev=1393955&view=rev
Log:
[jira] [HBASE-6872] [89-fb] Fix TestRegionServerMetrics.testNumReadsAndWrites

Author: mbautin

Summary: rHBASEEIGHTNINEFBBRANCH1389841 introduced an unstable test in TestRegionServerMetrics:
testNumReadsAndWrites. Read and write counters should be reset to zero before starting the
test.

Test Plan: Run TestRegionServerMetrics

Reviewers: kannan, kranganathan, liyintang

Reviewed By: liyintang

CC: adela, Liyin, aaiyer, avf

Differential Revision: https://reviews.facebook.net/D5853

Modified:
    hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
    hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java

Modified: hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java?rev=1393955&r1=1393954&r2=1393955&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
(original)
+++ hbase/branches/0.89-fb/src/main/java/org/apache/hadoop/hbase/regionserver/HRegionServer.java
Thu Oct  4 08:41:25 2012
@@ -645,8 +645,6 @@ public class HRegionServer implements HR
             }
             // XXX add a field in serverInfo to report to fsOK to master?
             this.serverInfo.setLoad(hsl);
-            numReads.set(0);
-            numWrites.set(0);
             addOutboundMsgs(outboundMessages);
             HMsg msgs[] = this.hbaseMaster.regionServerReport(
               serverInfo, outboundMessages.toArray(EMPTY_HMSG_ARRAY),
@@ -1300,7 +1298,10 @@ public class HRegionServer implements HR
 
   protected void metrics() {
     int numReads = this.numReads.get();
+    this.numReads.addAndGet(-numReads);
+
     int numWrites = this.numWrites.get();
+    this.numWrites.addAndGet(-numWrites);
 
     this.metrics.regions.set(this.onlineRegions.size());
     this.metrics.incrementRequests(numReads + numWrites);

Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java?rev=1393955&r1=1393954&r2=1393955&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java
(original)
+++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/regionserver/TestRegionServerMetrics.java
Thu Oct  4 08:41:25 2012
@@ -21,7 +21,6 @@ package org.apache.hadoop.hbase.regionse
 import static org.junit.Assert.assertEquals;
 
 import java.io.IOException;
-import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Map;
 
@@ -30,13 +29,11 @@ import org.apache.commons.logging.LogFac
 import org.apache.hadoop.hbase.HBaseTestingUtility;
 import org.apache.hadoop.hbase.KeyValue;
 import org.apache.hadoop.hbase.client.Get;
-import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.client.HTable;
 import org.apache.hadoop.hbase.client.Put;
 import org.apache.hadoop.hbase.client.Result;
 import org.apache.hadoop.hbase.regionserver.metrics.SchemaMetrics;
-import org.apache.hadoop.hbase.regionserver.metrics.SchemaMetrics.
-    StoreMetricType;
+import org.apache.hadoop.hbase.regionserver.metrics.SchemaMetrics.StoreMetricType;
 import org.apache.hadoop.hbase.util.Bytes;
 import org.junit.After;
 import org.junit.Assert;
@@ -136,7 +133,7 @@ public class TestRegionServerMetrics {
     // we have getsize & nextsize for each column family
     assertEquals(cfs.length * 2, metrics.length);
 
-    for (int i =0; i < cfs.length; ++i) {
+    for (int i = 0; i < cfs.length; ++i) {
       String prefix = SchemaMetrics.generateSchemaMetricsPrefix(table, cfs[i]);
       String getMetric = prefix + HRegion.METRIC_GETSIZE;
       String nextMetric = prefix + HRegion.METRIC_NEXTSIZE;
@@ -152,6 +149,7 @@ public class TestRegionServerMetrics {
     }
   }
 
+  @SuppressWarnings("unused")
   @Test
   public void testGetNextSize() throws IOException, InterruptedException {
     String rowName = "row1";
@@ -166,7 +164,6 @@ public class TestRegionServerMetrics {
 
     long ts = 1234;
     HTable hTable = TEST_UTIL.createTable(TABLE, new byte[][]{CF1, CF2});
-    HBaseAdmin admin = new HBaseAdmin(TEST_UTIL.getConfiguration());
 
     Put p = new Put(ROW);
     p.add(CF1, CF1, ts, CF1);
@@ -189,12 +186,14 @@ public class TestRegionServerMetrics {
     // only cf2.nextsize is set
     for (Result res : hTable.getScanner(CF2)) {
     }
+
     assertSizeMetric(tableName, cfs,
         new int[] {kvLength, kvLength, 0, kvLength});
 
     // only cf2.nextsize is set
     for (Result res : hTable.getScanner(CF1)) {
     }
+
     assertSizeMetric(tableName, cfs,
         new int[] {kvLength, kvLength, kvLength, kvLength});
 
@@ -215,12 +214,16 @@ public class TestRegionServerMetrics {
         MAX_VERSIONS, NUM_COLS_PER_ROW, NUM_FLUSHES, NUM_REGIONS, 1000);
     final HRegionServer rs =
         TEST_UTIL.getMiniHBaseCluster().getRegionServer(0);
-    rs.doMetrics();
+
+    // This may not be necessary since we verify the number of reads and writes from atomic
+    // variables and not from collected metrics.
+    rs.doMetrics(); 
+    
     for (HRegion r : rs.getOnlineRegions()) {
       Get g = new Get(new byte[]{});
       rs.get(r.getRegionName(), g);
     }
     Assert.assertEquals(rs.getOnlineRegions().size(), rs.getNumReads().get());
-    Assert.assertEquals(rs.getNumWrites().get(), 0);
+    Assert.assertEquals(0, rs.getNumWrites().get());
   }
 }



Mime
View raw message