Search in sources :

Example 56 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.

the class TestAccessController method testGlobalAuthorizationForNewRegisteredRS.

@Test(timeout = 180000)
public void testGlobalAuthorizationForNewRegisteredRS() throws Exception {
    LOG.debug("Test for global authorization for a new registered RegionServer.");
    MiniHBaseCluster hbaseCluster = TEST_UTIL.getHBaseCluster();
    final Admin admin = TEST_UTIL.getAdmin();
    HTableDescriptor htd = new HTableDescriptor(TEST_TABLE2);
    htd.addFamily(new HColumnDescriptor(TEST_FAMILY));
    createTable(TEST_UTIL, htd);
    // Starting a new RegionServer.
    JVMClusterUtil.RegionServerThread newRsThread = hbaseCluster.startRegionServer();
    final HRegionServer newRs = newRsThread.getRegionServer();
    // Move region to the new RegionServer.
    List<HRegionLocation> regions;
    try (RegionLocator locator = systemUserConnection.getRegionLocator(TEST_TABLE2)) {
        regions = locator.getAllRegionLocations();
    }
    HRegionLocation location = regions.get(0);
    final HRegionInfo hri = location.getRegionInfo();
    final ServerName server = location.getServerName();
    try (Table table = systemUserConnection.getTable(TEST_TABLE2)) {
        AccessTestAction moveAction = new AccessTestAction() {

            @Override
            public Object run() throws Exception {
                admin.move(hri.getEncodedNameAsBytes(), Bytes.toBytes(newRs.getServerName().getServerName()));
                return null;
            }
        };
        SUPERUSER.runAs(moveAction);
        final int RETRIES_LIMIT = 10;
        int retries = 0;
        while (newRs.getOnlineRegions(TEST_TABLE2).size() < 1 && retries < RETRIES_LIMIT) {
            LOG.debug("Waiting for region to be opened. Already retried " + retries + " times.");
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }
            retries++;
            if (retries == RETRIES_LIMIT - 1) {
                fail("Retry exhaust for waiting region to be opened.");
            }
        }
        // Verify write permission for user "admin2" who has the global
        // permissions.
        AccessTestAction putAction = new AccessTestAction() {

            @Override
            public Object run() throws Exception {
                Put put = new Put(Bytes.toBytes("test"));
                put.addColumn(TEST_FAMILY, Bytes.toBytes("qual"), Bytes.toBytes("value"));
                table.put(put);
                return null;
            }
        };
        USER_ADMIN.runAs(putAction);
    }
}
Also used : RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) Table(org.apache.hadoop.hbase.client.Table) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) Admin(org.apache.hadoop.hbase.client.Admin) Put(org.apache.hadoop.hbase.client.Put) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) JVMClusterUtil(org.apache.hadoop.hbase.util.JVMClusterUtil) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Example 57 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.

the class TestAssignmentListener method testServerListener.

@Test(timeout = 60000)
public void testServerListener() throws IOException, InterruptedException {
    ServerManager serverManager = TEST_UTIL.getHBaseCluster().getMaster().getServerManager();
    DummyServerListener listener = new DummyServerListener();
    serverManager.registerListener(listener);
    try {
        MiniHBaseCluster miniCluster = TEST_UTIL.getMiniHBaseCluster();
        // Start a new Region Server
        miniCluster.startRegionServer();
        listener.awaitModifications(1);
        assertEquals(1, listener.getAddedCount());
        assertEquals(0, listener.getRemovedCount());
        // Start another Region Server
        listener.reset();
        miniCluster.startRegionServer();
        listener.awaitModifications(1);
        assertEquals(1, listener.getAddedCount());
        assertEquals(0, listener.getRemovedCount());
        int nrs = miniCluster.getRegionServerThreads().size();
        // Stop a Region Server
        listener.reset();
        miniCluster.stopRegionServer(nrs - 1);
        listener.awaitModifications(1);
        assertEquals(0, listener.getAddedCount());
        assertEquals(1, listener.getRemovedCount());
        // Stop another Region Server
        listener.reset();
        miniCluster.stopRegionServer(nrs - 2);
        listener.awaitModifications(1);
        assertEquals(0, listener.getAddedCount());
        assertEquals(1, listener.getRemovedCount());
    } finally {
        serverManager.unregisterListener(listener);
    }
}
Also used : MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) Test(org.junit.Test)

Example 58 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.

the class TestAssignmentManagerOnCluster method testSSHWaitForServerToAssignRegion.

/**
   * Test SSH waiting for extra region server for assignment
   */
@Test(timeout = 300000)
public void testSSHWaitForServerToAssignRegion() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    boolean startAServer = false;
    try {
        HTableDescriptor desc = new HTableDescriptor(tableName);
        desc.addFamily(new HColumnDescriptor(FAMILY));
        admin.createTable(desc);
        HMaster master = cluster.getMaster();
        final ServerManager serverManager = master.getServerManager();
        MyLoadBalancer.countRegionServers = Integer.valueOf(serverManager.countOfRegionServers());
        HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(tableName);
        assertNotNull("First region should be assigned", rs);
        final ServerName serverName = rs.getServerName();
        // Wait till SSH tried to assign regions a several times
        int counter = MyLoadBalancer.counter.get() + 5;
        cluster.killRegionServer(serverName);
        startAServer = true;
        cluster.waitForRegionServerToStop(serverName, -1);
        while (counter > MyLoadBalancer.counter.get()) {
            Thread.sleep(1000);
        }
        cluster.startRegionServer();
        startAServer = false;
        // Wait till the dead server is processed by SSH
        TEST_UTIL.waitFor(120000, 1000, new Waiter.Predicate<Exception>() {

            @Override
            public boolean evaluate() throws Exception {
                return serverManager.isServerDead(serverName) && !serverManager.areDeadServersInProgress();
            }
        });
        TEST_UTIL.waitUntilNoRegionsInTransition(300000);
        rs = TEST_UTIL.getRSForFirstRegionInTable(tableName);
        assertTrue("First region should be re-assigned to a different server", rs != null && !serverName.equals(rs.getServerName()));
    } finally {
        MyLoadBalancer.countRegionServers = null;
        TEST_UTIL.deleteTable(tableName);
        if (startAServer) {
            cluster.startRegionServer();
        }
    }
}
Also used : HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) UnknownRegionException(org.apache.hadoop.hbase.UnknownRegionException) KeeperException(org.apache.zookeeper.KeeperException) IOException(java.io.IOException) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) TableName(org.apache.hadoop.hbase.TableName) ServerName(org.apache.hadoop.hbase.ServerName) Waiter(org.apache.hadoop.hbase.Waiter) Test(org.junit.Test)

Example 59 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.

the class TestAssignmentManagerOnCluster method testAssignRacingWithSSH.

/**
   * Test force unassign/assign a region hosted on a dead server
   */
@Test(timeout = 60000)
public void testAssignRacingWithSSH() throws Exception {
    final TableName tableName = TableName.valueOf(name.getMethodName());
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    MyMaster master = null;
    try {
        HTableDescriptor desc = new HTableDescriptor(tableName);
        desc.addFamily(new HColumnDescriptor(FAMILY));
        admin.createTable(desc);
        Table meta = TEST_UTIL.getConnection().getTable(TableName.META_TABLE_NAME);
        HRegionInfo hri = new HRegionInfo(desc.getTableName(), Bytes.toBytes("A"), Bytes.toBytes("Z"));
        MetaTableAccessor.addRegionToMeta(meta, hri);
        // Assign the region
        master = (MyMaster) cluster.getMaster();
        AssignmentManager am = master.getAssignmentManager();
        am.assign(hri);
        // Hold SSH before killing the hosting server
        master.enableSSH(false);
        RegionStates regionStates = am.getRegionStates();
        ServerName metaServer = regionStates.getRegionServerOfRegion(HRegionInfo.FIRST_META_REGIONINFO);
        while (true) {
            assertTrue(am.waitForAssignment(hri));
            RegionState state = regionStates.getRegionState(hri);
            ServerName oldServerName = state.getServerName();
            if (!ServerName.isSameHostnameAndPort(oldServerName, metaServer)) {
                // Kill the hosting server, which doesn't have meta on it.
                cluster.killRegionServer(oldServerName);
                cluster.waitForRegionServerToStop(oldServerName, -1);
                break;
            }
            int i = cluster.getServerWithMeta();
            HRegionServer rs = cluster.getRegionServer(i == 0 ? 1 : 0);
            oldServerName = rs.getServerName();
            master.move(hri.getEncodedNameAsBytes(), Bytes.toBytes(oldServerName.getServerName()));
        }
        // You can't assign a dead region before SSH
        am.assign(hri, true);
        RegionState state = regionStates.getRegionState(hri);
        assertTrue(state.isFailedClose());
        // You can't unassign a dead region before SSH either
        am.unassign(hri);
        state = regionStates.getRegionState(hri);
        assertTrue(state.isFailedClose());
        // Enable SSH so that log can be split
        master.enableSSH(true);
        // let's check if it's assigned after it's out of transition.
        // no need to assign it manually, SSH should do it
        am.waitOnRegionToClearRegionsInTransition(hri);
        assertTrue(am.waitForAssignment(hri));
        ServerName serverName = master.getAssignmentManager().getRegionStates().getRegionServerOfRegion(hri);
        TEST_UTIL.assertRegionOnlyOnServer(hri, serverName, 6000);
    } finally {
        if (master != null) {
            master.enableSSH(true);
        }
        TEST_UTIL.deleteTable(tableName);
        cluster.startRegionServer();
    }
}
Also used : Table(org.apache.hadoop.hbase.client.Table) HColumnDescriptor(org.apache.hadoop.hbase.HColumnDescriptor) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) HTableDescriptor(org.apache.hadoop.hbase.HTableDescriptor) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Example 60 with MiniHBaseCluster

use of org.apache.hadoop.hbase.MiniHBaseCluster in project hbase by apache.

the class TestDistributedLogSplitting method abortRSAndWaitForRecovery.

private void abortRSAndWaitForRecovery(HRegionServer hrs, final ZooKeeperWatcher zkw, final int numRegions) throws Exception {
    final MiniHBaseCluster tmpCluster = this.cluster;
    // abort RS
    LOG.info("Aborting region server: " + hrs.getServerName());
    hrs.abort("testing");
    // wait for abort completes
    TEST_UTIL.waitFor(120000, 200, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return (tmpCluster.getLiveRegionServerThreads().size() <= (NUM_RS - 1));
        }
    });
    // wait for regions come online
    TEST_UTIL.waitFor(180000, 200, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return (HBaseTestingUtility.getAllOnlineRegions(tmpCluster).size() >= (numRegions + 1));
        }
    });
    // wait for all regions are fully recovered
    TEST_UTIL.waitFor(180000, 200, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            List<String> recoveringRegions = zkw.getRecoverableZooKeeper().getChildren(zkw.znodePaths.recoveringRegionsZNode, false);
            return (recoveringRegions != null && recoveringRegions.isEmpty());
        }
    });
}
Also used : MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Waiter(org.apache.hadoop.hbase.Waiter) OperationConflictException(org.apache.hadoop.hbase.exceptions.OperationConflictException) RegionInRecoveryException(org.apache.hadoop.hbase.exceptions.RegionInRecoveryException) IOException(java.io.IOException) TimeoutException(java.util.concurrent.TimeoutException) RetriesExhaustedWithDetailsException(org.apache.hadoop.hbase.client.RetriesExhaustedWithDetailsException) ServerNotRunningYetException(org.apache.hadoop.hbase.ipc.ServerNotRunningYetException)

Aggregations

MiniHBaseCluster (org.apache.hadoop.hbase.MiniHBaseCluster)86 Test (org.junit.Test)58 TableName (org.apache.hadoop.hbase.TableName)32 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)25 Table (org.apache.hadoop.hbase.client.Table)23 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)21 HMaster (org.apache.hadoop.hbase.master.HMaster)21 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)20 ServerName (org.apache.hadoop.hbase.ServerName)19 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)19 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)18 JVMClusterUtil (org.apache.hadoop.hbase.util.JVMClusterUtil)14 Admin (org.apache.hadoop.hbase.client.Admin)12 MasterCoprocessorHost (org.apache.hadoop.hbase.master.MasterCoprocessorHost)12 IOException (java.io.IOException)11 Region (org.apache.hadoop.hbase.regionserver.Region)11 HBaseTestingUtility (org.apache.hadoop.hbase.HBaseTestingUtility)10 Put (org.apache.hadoop.hbase.client.Put)8 TreeMap (java.util.TreeMap)7 Waiter (org.apache.hadoop.hbase.Waiter)7