use of org.apache.accumulo.core.spi.balancer.data.TabletServerId in project accumulo by apache.
the class ChaoticLoadBalancer method getAssignments.
@Override
public void getAssignments(AssignmentParameters params) {
long total = params.unassignedTablets().size();
long avg = (long) Math.ceil(((double) total) / params.currentStatus().size());
Map<TabletServerId, Long> toAssign = new HashMap<>();
List<TabletServerId> tServerArray = new ArrayList<>();
for (Entry<TabletServerId, TServerStatus> e : params.currentStatus().entrySet()) {
long numTablets = 0;
for (TableStatistics ti : e.getValue().getTableMap().values()) {
numTablets += ti.getTabletCount();
}
if (numTablets <= avg) {
tServerArray.add(e.getKey());
toAssign.put(e.getKey(), avg - numTablets);
}
}
if (tServerArray.isEmpty()) {
// No tservers to assign to
return;
}
for (TabletId tabletId : params.unassignedTablets().keySet()) {
int index = random.nextInt(tServerArray.size());
TabletServerId dest = tServerArray.get(index);
params.addAssignment(tabletId, dest);
long remaining = toAssign.get(dest) - 1;
if (remaining == 0) {
tServerArray.remove(index);
toAssign.remove(dest);
} else {
toAssign.put(dest, remaining);
}
}
}
Aggregations