Search in sources :

Example 91 with RegionInfo

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

the class MetaTableAccessor method getDaughterRegions.

/**
 * Returns the daughter regions by reading the corresponding columns of the catalog table Result.
 * @param data a Result object from the catalog table scan
 * @return pair of RegionInfo or PairOfSameType(null, null) if region is not a split parent
 */
public static PairOfSameType<RegionInfo> getDaughterRegions(Result data) {
    RegionInfo splitA = CatalogFamilyFormat.getRegionInfo(data, HConstants.SPLITA_QUALIFIER);
    RegionInfo splitB = CatalogFamilyFormat.getRegionInfo(data, HConstants.SPLITB_QUALIFIER);
    return new PairOfSameType<>(splitA, splitB);
}
Also used : RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) PairOfSameType(org.apache.hadoop.hbase.util.PairOfSameType)

Example 92 with RegionInfo

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

the class TestBaseLoadBalancer method testRegionAvailabilityWithRegionMoves.

@Test
public void testRegionAvailabilityWithRegionMoves() throws Exception {
    List<RegionInfo> list0 = new ArrayList<>();
    List<RegionInfo> list1 = new ArrayList<>();
    List<RegionInfo> list2 = new ArrayList<>();
    // create a region (region1)
    RegionInfo hri1 = RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName())).setStartKey(Bytes.toBytes("key1")).setEndKey(Bytes.toBytes("key2")).setSplit(false).setRegionId(100).build();
    // create a replica of the region (replica_of_region1)
    RegionInfo hri2 = RegionReplicaUtil.getRegionInfoForReplica(hri1, 1);
    // create a second region (region2)
    RegionInfo hri3 = RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName())).setStartKey(Bytes.toBytes("key2")).setEndKey(Bytes.toBytes("key3")).setSplit(false).setRegionId(101).build();
    // only region1
    list0.add(hri1);
    // only replica_of_region1
    list1.add(hri2);
    // only region2
    list2.add(hri3);
    Map<ServerName, List<RegionInfo>> clusterState = new LinkedHashMap<>();
    // servers[0] hosts region1
    clusterState.put(servers[0], list0);
    // servers[1] hosts replica_of_region1
    clusterState.put(servers[1], list1);
    // servers[2] hosts region2
    clusterState.put(servers[2], list2);
    // create a cluster with the above clusterState. The way in which the
    // cluster is created (constructor code) would make sure the indices of
    // the servers are in the order in which it is inserted in the clusterState
    // map (linkedhashmap is important).
    BalancerClusterState cluster = new BalancerClusterState(clusterState, null, null, rackManager);
    // check whether moving region1 from servers[1] to servers[2] would lower availability
    assertTrue(!cluster.wouldLowerAvailability(hri1, servers[2]));
    // now move region1 from servers[0] to servers[2]
    cluster.doAction(new MoveRegionAction(0, 0, 2));
    // now repeat check whether moving region1 from servers[1] to servers[2]
    // would lower availability
    assertTrue(cluster.wouldLowerAvailability(hri1, servers[2]));
    // start over again
    clusterState.clear();
    List<RegionInfo> list3 = new ArrayList<>();
    RegionInfo hri4 = RegionReplicaUtil.getRegionInfoForReplica(hri3, 1);
    list3.add(hri4);
    // servers[0], rack1 hosts region1
    clusterState.put(servers[0], list0);
    // servers[5], rack2 hosts replica_of_region1
    clusterState.put(servers[5], list1);
    // servers[6], rack2 hosts region2
    clusterState.put(servers[6], list2);
    // servers[12], rack3 hosts replica_of_region2
    clusterState.put(servers[12], list3);
    // create a cluster with the above clusterState
    cluster = new BalancerClusterState(clusterState, null, null, rackManager);
    // check whether a move of replica_of_region2 from servers[12],rack3 to servers[0],rack1 would
    // lower the availability
    assertTrue(!cluster.wouldLowerAvailability(hri4, servers[0]));
    // now move region2 from servers[6],rack2 to servers[0],rack1
    cluster.doAction(new MoveRegionAction(2, 2, 0));
    // now repeat check if replica_of_region2 from servers[12],rack3 to servers[0],rack1 would
    // lower the availability
    assertTrue(cluster.wouldLowerAvailability(hri3, servers[0]));
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 93 with RegionInfo

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

the class TestBaseLoadBalancer method testRegionAvailability.

@Test
public void testRegionAvailability() throws Exception {
    // Create a cluster with a few servers, assign them to specific racks
    // then assign some regions. The tests should check whether moving a
    // replica from one node to a specific other node or rack lowers the
    // availability of the region or not
    List<RegionInfo> list0 = new ArrayList<>();
    List<RegionInfo> list1 = new ArrayList<>();
    List<RegionInfo> list2 = new ArrayList<>();
    // create a region (region1)
    RegionInfo hri1 = RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName())).setStartKey(Bytes.toBytes("key1")).setEndKey(Bytes.toBytes("key2")).setSplit(false).setRegionId(100).build();
    // create a replica of the region (replica_of_region1)
    RegionInfo hri2 = RegionReplicaUtil.getRegionInfoForReplica(hri1, 1);
    // create a second region (region2)
    RegionInfo hri3 = RegionInfoBuilder.newBuilder(TableName.valueOf(name.getMethodName())).setStartKey(Bytes.toBytes("key2")).setEndKey(Bytes.toBytes("key3")).setSplit(false).setRegionId(101).build();
    // only region1
    list0.add(hri1);
    // only replica_of_region1
    list1.add(hri2);
    // only region2
    list2.add(hri3);
    Map<ServerName, List<RegionInfo>> clusterState = new LinkedHashMap<>();
    // servers[0] hosts region1
    clusterState.put(servers[0], list0);
    // servers[1] hosts replica_of_region1
    clusterState.put(servers[1], list1);
    // servers[2] hosts region2
    clusterState.put(servers[2], list2);
    // create a cluster with the above clusterState. The way in which the
    // cluster is created (constructor code) would make sure the indices of
    // the servers are in the order in which it is inserted in the clusterState
    // map (linkedhashmap is important). A similar thing applies to the region lists
    BalancerClusterState cluster = new BalancerClusterState(clusterState, null, null, rackManager);
    // check whether a move of region1 from servers[0] to servers[1] would lower
    // the availability of region1
    assertTrue(cluster.wouldLowerAvailability(hri1, servers[1]));
    // check whether a move of region1 from servers[0] to servers[2] would lower
    // the availability of region1
    assertTrue(!cluster.wouldLowerAvailability(hri1, servers[2]));
    // check whether a move of replica_of_region1 from servers[0] to servers[2] would lower
    // the availability of replica_of_region1
    assertTrue(!cluster.wouldLowerAvailability(hri2, servers[2]));
    // check whether a move of region2 from servers[0] to servers[1] would lower
    // the availability of region2
    assertTrue(!cluster.wouldLowerAvailability(hri3, servers[1]));
    // now lets have servers[1] host replica_of_region2
    list1.add(RegionReplicaUtil.getRegionInfoForReplica(hri3, 1));
    // create a new clusterState with the above change
    cluster = new BalancerClusterState(clusterState, null, null, rackManager);
    // now check whether a move of a replica from servers[0] to servers[1] would lower
    // the availability of region2
    assertTrue(cluster.wouldLowerAvailability(hri3, servers[1]));
    // start over again
    clusterState.clear();
    // servers[0], rack1 hosts region1
    clusterState.put(servers[0], list0);
    // servers[5], rack2 hosts replica_of_region1 and replica_of_region2
    clusterState.put(servers[5], list1);
    // servers[6], rack2 hosts region2
    clusterState.put(servers[6], list2);
    // servers[10], rack3 hosts no region
    clusterState.put(servers[10], new ArrayList<>());
    // create a cluster with the above clusterState
    cluster = new BalancerClusterState(clusterState, null, null, rackManager);
    // check whether a move of region1 from servers[0],rack1 to servers[6],rack2 would
    // lower the availability
    assertTrue(cluster.wouldLowerAvailability(hri1, servers[0]));
    // now create a cluster without the rack manager
    cluster = new BalancerClusterState(clusterState, null, null, null);
    // now repeat check whether a move of region1 from servers[0] to servers[6] would
    // lower the availability
    assertTrue(!cluster.wouldLowerAvailability(hri1, servers[6]));
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) ArrayList(java.util.ArrayList) List(java.util.List) LinkedHashMap(java.util.LinkedHashMap) Test(org.junit.Test)

Example 94 with RegionInfo

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

the class TestBaseLoadBalancer method assignRegions.

private void assignRegions(List<RegionInfo> regions, List<ServerName> servers, Map<ServerName, List<RegionInfo>> clusterState) {
    for (int i = 0; i < regions.size(); i++) {
        ServerName sn = servers.get(i % servers.size());
        List<RegionInfo> regionsOfServer = clusterState.get(sn);
        if (regionsOfServer == null) {
            regionsOfServer = new ArrayList<>(10);
            clusterState.put(sn, regionsOfServer);
        }
        regionsOfServer.add(regions.get(i));
    }
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo)

Example 95 with RegionInfo

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

the class TestBaseLoadBalancer method testRetainAssignment.

/**
 * Test the cluster startup bulk assignment which attempts to retain
 * assignment info.
 */
@Test
public void testRetainAssignment() throws Exception {
    // Test simple case where all same servers are there
    List<ServerAndLoad> servers = randomServers(10, 10);
    List<RegionInfo> regions = randomRegions(100);
    Map<RegionInfo, ServerName> existing = new TreeMap<>(RegionInfo.COMPARATOR);
    for (int i = 0; i < regions.size(); i++) {
        ServerName sn = servers.get(i % servers.size()).getServerName();
        // The old server would have had same host and port, but different
        // start code!
        ServerName snWithOldStartCode = ServerName.valueOf(sn.getHostname(), sn.getPort(), sn.getStartcode() - 10);
        existing.put(regions.get(i), snWithOldStartCode);
    }
    List<ServerName> listOfServerNames = getListOfServerNames(servers);
    Map<ServerName, List<RegionInfo>> assignment = loadBalancer.retainAssignment(existing, listOfServerNames);
    assertRetainedAssignment(existing, listOfServerNames, assignment);
    // Include two new servers that were not there before
    List<ServerAndLoad> servers2 = new ArrayList<>(servers);
    servers2.add(randomServer(10));
    servers2.add(randomServer(10));
    listOfServerNames = getListOfServerNames(servers2);
    assignment = loadBalancer.retainAssignment(existing, listOfServerNames);
    assertRetainedAssignment(existing, listOfServerNames, assignment);
    // Remove two of the servers that were previously there
    List<ServerAndLoad> servers3 = new ArrayList<>(servers);
    servers3.remove(0);
    servers3.remove(0);
    listOfServerNames = getListOfServerNames(servers3);
    assignment = loadBalancer.retainAssignment(existing, listOfServerNames);
    assertRetainedAssignment(existing, listOfServerNames, assignment);
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) ArrayList(java.util.ArrayList) RegionInfo(org.apache.hadoop.hbase.client.RegionInfo) ArrayList(java.util.ArrayList) List(java.util.List) TreeMap(java.util.TreeMap) Test(org.junit.Test)

Aggregations

RegionInfo (org.apache.hadoop.hbase.client.RegionInfo)824 Test (org.junit.Test)416 TableName (org.apache.hadoop.hbase.TableName)311 ServerName (org.apache.hadoop.hbase.ServerName)191 ArrayList (java.util.ArrayList)175 IOException (java.io.IOException)174 TableDescriptor (org.apache.hadoop.hbase.client.TableDescriptor)174 Path (org.apache.hadoop.fs.Path)141 List (java.util.List)118 HashMap (java.util.HashMap)90 Table (org.apache.hadoop.hbase.client.Table)90 Map (java.util.Map)81 Put (org.apache.hadoop.hbase.client.Put)81 Configuration (org.apache.hadoop.conf.Configuration)80 HRegion (org.apache.hadoop.hbase.regionserver.HRegion)67 TreeMap (java.util.TreeMap)66 Result (org.apache.hadoop.hbase.client.Result)59 FileSystem (org.apache.hadoop.fs.FileSystem)58 Cell (org.apache.hadoop.hbase.Cell)50 Scan (org.apache.hadoop.hbase.client.Scan)46