HBASE-15277 TestRegionMergeTransactionOnCluster.testWholesomeMerge fails with no connection to master

This commit is contained in:
stack 2016-02-16 13:13:13 -08:00
parent bb881eb80d
commit a8077080ba
1 changed files with 45 additions and 41 deletions

View File

@ -34,6 +34,7 @@ import org.apache.commons.logging.LogFactory;
import org.apache.hadoop.conf.Configuration; import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.FileSystem;
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.hbase.CategoryBasedTimeout;
import org.apache.hadoop.hbase.CoordinatedStateManager; import org.apache.hadoop.hbase.CoordinatedStateManager;
import org.apache.hadoop.hbase.HBaseTestingUtility; import org.apache.hadoop.hbase.HBaseTestingUtility;
import org.apache.hadoop.hbase.HColumnDescriptor; import org.apache.hadoop.hbase.HColumnDescriptor;
@ -74,8 +75,10 @@ import org.apache.hadoop.util.StringUtils;
import org.apache.zookeeper.KeeperException; import org.apache.zookeeper.KeeperException;
import org.junit.AfterClass; import org.junit.AfterClass;
import org.junit.BeforeClass; import org.junit.BeforeClass;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.experimental.categories.Category; import org.junit.experimental.categories.Category;
import org.junit.rules.TestRule;
import com.google.common.base.Joiner; import com.google.common.base.Joiner;
import com.google.protobuf.RpcController; import com.google.protobuf.RpcController;
@ -91,6 +94,8 @@ import com.google.protobuf.ServiceException;
public class TestRegionMergeTransactionOnCluster { public class TestRegionMergeTransactionOnCluster {
private static final Log LOG = LogFactory private static final Log LOG = LogFactory
.getLog(TestRegionMergeTransactionOnCluster.class); .getLog(TestRegionMergeTransactionOnCluster.class);
@Rule public final TestRule timeout = CategoryBasedTimeout.builder().withTimeout(this.getClass()).
withLookingForStuckThread(true).build();
private static final int NB_SERVERS = 3; private static final int NB_SERVERS = 3;
private static final byte[] FAMILYNAME = Bytes.toBytes("fam"); private static final byte[] FAMILYNAME = Bytes.toBytes("fam");
@ -105,22 +110,23 @@ public class TestRegionMergeTransactionOnCluster {
static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility(); static final HBaseTestingUtility TEST_UTIL = new HBaseTestingUtility();
private static HMaster master; private static HMaster MASTER;
private static Admin admin; private static Admin ADMIN;
@BeforeClass @BeforeClass
public static void beforeAllTests() throws Exception { public static void beforeAllTests() throws Exception {
// Start a cluster // Start a cluster
TEST_UTIL.startMiniCluster(1, NB_SERVERS, null, MyMaster.class, null); TEST_UTIL.startMiniCluster(1, NB_SERVERS, null, MyMaster.class, null);
MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster(); MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
master = cluster.getMaster(); MASTER = cluster.getMaster();
master.balanceSwitch(false); MASTER.balanceSwitch(false);
admin = TEST_UTIL.getHBaseAdmin(); ADMIN = TEST_UTIL.getConnection().getAdmin();
} }
@AfterClass @AfterClass
public static void afterAllTests() throws Exception { public static void afterAllTests() throws Exception {
TEST_UTIL.shutdownMiniCluster(); TEST_UTIL.shutdownMiniCluster();
if (ADMIN != null) ADMIN.close();
} }
@Test @Test
@ -130,14 +136,14 @@ public class TestRegionMergeTransactionOnCluster {
TableName.valueOf("testWholesomeMerge"); TableName.valueOf("testWholesomeMerge");
// Create table and load data. // Create table and load data.
Table table = createTableAndLoadData(master, tableName); Table table = createTableAndLoadData(MASTER, tableName);
// Merge 1st and 2nd region // Merge 1st and 2nd region
mergeRegionsAndVerifyRegionNum(master, tableName, 0, 1, mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1,
INITIAL_REGION_NUM - 1); INITIAL_REGION_NUM - 1);
// Merge 2nd and 3th region // Merge 2nd and 3th region
PairOfSameType<HRegionInfo> mergedRegions = PairOfSameType<HRegionInfo> mergedRegions =
mergeRegionsAndVerifyRegionNum(master, tableName, 1, 2, mergeRegionsAndVerifyRegionNum(MASTER, tableName, 1, 2,
INITIAL_REGION_NUM - 2); INITIAL_REGION_NUM - 2);
verifyRowCount(table, ROWSIZE); verifyRowCount(table, ROWSIZE);
@ -180,14 +186,13 @@ public class TestRegionMergeTransactionOnCluster {
final TableName tableName = TableName.valueOf("testMergeAndRestartingMaster"); final TableName tableName = TableName.valueOf("testMergeAndRestartingMaster");
// Create table and load data. // Create table and load data.
Table table = createTableAndLoadData(master, tableName); Table table = createTableAndLoadData(MASTER, tableName);
try { try {
MyMasterRpcServices.enabled.set(true); MyMasterRpcServices.enabled.set(true);
// Merge 1st and 2nd region // Merge 1st and 2nd region
mergeRegionsAndVerifyRegionNum(master, tableName, 0, 1, mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1, INITIAL_REGION_NUM - 1);
INITIAL_REGION_NUM - 1);
} finally { } finally {
MyMasterRpcServices.enabled.set(false); MyMasterRpcServices.enabled.set(false);
} }
@ -195,29 +200,28 @@ public class TestRegionMergeTransactionOnCluster {
table.close(); table.close();
} }
@SuppressWarnings("deprecation")
@Test @Test
public void testCleanMergeReference() throws Exception { public void testCleanMergeReference() throws Exception {
LOG.info("Starting testCleanMergeReference"); LOG.info("Starting testCleanMergeReference");
admin.enableCatalogJanitor(false); ADMIN.enableCatalogJanitor(false);
try { try {
final TableName tableName = final TableName tableName =
TableName.valueOf("testCleanMergeReference"); TableName.valueOf("testCleanMergeReference");
// Create table and load data. // Create table and load data.
Table table = createTableAndLoadData(master, tableName); Table table = createTableAndLoadData(MASTER, tableName);
// Merge 1st and 2nd region // Merge 1st and 2nd region
mergeRegionsAndVerifyRegionNum(master, tableName, 0, 1, mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1,
INITIAL_REGION_NUM - 1); INITIAL_REGION_NUM - 1);
verifyRowCount(table, ROWSIZE); verifyRowCount(table, ROWSIZE);
table.close(); table.close();
List<Pair<HRegionInfo, ServerName>> tableRegions = MetaTableAccessor List<Pair<HRegionInfo, ServerName>> tableRegions = MetaTableAccessor
.getTableRegionsAndLocations(master.getConnection(), tableName); .getTableRegionsAndLocations(MASTER.getConnection(), tableName);
HRegionInfo mergedRegionInfo = tableRegions.get(0).getFirst(); HRegionInfo mergedRegionInfo = tableRegions.get(0).getFirst();
HTableDescriptor tableDescriptor = master.getTableDescriptors().get( HTableDescriptor tableDescriptor = MASTER.getTableDescriptors().get(
tableName); tableName);
Result mergedRegionResult = MetaTableAccessor.getRegionResult( Result mergedRegionResult = MetaTableAccessor.getRegionResult(
master.getConnection(), mergedRegionInfo.getRegionName()); MASTER.getConnection(), mergedRegionInfo.getRegionName());
// contains merge reference in META // contains merge reference in META
assertTrue(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY, assertTrue(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,
@ -229,8 +233,8 @@ public class TestRegionMergeTransactionOnCluster {
PairOfSameType<HRegionInfo> p = MetaTableAccessor.getMergeRegions(mergedRegionResult); PairOfSameType<HRegionInfo> p = MetaTableAccessor.getMergeRegions(mergedRegionResult);
HRegionInfo regionA = p.getFirst(); HRegionInfo regionA = p.getFirst();
HRegionInfo regionB = p.getSecond(); HRegionInfo regionB = p.getSecond();
FileSystem fs = master.getMasterFileSystem().getFileSystem(); FileSystem fs = MASTER.getMasterFileSystem().getFileSystem();
Path rootDir = master.getMasterFileSystem().getRootDir(); Path rootDir = MASTER.getMasterFileSystem().getRootDir();
Path tabledir = FSUtils.getTableDir(rootDir, mergedRegionInfo.getTable()); Path tabledir = FSUtils.getTableDir(rootDir, mergedRegionInfo.getTable());
Path regionAdir = new Path(tabledir, regionA.getEncodedName()); Path regionAdir = new Path(tabledir, regionA.getEncodedName());
@ -245,7 +249,7 @@ public class TestRegionMergeTransactionOnCluster {
for(HColumnDescriptor colFamily : columnFamilies) { for(HColumnDescriptor colFamily : columnFamilies) {
count += hrfs.getStoreFiles(colFamily.getName()).size(); count += hrfs.getStoreFiles(colFamily.getName()).size();
} }
admin.compactRegion(mergedRegionInfo.getRegionName()); ADMIN.compactRegion(mergedRegionInfo.getRegionName());
// clean up the merged region store files // clean up the merged region store files
// wait until merged region have reference file // wait until merged region have reference file
long timeout = System.currentTimeMillis() + waitTime; long timeout = System.currentTimeMillis() + waitTime;
@ -282,7 +286,7 @@ public class TestRegionMergeTransactionOnCluster {
// files of merging regions // files of merging regions
int cleaned = 0; int cleaned = 0;
while (cleaned == 0) { while (cleaned == 0) {
cleaned = admin.runCatalogScan(); cleaned = ADMIN.runCatalogScan();
LOG.debug("catalog janitor returned " + cleaned); LOG.debug("catalog janitor returned " + cleaned);
Thread.sleep(50); Thread.sleep(50);
} }
@ -291,14 +295,14 @@ public class TestRegionMergeTransactionOnCluster {
assertTrue(cleaned > 0); assertTrue(cleaned > 0);
mergedRegionResult = MetaTableAccessor.getRegionResult( mergedRegionResult = MetaTableAccessor.getRegionResult(
master.getConnection(), mergedRegionInfo.getRegionName()); TEST_UTIL.getConnection(), mergedRegionInfo.getRegionName());
assertFalse(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY, assertFalse(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,
HConstants.MERGEA_QUALIFIER) != null); HConstants.MERGEA_QUALIFIER) != null);
assertFalse(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY, assertFalse(mergedRegionResult.getValue(HConstants.CATALOG_FAMILY,
HConstants.MERGEB_QUALIFIER) != null); HConstants.MERGEB_QUALIFIER) != null);
} finally { } finally {
admin.enableCatalogJanitor(true); ADMIN.enableCatalogJanitor(true);
} }
} }
@ -315,8 +319,8 @@ public class TestRegionMergeTransactionOnCluster {
try { try {
// Create table and load data. // Create table and load data.
Table table = createTableAndLoadData(master, tableName); Table table = createTableAndLoadData(MASTER, tableName);
RegionStates regionStates = master.getAssignmentManager().getRegionStates(); RegionStates regionStates = MASTER.getAssignmentManager().getRegionStates();
List<HRegionInfo> regions = regionStates.getRegionsOfTable(tableName); List<HRegionInfo> regions = regionStates.getRegionsOfTable(tableName);
// Fake offline one region // Fake offline one region
HRegionInfo a = regions.get(0); HRegionInfo a = regions.get(0);
@ -324,7 +328,7 @@ public class TestRegionMergeTransactionOnCluster {
regionStates.regionOffline(a); regionStates.regionOffline(a);
try { try {
// Merge offline region. Region a is offline here // Merge offline region. Region a is offline here
admin.mergeRegions(a.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), false); ADMIN.mergeRegions(a.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), false);
fail("Offline regions should not be able to merge"); fail("Offline regions should not be able to merge");
} catch (IOException ie) { } catch (IOException ie) {
System.out.println(ie); System.out.println(ie);
@ -334,7 +338,7 @@ public class TestRegionMergeTransactionOnCluster {
} }
try { try {
// Merge the same region: b and b. // Merge the same region: b and b.
admin.mergeRegions(b.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), true); ADMIN.mergeRegions(b.getEncodedNameAsBytes(), b.getEncodedNameAsBytes(), true);
fail("A region should not be able to merge with itself, even forcifully"); fail("A region should not be able to merge with itself, even forcifully");
} catch (IOException ie) { } catch (IOException ie) {
assertTrue("Exception should mention regions not online", assertTrue("Exception should mention regions not online",
@ -343,7 +347,7 @@ public class TestRegionMergeTransactionOnCluster {
} }
try { try {
// Merge unknown regions // Merge unknown regions
admin.mergeRegions(Bytes.toBytes("-f1"), Bytes.toBytes("-f2"), true); ADMIN.mergeRegions(Bytes.toBytes("-f1"), Bytes.toBytes("-f2"), true);
fail("Unknown region could not be merged"); fail("Unknown region could not be merged");
} catch (IOException ie) { } catch (IOException ie) {
assertTrue("UnknownRegionException should be thrown", assertTrue("UnknownRegionException should be thrown",
@ -359,16 +363,16 @@ public class TestRegionMergeTransactionOnCluster {
public void testMergeWithReplicas() throws Exception { public void testMergeWithReplicas() throws Exception {
final TableName tableName = TableName.valueOf("testMergeWithReplicas"); final TableName tableName = TableName.valueOf("testMergeWithReplicas");
// Create table and load data. // Create table and load data.
createTableAndLoadData(master, tableName, 5, 2); createTableAndLoadData(MASTER, tableName, 5, 2);
List<Pair<HRegionInfo, ServerName>> initialRegionToServers = List<Pair<HRegionInfo, ServerName>> initialRegionToServers =
MetaTableAccessor.getTableRegionsAndLocations( MetaTableAccessor.getTableRegionsAndLocations(
master.getConnection(), tableName); TEST_UTIL.getConnection(), tableName);
// Merge 1st and 2nd region // Merge 1st and 2nd region
PairOfSameType<HRegionInfo> mergedRegions = mergeRegionsAndVerifyRegionNum(master, tableName, PairOfSameType<HRegionInfo> mergedRegions = mergeRegionsAndVerifyRegionNum(MASTER, tableName,
0, 2, 5 * 2 - 2); 0, 2, 5 * 2 - 2);
List<Pair<HRegionInfo, ServerName>> currentRegionToServers = List<Pair<HRegionInfo, ServerName>> currentRegionToServers =
MetaTableAccessor.getTableRegionsAndLocations( MetaTableAccessor.getTableRegionsAndLocations(
master.getConnection(), tableName); TEST_UTIL.getConnection(), tableName);
List<HRegionInfo> initialRegions = new ArrayList<HRegionInfo>(); List<HRegionInfo> initialRegions = new ArrayList<HRegionInfo>();
for (Pair<HRegionInfo, ServerName> p : initialRegionToServers) { for (Pair<HRegionInfo, ServerName> p : initialRegionToServers) {
initialRegions.add(p.getFirst()); initialRegions.add(p.getFirst());
@ -408,10 +412,10 @@ public class TestRegionMergeTransactionOnCluster {
int regionAnum, int regionBnum) throws Exception { int regionAnum, int regionBnum) throws Exception {
List<Pair<HRegionInfo, ServerName>> tableRegions = MetaTableAccessor List<Pair<HRegionInfo, ServerName>> tableRegions = MetaTableAccessor
.getTableRegionsAndLocations( .getTableRegionsAndLocations(
master.getConnection(), tablename); TEST_UTIL.getConnection(), tablename);
HRegionInfo regionA = tableRegions.get(regionAnum).getFirst(); HRegionInfo regionA = tableRegions.get(regionAnum).getFirst();
HRegionInfo regionB = tableRegions.get(regionBnum).getFirst(); HRegionInfo regionB = tableRegions.get(regionBnum).getFirst();
TEST_UTIL.getHBaseAdmin().mergeRegions( ADMIN.mergeRegions(
regionA.getEncodedNameAsBytes(), regionA.getEncodedNameAsBytes(),
regionB.getEncodedNameAsBytes(), false); regionB.getEncodedNameAsBytes(), false);
return new PairOfSameType<HRegionInfo>(regionA, regionB); return new PairOfSameType<HRegionInfo>(regionA, regionB);
@ -424,7 +428,7 @@ public class TestRegionMergeTransactionOnCluster {
long timeout = System.currentTimeMillis() + waitTime; long timeout = System.currentTimeMillis() + waitTime;
while (System.currentTimeMillis() < timeout) { while (System.currentTimeMillis() < timeout) {
tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations( tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations(
master.getConnection(), tablename); TEST_UTIL.getConnection(), tablename);
tableRegionsInMaster = master.getAssignmentManager().getRegionStates() tableRegionsInMaster = master.getAssignmentManager().getRegionStates()
.getRegionsOfTable(tablename); .getRegionsOfTable(tablename);
if (tableRegionsInMeta.size() == expectedRegionNum if (tableRegionsInMeta.size() == expectedRegionNum
@ -435,7 +439,7 @@ public class TestRegionMergeTransactionOnCluster {
} }
tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations( tableRegionsInMeta = MetaTableAccessor.getTableRegionsAndLocations(
master.getConnection(), tablename); TEST_UTIL.getConnection(), tablename);
LOG.info("Regions after merge:" + Joiner.on(',').join(tableRegionsInMeta)); LOG.info("Regions after merge:" + Joiner.on(',').join(tableRegionsInMeta));
assertEquals(expectedRegionNum, tableRegionsInMeta.size()); assertEquals(expectedRegionNum, tableRegionsInMeta.size());
} }
@ -455,7 +459,7 @@ public class TestRegionMergeTransactionOnCluster {
Table table = TEST_UTIL.createTable(tablename, FAMILYNAME, splitRows); Table table = TEST_UTIL.createTable(tablename, FAMILYNAME, splitRows);
if (replication > 1) { if (replication > 1) {
HBaseTestingUtility.setReplicas(admin, tablename, replication); HBaseTestingUtility.setReplicas(ADMIN, tablename, replication);
} }
loadData(table); loadData(table);
verifyRowCount(table, ROWSIZE); verifyRowCount(table, ROWSIZE);
@ -465,14 +469,14 @@ public class TestRegionMergeTransactionOnCluster {
List<Pair<HRegionInfo, ServerName>> tableRegions; List<Pair<HRegionInfo, ServerName>> tableRegions;
while (System.currentTimeMillis() < timeout) { while (System.currentTimeMillis() < timeout) {
tableRegions = MetaTableAccessor.getTableRegionsAndLocations( tableRegions = MetaTableAccessor.getTableRegionsAndLocations(
master.getConnection(), tablename); TEST_UTIL.getConnection(), tablename);
if (tableRegions.size() == numRegions * replication) if (tableRegions.size() == numRegions * replication)
break; break;
Thread.sleep(250); Thread.sleep(250);
} }
tableRegions = MetaTableAccessor.getTableRegionsAndLocations( tableRegions = MetaTableAccessor.getTableRegionsAndLocations(
master.getConnection(), tablename); TEST_UTIL.getConnection(), tablename);
LOG.info("Regions after load: " + Joiner.on(',').join(tableRegions)); LOG.info("Regions after load: " + Joiner.on(',').join(tableRegions));
assertEquals(numRegions * replication, tableRegions.size()); assertEquals(numRegions * replication, tableRegions.size());
return table; return table;