Search in sources :

Example 66 with ServerName

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

the class TestAdmin1 method verifyRoundRobinDistribution.

protected void verifyRoundRobinDistribution(ClusterConnection c, RegionLocator regionLocator, int expectedRegions) throws IOException {
    int numRS = c.getCurrentNrHRS();
    List<HRegionLocation> regions = regionLocator.getAllRegionLocations();
    Map<ServerName, List<HRegionInfo>> server2Regions = new HashMap<>();
    for (HRegionLocation loc : regions) {
        ServerName server = loc.getServerName();
        List<HRegionInfo> regs = server2Regions.get(server);
        if (regs == null) {
            regs = new ArrayList<>();
            server2Regions.put(server, regs);
        }
        regs.add(loc.getRegionInfo());
    }
    if (numRS >= 2) {
        // Ignore the master region server,
        // which contains less regions by intention.
        numRS--;
    }
    float average = (float) expectedRegions / numRS;
    int min = (int) Math.floor(average);
    int max = (int) Math.ceil(average);
    for (List<HRegionInfo> regionList : server2Regions.values()) {
        assertTrue(regionList.size() == min || regionList.size() == max);
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) HashMap(java.util.HashMap) ServerName(org.apache.hadoop.hbase.ServerName) List(java.util.List) ArrayList(java.util.ArrayList)

Example 67 with ServerName

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

the class TestAsyncNonMetaRegionLocator method testSingleRegionTable.

@Test
public void testSingleRegionTable() throws IOException, InterruptedException, ExecutionException {
    createSingleRegionTable();
    ServerName serverName = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName();
    for (RegionLocateType locateType : RegionLocateType.values()) {
        assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, serverName, LOCATOR.getRegionLocation(TABLE_NAME, EMPTY_START_ROW, locateType).get());
    }
    byte[] randKey = new byte[ThreadLocalRandom.current().nextInt(128)];
    ThreadLocalRandom.current().nextBytes(randKey);
    for (RegionLocateType locateType : RegionLocateType.values()) {
        assertLocEquals(EMPTY_START_ROW, EMPTY_END_ROW, serverName, LOCATOR.getRegionLocation(TABLE_NAME, randKey, locateType).get());
    }
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Example 68 with ServerName

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

the class TestAsyncNonMetaRegionLocator method testLocateAfter.

// usually locate after will return the same result, so we add a test to make it return different
// result.
@Test
public void testLocateAfter() throws IOException, InterruptedException, ExecutionException {
    byte[] row = Bytes.toBytes("1");
    byte[] splitKey = Arrays.copyOf(row, 2);
    TEST_UTIL.createTable(TABLE_NAME, FAMILY, new byte[][] { splitKey });
    TEST_UTIL.waitTableAvailable(TABLE_NAME);
    HRegionLocation currentLoc = LOCATOR.getRegionLocation(TABLE_NAME, row, RegionLocateType.CURRENT).get();
    ServerName currentServerName = TEST_UTIL.getRSForFirstRegionInTable(TABLE_NAME).getServerName();
    assertLocEquals(EMPTY_START_ROW, splitKey, currentServerName, currentLoc);
    HRegionLocation afterLoc = LOCATOR.getRegionLocation(TABLE_NAME, row, RegionLocateType.AFTER).get();
    ServerName afterServerName = TEST_UTIL.getHBaseCluster().getRegionServerThreads().stream().map(t -> t.getRegionServer()).filter(rs -> rs.getOnlineRegions(TABLE_NAME).stream().anyMatch(r -> Bytes.equals(splitKey, r.getRegionInfo().getStartKey()))).findAny().get().getServerName();
    assertLocEquals(splitKey, EMPTY_END_ROW, afterServerName, afterLoc);
    assertSame(afterLoc, LOCATOR.getRegionLocation(TABLE_NAME, row, RegionLocateType.AFTER).get());
}
Also used : IntStream(java.util.stream.IntStream) Arrays(java.util.Arrays) TableNotFoundException(org.apache.hadoop.hbase.TableNotFoundException) BeforeClass(org.junit.BeforeClass) EMPTY_START_ROW(org.apache.hadoop.hbase.HConstants.EMPTY_START_ROW) CompletableFuture(java.util.concurrent.CompletableFuture) ClientTests(org.apache.hadoop.hbase.testclassification.ClientTests) User(org.apache.hadoop.hbase.security.User) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertSame(org.junit.Assert.assertSame) Assert.assertThat(org.junit.Assert.assertThat) NotServingRegionException(org.apache.hadoop.hbase.NotServingRegionException) Assert.assertArrayEquals(org.junit.Assert.assertArrayEquals) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) After(org.junit.After) ServerName(org.apache.hadoop.hbase.ServerName) Bytes(org.apache.hadoop.hbase.util.Bytes) TableName(org.apache.hadoop.hbase.TableName) AfterClass(org.junit.AfterClass) MediumTests(org.apache.hadoop.hbase.testclassification.MediumTests) IOException(java.io.IOException) Test(org.junit.Test) Category(org.junit.experimental.categories.Category) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) ExecutionException(java.util.concurrent.ExecutionException) IOUtils(org.apache.commons.io.IOUtils) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) HBaseTestingUtility(org.apache.hadoop.hbase.HBaseTestingUtility) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) EMPTY_END_ROW(org.apache.hadoop.hbase.HConstants.EMPTY_END_ROW) Assert.assertEquals(org.junit.Assert.assertEquals) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) Test(org.junit.Test)

Example 69 with ServerName

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

the class TestAdmin2 method testGetRegion.

@Test(timeout = 300000)
public void testGetRegion() throws Exception {
    // We use actual HBaseAdmin instance instead of going via Admin interface in
    // here because makes use of an internal HBA method (TODO: Fix.).
    HBaseAdmin rawAdmin = TEST_UTIL.getHBaseAdmin();
    final TableName tableName = TableName.valueOf(name.getMethodName());
    LOG.info("Started " + tableName);
    Table t = TEST_UTIL.createMultiRegionTable(tableName, HConstants.CATALOG_FAMILY);
    try (RegionLocator locator = TEST_UTIL.getConnection().getRegionLocator(tableName)) {
        HRegionLocation regionLocation = locator.getRegionLocation(Bytes.toBytes("mmm"));
        HRegionInfo region = regionLocation.getRegionInfo();
        byte[] regionName = region.getRegionName();
        Pair<HRegionInfo, ServerName> pair = rawAdmin.getRegion(regionName);
        assertTrue(Bytes.equals(regionName, pair.getFirst().getRegionName()));
        pair = rawAdmin.getRegion(region.getEncodedNameAsBytes());
        assertTrue(Bytes.equals(regionName, pair.getFirst().getRegionName()));
    }
}
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) Test(org.junit.Test)

Example 70 with ServerName

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

the class TestAdmin2 method testMoveToPreviouslyAssignedRS.

@Test(timeout = 300000)
public void testMoveToPreviouslyAssignedRS() throws IOException, InterruptedException {
    MiniHBaseCluster cluster = TEST_UTIL.getHBaseCluster();
    HMaster master = cluster.getMaster();
    final TableName tableName = TableName.valueOf(name.getMethodName());
    Admin localAdmin = createTable(tableName);
    List<HRegionInfo> tableRegions = localAdmin.getTableRegions(tableName);
    HRegionInfo hri = tableRegions.get(0);
    AssignmentManager am = master.getAssignmentManager();
    assertTrue("Region " + hri.getRegionNameAsString() + " should be assigned properly", am.waitForAssignment(hri));
    ServerName server = am.getRegionStates().getRegionServerOfRegion(hri);
    localAdmin.move(hri.getEncodedNameAsBytes(), Bytes.toBytes(server.getServerName()));
    assertEquals("Current region server and region server before move should be same.", server, am.getRegionStates().getRegionServerOfRegion(hri));
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TableName(org.apache.hadoop.hbase.TableName) ServerName(org.apache.hadoop.hbase.ServerName) HMaster(org.apache.hadoop.hbase.master.HMaster) AssignmentManager(org.apache.hadoop.hbase.master.AssignmentManager) MiniHBaseCluster(org.apache.hadoop.hbase.MiniHBaseCluster) Test(org.junit.Test)

Aggregations

ServerName (org.apache.hadoop.hbase.ServerName)426 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)202 Test (org.junit.Test)163 ArrayList (java.util.ArrayList)97 TableName (org.apache.hadoop.hbase.TableName)89 IOException (java.io.IOException)87 HashMap (java.util.HashMap)81 List (java.util.List)72 Map (java.util.Map)54 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)45 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)34 Table (org.apache.hadoop.hbase.client.Table)33 HashSet (java.util.HashSet)32 TreeMap (java.util.TreeMap)31 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)29 Configuration (org.apache.hadoop.conf.Configuration)26 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)26 Pair (org.apache.hadoop.hbase.util.Pair)24 KeeperException (org.apache.zookeeper.KeeperException)23 InterruptedIOException (java.io.InterruptedIOException)22