Search in sources :

Example 26 with TabletServerId

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);
        }
    }
}
Also used : HashMap(java.util.HashMap) TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) ArrayList(java.util.ArrayList) TServerStatus(org.apache.accumulo.core.spi.balancer.data.TServerStatus) TableStatistics(org.apache.accumulo.core.spi.balancer.data.TableStatistics) TabletId(org.apache.accumulo.core.data.TabletId)

Aggregations

TabletServerId (org.apache.accumulo.core.spi.balancer.data.TabletServerId)26 TabletId (org.apache.accumulo.core.data.TabletId)22 HashMap (java.util.HashMap)17 ArrayList (java.util.ArrayList)14 TabletMigration (org.apache.accumulo.core.spi.balancer.data.TabletMigration)11 AssignmentParamsImpl (org.apache.accumulo.core.manager.balancer.AssignmentParamsImpl)10 TabletServerIdImpl (org.apache.accumulo.core.manager.balancer.TabletServerIdImpl)10 TServerStatus (org.apache.accumulo.core.spi.balancer.data.TServerStatus)10 Test (org.junit.jupiter.api.Test)10 TableId (org.apache.accumulo.core.data.TableId)8 TreeMap (java.util.TreeMap)7 BalanceParamsImpl (org.apache.accumulo.core.manager.balancer.BalanceParamsImpl)7 Map (java.util.Map)6 SortedMap (java.util.SortedMap)5 TServerStatusImpl (org.apache.accumulo.core.manager.balancer.TServerStatusImpl)4 TabletStatistics (org.apache.accumulo.core.spi.balancer.data.TabletStatistics)4 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)3 TableInfo (org.apache.accumulo.core.master.thrift.TableInfo)3 TableStatistics (org.apache.accumulo.core.spi.balancer.data.TableStatistics)3 Collections (java.util.Collections)2