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;
}
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;
}
Aggregations