HBASE-15864 Reuse the testing helper to wait regions in transition

This commit is contained in:
Matteo Bertozzi 2016-05-20 06:49:14 -07:00
parent d038b762a5
commit 233264bc17
9 changed files with 38 additions and 106 deletions

View File

@ -4092,13 +4092,20 @@ public class HBaseTestingUtility extends HBaseCommonTestingUtility {
/**
* Wait until no regions in transition.
* @param timeout How long to wait.
* @throws Exception
* @throws IOException
*/
public void waitUntilNoRegionsInTransition(
final long timeout) throws Exception {
public void waitUntilNoRegionsInTransition(final long timeout) throws IOException {
waitFor(timeout, predicateNoRegionsInTransition());
}
/**
* Wait until no regions in transition. (time limit 15min)
* @throws IOException
*/
public void waitUntilNoRegionsInTransition() throws IOException {
waitUntilNoRegionsInTransition(15 * 60000);
}
/**
* Wait until labels is ready in VisibilityLabelsCache.
* @param timeoutMillis

View File

@ -102,39 +102,39 @@ public class TestRegionRebalancing {
admin.createTable(this.desc, Arrays.copyOfRange(HBaseTestingUtility.KEYS,
1, HBaseTestingUtility.KEYS.length));
this.regionLocator = connection.getRegionLocator(this.desc.getTableName());
MetaTableAccessor.fullScanMetaAndPrint(admin.getConnection());
assertEquals("Test table should have right number of regions",
HBaseTestingUtility.KEYS.length,
this.regionLocator.getStartKeys().length);
// verify that the region assignments are balanced to start out
assertRegionsAreBalanced();
// add a region server - total of 2
LOG.info("Started second server=" +
UTIL.getHBaseCluster().startRegionServer().getRegionServer().getServerName());
UTIL.getHBaseCluster().getMaster().balance();
assertRegionsAreBalanced();
// On a balanced cluster, calling balance() should return true
assert(UTIL.getHBaseCluster().getMaster().balance() == true);
// if we add a server, then the balance() call should return true
// add a region server - total of 3
LOG.info("Started third server=" +
UTIL.getHBaseCluster().startRegionServer().getRegionServer().getServerName());
assert(UTIL.getHBaseCluster().getMaster().balance() == true);
assertRegionsAreBalanced();
// kill a region server - total of 2
LOG.info("Stopped third server=" + UTIL.getHBaseCluster().stopRegionServer(2, false));
UTIL.getHBaseCluster().waitOnRegionServer(2);
waitOnCrashProcessing();
UTIL.getHBaseCluster().getMaster().balance();
assertRegionsAreBalanced();
// start two more region servers - total of 4
LOG.info("Readding third server=" +
UTIL.getHBaseCluster().startRegionServer().getRegionServer().getServerName());
@ -252,10 +252,7 @@ public class TestRegionRebalancing {
Thread.sleep(200);
} catch (InterruptedException e) {}
}
RegionStates regionStates = UTIL.getHBaseCluster().getMaster().getAssignmentManager().getRegionStates();
while (!regionStates.getRegionsInTransition().isEmpty()) {
Threads.sleep(100);
}
UTIL.waitUntilNoRegionsInTransition();
}
}

View File

@ -260,19 +260,13 @@ public class TestHCM {
HTable t = TEST_UTIL.createTable(tn, cf);
TEST_UTIL.waitTableAvailable(tn);
TEST_UTIL.waitUntilNoRegionsInTransition();
while(TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager().
getRegionStates().isRegionsInTransition()){
Thread.sleep(1);
}
final HConnectionImplementation hci = (HConnectionImplementation)t.getConnection();
while (t.getRegionLocation(rk).getPort() != sn.getPort()){
TEST_UTIL.getHBaseAdmin().move(t.getRegionLocation(rk).getRegionInfo().
getEncodedNameAsBytes(), Bytes.toBytes(sn.toString()));
while(TEST_UTIL.getHBaseCluster().getMaster().getAssignmentManager().
getRegionStates().isRegionsInTransition()){
Thread.sleep(1);
}
TEST_UTIL.waitUntilNoRegionsInTransition();
hci.clearRegionCache(tn);
}
Assert.assertNotNull(hci.clusterStatusListener);
@ -753,9 +747,7 @@ public class TestHCM {
HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
// We can wait for all regions to be online, that makes log reading easier when debugging
while (master.getAssignmentManager().getRegionStates().isRegionsInTransition()) {
Thread.sleep(1);
}
TEST_UTIL.waitUntilNoRegionsInTransition();
// Now moving the region to the second server
HRegionLocation toMove = conn.getCachedLocation(TABLE_NAME, ROW).getRegionLocation();
@ -1132,7 +1124,7 @@ public class TestHCM {
@Test
public void testMulti() throws Exception {
HTable table = TEST_UTIL.createMultiRegionTable(TABLE_NAME3, FAM_NAM);
try {
try {
ConnectionManager.HConnectionImplementation conn =
( ConnectionManager.HConnectionImplementation)table.getConnection();
@ -1145,9 +1137,7 @@ public class TestHCM {
HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
// We can wait for all regions to be online, that makes log reading easier when debugging
while (master.getAssignmentManager().getRegionStates().isRegionsInTransition()) {
Thread.sleep(1);
}
TEST_UTIL.waitUntilNoRegionsInTransition();
Put put = new Put(ROW_X);
put.add(FAM_NAM, ROW_X, ROW_X);

View File

@ -52,11 +52,9 @@ import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.apache.hadoop.hbase.client.HTable;
import org.apache.hadoop.hbase.client.RegionLocator;
import org.apache.hadoop.hbase.master.AssignmentManager;
import org.apache.hadoop.hbase.master.HMaster;
import org.apache.hadoop.hbase.master.MasterCoprocessorHost;
import org.apache.hadoop.hbase.master.RegionPlan;
import org.apache.hadoop.hbase.master.RegionState;
import org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv;
import org.apache.hadoop.hbase.procedure2.ProcedureExecutor;
import org.apache.hadoop.hbase.protobuf.ProtobufUtil;
@ -1681,17 +1679,13 @@ public class TestMasterObserver {
master.balanceSwitch(false);
// wait for assignments to finish, if any
AssignmentManager mgr = master.getAssignmentManager();
Set<RegionState> transRegions = mgr.getRegionStates().getRegionsInTransition();
for (RegionState state : transRegions) {
mgr.getRegionStates().waitOnRegionToClearRegionsInTransition(state.getRegion());
}
UTIL.waitUntilNoRegionsInTransition();
// move half the open regions from RS 0 to RS 1
HRegionServer rs = cluster.getRegionServer(0);
byte[] destRS = Bytes.toBytes(cluster.getRegionServer(1).getServerName().toString());
//Make sure no regions are in transition now
waitForRITtoBeZero(master);
UTIL.waitUntilNoRegionsInTransition();
List<HRegionInfo> openRegions = ProtobufUtil.getOnlineRegions(rs.getRSRpcServices());
int moveCnt = openRegions.size()/2;
for (int i=0; i<moveCnt; i++) {
@ -1702,7 +1696,7 @@ public class TestMasterObserver {
}
}
//Make sure no regions are in transition now
waitForRITtoBeZero(master);
UTIL.waitUntilNoRegionsInTransition();
// now trigger a balance
master.balanceSwitch(true);
boolean balanceRun = master.balance();
@ -1715,15 +1709,6 @@ public class TestMasterObserver {
}
}
private void waitForRITtoBeZero(HMaster master) throws Exception {
// wait for assignments to finish
AssignmentManager mgr = master.getAssignmentManager();
Set<RegionState> transRegions = mgr.getRegionStates().getRegionsInTransition();
for (RegionState state : transRegions) {
mgr.getRegionStates().waitOnRegionToClearRegionsInTransition(state.getRegion());
}
}
@Test (timeout=180000)
public void testTableDescriptorsEnumeration() throws Exception {
MiniHBaseCluster cluster = UTIL.getHBaseCluster();

View File

@ -510,11 +510,8 @@ public class TestHFileOutputFormat2 {
if (shouldChangeRegions) {
LOG.info("Changing regions in table");
admin.disableTable(table.getName());
while (util.getMiniHBaseCluster().getMaster().getAssignmentManager().getRegionStates()
.isRegionsInTransition()) {
Threads.sleep(200);
LOG.info("Waiting on table to finish disabling");
}
util.waitUntilNoRegionsInTransition();
util.deleteTable(table.getName());
byte[][] newSplitKeys = generateRandomSplitKeys(14);
table = util.createTable(TABLE_NAME, FAMILIES, newSplitKeys);

View File

@ -81,16 +81,10 @@ public class TestTableDeleteFamilyHandler {
public void setup() throws IOException, InterruptedException {
// Create a table of three families. This will assign a region.
TEST_UTIL.createTable(TABLENAME, FAMILIES);
HTable t = new HTable(TEST_UTIL.getConfiguration(), TABLENAME);
while(TEST_UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager()
.getRegionStates().getRegionsInTransition().size() > 0) {
Thread.sleep(100);
}
// Create multiple regions in all the three column families
while(TEST_UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager()
.getRegionStates().getRegionsInTransition().size() > 0) {
Thread.sleep(100);
}
TEST_UTIL.waitUntilNoRegionsInTransition();
// Load the table with data for all families
TEST_UTIL.loadTable(t, FAMILIES);

View File

@ -164,29 +164,12 @@ public class TestSplitTransactionOnCluster {
this.admin.close();
}
private HRegionInfo getAndCheckSingleTableRegion(final List<HRegion> regions) {
private HRegionInfo getAndCheckSingleTableRegion(final List<HRegion> regions)
throws IOException, InterruptedException {
assertEquals(1, regions.size());
HRegionInfo hri = regions.get(0).getRegionInfo();
return waitOnRIT(hri);
}
/**
* Often region has not yet fully opened. If we try to use it -- do a move for instance -- it
* will fail silently if the region is not yet opened.
* @param hri Region to check if in Regions In Transition... wait until out of transition before
* returning
* @return Passed in <code>hri</code>
*/
private HRegionInfo waitOnRIT(final HRegionInfo hri) {
// Close worked but we are going to open the region elsewhere. Before going on, make sure
// this completes.
while (TESTING_UTIL.getHBaseCluster().getMaster().getAssignmentManager().
getRegionStates().isRegionInTransition(hri)) {
LOG.info("Waiting on region in transition: " +
TESTING_UTIL.getHBaseCluster().getMaster().getAssignmentManager().getRegionStates().
getRegionTransitionState(hri));
Threads.sleep(10);
}
TESTING_UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager()
.waitOnRegionToClearRegionsInTransition(hri, 600000);
return hri;
}
@ -316,13 +299,7 @@ public class TestSplitTransactionOnCluster {
observer.latch.await();
LOG.info("Waiting for region to come out of RIT");
TESTING_UTIL.waitFor(60000, 1000, new Waiter.Predicate<Exception>() {
@Override
public boolean evaluate() throws Exception {
RegionStates regionStates = cluster.getMaster().getAssignmentManager().getRegionStates();
return !regionStates.isRegionsInTransition();
}
});
TESTING_UTIL.waitUntilNoRegionsInTransition(60000);
} finally {
admin.setBalancerRunning(true, false);
cluster.getMaster().setCatalogJanitorEnabled(true);

View File

@ -80,14 +80,7 @@ public class TestOfflineMetaRebuildHole extends OfflineMetaRebuildTestCore {
LOG.info("Waiting for no more RIT");
ZKAssign.blockUntilNoRIT(zkw);
LOG.info("No more RIT in ZK, now doing final test verification");
int tries = 60;
while(TEST_UTIL.getHBaseCluster()
.getMaster().getAssignmentManager().getRegionStates().getRegionsInTransition().size() > 0 &&
tries-- > 0) {
LOG.info("Waiting for RIT: "+TEST_UTIL.getHBaseCluster()
.getMaster().getAssignmentManager().getRegionStates().getRegionsInTransition());
Thread.sleep(1000);
}
TEST_UTIL.waitUntilNoRegionsInTransition(60000);
// Meta still messed up.
assertEquals(1, scanMeta());

View File

@ -88,14 +88,6 @@ public class TestOfflineMetaRebuildOverlap extends OfflineMetaRebuildTestCore {
LOG.info("Waiting for no more RIT");
ZKAssign.blockUntilNoRIT(zkw);
LOG.info("No more RIT in ZK, now doing final test verification");
int tries = 60;
while(TEST_UTIL.getHBaseCluster()
.getMaster().getAssignmentManager().getRegionStates().getRegionsInTransition().size() > 0 &&
tries-- > 0) {
LOG.info("Waiting for RIT: "+TEST_UTIL.getHBaseCluster()
.getMaster().getAssignmentManager().getRegionStates().getRegionsInTransition());
Thread.sleep(1000);
}
// Meta still messed up.
assertEquals(1, scanMeta());