Search in sources :

Example 1 with DrRegionInfo

use of io.datarouter.client.hbase.cluster.DrRegionInfo in project datarouter by hotpads.

the class EntityPartitionBalancer method call.

@Override
public SortedMap<DrRegionInfo<?>, ServerName> call() {
    initRegionByPartitionMap();
    // set up the ring of servers
    SortedMap<Long, ServerName> consistentHashRing = ConsistentHashBalancer.buildServerHashRing(drhServerList, ConsistentHashBalancer.BUCKETS_PER_NODE);
    // calculate each partition's position in the ring and store it
    SortedMap<Integer, ServerName> serverByPartition = new TreeMap<>();
    for (Integer partition : regionsByPartition.keySet()) {
        byte[] consistentHashInput = entityPartitioner.getPrefix(partition);
        ServerName serverName = ConsistentHashBalancer.calcServerNameForItem(consistentHashRing, consistentHashInput);
        // now region->server mapping is known
        serverByPartition.put(partition, serverName);
    }
    // level out any imbalances from the hashing
    HBaseBalanceLeveler<Integer> leveler = new HBaseBalanceLeveler<>(drhServerList.getServerNames(), serverByPartition, tableName);
    serverByPartition = leveler.getBalancedDestinationByItem();
    // map individual regions to servers based on their prefix
    for (Entry<Integer, ServerName> entry : serverByPartition.entrySet()) {
        List<DrRegionInfo<?>> regionsInPartition = regionsByPartition.get(entry.getKey());
        for (DrRegionInfo<?> region : regionsInPartition) {
            serverByRegion.put(region, entry.getValue());
        }
    }
    assertRegionCountsConsistent();
    return serverByRegion;
}
Also used : HBaseBalanceLeveler(io.datarouter.client.hbase.balancer.HBaseBalanceLeveler) TreeMap(java.util.TreeMap) ServerName(org.apache.hadoop.hbase.ServerName) DrRegionInfo(io.datarouter.client.hbase.cluster.DrRegionInfo)

Example 2 with DrRegionInfo

use of io.datarouter.client.hbase.cluster.DrRegionInfo in project datarouter by hotpads.

the class ConsistentHashBalancer method call.

@Override
public Map<DrRegionInfo<?>, ServerName> call() {
    // set up the ring of servers
    SortedMap<Long, ServerName> consistentHashRing = buildServerHashRing(drhServerList, BUCKETS_PER_NODE);
    // calculate each region's position in the ring and store it
    for (DrRegionInfo<?> drhRegionInfo : drhRegionList.getRegions()) {
        byte[] consistentHashInput = drhRegionInfo.getRegion().getEncodedNameAsBytes();
        ServerName serverName = calcServerNameForItem(consistentHashRing, consistentHashInput);
        // now region->server mapping is known
        serverByRegion.put(drhRegionInfo, serverName);
    }
    assertRegionCountsConsistent();
    // level out any imbalances from the hashing
    HBaseBalanceLeveler<DrRegionInfo<?>> leveler = new HBaseBalanceLeveler<>(drhServerList.getServerNames(), serverByRegion, tableName);
    serverByRegion = leveler.getBalancedDestinationByItem();
    assertRegionCountsConsistent();
    return serverByRegion;
}
Also used : ServerName(org.apache.hadoop.hbase.ServerName) HBaseBalanceLeveler(io.datarouter.client.hbase.balancer.HBaseBalanceLeveler) DrRegionInfo(io.datarouter.client.hbase.cluster.DrRegionInfo)

Aggregations

HBaseBalanceLeveler (io.datarouter.client.hbase.balancer.HBaseBalanceLeveler)2 DrRegionInfo (io.datarouter.client.hbase.cluster.DrRegionInfo)2 ServerName (org.apache.hadoop.hbase.ServerName)2 TreeMap (java.util.TreeMap)1