Search in sources :

Example 56 with RegionLocator

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

the class TestRegionSizeCalculator method mockRegionLocator.

/**
   * Makes some table with given region names.
   * */
private RegionLocator mockRegionLocator(String... regionNames) throws IOException {
    RegionLocator mockedTable = Mockito.mock(RegionLocator.class);
    when(mockedTable.getName()).thenReturn(TableName.valueOf("sizeTestTable"));
    List<HRegionLocation> regionLocations = new ArrayList<>(regionNames.length);
    when(mockedTable.getAllRegionLocations()).thenReturn(regionLocations);
    for (String regionName : regionNames) {
        HRegionInfo info = Mockito.mock(HRegionInfo.class);
        when(info.getRegionName()).thenReturn(regionName.getBytes());
        regionLocations.add(new HRegionLocation(info, sn));
    }
    return mockedTable;
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ArrayList(java.util.ArrayList)

Example 57 with RegionLocator

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

the class TestRegionSplitter method verifyBounds.

private void verifyBounds(List<byte[]> expectedBounds, TableName tableName) throws Exception {
    // Get region boundaries from the cluster and verify their endpoints
    final int numRegions = expectedBounds.size() - 1;
    try (Table table = UTIL.getConnection().getTable(tableName);
        RegionLocator locator = UTIL.getConnection().getRegionLocator(tableName)) {
        final List<HRegionLocation> regionInfoMap = locator.getAllRegionLocations();
        assertEquals(numRegions, regionInfoMap.size());
        for (HRegionLocation entry : regionInfoMap) {
            final HRegionInfo regionInfo = entry.getRegionInfo();
            byte[] regionStart = regionInfo.getStartKey();
            byte[] regionEnd = regionInfo.getEndKey();
            // This region's start key should be one of the region boundaries
            int startBoundaryIndex = indexOfBytes(expectedBounds, regionStart);
            assertNotSame(-1, startBoundaryIndex);
            // This region's end key should be the region boundary that comes
            // after the starting boundary.
            byte[] expectedRegionEnd = expectedBounds.get(startBoundaryIndex + 1);
            assertEquals(0, Bytes.compareTo(regionEnd, expectedRegionEnd));
        }
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) Table(org.apache.hadoop.hbase.client.Table) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation)

Example 58 with RegionLocator

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

the class TestServerCustomProtocol method testRowRange.

@Test
public void testRowRange() throws Throwable {
    try (Table table = util.getConnection().getTable(TEST_TABLE);
        RegionLocator locator = util.getConnection().getRegionLocator(TEST_TABLE)) {
        for (HRegionLocation e : locator.getAllRegionLocations()) {
            LOG.info("Region " + e.getRegionInfo().getRegionNameAsString() + ", servername=" + e.getServerName());
        }
        // Here are what regions looked like on a run:
        //
        // test,,1355943549657.c65d4822d8bdecc033a96451f3a0f55d.
        // test,bbb,1355943549661.110393b070dd1ed93441e0bc9b3ffb7e.
        // test,ccc,1355943549665.c3d6d125141359cbbd2a43eaff3cdf74.
        Map<byte[], String> results = ping(table, null, ROW_A);
        // Should contain first region only.
        assertEquals(1, results.size());
        verifyRegionResults(locator, results, ROW_A);
        // Test start row + empty end
        results = ping(table, ROW_BC, null);
        assertEquals(2, results.size());
        // should contain last 2 regions
        HRegionLocation loc = locator.getRegionLocation(ROW_A, true);
        assertNull("Should be missing region for row aaa (prior to start row)", results.get(loc.getRegionInfo().getRegionName()));
        verifyRegionResults(locator, results, ROW_B);
        verifyRegionResults(locator, results, ROW_C);
        // test empty start + end
        results = ping(table, null, ROW_BC);
        // should contain the first 2 regions
        assertEquals(2, results.size());
        verifyRegionResults(locator, results, ROW_A);
        verifyRegionResults(locator, results, ROW_B);
        loc = locator.getRegionLocation(ROW_C, true);
        assertNull("Should be missing region for row ccc (past stop row)", results.get(loc.getRegionInfo().getRegionName()));
        // test explicit start + end
        results = ping(table, ROW_AB, ROW_BC);
        // should contain first 2 regions
        assertEquals(2, results.size());
        verifyRegionResults(locator, results, ROW_A);
        verifyRegionResults(locator, results, ROW_B);
        loc = locator.getRegionLocation(ROW_C, true);
        assertNull("Should be missing region for row ccc (past stop row)", results.get(loc.getRegionInfo().getRegionName()));
        // test single region
        results = ping(table, ROW_B, ROW_BC);
        // should only contain region bbb
        assertEquals(1, results.size());
        verifyRegionResults(locator, results, ROW_B);
        loc = locator.getRegionLocation(ROW_A, true);
        assertNull("Should be missing region for row aaa (prior to start)", results.get(loc.getRegionInfo().getRegionName()));
        loc = locator.getRegionLocation(ROW_C, true);
        assertNull("Should be missing region for row ccc (past stop row)", results.get(loc.getRegionInfo().getRegionName()));
    }
}
Also used : RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) Table(org.apache.hadoop.hbase.client.Table) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) Test(org.junit.Test)

Example 59 with RegionLocator

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

the class TestServerCustomProtocol method testNullReturn.

@Test
public void testNullReturn() throws Throwable {
    try (Table table = util.getConnection().getTable(TEST_TABLE);
        RegionLocator locator = util.getConnection().getRegionLocator(TEST_TABLE)) {
        Map<byte[], String> results = hello(table, "nobody", ROW_A, ROW_C);
        verifyRegionResults(locator, results, null, ROW_A);
        verifyRegionResults(locator, results, null, ROW_B);
        verifyRegionResults(locator, results, null, ROW_C);
    }
}
Also used : RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) Table(org.apache.hadoop.hbase.client.Table) Test(org.junit.Test)

Example 60 with RegionLocator

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

the class MasterDDLOperationHelper method reOpenAllRegions.

/**
   * Reopen all regions from a table after a schema change operation.
   **/
public static boolean reOpenAllRegions(final MasterProcedureEnv env, final TableName tableName, final List<HRegionInfo> regionInfoList) throws IOException {
    boolean done = false;
    LOG.info("Bucketing regions by region server...");
    List<HRegionLocation> regionLocations = null;
    Connection connection = env.getMasterServices().getConnection();
    try (RegionLocator locator = connection.getRegionLocator(tableName)) {
        regionLocations = locator.getAllRegionLocations();
    }
    // Convert List<HRegionLocation> to Map<HRegionInfo, ServerName>.
    NavigableMap<HRegionInfo, ServerName> hri2Sn = new TreeMap<>();
    for (HRegionLocation location : regionLocations) {
        hri2Sn.put(location.getRegionInfo(), location.getServerName());
    }
    TreeMap<ServerName, List<HRegionInfo>> serverToRegions = Maps.newTreeMap();
    List<HRegionInfo> reRegions = new ArrayList<>();
    for (HRegionInfo hri : regionInfoList) {
        ServerName sn = hri2Sn.get(hri);
        // See HBASE-4578 for more information.
        if (null == sn) {
            LOG.info("Skip " + hri);
            continue;
        }
        if (!serverToRegions.containsKey(sn)) {
            LinkedList<HRegionInfo> hriList = Lists.newLinkedList();
            serverToRegions.put(sn, hriList);
        }
        reRegions.add(hri);
        serverToRegions.get(sn).add(hri);
    }
    LOG.info("Reopening " + reRegions.size() + " regions on " + serverToRegions.size() + " region servers.");
    AssignmentManager am = env.getMasterServices().getAssignmentManager();
    am.setRegionsToReopen(reRegions);
    BulkReOpen bulkReopen = new BulkReOpen(env.getMasterServices(), serverToRegions, am);
    while (true) {
        try {
            if (bulkReopen.bulkReOpen()) {
                done = true;
                break;
            } else {
                LOG.warn("Timeout before reopening all regions");
            }
        } catch (InterruptedException e) {
            LOG.warn("Reopen was interrupted");
            // Preserve the interrupt.
            Thread.currentThread().interrupt();
            break;
        }
    }
    return done;
}
Also used : RegionLocator(org.apache.hadoop.hbase.client.RegionLocator) Connection(org.apache.hadoop.hbase.client.Connection) ArrayList(java.util.ArrayList) AssignmentManager(org.apache.hadoop.hbase.master.AssignmentManager) TreeMap(java.util.TreeMap) HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) BulkReOpen(org.apache.hadoop.hbase.master.BulkReOpen)

Aggregations

RegionLocator (org.apache.hadoop.hbase.client.RegionLocator)84 Table (org.apache.hadoop.hbase.client.Table)59 Test (org.junit.Test)49 TableName (org.apache.hadoop.hbase.TableName)39 Admin (org.apache.hadoop.hbase.client.Admin)33 Path (org.apache.hadoop.fs.Path)31 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)30 HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)29 Connection (org.apache.hadoop.hbase.client.Connection)25 Configuration (org.apache.hadoop.conf.Configuration)21 IOException (java.io.IOException)19 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)15 FileSystem (org.apache.hadoop.fs.FileSystem)14 HBaseConfiguration (org.apache.hadoop.hbase.HBaseConfiguration)13 ServerName (org.apache.hadoop.hbase.ServerName)13 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)12 ClusterConnection (org.apache.hadoop.hbase.client.ClusterConnection)10 Put (org.apache.hadoop.hbase.client.Put)10 ArrayList (java.util.ArrayList)9 Result (org.apache.hadoop.hbase.client.Result)8