Search in sources :

Example 31 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 32 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 33 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 34 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)

Example 35 with HRegionServer

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

the class TestScannerTimeout method test3686b.

/**
   * Make sure that no rows are lost if the scanner timeout is longer on the
   * client than the server, and the scan times out on the server but not the
   * client.
   * @throws Exception
   */
@Test(timeout = 300000)
public void test3686b() throws Exception {
    LOG.info("START ************ test3686b");
    HRegionServer rs = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME);
    Scan scan = new Scan();
    scan.setCaching(SCANNER_CACHING);
    // Set a very high timeout, we want to test what happens when a RS
    // fails but the region is recovered before the lease times out.
    // Since the RS is already created, this conf is client-side only for
    // this new table
    Configuration conf = new Configuration(TEST_UTIL.getConfiguration());
    conf.setInt(HConstants.HBASE_CLIENT_SCANNER_TIMEOUT_PERIOD, SCANNER_TIMEOUT * 100);
    Connection connection = ConnectionFactory.createConnection(conf);
    Table higherScanTimeoutTable = connection.getTable(TABLE_NAME);
    ResultScanner r = higherScanTimeoutTable.getScanner(scan);
    int count = 1;
    r.next();
    // Sleep, allowing the scan to timeout on the server but not on the client.
    Thread.sleep(SCANNER_TIMEOUT + 2000);
    while (r.next() != null) {
        count++;
    }
    assertEquals(NB_ROWS, count);
    r.close();
    higherScanTimeoutTable.close();
    connection.close();
    LOG.info("END ************ END test3686b");
}
Also used : Configuration(org.apache.hadoop.conf.Configuration) 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