HBASE-19554 For debug: Modify HTU.waitUntilAllRegionsAssigned to handle the case where we do not have entries for the given table

This commit is contained in:
zhangduo 2017-12-19 21:21:46 +08:00 committed by Michael Stack
parent 6c6a9d2d1c
commit 084e324fb9
No known key found for this signature in database
GPG Key ID: 9816C7FC8ACC93D2
2 changed files with 48 additions and 51 deletions

View File

@ -3231,7 +3231,7 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility {
* @throws IOException * @throws IOException
*/ */
public void waitUntilAllRegionsAssigned(final TableName tableName) throws IOException { public void waitUntilAllRegionsAssigned(final TableName tableName) throws IOException {
waitUntilAllRegionsAssigned( tableName, waitUntilAllRegionsAssigned(tableName,
this.conf.getLong("hbase.client.sync.wait.timeout.msec", 60000)); this.conf.getLong("hbase.client.sync.wait.timeout.msec", 60000));
} }
@ -3255,59 +3255,59 @@ public class HBaseTestingUtility extends HBaseZKTestingUtility {
*/ */
public void waitUntilAllRegionsAssigned(final TableName tableName, final long timeout) public void waitUntilAllRegionsAssigned(final TableName tableName, final long timeout)
throws IOException { throws IOException {
final Table meta = getConnection().getTable(TableName.META_TABLE_NAME); if (!TableName.isMetaTableName(tableName)) {
try { try (final Table meta = getConnection().getTable(TableName.META_TABLE_NAME)) {
LOG.debug("Waiting until all regions of table " + tableName + " get assigned. Timeout = " + LOG.debug("Waiting until all regions of table " + tableName + " get assigned. Timeout = " +
timeout + "ms"); timeout + "ms");
waitFor(timeout, 200, true, new ExplainingPredicate<IOException>() { waitFor(timeout, 200, true, new ExplainingPredicate<IOException>() {
@Override @Override
public String explainFailure() throws IOException { public String explainFailure() throws IOException {
return explainTableAvailability(tableName); return explainTableAvailability(tableName);
} }
@Override @Override
public boolean evaluate() throws IOException { public boolean evaluate() throws IOException {
Scan scan = new Scan(); Scan scan = new Scan();
scan.addFamily(HConstants.CATALOG_FAMILY); scan.addFamily(HConstants.CATALOG_FAMILY);
ResultScanner s = meta.getScanner(scan); boolean tableFound = false;
try { try (ResultScanner s = meta.getScanner(scan)) {
Result r; for (Result r; (r = s.next()) != null;) {
while ((r = s.next()) != null) { byte[] b = r.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER);
byte[] b = r.getValue(HConstants.CATALOG_FAMILY, HConstants.REGIONINFO_QUALIFIER); HRegionInfo info = HRegionInfo.parseFromOrNull(b);
HRegionInfo info = HRegionInfo.parseFromOrNull(b); if (info != null && info.getTable().equals(tableName)) {
if (info != null && info.getTable().equals(tableName)) { // Get server hosting this region from catalog family. Return false if no server
// Get server hosting this region from catalog family. Return false if no server // hosting this region, or if the server hosting this region was recently killed
// hosting this region, or if the server hosting this region was recently killed // (for fault tolerance testing).
// (for fault tolerance testing). tableFound = true;
byte[] server = byte[] server =
r.getValue(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER); r.getValue(HConstants.CATALOG_FAMILY, HConstants.SERVER_QUALIFIER);
if (server == null) { if (server == null) {
return false; return false;
} else { } else {
byte[] startCode = byte[] startCode =
r.getValue(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER); r.getValue(HConstants.CATALOG_FAMILY, HConstants.STARTCODE_QUALIFIER);
ServerName serverName = ServerName serverName =
ServerName.valueOf(Bytes.toString(server).replaceFirst(":", ",") + "," + ServerName.valueOf(Bytes.toString(server).replaceFirst(":", ",") + "," +
Bytes.toLong(startCode)); Bytes.toLong(startCode));
if (!getHBaseClusterInterface().isDistributedCluster() if (!getHBaseClusterInterface().isDistributedCluster() &&
&& getHBaseCluster().isKilledRS(serverName)) { getHBaseCluster().isKilledRS(serverName)) {
return false;
}
}
if (RegionStateStore.getRegionState(r,
info.getReplicaId()) != RegionState.State.OPEN) {
return false; return false;
} }
} }
if (RegionStateStore.getRegionState(r, info.getReplicaId())
!= RegionState.State.OPEN) {
return false;
}
} }
} }
} finally { if (!tableFound) {
s.close(); LOG.warn("Didn't find the entries for table " + tableName + " in meta, already deleted?");
}
return tableFound;
} }
return true; });
} }
});
} finally {
meta.close();
} }
LOG.info("All regions for table " + tableName + " assigned to meta. Checking AM states."); LOG.info("All regions for table " + tableName + " assigned to meta. Checking AM states.");
// check from the master state if we are using a mini cluster // check from the master state if we are using a mini cluster

View File

@ -89,7 +89,6 @@ import org.junit.After;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.Before; import org.junit.Before;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Ignore;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.TestName; import org.junit.rules.TestName;
@ -274,15 +273,13 @@ public abstract class AbstractTestDLS {
// abort RS // abort RS
LOG.info("Aborting region server: " + hrs.getServerName()); LOG.info("Aborting region server: " + hrs.getServerName());
int countBefore = cluster.getLiveRegionServerThreads().size();
hrs.abort("testing"); hrs.abort("testing");
// wait for abort completes // wait for abort completes
TEST_UTIL.waitFor(120000, 200, new Waiter.Predicate<Exception>() { TEST_UTIL.waitFor(120000, 200, new Waiter.Predicate<Exception>() {
@Override @Override
public boolean evaluate() throws Exception { public boolean evaluate() throws Exception {
int count = cluster.getLiveRegionServerThreads().size(); return cluster.getLiveRegionServerThreads().size() <= NUM_RS - 1;
return count <= (NUM_RS - 1);
} }
}); });