hbase-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From mberto...@apache.org
Subject svn commit: r1452996 - /hbase/trunk/hbase-server/src/test/java/org/apache/hadoop/hbase/regionserver/TestSplitTransactionOnCluster.java
Date Tue, 05 Mar 2013 21:03:56 GMT
Author: mbertozzi
Date: Tue Mar  5 21:03:56 2013
New Revision: 1452996

URL: http://svn.apache.org/r1452996
Log:
HBASE-7686 TestSplitTransactionOnCluster fails occasionally in trunk builds -- MORE DEBUG

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=1452996&r1=1452995&r2=1452996&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
Tue Mar  5 21:03:56 2013
@@ -69,6 +69,7 @@ import org.apache.zookeeper.KeeperExcept
 import org.apache.zookeeper.KeeperException.NodeExistsException;
 import org.apache.zookeeper.data.Stat;
 import org.junit.AfterClass;
+import org.junit.After;
 import org.junit.Before;
 import org.junit.BeforeClass;
 import org.junit.Test;
@@ -115,6 +116,11 @@ public class TestSplitTransactionOnClust
     this.cluster = TESTING_UTIL.getMiniHBaseCluster();
   }
 
+  @After
+  public void tearDown() throws Exception {
+    this.admin.close();
+  }
+
   private HRegionInfo getAndCheckSingleTableRegion(final List<HRegion> regions) {
     assertEquals(1, regions.size());
     return regions.get(0).getRegionInfo();
@@ -124,7 +130,6 @@ public class TestSplitTransactionOnClust
   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 = createTableAndWait(tableName, Bytes.toBytes("cf"));
@@ -133,15 +138,21 @@ public class TestSplitTransactionOnClust
       int regionServerIndex = cluster.getServerWith(regions.get(0).getRegionName());
       final HRegionServer regionServer = cluster.getRegionServer(regionServerIndex);
       insertData(tableName, admin, t);
+      t.close();
+
       // Turn off balancer so it doesn't cut in and mess up our placements.
-      this.admin.setBalancerRunning(false, false);
+      this.admin.setBalancerRunning(false, true);
       // Turn off the meta scanner so it don't remove parent on us.
       cluster.getMaster().setCatalogJanitorEnabled(false);
 
+      // find a splittable region
+      final HRegion region = findSplittableRegion(regions);
+      assertTrue("not able to find a splittable region", region != null);
+
       new Thread() {
         public void run() {
           SplitTransaction st = null;
-          st = new MockedSplitTransaction(regions.get(0), Bytes.toBytes("row2"));
+          st = new MockedSplitTransaction(region, Bytes.toBytes("row2"));
           try {
             st.prepare();
             st.execute(regionServer, regionServer);
@@ -154,8 +165,7 @@ public class TestSplitTransactionOnClust
         Thread.sleep(100);
       }
       assertTrue("Waited too long for rollback", callRollBack);
-      SplitTransaction st = null;
-      st = new MockedSplitTransaction(regions.get(0), Bytes.toBytes("row2"));
+      SplitTransaction st = new MockedSplitTransaction(region, Bytes.toBytes("row3"));
       try {
         secondSplit = true;
         st.prepare();
@@ -191,11 +201,7 @@ public class TestSplitTransactionOnClust
       firstSplitCompleted = false;
       callRollBack = false;
       cluster.getMaster().setCatalogJanitorEnabled(true);
-      if (admin.isTableAvailable(tableName) && admin.isTableEnabled(tableName)) {
-        admin.disableTable(tableName);
-        admin.deleteTable(tableName);
-        admin.close();
-      }
+      TESTING_UTIL.deleteTable(tableName);
     }
   }
 
@@ -638,24 +644,23 @@ public class TestSplitTransactionOnClust
   public void testTableExistsIfTheSpecifiedTableRegionIsSplitParent() throws Exception {
     final byte[] tableName =
         Bytes.toBytes("testTableExistsIfTheSpecifiedTableRegionIsSplitParent");
-    HRegionServer regionServer = null;
-    List<HRegion> regions = null;
-    HBaseAdmin admin = new HBaseAdmin(TESTING_UTIL.getConfiguration());
+    // Create table then get the single region for our new table.
+    HTable t = createTableAndWait(tableName, Bytes.toBytes("cf"));
     try {
-      // Create table then get the single region for our new table.
-      HTable t = createTableAndWait(tableName, Bytes.toBytes("cf"));
-      regions = cluster.getRegions(tableName);
+      List<HRegion> regions = cluster.getRegions(tableName);
       int regionServerIndex = cluster.getServerWith(regions.get(0).getRegionName());
-      regionServer = cluster.getRegionServer(regionServerIndex);
+      HRegionServer regionServer = cluster.getRegionServer(regionServerIndex);
       insertData(tableName, admin, t);
       // Turn off balancer so it doesn't cut in and mess up our placements.
-      admin.setBalancerRunning(false, false);
+      admin.setBalancerRunning(false, true);
       // Turn off the meta scanner so it don't remove parent on us.
       cluster.getMaster().setCatalogJanitorEnabled(false);
       boolean tableExists = MetaReader.tableExists(regionServer.getCatalogTracker(),
           Bytes.toString(tableName));
       assertEquals("The specified table should present.", true, tableExists);
-      SplitTransaction st = new SplitTransaction(regions.get(0), Bytes.toBytes("row2"));
+      final HRegion region = findSplittableRegion(regions);
+      assertTrue("not able to find a splittable region", region != null);
+      SplitTransaction st = new SplitTransaction(region, Bytes.toBytes("row2"));
       try {
         st.prepare();
         st.createDaughters(regionServer, regionServer);
@@ -668,7 +673,7 @@ public class TestSplitTransactionOnClust
     } finally {
       admin.setBalancerRunning(true, false);
       cluster.getMaster().setCatalogJanitorEnabled(true);
-      admin.close();
+      t.close();
     }
   }
 
@@ -701,23 +706,28 @@ public class TestSplitTransactionOnClust
     int regionServerIndex = cluster.getServerWith(regions.get(0).getRegionName());
     HRegionServer regionServer = cluster.getRegionServer(regionServerIndex);
     // Turn off balancer so it doesn't cut in and mess up our placements.
-    this.admin.setBalancerRunning(false, false);
+    this.admin.setBalancerRunning(false, true);
     // Turn off the meta scanner so it don't remove parent on us.
     cluster.getMaster().setCatalogJanitorEnabled(false);
     try {
       HRegionServer server = cluster.getRegionServer(tableRegionIndex);
       printOutRegions(server, "Initial regions: ");
+
+      // find a splittable region
+      final HRegion region = findSplittableRegion(regions);
+      assertTrue("not able to find a splittable region", region != null);
+
       // Now split.
-      SplitTransaction st = null;
-      st = new MockedSplitTransaction(regions.get(0), null);
+      SplitTransaction st = new MockedSplitTransaction(region, Bytes.toBytes("row2"));
       try {
+        st.prepare();
         st.execute(regionServer, regionServer);
       } catch (IOException e) {
         List<HRegion> daughters = cluster.getRegions(tableName);
         assertTrue(daughters.size() == 1);
 
-        String node = ZKAssign.getNodeName(regionServer.getZooKeeper(), regions.get(0)
-            .getRegionInfo().getEncodedName());
+        String node = ZKAssign.getNodeName(regionServer.getZooKeeper(),
+            region.getRegionInfo().getEncodedName());
         assertFalse(ZKUtil.checkExists(regionServer.getZooKeeper(), node) == -1);
         assertTrue(st.rollback(regionServer, regionServer));
         assertTrue(ZKUtil.checkExists(regionServer.getZooKeeper(), node) == -1);
@@ -731,37 +741,26 @@ public class TestSplitTransactionOnClust
 
   private void testSplitBeforeSettingSplittingInZKInternals() throws Exception {
     final byte[] tableName = Bytes.toBytes("testSplitBeforeSettingSplittingInZK");
-    HBaseAdmin admin = TESTING_UTIL.getHBaseAdmin();
     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);
-      for (int i = 0; cluster.getRegions(tableName).size() == 0 && i < 100; i++)
{
-        Thread.sleep(100);
-      }
+      HTable t = createTableAndWait(tableName, Bytes.toBytes("cf"));
+
+      List<HRegion> regions = awaitTableRegions(tableName);
       assertTrue("Table not online", cluster.getRegions(tableName).size() != 0);
 
-      List<HRegion> regions = null;
-      for (int i=0; i<100; i++) {
-        regions = cluster.getRegions(tableName);
-        if (regions.size() > 0) break;
-        Thread.sleep(100);
-      }
       int regionServerIndex = cluster.getServerWith(regions.get(0).getRegionName());
       HRegionServer regionServer = cluster.getRegionServer(regionServerIndex);
-      SplitTransaction st = null;
-      {
-        st = new MockedSplitTransaction(regions.get(0), null) {
-          @Override
-          int createNodeSplitting(ZooKeeperWatcher zkw, HRegionInfo region, ServerName serverName)
-              throws KeeperException, IOException {
-            throw new SplittingNodeCreationFailedException ();
-          }
-        };
-      }
-      String node = ZKAssign.getNodeName(regionServer.getZooKeeper(), regions.get(0)
-          .getRegionInfo().getEncodedName());
+      final HRegion region = findSplittableRegion(regions);
+      assertTrue("not able to find a splittable region", region != null);
+      SplitTransaction st = new MockedSplitTransaction(region, Bytes.toBytes("row2")) {
+        @Override
+        int createNodeSplitting(ZooKeeperWatcher zkw, HRegionInfo region, ServerName serverName)
+            throws KeeperException, IOException {
+          throw new SplittingNodeCreationFailedException ();
+        }
+      };
+      String node = ZKAssign.getNodeName(regionServer.getZooKeeper(),
+          region.getRegionInfo().getEncodedName());
       regionServer.getZooKeeper().sync(node);
       for (int i = 0; i < 100; i++) {
         // We expect the znode to be deleted by this time. Here the
@@ -772,6 +771,7 @@ public class TestSplitTransactionOnClust
         }
       }
       try {
+        st.prepare();
         st.execute(regionServer, regionServer);
       } catch (IOException e) {
         // check for the specific instance in case the Split failed due to the
@@ -779,8 +779,8 @@ public class TestSplitTransactionOnClust
         // This will at least make the test to fail;
         assertTrue("Should be instance of CreateSplittingNodeFailedException",
             e instanceof SplittingNodeCreationFailedException );
-        node = ZKAssign.getNodeName(regionServer.getZooKeeper(), regions.get(0).getRegionInfo()
-            .getEncodedName());
+        node = ZKAssign.getNodeName(regionServer.getZooKeeper(),
+            region.getRegionInfo().getEncodedName());
         {
           assertTrue(ZKUtil.checkExists(regionServer.getZooKeeper(), node) == -1);
         }
@@ -788,10 +788,7 @@ public class TestSplitTransactionOnClust
         assertTrue(ZKUtil.checkExists(regionServer.getZooKeeper(), node) == -1);
       }
     } finally {
-      if (admin.isTableAvailable(tableName) && admin.isTableEnabled(tableName)) {
-        admin.disableTable(tableName);
-        admin.deleteTable(tableName);
-      }
+      TESTING_UTIL.deleteTable(tableName);
     }
   }
 
@@ -838,6 +835,19 @@ public class TestSplitTransactionOnClust
 
   }
 
+  private HRegion findSplittableRegion(final List<HRegion> regions) throws InterruptedException
{
+    HRegion region = null;
+    for (int i = 0; i < 5; ++i) {
+      for (HRegion r: regions) {
+        if (r.isSplittable()) {
+          return(r);
+        }
+      }
+      Thread.sleep(100);
+    }
+    return(null);
+  }
+
   private List<HRegion> checkAndGetDaughters(byte[] tableName)
       throws InterruptedException {
     List<HRegion> daughters = null;
@@ -863,14 +873,14 @@ public class TestSplitTransactionOnClust
     return master;
   }
 
-  private void split(final HRegionInfo hri, final HRegionServer server,
-      final int regionCount)
-  throws IOException, InterruptedException {
+  private void split(final HRegionInfo hri, final HRegionServer server, final int regionCount)
+      throws IOException, InterruptedException {
     this.admin.split(hri.getRegionNameAsString());
     for (int i = 0; ProtobufUtil.getOnlineRegions(server).size() <= regionCount &&
i < 100; i++) {
       LOG.debug("Waiting on region to split");
       Thread.sleep(100);
     }
+
     assertFalse("Waited too long for split",
         ProtobufUtil.getOnlineRegions(server).size() <= regionCount);
   }
@@ -901,7 +911,6 @@ public class TestSplitTransactionOnClust
       final HRegionInfo hri)
   throws UnknownRegionException, MasterNotRunningException,
   ZooKeeperConnectionException, InterruptedException {
-    MiniHBaseCluster cluster = TESTING_UTIL.getMiniHBaseCluster();
     // Now make sure that the table region is not on same server as that hosting
     // .META.  We don't want .META. replay polluting our test when we later crash
     // the table region serving server.
@@ -987,14 +996,22 @@ public class TestSplitTransactionOnClust
     }
   }
 
+  private List<HRegion> awaitTableRegions(final byte[] tableName) throws InterruptedException
{
+    List<HRegion> regions = null;
+    for (int i = 0; i < 100; i++) {
+      regions = cluster.getRegions(tableName);
+      if (regions.size() > 0) break;
+      Thread.sleep(100);
+    }
+    return regions;
+  }
+
   private HTable createTableAndWait(byte[] tableName, byte[] cf) throws IOException,
       InterruptedException {
     HTable t = TESTING_UTIL.createTable(tableName, cf);
-    for (int i = 0; cluster.getRegions(tableName).size() == 0 && i < 100; i++)
{
-      Thread.sleep(100);
-    }
-    assertTrue("Table not online: " + Bytes.toString(tableName), cluster.getRegions(tableName)
-        .size() != 0);
+    awaitTableRegions(tableName);
+    assertTrue("Table not online: " + Bytes.toString(tableName),
+      cluster.getRegions(tableName).size() != 0);
     return t;
   }
 



Mime
View raw message