HBASE-7717 Wait until regions are assigned in TestSplitTransactionOnCluster (Lars H and Ted Yu)

git-svn-id: https://svn.apache.org/repos/asf/hbase/trunk@1440800 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Zhihong Yu 2013-01-31 02:25:03 +00:00
parent e1118764de
commit e2468f61f3
1 changed files with 97 additions and 97 deletions

View File

@ -89,9 +89,9 @@ public class TestSplitTransactionOnCluster {
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 TestSplitTransactionOnCluster {
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 TestSplitTransactionOnCluster {
SplitRegionHandler.TEST_SKIP = false;
admin.setBalancerRunning(true, false);
cluster.getMaster().setCatalogJanitorEnabled(true);
t.close();
}
}
@ -249,6 +330,7 @@ public class TestSplitTransactionOnCluster {
} finally {
admin.setBalancerRunning(true, false);
cluster.getMaster().setCatalogJanitorEnabled(true);
t.close();
}
}
@ -302,6 +384,7 @@ public class TestSplitTransactionOnCluster {
} finally {
admin.setBalancerRunning(true, false);
cluster.getMaster().setCatalogJanitorEnabled(true);
t.close();
}
}
@ -373,6 +456,7 @@ public class TestSplitTransactionOnCluster {
} finally {
admin.setBalancerRunning(true, false);
cluster.getMaster().setCatalogJanitorEnabled(true);
t.close();
}
}
@ -448,6 +532,7 @@ public class TestSplitTransactionOnCluster {
SplitRegionHandler.TEST_SKIP = false;
admin.setBalancerRunning(true, false);
cluster.getMaster().setCatalogJanitorEnabled(true);
t.close();
}
}
@ -521,6 +606,7 @@ public class TestSplitTransactionOnCluster {
SplitRegionHandler.TEST_SKIP = false;
this.admin.setBalancerRunning(true, false);
cluster.getMaster().setCatalogJanitorEnabled(true);
t.close();
}
}
@ -541,94 +627,6 @@ public class TestSplitTransactionOnCluster {
testSplitBeforeSettingSplittingInZKInternals();
}
@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 =
@ -638,10 +636,8 @@ public class TestSplitTransactionOnCluster {
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 TestSplitTransactionOnCluster {
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);