use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.
the class TestAsyncRegionAdminApi method testAssignRegionAndUnassignRegion.
@Test
public void testAssignRegionAndUnassignRegion() throws Exception {
createTableWithDefaultConf(tableName);
// assign region.
HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
AssignmentManager am = master.getAssignmentManager();
RegionInfo hri = am.getRegionStates().getRegionsOfTable(tableName).get(0);
// assert region on server
RegionStates regionStates = am.getRegionStates();
ServerName serverName = regionStates.getRegionServerOfRegion(hri);
TEST_UTIL.assertRegionOnServer(hri, serverName, 200);
assertTrue(regionStates.getRegionState(hri).isOpened());
// Master should not abort, and region should stay assigned.
try {
admin.assign(hri.getRegionName()).get();
fail("Should fail when assigning an already onlined region");
} catch (ExecutionException e) {
// Expected
assertThat(e.getCause(), instanceOf(DoNotRetryRegionException.class));
}
assertFalse(am.getRegionStates().getRegionStateNode(hri).isInTransition());
assertTrue(regionStates.getRegionState(hri).isOpened());
// unassign region
admin.unassign(hri.getRegionName(), true).get();
assertFalse(am.getRegionStates().getRegionStateNode(hri).isInTransition());
assertTrue(regionStates.getRegionState(hri).isClosed());
}
use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.
the class TestAsyncRegionAdminApi method testMoveRegion.
@Test
public void testMoveRegion() throws Exception {
admin.balancerSwitch(false).join();
RegionInfo hri = createTableAndGetOneRegion(tableName);
RawAsyncHBaseAdmin rawAdmin = (RawAsyncHBaseAdmin) ASYNC_CONN.getAdmin();
ServerName serverName = rawAdmin.getRegionLocation(hri.getRegionName()).get().getServerName();
HMaster master = TEST_UTIL.getHBaseCluster().getMaster();
ServerManager serverManager = master.getServerManager();
ServerName destServerName = null;
List<JVMClusterUtil.RegionServerThread> regionServers = TEST_UTIL.getHBaseCluster().getLiveRegionServerThreads();
for (JVMClusterUtil.RegionServerThread regionServer : regionServers) {
HRegionServer destServer = regionServer.getRegionServer();
destServerName = destServer.getServerName();
if (!destServerName.equals(serverName) && serverManager.isServerOnline(destServerName)) {
break;
}
}
assertTrue(destServerName != null && !destServerName.equals(serverName));
admin.move(hri.getRegionName(), destServerName).get();
long timeoutTime = EnvironmentEdgeManager.currentTime() + 30000;
while (true) {
ServerName sn = rawAdmin.getRegionLocation(hri.getRegionName()).get().getServerName();
if (sn != null && sn.equals(destServerName)) {
break;
}
long now = EnvironmentEdgeManager.currentTime();
if (now > timeoutTime) {
fail("Failed to move the region in time: " + hri);
}
Thread.sleep(100);
}
admin.balancerSwitch(true).join();
}
use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.
the class TestAsyncRegionAdminApi2 method testMergeRegions.
@Test
public void testMergeRegions() throws Exception {
byte[][] splitRows = new byte[][] { Bytes.toBytes("3"), Bytes.toBytes("6") };
createTableWithDefaultConf(tableName, splitRows);
AsyncTable<AdvancedScanResultConsumer> metaTable = ASYNC_CONN.getTable(META_TABLE_NAME);
List<HRegionLocation> regionLocations = ClientMetaTableAccessor.getTableHRegionLocations(metaTable, tableName).get();
RegionInfo regionA;
RegionInfo regionB;
RegionInfo regionC;
RegionInfo mergedChildRegion = null;
// merge with full name
assertEquals(3, regionLocations.size());
regionA = regionLocations.get(0).getRegion();
regionB = regionLocations.get(1).getRegion();
regionC = regionLocations.get(2).getRegion();
admin.mergeRegions(regionA.getRegionName(), regionB.getRegionName(), false).get();
regionLocations = ClientMetaTableAccessor.getTableHRegionLocations(metaTable, tableName).get();
assertEquals(2, regionLocations.size());
for (HRegionLocation rl : regionLocations) {
if (regionC.compareTo(rl.getRegion()) != 0) {
mergedChildRegion = rl.getRegion();
break;
}
}
assertNotNull(mergedChildRegion);
// Need to wait GC for merged child region is done.
HMaster services = TEST_UTIL.getHBaseCluster().getMaster();
CatalogJanitor cj = services.getCatalogJanitor();
assertTrue(cj.scan() > 0);
// Wait until all procedures settled down
while (!services.getMasterProcedureExecutor().getActiveProcIds().isEmpty()) {
Thread.sleep(200);
}
// merge with encoded name
admin.mergeRegions(regionC.getRegionName(), mergedChildRegion.getRegionName(), false).get();
regionLocations = ClientMetaTableAccessor.getTableHRegionLocations(metaTable, tableName).get();
assertEquals(1, regionLocations.size());
}
use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.
the class TestMetaTableAccessor method testIsMetaWhenAllHealthy.
@Test
public void testIsMetaWhenAllHealthy() throws InterruptedException {
HMaster m = UTIL.getMiniHBaseCluster().getMaster();
assertTrue(m.waitForMetaOnline());
}
use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.
the class TestZooKeeper method testLogSplittingAfterMasterRecoveryDueToZKExpiry.
/**
* Tests whether the logs are split when master recovers from a expired zookeeper session and an
* RS goes down.
*/
@Test
public void testLogSplittingAfterMasterRecoveryDueToZKExpiry() throws Exception {
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
cluster.startRegionServer();
TableName tableName = TableName.valueOf(name.getMethodName());
byte[] family = Bytes.toBytes("col");
try (Admin admin = TEST_UTIL.getAdmin()) {
byte[][] SPLIT_KEYS = new byte[][] { Bytes.toBytes("1"), Bytes.toBytes("2"), Bytes.toBytes("3"), Bytes.toBytes("4"), Bytes.toBytes("5") };
TableDescriptor htd = TableDescriptorBuilder.newBuilder(tableName).setColumnFamily(ColumnFamilyDescriptorBuilder.of(family)).build();
admin.createTable(htd, SPLIT_KEYS);
}
TEST_UTIL.waitUntilNoRegionsInTransition(60000);
HMaster m = cluster.getMaster();
try (Table table = TEST_UTIL.getConnection().getTable(tableName)) {
int numberOfPuts;
for (numberOfPuts = 0; numberOfPuts < 6; numberOfPuts++) {
Put p = new Put(Bytes.toBytes(numberOfPuts));
p.addColumn(Bytes.toBytes("col"), Bytes.toBytes("ql"), Bytes.toBytes("value" + numberOfPuts));
table.put(p);
}
m.abort("Test recovery from zk session expired", new KeeperException.SessionExpiredException());
// Master doesn't recover any more
assertTrue(m.isStopped());
cluster.killRegionServer(TEST_UTIL.getRSForFirstRegionInTable(tableName).getServerName());
// Without patch for HBASE-6046 this test case will always timeout
// with patch the test case should pass.
int numberOfRows = 0;
try (ResultScanner scanner = table.getScanner(new Scan())) {
while (scanner.next() != null) {
numberOfRows++;
}
}
assertEquals("Number of rows should be equal to number of puts.", numberOfPuts, numberOfRows);
}
}
Aggregations