Search in sources :

Example 11 with AssignmentManager

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));
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) TableName(org.apache.hadoop.hbase.TableName) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) Test(org.junit.Test)

Example 12 with AssignmentManager

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");
}
Also used : AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) LoadBalancerTracker(org.apache.hadoop.hbase.zookeeper.LoadBalancerTracker) Abortable(org.apache.hadoop.hbase.Abortable) ServerName(org.apache.hadoop.hbase.ServerName) StartTestingClusterOption(org.apache.hadoop.hbase.StartTestingClusterOption) HashSet(java.util.HashSet)

Example 13 with AssignmentManager

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);
}
Also used : ServerManager(org.apache.hadoop.hbase.master.ServerManager) RegionState(org.apache.hadoop.hbase.master.RegionState) RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates) ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) HMaster(org.apache.hadoop.hbase.master.HMaster) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) ArrayList(java.util.ArrayList) ZNodePaths(org.apache.hadoop.hbase.zookeeper.ZNodePaths) Admin(org.apache.hadoop.hbase.client.Admin) DeadServer(org.apache.hadoop.hbase.master.DeadServer) Before(org.junit.Before)

Example 14 with AssignmentManager

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);
    }
}
Also used : SingleProcessHBaseCluster(org.apache.hadoop.hbase.SingleProcessHBaseCluster) TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Test(org.junit.Test)

Example 15 with AssignmentManager

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));
}
Also used : TableName(org.apache.hadoop.hbase.TableName) RegionStates(org.apache.hadoop.hbase.master.assignment.RegionStates) ServerName(org.apache.hadoop.hbase.ServerName) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Map(java.util.Map) Test(org.junit.Test)

Aggregations

AssignmentManager (org.apache.hadoop.hbase.master.assignment.AssignmentManager)30 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)13 Test (org.junit.Test)13 TableName (org.apache.hadoop.hbase.TableName)10 HMaster (org.apache.hadoop.hbase.master.HMaster)10 IOException (java.io.IOException)9 RegionStates (org.apache.hadoop.hbase.master.assignment.RegionStates)9 ServerName (org.apache.hadoop.hbase.ServerName)7 RegionStateNode (org.apache.hadoop.hbase.master.assignment.RegionStateNode)6 TransitRegionStateProcedure (org.apache.hadoop.hbase.master.assignment.TransitRegionStateProcedure)5 ArrayList (java.util.ArrayList)4 DoNotRetryIOException (org.apache.hadoop.hbase.DoNotRetryIOException)4 List (java.util.List)3 Map (java.util.Map)3 Path (org.apache.hadoop.fs.Path)3 SingleProcessHBaseCluster (org.apache.hadoop.hbase.SingleProcessHBaseCluster)3 Admin (org.apache.hadoop.hbase.client.Admin)3 HashMap (java.util.HashMap)2 HashSet (java.util.HashSet)2 ExecutionException (java.util.concurrent.ExecutionException)2