Search in sources :

Example 1 with TableStatisticsImpl

use of org.apache.accumulo.core.manager.balancer.TableStatisticsImpl 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 TableStatisticsImpl

use of org.apache.accumulo.core.manager.balancer.TableStatisticsImpl 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 TableStatisticsImpl

use of org.apache.accumulo.core.manager.balancer.TableStatisticsImpl in project accumulo by apache.

the class HostRegexTableLoadBalancer method balance.

@Override
public long balance(BalanceParameters params) {
    long minBalanceTime = 20_000;
    // Iterate over the tables and balance each of them
    Map<String, TableId> tableIdMap = environment.getTableIdMap();
    Map<TableId, String> tableIdToTableName = tableIdMap.entrySet().stream().collect(Collectors.toMap(Map.Entry::getValue, Map.Entry::getKey));
    tableIdToTableName.keySet().forEach(this::checkTableConfig);
    long now = System.currentTimeMillis();
    HrtlbConf myConf = hrtlbConf.get();
    SortedMap<TabletServerId, TServerStatus> current = params.currentStatus();
    Set<TabletId> migrations = params.currentMigrations();
    List<TabletMigration> migrationsOut = params.migrationsOut();
    Map<String, SortedMap<TabletServerId, TServerStatus>> currentGrouped = splitCurrentByRegex(params.currentStatus());
    if ((now - this.lastOOBCheck) > myConf.oobCheckMillis) {
        try {
            // Check to see if a tablet is assigned outside the bounds of the pool. If so, migrate it.
            for (String table : tableIdMap.keySet()) {
                LOG.debug("Checking for out of bounds tablets for table {}", table);
                String tablePoolName = getPoolNameForTable(table);
                for (Entry<TabletServerId, TServerStatus> e : current.entrySet()) {
                    // pool names are the same as table names, except in the DEFAULT case.
                    // If this table is assigned to a pool for this host, then move on.
                    List<String> hostPools = getPoolNamesForHost(e.getKey());
                    if (hostPools.contains(tablePoolName)) {
                        continue;
                    }
                    TableId tid = tableIdMap.get(table);
                    if (tid == null) {
                        LOG.warn("Unable to check for out of bounds tablets for table {}," + " it may have been deleted or renamed.", table);
                        continue;
                    }
                    try {
                        List<TabletStatistics> outOfBoundsTablets = getOnlineTabletsForTable(e.getKey(), tid);
                        if (outOfBoundsTablets == null) {
                            continue;
                        }
                        for (TabletStatistics ts : outOfBoundsTablets) {
                            if (migrations.contains(ts.getTabletId())) {
                                LOG.debug("Migration for out of bounds tablet {} has already been requested", ts.getTabletId());
                                continue;
                            }
                            String poolName = getPoolNameForTable(table);
                            SortedMap<TabletServerId, TServerStatus> currentView = currentGrouped.get(poolName);
                            if (currentView != null) {
                                int skip = random.nextInt(currentView.size());
                                Iterator<TabletServerId> iter = currentView.keySet().iterator();
                                for (int i = 0; i < skip; i++) {
                                    iter.next();
                                }
                                TabletServerId nextTS = iter.next();
                                LOG.info("Tablet {} is currently outside the bounds of the" + " regex, migrating from {} to {}", ts.getTabletId(), e.getKey(), nextTS);
                                migrationsOut.add(new TabletMigration(ts.getTabletId(), e.getKey(), nextTS));
                                if (migrationsOut.size() >= myConf.maxTServerMigrations) {
                                    break;
                                }
                            } else {
                                LOG.warn("No tablet servers online for pool {}, unable to" + " migrate out of bounds tablets", poolName);
                            }
                        }
                    } catch (AccumuloException | AccumuloSecurityException e1) {
                        LOG.error("Error in OOB check getting tablets for table {} from server {} {}", tid, e.getKey().getHost(), e);
                    }
                }
            }
        } finally {
            // this could have taken a while...get a new time
            this.lastOOBCheck = System.currentTimeMillis();
        }
    }
    if (!migrationsOut.isEmpty()) {
        LOG.warn("Not balancing tables due to moving {} out of bounds tablets", migrationsOut.size());
        LOG.info("Migrating out of bounds tablets: {}", migrationsOut);
        return minBalanceTime;
    }
    if (migrations != null && !migrations.isEmpty()) {
        if (migrations.size() >= myConf.maxOutstandingMigrations) {
            LOG.warn("Not balancing tables due to {} outstanding migrations", migrations.size());
            if (LOG.isTraceEnabled()) {
                LOG.trace("Sample up to 10 outstanding migrations: {}", Iterables.limit(migrations, 10));
            }
            return minBalanceTime;
        }
        LOG.debug("Current outstanding migrations of {} being applied", migrations.size());
        if (LOG.isTraceEnabled()) {
            LOG.trace("Sample up to 10 outstanding migrations: {}", Iterables.limit(migrations, 10));
        }
        migrationsFromLastPass.keySet().retainAll(migrations);
        SortedMap<TabletServerId, TServerStatusImpl> currentCopy = new TreeMap<>();
        current.forEach((tid, status) -> currentCopy.put(tid, (TServerStatusImpl) status));
        Multimap<TabletServerId, String> serverTableIdCopied = HashMultimap.create();
        for (TabletMigration migration : migrationsFromLastPass.values()) {
            TableStatisticsImpl fromInfo = getTableInfo(currentCopy, serverTableIdCopied, migration.getTablet().getTable().canonical(), migration.getOldTabletServer());
            if (fromInfo != null) {
                fromInfo.setOnlineTabletCount(fromInfo.getOnlineTabletCount() - 1);
            }
            TableStatisticsImpl toInfo = getTableInfo(currentCopy, serverTableIdCopied, migration.getTablet().getTable().canonical(), migration.getNewTabletServer());
            if (toInfo != null) {
                toInfo.setOnlineTabletCount(toInfo.getOnlineTabletCount() + 1);
            }
        }
        migrations = EMPTY_MIGRATIONS;
    } else {
        migrationsFromLastPass.clear();
    }
    for (TableId tableId : tableIdMap.values()) {
        String tableName = tableIdToTableName.get(tableId);
        String regexTableName = getPoolNameForTable(tableName);
        SortedMap<TabletServerId, TServerStatus> currentView = currentGrouped.get(regexTableName);
        if (currentView == null) {
            LOG.warn("Skipping balance for table {} as no tablet servers are online.", tableName);
            continue;
        }
        ArrayList<TabletMigration> newMigrations = new ArrayList<>();
        getBalancerForTable(tableId).balance(new BalanceParamsImpl(currentView, migrations, newMigrations));
        if (newMigrations.isEmpty()) {
            tableToTimeSinceNoMigrations.remove(tableId);
        } else if (tableToTimeSinceNoMigrations.containsKey(tableId)) {
            if ((now - tableToTimeSinceNoMigrations.get(tableId)) > HOURS.toMillis(1)) {
                LOG.warn("We have been consistently producing migrations for {}: {}", tableName, Iterables.limit(newMigrations, 10));
            }
        } else {
            tableToTimeSinceNoMigrations.put(tableId, now);
        }
        migrationsOut.addAll(newMigrations);
        if (migrationsOut.size() >= myConf.maxTServerMigrations) {
            break;
        }
    }
    for (TabletMigration migration : migrationsOut) {
        migrationsFromLastPass.put(migration.getTablet(), migration);
    }
    LOG.info("Migrating tablets for balance: {}", migrationsOut);
    return minBalanceTime;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) ArrayList(java.util.ArrayList) TServerStatusImpl(org.apache.accumulo.core.manager.balancer.TServerStatusImpl) TabletServerId(org.apache.accumulo.core.spi.balancer.data.TabletServerId) TabletStatistics(org.apache.accumulo.core.spi.balancer.data.TabletStatistics) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) BalanceParamsImpl(org.apache.accumulo.core.manager.balancer.BalanceParamsImpl) TabletMigration(org.apache.accumulo.core.spi.balancer.data.TabletMigration) TServerStatus(org.apache.accumulo.core.spi.balancer.data.TServerStatus) TreeMap(java.util.TreeMap) TableStatisticsImpl(org.apache.accumulo.core.manager.balancer.TableStatisticsImpl) SortedMap(java.util.SortedMap) TabletId(org.apache.accumulo.core.data.TabletId) HashMap(java.util.HashMap) Map(java.util.Map) TreeMap(java.util.TreeMap) SortedMap(java.util.SortedMap)

Aggregations

TableStatisticsImpl (org.apache.accumulo.core.manager.balancer.TableStatisticsImpl)3 HashMap (java.util.HashMap)2 Map (java.util.Map)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2 TableId (org.apache.accumulo.core.data.TableId)2 TServerStatusImpl (org.apache.accumulo.core.manager.balancer.TServerStatusImpl)2 TServerStatus (org.apache.accumulo.core.spi.balancer.data.TServerStatus)2 TableStatistics (org.apache.accumulo.core.spi.balancer.data.TableStatistics)2 TabletServerId (org.apache.accumulo.core.spi.balancer.data.TabletServerId)2 ArrayList (java.util.ArrayList)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 BalanceParamsImpl (org.apache.accumulo.core.manager.balancer.BalanceParamsImpl)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