use of org.apache.hadoop.hbase.master.assignment.AssignmentManager in project hbase by apache.
the class TestAdmin2 method testMoveToPreviouslyAssignedRS.
@Test
public void testMoveToPreviouslyAssignedRS() throws IOException, InterruptedException {
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
HMaster master = cluster.getMaster();
final TableName tableName = TableName.valueOf(name.getMethodName());
Admin localAdmin = createTable(tableName);
List<RegionInfo> tableRegions = localAdmin.getRegions(tableName);
RegionInfo hri = tableRegions.get(0);
AssignmentManager am = master.getAssignmentManager();
ServerName server = am.getRegionStates().getRegionServerOfRegion(hri);
localAdmin.move(hri.getEncodedNameAsBytes(), server);
assertEquals("Current region server and region server before move should be same.", server, am.getRegionStates().getRegionServerOfRegion(hri));
}
use of org.apache.hadoop.hbase.master.assignment.AssignmentManager in project hbase by apache.
the class MetaWithReplicasTestBase method startCluster.
protected static void startCluster() throws Exception {
TEST_UTIL.getConfiguration().setInt("zookeeper.session.timeout", 30000);
TEST_UTIL.getConfiguration().setInt(StorefileRefresherChore.REGIONSERVER_STOREFILE_REFRESH_PERIOD, 1000);
StartTestingClusterOption option = StartTestingClusterOption.builder().numAlwaysStandByMasters(1).numMasters(1).numRegionServers(REGIONSERVERS_COUNT).build();
TEST_UTIL.startMiniCluster(option);
Admin admin = TEST_UTIL.getAdmin();
HBaseTestingUtil.setReplicas(admin, TableName.META_TABLE_NAME, 3);
AssignmentManager am = TEST_UTIL.getMiniHBaseCluster().getMaster().getAssignmentManager();
Set<ServerName> sns = new HashSet<ServerName>();
ServerName hbaseMetaServerName = am.getRegionStates().getRegionStateNode(RegionInfoBuilder.FIRST_META_REGIONINFO).getRegionLocation();
LOG.info("HBASE:META DEPLOY: on " + hbaseMetaServerName);
sns.add(hbaseMetaServerName);
for (int replicaId = 1; replicaId < 3; replicaId++) {
RegionInfo h = RegionReplicaUtil.getRegionInfoForReplica(RegionInfoBuilder.FIRST_META_REGIONINFO, replicaId);
AssignmentTestingUtil.waitForAssignment(am, h);
ServerName sn = am.getRegionStates().getRegionServerOfRegion(h);
assertNotNull(sn);
LOG.info("HBASE:META DEPLOY: " + h.getRegionNameAsString() + " on " + sn);
sns.add(sn);
}
// to fail ... sometimes.
if (sns.size() == 1) {
int count = TEST_UTIL.getMiniHBaseCluster().getLiveRegionServerThreads().size();
assertTrue("count=" + count, count == REGIONSERVERS_COUNT);
LOG.warn("All hbase:meta replicas are on the one server; moving hbase:meta: " + sns);
int metaServerIndex = TEST_UTIL.getHBaseCluster().getServerWithMeta();
int newServerIndex = metaServerIndex;
while (newServerIndex == metaServerIndex) {
newServerIndex = (newServerIndex + 1) % REGIONSERVERS_COUNT;
}
assertNotEquals(metaServerIndex, newServerIndex);
ServerName destinationServerName = TEST_UTIL.getHBaseCluster().getRegionServer(newServerIndex).getServerName();
ServerName metaServerName = TEST_UTIL.getHBaseCluster().getRegionServer(metaServerIndex).getServerName();
assertNotEquals(destinationServerName, metaServerName);
TEST_UTIL.getAdmin().move(RegionInfoBuilder.FIRST_META_REGIONINFO.getEncodedNameAsBytes(), destinationServerName);
}
// Disable the balancer
LoadBalancerTracker l = new LoadBalancerTracker(TEST_UTIL.getZooKeeperWatcher(), new Abortable() {
AtomicBoolean aborted = new AtomicBoolean(false);
@Override
public boolean isAborted() {
return aborted.get();
}
@Override
public void abort(String why, Throwable e) {
aborted.set(true);
}
});
l.setBalancerOn(false);
LOG.debug("All meta replicas assigned");
}
use of org.apache.hadoop.hbase.master.assignment.AssignmentManager in project hbase by apache.
the class TestMasterStatusServlet method setupBasicMocks.
@Before
public void setupBasicMocks() {
conf = HBaseConfiguration.create();
master = Mockito.mock(HMaster.class);
Mockito.doReturn(FAKE_HOST).when(master).getServerName();
Mockito.doReturn(conf).when(master).getConfiguration();
// Fake DeadServer
DeadServer deadServer = Mockito.mock(DeadServer.class);
// Fake serverManager
ServerManager serverManager = Mockito.mock(ServerManager.class);
Mockito.doReturn(1.0).when(serverManager).getAverageLoad();
Mockito.doReturn(serverManager).when(master).getServerManager();
Mockito.doReturn(deadServer).when(serverManager).getDeadServers();
// Fake AssignmentManager and RIT
AssignmentManager am = Mockito.mock(AssignmentManager.class);
RegionStates rs = Mockito.mock(RegionStates.class);
List<RegionState> regionsInTransition = new ArrayList<>();
regionsInTransition.add(new RegionState(FAKE_HRI, RegionState.State.CLOSING, 12345L, FAKE_HOST));
Mockito.doReturn(rs).when(am).getRegionStates();
Mockito.doReturn(regionsInTransition).when(rs).getRegionsInTransition();
Mockito.doReturn(am).when(master).getAssignmentManager();
Mockito.doReturn(serverManager).when(master).getServerManager();
// Fake ZKW
ZKWatcher zkw = Mockito.mock(ZKWatcher.class);
Mockito.doReturn(new ZNodePaths(conf)).when(zkw).getZNodePaths();
Mockito.doReturn("fakequorum").when(zkw).getQuorum();
Mockito.doReturn(zkw).when(master).getZooKeeper();
// Fake ActiveMaster
Mockito.doReturn(Optional.of(FAKE_HOST)).when(master).getActiveMaster();
// Mock admin
admin = Mockito.mock(Admin.class);
}
use of org.apache.hadoop.hbase.master.assignment.AssignmentManager in project hbase by apache.
the class TestRegionMergeTransactionOnCluster method testWholesomeMerge.
@Test
public void testWholesomeMerge() throws Exception {
LOG.info("Starting " + name.getMethodName());
final TableName tableName = TableName.valueOf(name.getMethodName());
try {
// Create table and load data.
Table table = createTableAndLoadData(MASTER, tableName);
// Merge 1st and 2nd region
mergeRegionsAndVerifyRegionNum(MASTER, tableName, 0, 1, INITIAL_REGION_NUM - 1);
// Merge 2nd and 3th region
PairOfSameType<RegionInfo> mergedRegions = mergeRegionsAndVerifyRegionNum(MASTER, tableName, 1, 2, INITIAL_REGION_NUM - 2);
verifyRowCount(table, ROWSIZE);
// Randomly choose one of the two merged regions
RegionInfo hri = RandomUtils.nextBoolean() ? mergedRegions.getFirst() : mergedRegions.getSecond();
SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
AssignmentManager am = cluster.getMaster().getAssignmentManager();
RegionStates regionStates = am.getRegionStates();
// We should not be able to assign it again
am.assign(hri);
assertFalse("Merged region can't be assigned", regionStates.isRegionInTransition(hri));
// We should not be able to unassign it either
am.unassign(hri);
assertFalse("Merged region can't be unassigned", regionStates.isRegionInTransition(hri));
table.close();
} finally {
TEST_UTIL.deleteTable(tableName);
}
}
use of org.apache.hadoop.hbase.master.assignment.AssignmentManager in project hbase by apache.
the class TestBalancer method testAssignmentsForBalancer.
@Test
public void testAssignmentsForBalancer() throws Exception {
final TableName tableName = TableName.valueOf(name.getMethodName());
TEST_UTIL.createMultiRegionTable(tableName, HConstants.CATALOG_FAMILY, 10);
// disable table
final TableName disableTableName = TableName.valueOf("testDisableTable");
TEST_UTIL.createMultiRegionTable(disableTableName, HConstants.CATALOG_FAMILY, 10);
TEST_UTIL.getAdmin().disableTable(disableTableName);
HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
AssignmentManager assignmentManager = master.getAssignmentManager();
RegionStates regionStates = assignmentManager.getRegionStates();
ServerName sn1 = ServerName.parseServerName("asf903.gq1.ygridcore.net,52690,1517835491385");
regionStates.getOrCreateServer(sn1);
TableStateManager tableStateManager = master.getTableStateManager();
ServerManager serverManager = master.getServerManager();
Map<TableName, Map<ServerName, List<RegionInfo>>> assignments = assignmentManager.getRegionStates().getAssignmentsForBalancer(tableStateManager, serverManager.getOnlineServersList());
assertFalse(assignments.containsKey(disableTableName));
assertTrue(assignments.containsKey(tableName));
assertFalse(assignments.get(tableName).containsKey(sn1));
}
Aggregations