hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From te...@apache.org
Subject svn commit: r1440800 - /hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java
Date Thu, 31 Jan 2013 02:25:04 GMT
Author: tedyu
Date: Thu Jan 31 02:25:03 2013
New Revision: 1440800

URL: http://svn.apache.org/viewvc?rev=1440800&view=rev
Log:
HBASE-7717 Wait until regions are assigned in TestSplitTransactionOnCluster (Lars H and Ted
Yu)


Modified:
    hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java

Modified: hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java
URL: http://svn.apache.org/viewvc/hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java?rev=1440800&r1=1440799&r2=1440800&view=diff
==============================================================================
--- hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java
(original)
+++ hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java
Thu Jan 31 02:25:03 2013
@@ -89,9 +89,9 @@ public class TestSplitTransactionOnClust
   private MiniHBaseCluster cluster = null;
   private static final int NB_SERVERS = 2;
   private static CountDownLatch latch = new CountDownLatch(1);
-  private static boolean secondSplit = false;
-  private static boolean callRollBack = false;
-  private static boolean firstSplitCompleted = false;
+  private static volatile boolean secondSplit = false;
+  private static volatile boolean callRollBack = false;
+  private static volatile boolean firstSplitCompleted = false;
 
   private static final HBaseTestingUtility TESTING_UTIL =
     new HBaseTestingUtility();
@@ -120,7 +120,87 @@ public class TestSplitTransactionOnClust
     return regions.get(0).getRegionInfo();
   }
 
-  /**
+  @Test(timeout = 20000)
+  public void testShouldFailSplitIfZNodeDoesNotExistDueToPrevRollBack() throws Exception
{
+    final byte[] tableName = Bytes
+        .toBytes("testShouldFailSplitIfZNodeDoesNotExistDueToPrevRollBack");
+    HBaseAdmin admin = new HBaseAdmin(TESTING_UTIL.getConfiguration());
+    try {
+      // Create table then get the single region for our new table.
+      HTable t = TESTING_UTIL.createTable(tableName, Bytes.toBytes("cf"));
+
+      final List<HRegion> regions = cluster.getRegions(tableName);
+      HRegionInfo hri = getAndCheckSingleTableRegion(regions);
+      int regionServerIndex = cluster.getServerWith(regions.get(0).getRegionName());
+      final HRegionServer regionServer = cluster.getRegionServer(regionServerIndex);
+      insertData(tableName, admin, t);
+      // Turn off balancer so it doesn't cut in and mess up our placements.
+      this.admin.setBalancerRunning(false, false);
+      // Turn off the meta scanner so it don't remove parent on us.
+      cluster.getMaster().setCatalogJanitorEnabled(false);
+
+      new Thread() {
+        public void run() {
+          SplitTransaction st = null;
+          st = new MockedSplitTransaction(regions.get(0), Bytes.toBytes("row2"));
+          try {
+            st.prepare();
+            st.execute(regionServer, regionServer);
+          } catch (IOException e) {
+
+          }
+        }
+      }.start();
+      for (int i = 0; !callRollBack && i < 100; i++) {
+        Thread.sleep(100);
+      }
+      assertTrue("Waited too long for rollback", callRollBack);
+      SplitTransaction st = null;
+      st = new MockedSplitTransaction(regions.get(0), Bytes.toBytes("row2"));
+      try {
+        secondSplit = true;
+        st.prepare();
+        st.execute(regionServer, regionServer);
+      } catch (IOException e) {
+        LOG.debug("Rollback started :"+ e.getMessage());
+        st.rollback(regionServer, regionServer);
+      }
+      for (int i=0; !firstSplitCompleted && i<100; i++) {
+        Thread.sleep(100);
+      }
+      assertTrue("fist split did not complete", firstSplitCompleted);
+
+      RegionStates regionStates = cluster.getMaster().getAssignmentManager().getRegionStates();
+      Map<String, RegionState> rit = regionStates.getRegionsInTransition();
+      
+      for (int i=0; rit.containsKey(hri.getTableNameAsString()) && i<100; i++)
{
+        Thread.sleep(100);
+      }
+      assertFalse("region still in transition", rit.containsKey(rit.containsKey(hri.getTableNameAsString())));
+
+      List<HRegion> onlineRegions = regionServer.getOnlineRegions(tableName);
+      // Region server side split is successful.
+      assertEquals("The parent region should be splitted", 2, onlineRegions.size());
+      //Should be present in RIT
+      List<HRegionInfo> regionsOfTable = cluster.getMaster().getAssignmentManager()
+          .getRegionStates().getRegionsOfTable(tableName);
+      // Master side should also reflect the same
+      assertEquals("No of regions in master", 2, regionsOfTable.size());
+    } finally {
+      admin.setBalancerRunning(true, false);
+      secondSplit = false;
+      firstSplitCompleted = false;
+      callRollBack = false;
+      cluster.getMaster().setCatalogJanitorEnabled(true);
+      if (admin.isTableAvailable(tableName) && admin.isTableEnabled(tableName)) {
+        admin.disableTable(tableName);
+        admin.deleteTable(tableName);
+        admin.close();
+      }
+    }
+  }
+
+ /**
    * A test that intentionally has master fail the processing of the split message.
    * Tests that the regionserver split ephemeral node gets cleaned up if it
    * crashes and that after we process server shutdown, the daughters are up on
@@ -198,6 +278,7 @@ public class TestSplitTransactionOnClust
       SplitRegionHandler.TEST_SKIP = false;
       admin.setBalancerRunning(true, false);
       cluster.getMaster().setCatalogJanitorEnabled(true);
+      t.close();
     }
   }
 
@@ -249,6 +330,7 @@ public class TestSplitTransactionOnClust
     } finally {
       admin.setBalancerRunning(true, false);
       cluster.getMaster().setCatalogJanitorEnabled(true);
+      t.close();
     }
   }
 
@@ -302,6 +384,7 @@ public class TestSplitTransactionOnClust
     } finally {
       admin.setBalancerRunning(true, false);
       cluster.getMaster().setCatalogJanitorEnabled(true);
+      t.close();
     }
   }
 
@@ -373,6 +456,7 @@ public class TestSplitTransactionOnClust
     } finally {
       admin.setBalancerRunning(true, false);
       cluster.getMaster().setCatalogJanitorEnabled(true);
+      t.close();
     }
   }
   
@@ -448,6 +532,7 @@ public class TestSplitTransactionOnClust
       SplitRegionHandler.TEST_SKIP = false;
       admin.setBalancerRunning(true, false);
       cluster.getMaster().setCatalogJanitorEnabled(true);
+      t.close();
     }
   }
 
@@ -521,6 +606,7 @@ public class TestSplitTransactionOnClust
       SplitRegionHandler.TEST_SKIP = false;
       this.admin.setBalancerRunning(true, false);
       cluster.getMaster().setCatalogJanitorEnabled(true);
+      t.close();
     }
   }
 
@@ -542,94 +628,6 @@ public class TestSplitTransactionOnClust
   }
   
   @Test(timeout = 20000)
-  public void testShouldFailSplitIfZNodeDoesNotExistDueToPrevRollBack() throws Exception
{
-    final byte[] tableName = Bytes
-        .toBytes("testShouldFailSplitIfZNodeDoesNotExistDueToPrevRollBack");
-    HBaseAdmin admin = new HBaseAdmin(TESTING_UTIL.getConfiguration());
-    try {
-      // Create table then get the single region for our new table.
-      HTableDescriptor htd = new HTableDescriptor(tableName);
-      htd.addFamily(new HColumnDescriptor("cf"));
-      admin.createTable(htd);
-      HTable t = new HTable(cluster.getConfiguration(), tableName);
-      // wait for up to 10s
-      for (int i=0; cluster.getRegions(tableName).size() != 1 && i<100; i++) {
-        Thread.sleep(100);
-      }
-      assertTrue("waited too long for table to get online",
-          cluster.getRegions(tableName).size() == 1);
-      final List<HRegion> regions = cluster.getRegions(tableName);
-      HRegionInfo hri = getAndCheckSingleTableRegion(regions);
-      int regionServerIndex = cluster.getServerWith(regions.get(0).getRegionName());
-      final HRegionServer regionServer = cluster.getRegionServer(regionServerIndex);
-      insertData(tableName, admin, t);
-      // Turn off balancer so it doesn't cut in and mess up our placements.
-      this.admin.setBalancerRunning(false, false);
-      // Turn off the meta scanner so it don't remove parent on us.
-      cluster.getMaster().setCatalogJanitorEnabled(false);
-
-      new Thread() {
-        public void run() {
-          SplitTransaction st = null;
-          st = new MockedSplitTransaction(regions.get(0), Bytes.toBytes("row2"));
-          try {
-            st.prepare();
-            st.execute(regionServer, regionServer);
-          } catch (IOException e) {
-
-          }
-        }
-      }.start();
-      for (int i=0; !callRollBack && i<100; i++) {
-        Thread.sleep(100);
-      }
-      assertTrue("Waited too long for rollback", callRollBack);
-      SplitTransaction st = null;
-      st = new MockedSplitTransaction(regions.get(0), Bytes.toBytes("row2"));
-      try {
-        secondSplit = true;
-        st.prepare();
-        st.execute(regionServer, regionServer);
-      } catch (IOException e) {
-        LOG.debug("Rollback started :"+ e.getMessage());
-        st.rollback(regionServer, regionServer);
-      }
-      for (int i=0; !firstSplitCompleted && i<100; i++) {
-        Thread.sleep(100);
-      }
-      assertTrue("fist split did not complete", firstSplitCompleted);
-
-      RegionStates regionStates = cluster.getMaster().getAssignmentManager().getRegionStates();
-      Map<String, RegionState> rit = regionStates.getRegionsInTransition();
-      
-      for (int i=0; rit.containsKey(hri.getTableNameAsString()) && i<100; i++)
{
-        Thread.sleep(100);
-      }
-      assertFalse("region still in transition", rit.containsKey(rit.containsKey(hri.getTableNameAsString())));
-
-      List<HRegion> onlineRegions = regionServer.getOnlineRegions(tableName);
-      // Region server side split is successful.
-      assertEquals("The parent region should be splitted", 2, onlineRegions.size());
-      //Should be present in RIT
-      List<HRegionInfo> regionsOfTable = cluster.getMaster().getAssignmentManager()
-          .getRegionStates().getRegionsOfTable(tableName);
-      // Master side should also reflect the same
-      assertEquals("No of regions in master", 2, regionsOfTable.size());
-    } finally {
-      admin.setBalancerRunning(true, false);
-      secondSplit = false;
-      firstSplitCompleted = false;
-      callRollBack = false;
-      cluster.getMaster().setCatalogJanitorEnabled(true);
-      if (admin.isTableAvailable(tableName) && admin.isTableEnabled(tableName)) {
-        admin.disableTable(tableName);
-        admin.deleteTable(tableName);
-        admin.close();
-      }
-    }
-  }
-
-  @Test(timeout = 20000)
   public void testTableExistsIfTheSpecifiedTableRegionIsSplitParent() throws Exception {
     final byte[] tableName = 
         Bytes.toBytes("testTableExistsIfTheSpecifiedTableRegionIsSplitParent");
@@ -638,10 +636,8 @@ public class TestSplitTransactionOnClust
     HBaseAdmin admin = new HBaseAdmin(TESTING_UTIL.getConfiguration());
     try {
       // Create table then get the single region for our new table.
-      HTableDescriptor htd = new HTableDescriptor(tableName);
-      htd.addFamily(new HColumnDescriptor("cf"));
-      admin.createTable(htd);
-      HTable t = new HTable(cluster.getConfiguration(), tableName);
+      HTable t = TESTING_UTIL.createTable(tableName, Bytes.toBytes("cf"));
+
       regions = cluster.getRegions(tableName);
       int regionServerIndex = cluster.getServerWith(regions.get(0).getRegionName());
       regionServer = cluster.getRegionServer(regionServerIndex);
@@ -736,7 +732,11 @@ public class TestSplitTransactionOnClust
       HTableDescriptor htd = new HTableDescriptor(tableName);
       htd.addFamily(new HColumnDescriptor("cf"));
       admin.createTable(htd);
-
+      for (int i = 0; cluster.getRegions(tableName).size() == 0 && i < 100; i++)
{
+        Thread.sleep(100);
+      }
+      assertTrue("Table not online", cluster.getRegions(tableName).size() != 0);
+        
       List<HRegion> regions = null;
       for (int i=0; i<100; i++) {
         regions = cluster.getRegions(tableName);



Mime
View raw message