Search in sources :

Example 1 with TableStatistics

use of org.apache.accumulo.core.spi.balancer.data.TableStatistics in project accumulo by apache.

the class HostRegexTableLoadBalancer method getTableInfo.

/**
 * Get a mutable table info for the specified table and server
 */
private TableStatisticsImpl getTableInfo(SortedMap<TabletServerId, TServerStatusImpl> currentCopy, Multimap<TabletServerId, String> serverTableIdCopied, String tableId, TabletServerId server) {
    TableStatisticsImpl newInfo = null;
    if (currentCopy.containsKey(server)) {
        Map<String, TableStatistics> newTableMap = currentCopy.get(server).getTableMap();
        if (newTableMap != null) {
            newInfo = (TableStatisticsImpl) newTableMap.get(tableId);
            if (newInfo != null) {
                Collection<String> tableIdCopied = serverTableIdCopied.get(server);
                if (tableIdCopied.isEmpty()) {
                    newTableMap = new HashMap<>(newTableMap);
                    currentCopy.get(server).setTableMap(newTableMap);
                }
                if (!tableIdCopied.contains(tableId)) {
                    newInfo = new TableStatisticsImpl(newInfo);
                    newTableMap.put(tableId, newInfo);
                    tableIdCopied.add(tableId);
                }
            }
        }
    }
    return newInfo;
}
Also used : TableStatisticsImpl(org.apache.accumulo.core.manager.balancer.TableStatisticsImpl) TableStatistics(org.apache.accumulo.core.spi.balancer.data.TableStatistics)

Example 2 with TableStatistics

use of org.apache.accumulo.core.spi.balancer.data.TableStatistics in project accumulo by apache.

the class BaseHostRegexTableLoadBalancerTest method createCurrent.

protected SortedMap<TabletServerId, TServerStatus> createCurrent(int numTservers) {
    String base = "192.168.0.";
    TreeMap<TabletServerId, TServerStatus> current = new TreeMap<>();
    for (int i = 1; i <= numTservers; i++) {
        TServerStatusImpl status = new TServerStatusImpl(new org.apache.accumulo.core.master.thrift.TabletServerStatus());
        Map<String, TableStatistics> tableMap = new HashMap<>();
        tableMap.put(FOO.getId().canonical(), new TableStatisticsImpl(new TableInfo()));
        tableMap.put(BAR.getId().canonical(), new TableStatisticsImpl(new TableInfo()));
        tableMap.put(BAZ.getId().canonical(), new TableStatisticsImpl(new TableInfo()));
        status.setTableMap(tableMap);
        current.put(new TabletServerIdImpl(base + i, 9997, Integer.toHexString(1)), status);
    }
    // now put all of the tablets on one server
    for (Map.Entry<String, TabletServerId> entry : initialTableLocation.entrySet()) {
        TServerStatus status = current.get(entry.getValue());
        if (status != null) {
            TableId tableId = environment.getTableIdMap().get(entry.getKey());
            ((TableStatisticsImpl) status.getTableMap().get(tableId.canonical())).setOnlineTabletCount(5);
        }
    }
    return current;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) HashMap(java.util.HashMap) TServerStatus(org.apache.accumulo.core.spi.balancer.data.TServerStatus) TreeMap(java.util.TreeMap) TabletServerIdImpl(org.apache.accumulo.core.manager.balancer.TabletServerIdImpl) TServerStatusImpl(org.apache.accumulo.core.manager.balancer.TServerStatusImpl) TableStatisticsImpl(org.apache.accumulo.core.manager.balancer.TableStatisticsImpl) TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) TableStatistics(org.apache.accumulo.core.spi.balancer.data.TableStatistics) TableInfo(org.apache.accumulo.core.master.thrift.TableInfo) HashMap(java.util.HashMap) TreeMap(java.util.TreeMap) Map(java.util.Map) SortedMap(java.util.SortedMap)

Example 3 with TableStatistics

use of org.apache.accumulo.core.spi.balancer.data.TableStatistics in project accumulo by apache.

the class ChaoticLoadBalancer method balance.

@Override
public long balance(BalanceParameters params) {
    Map<TabletServerId, Long> numTablets = new HashMap<>();
    List<TabletServerId> underCapacityTServer = new ArrayList<>();
    if (!params.currentMigrations().isEmpty()) {
        outstandingMigrationsProblem.setMigrations(params.currentMigrations());
        problemReporter.reportProblem(outstandingMigrationsProblem);
        return 100;
    }
    problemReporter.clearProblemReportTimes();
    boolean moveMetadata = random.nextInt(4) == 0;
    long totalTablets = 0;
    for (Entry<TabletServerId, TServerStatus> e : params.currentStatus().entrySet()) {
        long tabletCount = 0;
        for (TableStatistics ti : e.getValue().getTableMap().values()) {
            tabletCount += ti.getTabletCount();
        }
        numTablets.put(e.getKey(), tabletCount);
        underCapacityTServer.add(e.getKey());
        totalTablets += tabletCount;
    }
    // totalTablets is fuzzy due to asynchronicity of the stats
    // *1.2 to handle fuzziness, and prevent locking for 'perfect' balancing scenarios
    long avg = (long) Math.ceil(((double) totalTablets) / params.currentStatus().size() * 1.2);
    for (Entry<TabletServerId, TServerStatus> e : params.currentStatus().entrySet()) {
        for (String tableId : e.getValue().getTableMap().keySet()) {
            TableId id = TableId.of(tableId);
            if (!moveMetadata && MetadataTable.ID.equals(id))
                continue;
            try {
                for (TabletStatistics ts : getOnlineTabletsForTable(e.getKey(), id)) {
                    int index = random.nextInt(underCapacityTServer.size());
                    TabletServerId dest = underCapacityTServer.get(index);
                    if (dest.equals(e.getKey()))
                        continue;
                    params.migrationsOut().add(new TabletMigration(ts.getTabletId(), e.getKey(), dest));
                    if (numTablets.put(dest, numTablets.get(dest) + 1) > avg)
                        underCapacityTServer.remove(index);
                    if (numTablets.put(e.getKey(), numTablets.get(e.getKey()) - 1) <= avg && !underCapacityTServer.contains(e.getKey()))
                        underCapacityTServer.add(e.getKey());
                    // option!
                    if (underCapacityTServer.isEmpty())
                        underCapacityTServer.addAll(numTablets.keySet());
                }
            } catch (AccumuloSecurityException e1) {
                // Shouldn't happen, but carry on if it does
                log.debug("Encountered AccumuloSecurityException.  This should not happen.  Carrying on anyway.", e1);
            } catch (AccumuloException e1) {
                // Shouldn't happen, but carry on if it does
                log.debug("Encountered AccumuloException.  This should not happen.  Carrying on anyway.", e1);
            }
        }
    }
    return 100;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TabletMigration(org.apache.accumulo.core.spi.balancer.data.TabletMigration) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) TServerStatus(org.apache.accumulo.core.spi.balancer.data.TServerStatus) TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) TableStatistics(org.apache.accumulo.core.spi.balancer.data.TableStatistics) TabletStatistics(org.apache.accumulo.core.spi.balancer.data.TabletStatistics) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException)

Example 4 with TableStatistics

use of org.apache.accumulo.core.spi.balancer.data.TableStatistics in project accumulo by apache.

the class SimpleLoadBalancer method busiest.

// define what it means for a tablet to be busy
private static TableId busiest(Map<String, TableStatistics> tables) {
    TableId result = null;
    double busiest = Double.NEGATIVE_INFINITY;
    for (Entry<String, TableStatistics> entry : tables.entrySet()) {
        TableStatistics info = entry.getValue();
        double busy = info.getIngestRate() + info.getQueryRate();
        if (busy > busiest) {
            busiest = busy;
            result = TableId.of(entry.getKey());
        }
    }
    return result;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TableStatistics(org.apache.accumulo.core.spi.balancer.data.TableStatistics)

Example 5 with TableStatistics

use of org.apache.accumulo.core.spi.balancer.data.TableStatistics 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

TableStatistics (org.apache.accumulo.core.spi.balancer.data.TableStatistics)5 HashMap (java.util.HashMap)3 TableId (org.apache.accumulo.core.data.TableId)3 TServerStatus (org.apache.accumulo.core.spi.balancer.data.TServerStatus)3 TabletServerId (org.apache.accumulo.core.spi.balancer.data.TabletServerId)3 ArrayList (java.util.ArrayList)2 TableStatisticsImpl (org.apache.accumulo.core.manager.balancer.TableStatisticsImpl)2 Map (java.util.Map)1 SortedMap (java.util.SortedMap)1 TreeMap (java.util.TreeMap)1 AccumuloException (org.apache.accumulo.core.client.AccumuloException)1 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)1 TabletId (org.apache.accumulo.core.data.TabletId)1 TServerStatusImpl (org.apache.accumulo.core.manager.balancer.TServerStatusImpl)1 TabletServerIdImpl (org.apache.accumulo.core.manager.balancer.TabletServerIdImpl)1 TableInfo (org.apache.accumulo.core.master.thrift.TableInfo)1 TabletMigration (org.apache.accumulo.core.spi.balancer.data.TabletMigration)1 TabletStatistics (org.apache.accumulo.core.spi.balancer.data.TabletStatistics)1