Search in sources :

Example 11 with HRegionServer

use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.

the class TestMetaTableAccessor method testMetaUpdatesGoToPriorityQueue.

@Test
public void testMetaUpdatesGoToPriorityQueue() throws Exception {
    // This test has to be end-to-end, and do the verification from the server side
    Configuration c = UTIL.getConfiguration();
    c.set(RSRpcServices.REGION_SERVER_RPC_SCHEDULER_FACTORY_CLASS, SpyingRpcSchedulerFactory.class.getName());
    // restart so that new config takes place
    afterClass();
    beforeClass();
    final TableName tableName = TableName.valueOf(name.getMethodName());
    try (Admin admin = connection.getAdmin();
        RegionLocator rl = connection.getRegionLocator(tableName)) {
        // create a table and prepare for a manual split
        UTIL.createTable(tableName, "cf1");
        HRegionLocation loc = rl.getAllRegionLocations().get(0);
        HRegionInfo parent = loc.getRegionInfo();
        long rid = 1000;
        byte[] splitKey = Bytes.toBytes("a");
        HRegionInfo splitA = new HRegionInfo(parent.getTable(), parent.getStartKey(), splitKey, false, rid);
        HRegionInfo splitB = new HRegionInfo(parent.getTable(), splitKey, parent.getEndKey(), false, rid);
        // find the meta server
        MiniHBaseCluster cluster = UTIL.getMiniHBaseCluster();
        int rsIndex = cluster.getServerWithMeta();
        HRegionServer rs;
        if (rsIndex >= 0) {
            rs = cluster.getRegionServer(rsIndex);
        } else {
            // it is in master
            rs = cluster.getMaster();
        }
        SpyingRpcScheduler scheduler = (SpyingRpcScheduler) rs.getRpcServer().getScheduler();
        long prevCalls = scheduler.numPriorityCalls;
        MetaTableAccessor.splitRegion(connection, parent, splitA, splitB, loc.getServerName(), 1, false);
        assertTrue(prevCalls < scheduler.numPriorityCalls);
    }
}
Also used : RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) Configuration(org.apache.hadoop.conf.Configuration) Admin(org.apache.hadoop.hbase.client.Admin) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 12 with HRegionServer

use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.

the class TestMvccConsistentScanner method move.

private void move() throws IOException, InterruptedException {
    HRegionInfo region = UTIL.getHBaseCluster().getRegions(tableName).stream().findAny().get().getRegionInfo();
    HRegionServer rs = UTIL.getHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer()).filter(r -> !r.getOnlineTables().contains(tableName)).findAny().get();
    UTIL.getAdmin().move(region.getEncodedNameAsBytes(), Bytes.toBytes(rs.getServerName().getServerName()));
    while (UTIL.getRSForFirstRegionInTable(tableName) != rs) {
        Thread.sleep(100);
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) BeforeClass(org.junit.BeforeClass) LargeTests(org.apache.hadoop.hbase.testclassification.LargeTests) IOException(java.io.IOException) Test(org.junit.Test) ClientTests(org.apache.hadoop.hbase.testclassification.ClientTests) Category(org.junit.experimental.categories.Category) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Assert.assertNull(org.junit.Assert.assertNull) Rule(org.junit.Rule) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) TestName(org.junit.rules.TestName) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) Assert.assertEquals(org.junit.Assert.assertEquals) Bytes(org.apache.hadoop.hbase.util.Bytes) Before(org.junit.Before) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer)

Example 13 with HRegionServer

use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.

the class TestFromClientSide3 method find.

private static Region find(final TableName tableName) throws IOException, InterruptedException {
    HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(tableName);
    List<Region> regions = rs.getOnlineRegions(tableName);
    assertEquals(1, regions.size());
    return regions.get(0);
}
Also used : Region(org.apache.hadoop.hbase.regionserver.Region) HRegion(org.apache.hadoop.hbase.regionserver.HRegion) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer)

Example 14 with HRegionServer

use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.

the class TestHTableMultiplexerFlushCache method testOnRegionMove.

@Test
public void testOnRegionMove() throws Exception {
    // This test is doing near exactly the same thing that testOnRegionChange but avoiding the
    // potential to get a ConnectionClosingException. By moving the region, we can be certain that
    // the connection is still valid and that the implementation is correctly handling an invalid
    // Region cache (and not just tearing down the entire connection).
    final TableName tableName = TableName.valueOf(name.getMethodName());
    final int NUM_REGIONS = 10;
    Table htable = TEST_UTIL.createTable(tableName, new byte[][] { FAMILY }, 3, Bytes.toBytes("aaaaa"), Bytes.toBytes("zzzzz"), NUM_REGIONS);
    HTableMultiplexer multiplexer = new HTableMultiplexer(TEST_UTIL.getConfiguration(), PER_REGIONSERVER_QUEUE_SIZE);
    final RegionLocator regionLocator = TEST_UTIL.getConnection().getRegionLocator(tableName);
    Pair<byte[][], byte[][]> startEndRows = regionLocator.getStartEndKeys();
    byte[] row = startEndRows.getFirst()[1];
    assertTrue("2nd region should not start with empty row", row != null && row.length > 0);
    Put put = new Put(row).addColumn(FAMILY, QUALIFIER1, VALUE1);
    assertTrue("multiplexer.put returns", multiplexer.put(tableName, put));
    checkExistence(htable, row, FAMILY, QUALIFIER1, VALUE1);
    final HRegionLocation loc = regionLocator.getRegionLocation(row);
    final MiniHBaseCluster hbaseCluster = TEST_UTIL.getHBaseCluster();
    // The current server for the region we're writing to
    final ServerName originalServer = loc.getServerName();
    ServerName newServer = null;
    // Find a new server to move that region to
    for (int i = 0; i < SLAVES; i++) {
        HRegionServer rs = hbaseCluster.getRegionServer(0);
        if (!rs.getServerName().equals(originalServer.getServerName())) {
            newServer = rs.getServerName();
            break;
        }
    }
    assertNotNull("Did not find a new RegionServer to use", newServer);
    // Move the region
    LOG.info("Moving " + loc.getRegionInfo().getEncodedName() + " from " + originalServer + " to " + newServer);
    TEST_UTIL.getAdmin().move(loc.getRegionInfo().getEncodedNameAsBytes(), Bytes.toBytes(newServer.getServerName()));
    TEST_UTIL.waitUntilAllRegionsAssigned(tableName);
    // Send a new Put
    put = new Put(row).addColumn(FAMILY, QUALIFIER2, VALUE2);
    assertTrue("multiplexer.put returns", multiplexer.put(tableName, put));
    // We should see the update make it to the new server eventually
    checkExistence(htable, row, FAMILY, QUALIFIER2, VALUE2);
}
Also used : TableName(org.apache.hadoop.hbase.TableName) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Example 15 with HRegionServer

use of org.apache.hadoop.hbase.regionserver.HRegionServer in project hbase by apache.

the class TestFromClientSide method testNonCachedGetRegionLocation.

@Test
public /**
   * Tests the non cached version of getRegionLocator by moving a region.
   */
void testNonCachedGetRegionLocation() throws Exception {
    // Test Initialization.
    final TableName tableName = TableName.valueOf(name.getMethodName());
    byte[] family1 = Bytes.toBytes("f1");
    byte[] family2 = Bytes.toBytes("f2");
    try (Table table = TEST_UTIL.createTable(tableName, new byte[][] { family1, family2 }, 10);
        Admin admin = TEST_UTIL.getAdmin();
        RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName)) {
        List<HRegionLocation> allRegionLocations = locator.getAllRegionLocations();
        assertEquals(1, allRegionLocations.size());
        HRegionInfo regionInfo = allRegionLocations.get(0).getRegionInfo();
        ServerName addrBefore = allRegionLocations.get(0).getServerName();
        // Verify region location before move.
        HRegionLocation addrCache = locator.getRegionLocation(regionInfo.getStartKey(), false);
        HRegionLocation addrNoCache = locator.getRegionLocation(regionInfo.getStartKey(), true);
        assertEquals(addrBefore.getPort(), addrCache.getPort());
        assertEquals(addrBefore.getPort(), addrNoCache.getPort());
        ServerName addrAfter = null;
        // Now move the region to a different server.
        for (int i = 0; i < SLAVES; i++) {
            HRegionServer regionServer = TEST_UTIL.getHBaseCluster().getRegionServer(i);
            ServerName addr = regionServer.getServerName();
            if (addr.getPort() != addrBefore.getPort()) {
                admin.move(regionInfo.getEncodedNameAsBytes(), Bytes.toBytes(addr.toString()));
                // Wait for the region to move.
                Thread.sleep(5000);
                addrAfter = addr;
                break;
            }
        }
        // Verify the region was moved.
        addrCache = locator.getRegionLocation(regionInfo.getStartKey(), false);
        addrNoCache = locator.getRegionLocation(regionInfo.getStartKey(), true);
        assertNotNull(addrAfter);
        assertTrue(addrAfter.getPort() != addrCache.getPort());
        assertEquals(addrAfter.getPort(), addrNoCache.getPort());
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) MultiRowMutationEndpoint(org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint) HRegionServer(org.apache.hadoop.hbase.regionserver.HRegionServer) Test(org.junit.Test)

Aggregations

HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)121 Test (org.junit.Test)91 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)48 Table (org.apache.hadoop.hbase.client.Table)38 Region (org.apache.hadoop.hbase.regionserver.Region)33 TableName (org.apache.hadoop.hbase.TableName)32 ServerName (org.apache.hadoop.hbase.ServerName)26 MiniHBaseCluster (org.apache.hadoop.hbase.MiniHBaseCluster)25 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)22 IOException (java.io.IOException)21 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)21 Configuration (org.apache.hadoop.conf.Configuration)19 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)18 RegionServerThread (org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread)18 Ignore (org.junit.Ignore)16 ZooKeeperWatcher (org.apache.hadoop.hbase.zookeeper.ZooKeeperWatcher)15 Put (org.apache.hadoop.hbase.client.Put)14 Waiter (org.apache.hadoop.hbase.Waiter)12 Admin (org.apache.hadoop.hbase.client.Admin)11 ArrayList (java.util.ArrayList)10