Search in sources :

Example 21 with HRegionLocation

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

the class TestFromClientSide method waitOnSplit.

/*
   * Wait on table split.  May return because we waited long enough on the split
   * and it didn't happen.  Caller should check.
   * @param t
   * @return Map of table regions; caller needs to check table actually split.
   */
private List<HRegionLocation> waitOnSplit(final Table t) throws IOException {
    try (RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(t.getName())) {
        List<HRegionLocation> regions = locator.getAllRegionLocations();
        int originalCount = regions.size();
        for (int i = 0; i < TEST_UTIL.getConfiguration().getInt("hbase.test.retries", 30); i++) {
            Thread.currentThread();
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            regions = locator.getAllRegionLocations();
            if (regions.size() > originalCount)
                break;
        }
        return regions;
    }
}
Also used : HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) MultiRowMutationEndpoint(org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint)

Example 22 with HRegionLocation

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

the class TestHCM method testCacheSeqNums.

/**
   * Test that stale cache updates don't override newer cached values.
   */
@Test
public void testCacheSeqNums() throws Exception {
    Table table = TEST_UTIL.createMultiRegionTable(TABLE_NAME2, FAM_NAM);
    Put put = new Put(ROW);
    put.addColumn(FAM_NAM, ROW, ROW);
    table.put(put);
    ConnectionImplementation conn = (ConnectionImplementation) TEST_UTIL.getConnection();
    HRegionLocation location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation();
    assertNotNull(location);
    ServerName anySource = ServerName.valueOf(location.getHostname(), location.getPort() - 1, 0L);
    // Same server as already in cache reporting - overwrites any value despite seqNum.
    int nextPort = location.getPort() + 1;
    conn.updateCachedLocation(location.getRegionInfo(), location.getServerName(), ServerName.valueOf("127.0.0.1", nextPort, 0), location.getSeqNum() - 1);
    location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation();
    Assert.assertEquals(nextPort, location.getPort());
    // No source specified - same.
    nextPort = location.getPort() + 1;
    conn.updateCachedLocation(location.getRegionInfo(), location.getServerName(), ServerName.valueOf("127.0.0.1", nextPort, 0), location.getSeqNum() - 1);
    location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation();
    Assert.assertEquals(nextPort, location.getPort());
    // Higher seqNum - overwrites lower seqNum.
    nextPort = location.getPort() + 1;
    conn.updateCachedLocation(location.getRegionInfo(), anySource, ServerName.valueOf("127.0.0.1", nextPort, 0), location.getSeqNum() + 1);
    location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation();
    Assert.assertEquals(nextPort, location.getPort());
    // Lower seqNum - does not overwrite higher seqNum.
    nextPort = location.getPort() + 1;
    conn.updateCachedLocation(location.getRegionInfo(), anySource, ServerName.valueOf("127.0.0.1", nextPort, 0), location.getSeqNum() - 1);
    location = conn.getCachedLocation(TABLE_NAME2, ROW).getRegionLocation();
    Assert.assertEquals(nextPort - 1, location.getPort());
    table.close();
}
Also used : HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Example 23 with HRegionLocation

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

the class TestMetaWithReplicas method testShutdownOfReplicaHolder.

@Test
public void testShutdownOfReplicaHolder() throws Exception {
    // can be recovered
    try (ClusterConnection conn = (ClusterConnection) ConnectionFactory.createConnection(TEST_UTIL.getConfiguration())) {
        RegionLocations rl = conn.locateRegion(TableName.META_TABLE_NAME, Bytes.toBytes(""), false, true);
        HRegionLocation hrl = rl.getRegionLocation(1);
        ServerName oldServer = hrl.getServerName();
        TEST_UTIL.getHBaseClusterInterface().killRegionServer(oldServer);
        int i = 0;
        do {
            LOG.debug("Waiting for the replica " + hrl.getRegionInfo() + " to come up");
            //wait for the detection/recovery
            Thread.sleep(30000);
            rl = conn.locateRegion(TableName.META_TABLE_NAME, Bytes.toBytes(""), false, true);
            hrl = rl.getRegionLocation(1);
            i++;
        } while ((hrl == null || hrl.getServerName().equals(oldServer)) && i < 3);
        assertTrue(i != 3);
    }
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Example 24 with HRegionLocation

use of org.apache.hadoop.hbase.HRegionLocation 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 25 with HRegionLocation

use of org.apache.hadoop.hbase.HRegionLocation 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

HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)213 Test (org.junit.Test)74 ServerName (org.apache.hadoop.hbase.ServerName)67 TableName (org.apache.hadoop.hbase.TableName)58 IOException (java.io.IOException)53 RegionLocations (org.apache.hadoop.hbase.RegionLocations)50 RegionLocator (org.apache.hadoop.hbase.client.RegionLocator)46 ArrayList (java.util.ArrayList)44 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)35 RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)27 Table (org.apache.hadoop.hbase.client.Table)21 List (java.util.List)19 Map (java.util.Map)15 Connection (org.apache.hadoop.hbase.client.Connection)15 Configuration (org.apache.hadoop.conf.Configuration)14 HashMap (java.util.HashMap)13 TableNotFoundException (org.apache.hadoop.hbase.TableNotFoundException)13 MultiRowMutationEndpoint (org.apache.hadoop.hbase.coprocessor.MultiRowMutationEndpoint)13 CompletableFuture (java.util.concurrent.CompletableFuture)12 Admin (org.apache.hadoop.hbase.client.Admin)12