Search in sources :

Example 91 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestZooKeeper method testRegionAssignmentAfterMasterRecoveryDueToZKExpiry.

/**
 * Tests that the master does not call retainAssignment after recovery from expired zookeeper
 * session. Without the HBASE-6046 fix master always tries to assign all the user regions by
 * calling retainAssignment.
 */
@Test
public void testRegionAssignmentAfterMasterRecoveryDueToZKExpiry() throws Exception {
    SingleProcessHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    cluster.startRegionServer();
    cluster.waitForActiveAndReadyMaster(10000);
    HMaster m = cluster.getMaster();
    final ZKWatcher zkw = m.getZooKeeper();
    // now the cluster is up. So assign some regions.
    try (Admin admin = TEST_UTIL.getAdmin()) {
        byte[][] SPLIT_KEYS = new byte[][] { Bytes.toBytes("a"), Bytes.toBytes("b"), Bytes.toBytes("c"), Bytes.toBytes("d"), Bytes.toBytes("e"), Bytes.toBytes("f"), Bytes.toBytes("g"), Bytes.toBytes("h"), Bytes.toBytes("i"), Bytes.toBytes("j") };
        TableDescriptor htd = TableDescriptorBuilder.newBuilder(TableName.valueOf(name.getMethodName())).setColumnFamily(ColumnFamilyDescriptorBuilder.of(HConstants.CATALOG_FAMILY)).build();
        admin.createTable(htd, SPLIT_KEYS);
        TEST_UTIL.waitUntilNoRegionsInTransition(60000);
        m.getZooKeeper().close();
        MockLoadBalancer.retainAssignCalled = false;
        final int expectedNumOfListeners = countPermanentListeners(zkw);
        m.abort("Test recovery from zk session expired", new KeeperException.SessionExpiredException());
        // Master doesn't recover any more
        assertTrue(m.isStopped());
        // The recovered master should not call retainAssignment, as it is not a
        // clean startup.
        assertFalse("Retain assignment should not be called", MockLoadBalancer.retainAssignCalled);
        // number of listeners should be same as the value before master aborted
        // wait for new master is initialized
        cluster.waitForActiveAndReadyMaster(120000);
        final HMaster newMaster = cluster.getMasterThread().getMaster();
        assertEquals(expectedNumOfListeners, countPermanentListeners(newMaster.getZooKeeper()));
    }
}
Also used : ZKWatcher(org.apache.hadoop.hbase.zookeeper.ZKWatcher) HMaster(org.apache.hadoop.hbase.master.HMaster) Admin(org.apache.hadoop.hbase.client.Admin) TableDescriptor(org.apache.hadoop.hbase.client.TableDescriptor) KeeperException(org.apache.zookeeper.KeeperException) Test(org.junit.Test)

Example 92 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestClientClusterStatus method testMasterAndBackupMastersStatus.

@Test
public void testMasterAndBackupMastersStatus() throws Exception {
    // get all the master threads
    List<MasterThread> masterThreads = CLUSTER.getMasterThreads();
    int numActive = 0;
    int activeIndex = 0;
    ServerName activeName = null;
    HMaster active = null;
    for (int i = 0; i < masterThreads.size(); i++) {
        if (masterThreads.get(i).getMaster().isActiveMaster()) {
            numActive++;
            activeIndex = i;
            active = masterThreads.get(activeIndex).getMaster();
            activeName = active.getServerName();
        }
    }
    Assert.assertNotNull(active);
    Assert.assertEquals(1, numActive);
    Assert.assertEquals(MASTERS, masterThreads.size());
    // Retrieve master and backup masters infos only.
    EnumSet<Option> options = EnumSet.of(Option.MASTER, Option.BACKUP_MASTERS);
    ClusterMetrics status = ADMIN.getClusterMetrics(options);
    Assert.assertTrue(status.getMasterName().equals(activeName));
    Assert.assertEquals(MASTERS - 1, status.getBackupMasterNames().size());
}
Also used : MasterThread(org.apache.hadoop.hbase.util.JVMClusterUtil.MasterThread) HMaster(org.apache.hadoop.hbase.master.HMaster) Option(org.apache.hadoop.hbase.ClusterMetrics.Option) Test(org.junit.Test)

Example 93 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestFailedMetaReplicaAssigment method testFailedReplicaAssignment.

@Test
public void testFailedReplicaAssignment() throws InterruptedException {
    HMaster master = TEST_UTIL.getMiniHBaseCluster().getMaster();
    // waiting for master to come up
    TEST_UTIL.waitFor(30000, () -> master.isInitialized());
    AssignmentManager am = master.getAssignmentManager();
    // showing one of the replicas got assigned
    RegionInfo metaReplicaHri = RegionReplicaUtil.getRegionInfoForReplica(RegionInfoBuilder.FIRST_META_REGIONINFO, 1);
    // we use assignAsync so we need to wait a bit
    TEST_UTIL.waitFor(30000, () -> {
        RegionStateNode metaReplicaRegionNode = am.getRegionStates().getOrCreateRegionStateNode(metaReplicaHri);
        return metaReplicaRegionNode.getRegionLocation() != null;
    });
    // showing one of the replicas failed to be assigned
    RegionInfo metaReplicaHri2 = RegionReplicaUtil.getRegionInfoForReplica(RegionInfoBuilder.FIRST_META_REGIONINFO, 2);
    RegionStateNode metaReplicaRegionNode2 = am.getRegionStates().getOrCreateRegionStateNode(metaReplicaHri2);
    // wait for several seconds to make sure that it is not assigned
    for (int i = 0; i < 3; i++) {
        Thread.sleep(2000);
        assertNull(metaReplicaRegionNode2.getRegionLocation());
    }
    // showing master is active and running
    assertFalse(master.isStopping());
    assertFalse(master.isStopped());
    assertTrue(master.isActiveMaster());
}
Also used : HMaster(org.apache.hadoop.hbase.master.HMaster) AssignmentManager(org.apache.hadoop.hbase.master.assignment.AssignmentManager) RegionStateNode(org.apache.hadoop.hbase.master.assignment.RegionStateNode) Test(org.junit.Test)

Example 94 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestTransitPeerSyncReplicationStateProcedureRetry method testRecoveryAndDoubleExecution.

@Test
public void testRecoveryAndDoubleExecution() throws Exception {
    UTIL2.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID, SyncReplicationState.STANDBY);
    UTIL1.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID, SyncReplicationState.ACTIVE);
    UTIL1.getAdmin().disableReplicationPeer(PEER_ID);
    write(UTIL1, 0, 100);
    Thread.sleep(2000);
    // peer is disabled so no data have been replicated
    verifyNotReplicatedThroughRegion(UTIL2, 0, 100);
    // transit the A to DA first to avoid too many error logs.
    UTIL1.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID, SyncReplicationState.DOWNGRADE_ACTIVE);
    HMaster master = UTIL2.getHBaseCluster().getMaster();
    ProcedureExecutor<MasterProcedureEnv> procExec = master.getMasterProcedureExecutor();
    // Enable test flags and then queue the procedure.
    ProcedureTestingUtility.waitNoProcedureRunning(procExec);
    ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, true);
    Thread t = new Thread() {

        @Override
        public void run() {
            try {
                UTIL2.getAdmin().transitReplicationPeerSyncReplicationState(PEER_ID, SyncReplicationState.DOWNGRADE_ACTIVE);
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }
    };
    t.start();
    UTIL2.waitFor(30000, () -> procExec.getProcedures().stream().anyMatch(p -> p instanceof TransitPeerSyncReplicationStateProcedure && !p.isFinished()));
    long procId = procExec.getProcedures().stream().filter(p -> p instanceof TransitPeerSyncReplicationStateProcedure && !p.isFinished()).mapToLong(Procedure::getProcId).min().getAsLong();
    MasterProcedureTestingUtility.testRecoveryAndDoubleExecution(procExec, procId);
    ProcedureTestingUtility.setKillAndToggleBeforeStoreUpdate(procExec, false);
    assertEquals(SyncReplicationState.DOWNGRADE_ACTIVE, UTIL2.getAdmin().getReplicationPeerSyncReplicationState(PEER_ID));
    verify(UTIL2, 0, 100);
}
Also used : BeforeClass(org.junit.BeforeClass) SyncReplicationState(org.apache.hadoop.hbase.replication.SyncReplicationState) HBaseClassTestRule(org.apache.hadoop.hbase.HBaseClassTestRule) ProcedureTestingUtility(org.apache.hadoop.hbase.procedure2.ProcedureTestingUtility) LargeTests(org.apache.hadoop.hbase.testclassification.LargeTests) IOException(java.io.IOException) Test(org.junit.Test) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) MasterProcedureTestingUtility(org.apache.hadoop.hbase.master.procedure.MasterProcedureTestingUtility) Category(org.junit.experimental.categories.Category) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) UncheckedIOException(java.io.UncheckedIOException) SyncReplicationTestBase(org.apache.hadoop.hbase.replication.SyncReplicationTestBase) ProcedureExecutor(org.apache.hadoop.hbase.procedure2.ProcedureExecutor) MasterTests(org.apache.hadoop.hbase.testclassification.MasterTests) MasterProcedureConstants(org.apache.hadoop.hbase.master.procedure.MasterProcedureConstants) ClassRule(org.junit.ClassRule) HMaster(org.apache.hadoop.hbase.master.HMaster) Assert.assertEquals(org.junit.Assert.assertEquals) HMaster(org.apache.hadoop.hbase.master.HMaster) Procedure(org.apache.hadoop.hbase.procedure2.Procedure) MasterProcedureEnv(org.apache.hadoop.hbase.master.procedure.MasterProcedureEnv) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) UncheckedIOException(java.io.UncheckedIOException) Test(org.junit.Test)

Example 95 with HMaster

use of org.apache.hadoop.hbase.master.HMaster in project hbase by apache.

the class TestSCP method testConcurrentSCPForSameServer.

@Test
public void testConcurrentSCPForSameServer() throws Exception {
    final TableName tableName = TableName.valueOf("testConcurrentSCPForSameServer");
    try (Table t = createTable(tableName)) {
        // Load the table with a bit of data so some logs to split and some edits in each region.
        this.util.loadTable(t, HBaseTestingUtil.COLUMNS[0]);
        final int count = HBaseTestingUtil.countRows(t);
        assertTrue("expected some rows", count > 0);
        // find the first server that match the request and executes the test
        ServerName rsToKill = null;
        for (RegionInfo hri : util.getAdmin().getRegions(tableName)) {
            final ServerName serverName = AssignmentTestingUtil.getServerHoldingRegion(util, hri);
            if (AssignmentTestingUtil.isServerHoldingMeta(util, serverName) == true) {
                rsToKill = serverName;
                break;
            }
        }
        HMaster master = util.getHBaseCluster().getMaster();
        final ProcedureExecutor<MasterProcedureEnv> pExecutor = master.getMasterProcedureExecutor();
        ServerCrashProcedure procB = new ServerCrashProcedure(pExecutor.getEnvironment(), rsToKill, false, false);
        AssignmentTestingUtil.killRs(util, rsToKill);
        long procId = getSCPProcId(pExecutor);
        Procedure<?> procA = pExecutor.getProcedure(procId);
        LOG.info("submit SCP procedureA");
        util.waitFor(5000, () -> procA.hasLock());
        LOG.info("procedureA acquired the lock");
        assertEquals(Procedure.LockState.LOCK_EVENT_WAIT, procB.acquireLock(pExecutor.getEnvironment()));
        LOG.info("procedureB should not be able to get the lock");
        util.waitFor(60000, () -> procB.acquireLock(pExecutor.getEnvironment()) == Procedure.LockState.LOCK_ACQUIRED);
        LOG.info("when procedure B get the lock, procedure A should be finished");
        assertTrue(procA.isFinished());
    }
}
Also used : TableName(org.apache.hadoop.hbase.TableName) Table(org.apache.hadoop.hbase.client.Table) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) Test(org.junit.Test)

Aggregations

HMaster (org.apache.hadoop.hbase.master.HMaster)132 Test (org.junit.Test)91 TableName (org.apache.hadoop.hbase.TableName)42 IOException (java.io.IOException)33 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)31 ServerName (org.apache.hadoop.hbase.ServerName)24 Admin (org.apache.hadoop.hbase.client.Admin)23 Table (org.apache.hadoop.hbase.client.Table)23 SingleProcessHBaseCluster (org.apache.hadoop.hbase.SingleProcessHBaseCluster)22 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)16 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)15 Configuration (org.apache.hadoop.conf.Configuration)13 MasterCoprocessorHost (org.apache.hadoop.hbase.master.MasterCoprocessorHost)12 BeforeClass (org.junit.BeforeClass)11 AssignmentManager (org.apache.hadoop.hbase.master.assignment.AssignmentManager)10 List (java.util.List)9 HBaseClassTestRule (org.apache.hadoop.hbase.HBaseClassTestRule)9 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)9 RegionStates (org.apache.hadoop.hbase.master.assignment.RegionStates)9 ClassRule (org.junit.ClassRule)9