hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From li...@apache.org
Subject svn commit: r1588121 - in /hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master: RegionPlacementTestBase.java TestRegionPlacement.java
Date Thu, 17 Apr 2014 00:49:26 GMT
Author: liyin
Date: Thu Apr 17 00:49:26 2014
New Revision: 1588121

URL: http://svn.apache.org/r1588121
Log:
[master] Pinned table tests for RegionPlacement

Author: elliott

Summary: Add test to make sure tables stay pinned after creation.

Test Plan: bin/test/loop_tests.sh -n 3 -t TestRegionPlacement

Reviewers: adela, daviddeng

Reviewed By: adela

CC: hbase-eng@

Differential Revision: https://phabricator.fb.com/D1280894

Task ID: 4114856

Modified:
    hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/RegionPlacementTestBase.java
    hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java

Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/RegionPlacementTestBase.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/RegionPlacementTestBase.java?rev=1588121&r1=1588120&r2=1588121&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/RegionPlacementTestBase.java
(original)
+++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/RegionPlacementTestBase.java
Thu Apr 17 00:49:26 2014
@@ -46,6 +46,7 @@ import java.util.ArrayList;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
+import java.util.Set;
 import java.util.concurrent.atomic.AtomicInteger;
 
 import static org.junit.Assert.assertEquals;
@@ -129,6 +130,9 @@ public class RegionPlacementTestBase {
   }
 
   protected void waitOnTable(String tableName) throws IOException {
+
+    TEST_UTIL.waitForTableConsistent();
+
     HTable ht = new HTable(TEST_UTIL.getConfiguration(), tableName);
     Scan s = new Scan();
     ResultScanner rs = null;
@@ -532,6 +536,29 @@ public class RegionPlacementTestBase {
     return expected.equals(rswithNumRegions);
   }
 
+  protected void assertPinned(String tableName, MiniHBaseCluster cluster,
+      Set<HServerAddress> servers, HRegionServer unusedServer) throws IOException {
+    // The un-used server should have no regions from testPinnedTable
+    for (HRegion hr : unusedServer.getOnlineRegions()) {
+      assertTrue("The Un-used server should not have a user table on it",
+          !hr.getTableDesc().getNameAsString().equals(tableName));
+    }
+
+    // all of the regions of testPinnedTable are on the pinned servers
+    int onPinned = 0;
+    for (int i = 0; i < cluster.getRegionServers().size(); i++) {
+      HRegionServer hrs = cluster.getRegionServer(i);
+      for (HRegion hRegion : hrs.getOnlineRegions()) {
+        if (hRegion.getTableDesc().getNameAsString().equals(tableName)) {
+          assertTrue("Region " + hRegion.toString() + " should be on one of the pinned servers",
+              servers.contains(hrs.getServerInfo().getServerAddress()));
+          onPinned += 1;
+        }
+      }
+    }
+    assertEquals("Expecting " + REGION_NUM + " regions on pinned servers", REGION_NUM, onPinned);
+  }
+
   protected void cleanUp() throws IOException, InterruptedException {
     final HBaseAdmin admin = TEST_UTIL.getHBaseAdmin();
     for (HTableDescriptor htd : admin.listTables()) {

Modified: hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java
URL: http://svn.apache.org/viewvc/hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java?rev=1588121&r1=1588120&r2=1588121&view=diff
==============================================================================
--- hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java
(original)
+++ hbase/branches/0.89-fb/src/test/java/org/apache/hadoop/hbase/master/TestRegionPlacement.java
Thu Apr 17 00:49:26 2014
@@ -19,30 +19,35 @@
  */
 package org.apache.hadoop.hbase.master;
 
+import org.apache.hadoop.hbase.HColumnDescriptor;
+import org.apache.hadoop.hbase.HServerAddress;
+import org.apache.hadoop.hbase.HTableDescriptor;
 import org.apache.hadoop.hbase.MiniHBaseCluster;
+import org.apache.hadoop.hbase.client.HBaseAdmin;
 import org.apache.hadoop.hbase.master.RegionManager.AssignmentLoadBalancer;
 import org.apache.hadoop.hbase.master.RegionManager.LoadBalancer;
-import org.apache.hadoop.hbase.util.TagRunner;
+import org.apache.hadoop.hbase.regionserver.HRegionServer;
+import org.apache.hadoop.hbase.util.Bytes;
 import org.codehaus.jackson.map.ObjectMapper;
 import org.junit.After;
 import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Test;
-import org.junit.runner.RunWith;
 
 import java.io.IOException;
 import java.util.Arrays;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.Map;
 import java.util.Random;
+import java.util.Set;
 
 import static org.junit.Assert.assertEquals;
 import static org.junit.Assert.assertTrue;
 
-@RunWith(TagRunner.class)
 public class TestRegionPlacement extends RegionPlacementTestBase {
 
-  private final static int SLAVES = 3;
+  private final static int SLAVES = 4;
 
   @BeforeClass
   public static void setupBeforeClass() throws Exception {
@@ -91,20 +96,21 @@ public class TestRegionPlacement extends
     // NumRegions -> Num Region Server with that num regions.
     Map<Integer, Integer> expected = new HashMap<Integer, Integer>();
 
-    // we expect 2 regionservers with 3 regions and 1 with 4 regions
-    expected.put(4, 1);
+    // we expect 2 regionservers with 3 regions and 2 with 2 regions
     expected.put(3, 2);
+    expected.put(2, 2);
 
     waitOnTable(tableName);
     waitOnStableRegionMovement();
 
+
     assertTrue(verifyNumPrimaries(expected, plan));
 
     //create additional table with 5 regions
-    createTable(tableNameTwo, 5);
+    createTable(tableNameTwo, 6);
     expected.clear();
-    // after this we expect 3 regionservers with 5 regions
-    expected.put(5, 3);
+    // after this we expect 4 regionservers with 4 regions
+    expected.put(4, 4);
 
     waitOnTable(tableName);
     waitOnTable(tableNameTwo);
@@ -201,10 +207,73 @@ public class TestRegionPlacement extends
   }
 
   /**
+   * Test to make sure that tables created with a specific server set
+   * will remain on those servers though region plan creation and updating.
+   *
+   * @throws Exception
+   */
+  @Test(timeout = 180000)
+  public void testPinnedTable() throws Exception {
+    String tableName = "testPinnedTable";
+
+    resetLastOpenedRegionCount();
+    resetLastRegionOnPrimary();
+
+    try {
+      MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
+
+      HTableDescriptor htd = new HTableDescriptor(tableName);
+      htd.addFamily(new HColumnDescriptor("d"));
+
+      Set<HServerAddress> servers = new HashSet<HServerAddress>(3);
+      HRegionServer unusedServer = cluster.getRegionServer(3);
+
+      for (int i =0 ; i <3; i++) {
+        servers.add(cluster.getRegionServer(i).getServerInfo().getServerAddress());
+      }
+
+      htd.setServers(servers);
+      admin = new HBaseAdmin(TEST_UTIL.getConfiguration());
+      admin.createTable(htd, Bytes.toBytes("aaaa"), Bytes.toBytes("zzzz"), REGION_NUM);
+
+      // Wait for things to stabilize
+      waitOnTable(tableName);
+      waitOnStableRegionMovement();
+
+      // Reset all of the counters.
+      resetLastRegionOnPrimary();
+      resetLastOpenedRegionCount();
+
+      verifyRegionAssignment(rp.getExistingAssignmentPlan(), 0, REGION_NUM);
+      assertPinned(tableName, cluster, servers, unusedServer);
+
+      // Generate and apply a new region plan.
+      rp.updateAssignmentPlan(rp.getNewAssignmentPlan());
+
+      // Wait for things to stabilize
+      waitOnTable(tableName);
+      waitOnStableRegionMovement();
+
+      // Verify current plan
+      verifyRegionAssignment(rp.getExistingAssignmentPlan(), 0, REGION_NUM);
+      // Make sure the plans are stable.
+      verifyRegionAssignment(rp.getNewAssignmentPlan(), 0, REGION_NUM);
+
+      // Assert that the regions are still on the correct servers
+      // Though they really should be since there haven't been any region moves.
+      assertPinned(tableName, cluster, servers, unusedServer);
+
+    } finally {
+      if (admin != null) admin.close();
+    }
+  }
+
+
+  /**
    * Used to test the correctness of this class.
    */
   @Test
-  public void testRandomizedMatrix() {
+  public void testRandomizedMatrix() throws Exception {
     int rows = 100;
     int cols = 100;
     float[][] matrix = new float[rows][cols];



Mime
View raw message