Search in sources :

Example 91 with HRegionInfo

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

the class TestRollingRestart method getDoubleAssignedRegions.

private NavigableSet<String> getDoubleAssignedRegions(MiniHBaseCluster cluster) throws IOException {
    NavigableSet<String> online = new TreeSet<>();
    NavigableSet<String> doubled = new TreeSet<>();
    for (RegionServerThread rst : cluster.getLiveRegionServerThreads()) {
        for (HRegionInfo region : ProtobufUtil.getOnlineRegions(rst.getRegionServer().getRSRpcServices())) {
            if (!online.add(region.getRegionNameAsString())) {
                doubled.add(region.getRegionNameAsString());
            }
        }
    }
    return doubled;
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TreeSet(java.util.TreeSet) RegionServerThread(org.apache.hadoop.hbase.util.JVMClusterUtil.RegionServerThread)

Example 92 with HRegionInfo

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

the class TestMasterOperationsForRegionReplicas method validateFromSnapshotFromMeta.

private void validateFromSnapshotFromMeta(HBaseTestingUtility util, TableName table, int numRegions, int numReplica, Connection connection) throws IOException {
    SnapshotOfRegionAssignmentFromMeta snapshot = new SnapshotOfRegionAssignmentFromMeta(connection);
    snapshot.initialize();
    Map<HRegionInfo, ServerName> regionToServerMap = snapshot.getRegionToRegionServerMap();
    //'1' for the namespace
    assert (regionToServerMap.size() == numRegions * numReplica + 1);
    Map<ServerName, List<HRegionInfo>> serverToRegionMap = snapshot.getRegionServerToRegionMap();
    for (Map.Entry<ServerName, List<HRegionInfo>> entry : serverToRegionMap.entrySet()) {
        if (entry.getKey().equals(util.getHBaseCluster().getMaster().getServerName())) {
            continue;
        }
        List<HRegionInfo> regions = entry.getValue();
        Set<byte[]> setOfStartKeys = new HashSet<>();
        for (HRegionInfo region : regions) {
            byte[] startKey = region.getStartKey();
            if (region.getTable().equals(table)) {
                //ignore other tables
                setOfStartKeys.add(startKey);
                LOG.info("--STARTKEY " + new String(startKey) + "--");
            }
        }
        // the number of startkeys will be equal to the number of regions hosted in each server
        // (each server will be hosting one replica of a region)
        assertEquals(numRegions, setOfStartKeys.size());
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) ServerName(org.apache.hadoop.hbase.ServerName) List(java.util.List) HashMap(java.util.HashMap) Map(java.util.Map) HashSet(java.util.HashSet)

Example 93 with HRegionInfo

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

the class TestMasterQosFunction method testRegionInTransition.

@Test
public void testRegionInTransition() throws IOException {
    // Check ReportRegionInTransition
    HBaseProtos.RegionInfo meta_ri = HRegionInfo.convert(HRegionInfo.FIRST_META_REGIONINFO);
    HBaseProtos.RegionInfo normal_ri = HRegionInfo.convert(new HRegionInfo(TableName.valueOf("test:table"), Bytes.toBytes("a"), Bytes.toBytes("b"), false));
    RegionServerStatusProtos.RegionStateTransition metaTransition = RegionServerStatusProtos.RegionStateTransition.newBuilder().addRegionInfo(meta_ri).setTransitionCode(RegionServerStatusProtos.RegionStateTransition.TransitionCode.CLOSED).build();
    RegionServerStatusProtos.RegionStateTransition normalTransition = RegionServerStatusProtos.RegionStateTransition.newBuilder().addRegionInfo(normal_ri).setTransitionCode(RegionServerStatusProtos.RegionStateTransition.TransitionCode.CLOSED).build();
    RegionServerStatusProtos.ReportRegionStateTransitionRequest metaTransitionRequest = RegionServerStatusProtos.ReportRegionStateTransitionRequest.newBuilder().setServer(ProtobufUtil.toServerName(ServerName.valueOf("locahost:60020", 100))).addTransition(normalTransition).addTransition(metaTransition).build();
    RegionServerStatusProtos.ReportRegionStateTransitionRequest normalTransitionRequest = RegionServerStatusProtos.ReportRegionStateTransitionRequest.newBuilder().setServer(ProtobufUtil.toServerName(ServerName.valueOf("locahost:60020", 100))).addTransition(normalTransition).build();
    final String reportFuncName = "ReportRegionStateTransition";
    checkMethod(conf, reportFuncName, HConstants.SYSTEMTABLE_QOS, qosFunction, metaTransitionRequest);
    checkMethod(conf, reportFuncName, HConstants.NORMAL_QOS, qosFunction, normalTransitionRequest);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) RegionServerStatusProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.RegionServerStatusProtos) HBaseProtos(org.apache.hadoop.hbase.shaded.protobuf.generated.HBaseProtos) Test(org.junit.Test)

Example 94 with HRegionInfo

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

the class TestBaseLoadBalancer method assertRetainedAssignment.

/**
   * Asserts a valid retained assignment plan.
   * <p>
   * Must meet the following conditions:
   * <ul>
   * <li>Every input region has an assignment, and to an online server
   * <li>If a region had an existing assignment to a server with the same
   * address a a currently online server, it will be assigned to it
   * </ul>
   * @param existing
   * @param servers
   * @param assignment
   */
private void assertRetainedAssignment(Map<HRegionInfo, ServerName> existing, List<ServerName> servers, Map<ServerName, List<HRegionInfo>> assignment) {
    // Verify condition 1, every region assigned, and to online server
    Set<ServerName> onlineServerSet = new TreeSet<>(servers);
    Set<HRegionInfo> assignedRegions = new TreeSet<>();
    for (Map.Entry<ServerName, List<HRegionInfo>> a : assignment.entrySet()) {
        assertTrue("Region assigned to server that was not listed as online", onlineServerSet.contains(a.getKey()));
        for (HRegionInfo r : a.getValue()) assignedRegions.add(r);
    }
    assertEquals(existing.size(), assignedRegions.size());
    // Verify condition 2, if server had existing assignment, must have same
    Set<String> onlineHostNames = new TreeSet<>();
    for (ServerName s : servers) {
        onlineHostNames.add(s.getHostname());
    }
    for (Map.Entry<ServerName, List<HRegionInfo>> a : assignment.entrySet()) {
        ServerName assignedTo = a.getKey();
        for (HRegionInfo r : a.getValue()) {
            ServerName address = existing.get(r);
            if (address != null && onlineHostNames.contains(address.getHostname())) {
                // this region was prevously assigned somewhere, and that
                // host is still around, then it should be re-assigned on the
                // same host
                assertEquals(address.getHostname(), assignedTo.getHostname());
            }
        }
    }
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) TreeSet(java.util.TreeSet) ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) List(java.util.List) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) TreeMap(java.util.TreeMap)

Example 95 with HRegionInfo

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

the class TestBaseLoadBalancer method testClusterRegionLocations.

@Test(timeout = 180000)
public void testClusterRegionLocations() {
    // tests whether region locations are handled correctly in Cluster
    List<ServerName> servers = getListOfServerNames(randomServers(10, 10));
    List<HRegionInfo> regions = randomRegions(101);
    Map<ServerName, List<HRegionInfo>> clusterState = new HashMap<>();
    assignRegions(regions, servers, clusterState);
    // mock block locality for some regions
    RegionLocationFinder locationFinder = mock(RegionLocationFinder.class);
    // block locality: region:0   => {server:0}
    //                 region:1   => {server:0, server:1}
    //                 region:42 => {server:4, server:9, server:5}
    when(locationFinder.getTopBlockLocations(regions.get(0))).thenReturn(Lists.newArrayList(servers.get(0)));
    when(locationFinder.getTopBlockLocations(regions.get(1))).thenReturn(Lists.newArrayList(servers.get(0), servers.get(1)));
    when(locationFinder.getTopBlockLocations(regions.get(42))).thenReturn(Lists.newArrayList(servers.get(4), servers.get(9), servers.get(5)));
    when(locationFinder.getTopBlockLocations(regions.get(43))).thenReturn(// this server does not exists in clusterStatus
    Lists.newArrayList(ServerName.valueOf("foo", 0, 0)));
    BaseLoadBalancer.Cluster cluster = new Cluster(clusterState, null, locationFinder, null);
    // this is ok, it is just a test
    int r0 = ArrayUtils.indexOf(cluster.regions, regions.get(0));
    int r1 = ArrayUtils.indexOf(cluster.regions, regions.get(1));
    int r10 = ArrayUtils.indexOf(cluster.regions, regions.get(10));
    int r42 = ArrayUtils.indexOf(cluster.regions, regions.get(42));
    int r43 = ArrayUtils.indexOf(cluster.regions, regions.get(43));
    int s0 = cluster.serversToIndex.get(servers.get(0).getHostAndPort());
    int s1 = cluster.serversToIndex.get(servers.get(1).getHostAndPort());
    int s4 = cluster.serversToIndex.get(servers.get(4).getHostAndPort());
    int s5 = cluster.serversToIndex.get(servers.get(5).getHostAndPort());
    int s9 = cluster.serversToIndex.get(servers.get(9).getHostAndPort());
    // region 0 locations
    assertEquals(1, cluster.regionLocations[r0].length);
    assertEquals(s0, cluster.regionLocations[r0][0]);
    // region 1 locations
    assertEquals(2, cluster.regionLocations[r1].length);
    assertEquals(s0, cluster.regionLocations[r1][0]);
    assertEquals(s1, cluster.regionLocations[r1][1]);
    // region 10 locations
    assertEquals(0, cluster.regionLocations[r10].length);
    // region 42 locations
    assertEquals(3, cluster.regionLocations[r42].length);
    assertEquals(s4, cluster.regionLocations[r42][0]);
    assertEquals(s9, cluster.regionLocations[r42][1]);
    assertEquals(s5, cluster.regionLocations[r42][2]);
    // region 43 locations
    assertEquals(1, cluster.regionLocations[r43].length);
    assertEquals(-1, cluster.regionLocations[r43][0]);
}
Also used : HRegionInfo(org.apache.hadoop.hbase.HRegionInfo) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) ServerName(org.apache.hadoop.hbase.ServerName) Cluster(org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster) ArrayList(java.util.ArrayList) List(java.util.List) Cluster(org.apache.hadoop.hbase.master.balancer.BaseLoadBalancer.Cluster) Test(org.junit.Test)

Aggregations

HRegionInfo (org.apache.hadoop.hbase.HRegionInfo)408 ServerName (org.apache.hadoop.hbase.ServerName)153 Test (org.junit.Test)141 TableName (org.apache.hadoop.hbase.TableName)118 ArrayList (java.util.ArrayList)86 IOException (java.io.IOException)83 HTableDescriptor (org.apache.hadoop.hbase.HTableDescriptor)75 Path (org.apache.hadoop.fs.Path)63 List (java.util.List)59 HashMap (java.util.HashMap)57 HColumnDescriptor (org.apache.hadoop.hbase.HColumnDescriptor)49 Table (org.apache.hadoop.hbase.client.Table)47 Map (java.util.Map)43 HRegionServer (org.apache.hadoop.hbase.regionserver.HRegionServer)41 FileSystem (org.apache.hadoop.fs.FileSystem)40 Configuration (org.apache.hadoop.conf.Configuration)38 HRegionLocation (org.apache.hadoop.hbase.HRegionLocation)35 TreeMap (java.util.TreeMap)26 HashSet (java.util.HashSet)23 HBaseIOException (org.apache.hadoop.hbase.HBaseIOException)22