Search in sources :

Example 16 with ClusterConnection

use of org.apache.hadoop.hbase.client.ClusterConnection in project hbase by apache.

the class TestRegionReplicaReplicationEndpointNoMaster method testReplayCallable.

@Test(timeout = 240000)
public void testReplayCallable() throws Exception {
    // tests replaying the edits to a secondary region replica using the Callable directly
    openRegion(HTU, rs0, hriSecondary);
    ClusterConnection connection = (ClusterConnection) ConnectionFactory.createConnection(HTU.getConfiguration());
    //load some data to primary
    HTU.loadNumericRows(table, f, 0, 1000);
    Assert.assertEquals(1000, entries.size());
    // replay the edits to the secondary using replay callable
    replicateUsingCallable(connection, entries);
    Region region = rs0.getFromOnlineRegions(hriSecondary.getEncodedName());
    HTU.verifyNumericRows(region, f, 0, 1000);
    HTU.deleteNumericRows(table, f, 0, 1000);
    closeRegion(HTU, rs0, hriSecondary);
    connection.close();
}
Also used : ClusterConnection(org.apache.hadoop.hbase.client.ClusterConnection) Region(org.apache.hadoop.hbase.regionserver.Region) TestRegionServerNoMaster.closeRegion(org.apache.hadoop.hbase.regionserver.TestRegionServerNoMaster.closeRegion) TestRegionServerNoMaster.openRegion(org.apache.hadoop.hbase.regionserver.TestRegionServerNoMaster.openRegion) Test(org.junit.Test)

Example 17 with ClusterConnection

use of org.apache.hadoop.hbase.client.ClusterConnection in project hbase by apache.

the class TestRegionReplicaReplicationEndpointNoMaster method testRegionReplicaReplicationEndpointReplicate.

@Test(timeout = 240000)
public void testRegionReplicaReplicationEndpointReplicate() throws Exception {
    // tests replaying the edits to a secondary region replica using the RRRE.replicate()
    openRegion(HTU, rs0, hriSecondary);
    ClusterConnection connection = (ClusterConnection) ConnectionFactory.createConnection(HTU.getConfiguration());
    RegionReplicaReplicationEndpoint replicator = new RegionReplicaReplicationEndpoint();
    ReplicationEndpoint.Context context = mock(ReplicationEndpoint.Context.class);
    when(context.getConfiguration()).thenReturn(HTU.getConfiguration());
    when(context.getMetrics()).thenReturn(mock(MetricsSource.class));
    replicator.init(context);
    replicator.start();
    //load some data to primary
    HTU.loadNumericRows(table, f, 0, 1000);
    Assert.assertEquals(1000, entries.size());
    // replay the edits to the secondary using replay callable
    final String fakeWalGroupId = "fakeWALGroup";
    replicator.replicate(new ReplicateContext().setEntries(Lists.newArrayList(entries)).setWalGroupId(fakeWalGroupId));
    Region region = rs0.getFromOnlineRegions(hriSecondary.getEncodedName());
    HTU.verifyNumericRows(region, f, 0, 1000);
    HTU.deleteNumericRows(table, f, 0, 1000);
    closeRegion(HTU, rs0, hriSecondary);
    connection.close();
}
Also used : ClusterConnection(org.apache.hadoop.hbase.client.ClusterConnection) ReplicationEndpoint(org.apache.hadoop.hbase.replication.ReplicationEndpoint) ReplicateContext(org.apache.hadoop.hbase.replication.ReplicationEndpoint.ReplicateContext) Region(org.apache.hadoop.hbase.regionserver.Region) TestRegionServerNoMaster.closeRegion(org.apache.hadoop.hbase.regionserver.TestRegionServerNoMaster.closeRegion) TestRegionServerNoMaster.openRegion(org.apache.hadoop.hbase.regionserver.TestRegionServerNoMaster.openRegion) Test(org.junit.Test)

Example 18 with ClusterConnection

use of org.apache.hadoop.hbase.client.ClusterConnection in project hbase by apache.

the class ServerCrashProcedure method isMetaAssignedQuickTest.

/**
   * A quick test that hbase:meta is assigned; blocks for short time only.
   * @return True if hbase:meta location is available and verified as good.
   * @throws InterruptedException
   * @throws IOException
   */
private boolean isMetaAssignedQuickTest(final MasterProcedureEnv env) throws InterruptedException, IOException {
    ZooKeeperWatcher zkw = env.getMasterServices().getZooKeeper();
    MetaTableLocator mtl = env.getMasterServices().getMetaTableLocator();
    boolean metaAssigned = false;
    // Is hbase:meta location available yet?
    if (mtl.isLocationAvailable(zkw)) {
        ClusterConnection connection = env.getMasterServices().getClusterConnection();
        // Is hbase:meta location good yet?
        long timeout = env.getMasterConfiguration().getLong(KEY_SHORT_WAIT_ON_META, DEFAULT_SHORT_WAIT_ON_META);
        if (mtl.verifyMetaRegionLocation(connection, zkw, timeout)) {
            metaAssigned = true;
        }
    }
    return metaAssigned;
}
Also used : ClusterConnection(org.apache.hadoop.hbase.client.ClusterConnection) MetaTableLocator(org.apache.hadoop.hbase.zookeeper.MetaTableLocator) ZooKeeperWatcher(org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)

Example 19 with ClusterConnection

use of org.apache.hadoop.hbase.client.ClusterConnection in project hbase by apache.

the class TestClockSkewDetection method testClockSkewDetection.

@Test
public void testClockSkewDetection() throws Exception {
    final Configuration conf = HBaseConfiguration.create();
    ServerManager sm = new ServerManager(new MockNoopMasterServices(conf) {

        @Override
        public ClusterConnection getClusterConnection() {
            ClusterConnection conn = mock(ClusterConnection.class);
            when(conn.getRpcControllerFactory()).thenReturn(mock(RpcControllerFactory.class));
            return conn;
        }
    }, true);
    LOG.debug("regionServerStartup 1");
    InetAddress ia1 = InetAddress.getLocalHost();
    RegionServerStartupRequest.Builder request = RegionServerStartupRequest.newBuilder();
    request.setPort(1234);
    request.setServerStartCode(-1);
    request.setServerCurrentTime(System.currentTimeMillis());
    sm.regionServerStartup(request.build(), ia1);
    final Configuration c = HBaseConfiguration.create();
    long maxSkew = c.getLong("hbase.master.maxclockskew", 30000);
    long warningSkew = c.getLong("hbase.master.warningclockskew", 1000);
    try {
        //Master Time > Region Server Time
        LOG.debug("Test: Master Time > Region Server Time");
        LOG.debug("regionServerStartup 2");
        InetAddress ia2 = InetAddress.getLocalHost();
        request = RegionServerStartupRequest.newBuilder();
        request.setPort(1235);
        request.setServerStartCode(-1);
        request.setServerCurrentTime(System.currentTimeMillis() - maxSkew * 2);
        sm.regionServerStartup(request.build(), ia2);
        fail("HMaster should have thrown a ClockOutOfSyncException but didn't.");
    } catch (ClockOutOfSyncException e) {
        //we want an exception
        LOG.info("Recieved expected exception: " + e);
    }
    try {
        // Master Time < Region Server Time
        LOG.debug("Test: Master Time < Region Server Time");
        LOG.debug("regionServerStartup 3");
        InetAddress ia3 = InetAddress.getLocalHost();
        request = RegionServerStartupRequest.newBuilder();
        request.setPort(1236);
        request.setServerStartCode(-1);
        request.setServerCurrentTime(System.currentTimeMillis() + maxSkew * 2);
        sm.regionServerStartup(request.build(), ia3);
        fail("HMaster should have thrown a ClockOutOfSyncException but didn't.");
    } catch (ClockOutOfSyncException e) {
        // we want an exception
        LOG.info("Recieved expected exception: " + e);
    }
    // make sure values above warning threshold but below max threshold don't kill
    LOG.debug("regionServerStartup 4");
    InetAddress ia4 = InetAddress.getLocalHost();
    request = RegionServerStartupRequest.newBuilder();
    request.setPort(1237);
    request.setServerStartCode(-1);
    request.setServerCurrentTime(System.currentTimeMillis() - warningSkew * 2);
    sm.regionServerStartup(request.build(), ia4);
    // make sure values above warning threshold but below max threshold don't kill
    LOG.debug("regionServerStartup 5");
    InetAddress ia5 = InetAddress.getLocalHost();
    request = RegionServerStartupRequest.newBuilder();
    request.setPort(1238);
    request.setServerStartCode(-1);
    request.setServerCurrentTime(System.currentTimeMillis() + warningSkew * 2);
    sm.regionServerStartup(request.build(), ia5);
}
Also used : ClusterConnection(org.apache.hadoop.hbase.client.ClusterConnection) HBaseConfiguration(org.apache.hadoop.hbase.HBaseConfiguration) Configuration(org.apache.hadoop.conf.Configuration) ClockOutOfSyncException(org.apache.hadoop.hbase.ClockOutOfSyncException) InetAddress(java.net.InetAddress) RegionServerStartupRequest(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos.RegionServerStartupRequest) Test(org.junit.Test)

Example 20 with ClusterConnection

use of org.apache.hadoop.hbase.client.ClusterConnection in project hbase by apache.

the class TestRSGroupsBase method testRegionMove.

@Test
public void testRegionMove() throws Exception {
    final RSGroupInfo newGroup = addGroup(getGroupName(name.getMethodName()), 1);
    final byte[] familyNameBytes = Bytes.toBytes("f");
    // All the regions created below will be assigned to the default group.
    TEST_UTIL.createMultiRegionTable(tableName, familyNameBytes, 6);
    TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            List<String> regions = getTableRegionMap().get(tableName);
            if (regions == null)
                return false;
            return getTableRegionMap().get(tableName).size() >= 6;
        }
    });
    //get target region to move
    Map<ServerName, List<String>> assignMap = getTableServerRegionMap().get(tableName);
    String targetRegion = null;
    for (ServerName server : assignMap.keySet()) {
        targetRegion = assignMap.get(server).size() > 0 ? assignMap.get(server).get(0) : null;
        if (targetRegion != null) {
            break;
        }
    }
    //get server which is not a member of new group
    ServerName targetServer = null;
    for (ServerName server : admin.getClusterStatus().getServers()) {
        if (!newGroup.containsServer(server.getAddress())) {
            targetServer = server;
            break;
        }
    }
    final AdminProtos.AdminService.BlockingInterface targetRS = ((ClusterConnection) admin.getConnection()).getAdmin(targetServer);
    //move target server to group
    rsGroupAdmin.moveServers(Sets.newHashSet(targetServer.getAddress()), newGroup.getName());
    TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return ProtobufUtil.getOnlineRegions(targetRS).size() <= 0;
        }
    });
    // Lets move this region to the new group.
    TEST_UTIL.getAdmin().move(Bytes.toBytes(HRegionInfo.encodeRegionName(Bytes.toBytes(targetRegion))), Bytes.toBytes(targetServer.getServerName()));
    TEST_UTIL.waitFor(WAIT_TIMEOUT, new Waiter.Predicate<Exception>() {

        @Override
        public boolean evaluate() throws Exception {
            return getTableRegionMap().get(tableName) != null && getTableRegionMap().get(tableName).size() == 6 && admin.getClusterStatus().getRegionsInTransition().size() < 1;
        }
    });
    //verify that targetServer didn't open it
    assertFalse(ProtobufUtil.getOnlineRegions(targetRS).contains(targetRegion));
}
Also used : IOException(java.io.IOException) ConstraintException(org.apache.hadoop.hbase.constraint.ConstraintException) ClusterConnection(org.apache.hadoop.hbase.client.ClusterConnection) ServerName(org.apache.hadoop.hbase.ServerName) LinkedList(java.util.LinkedList) List(java.util.List) Waiter(org.apache.hadoop.hbase.Waiter) Test(org.junit.Test)

Aggregations

ClusterConnection (org.apache.hadoop.hbase.client.ClusterConnection)23 Test (org.junit.Test)12 ServerName (org.apache.hadoop.hbase.ServerName)8 IOException (java.io.IOException)6 Configuration (org.apache.hadoop.conf.Configuration)4 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)4 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)4 TableName (org.apache.hadoop.hbase.TableName)4 ServiceException (org.apache.hadoop.hbase.shaded.com.google.protobuf.ServiceException)4 ArrayList (java.util.ArrayList)3 List (java.util.List)3 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)3 Waiter (org.apache.hadoop.hbase.Waiter)3 RegionLocator (org.apache.hadoop.hbase.client.RegionLocator)3 Result (org.apache.hadoop.hbase.client.Result)3 Table (org.apache.hadoop.hbase.client.Table)3 LinkedList (java.util.LinkedList)2 Map (java.util.Map)2 FileSystem (org.apache.hadoop.fs.FileSystem)2 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)2