Search in sources :

Example 16 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class ReplicationSchemaTest method extractTableIdUsingText.

@Test
public void extractTableIdUsingText() {
    TableId tableId = TableId.of("1");
    Key k = new Key(new Text("foo"), StatusSection.NAME, new Text(tableId.canonical()));
    assertEquals(tableId, StatusSection.getTableId(k));
}
Also used : TableId(org.apache.accumulo.core.data.TableId) Text(org.apache.hadoop.io.Text) Key(org.apache.accumulo.core.data.Key) Test(org.junit.jupiter.api.Test)

Example 17 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class DefaultLoadBalancer method move.

/**
 * Select a tablet based on differences between table loads; if the loads are even, use the
 * busiest table
 */
List<TabletMigration> move(ServerCounts tooMuch, ServerCounts tooLittle, int count, Map<TableId, Map<KeyExtent, TabletStats>> donerTabletStats) {
    if (count == 0) {
        return Collections.emptyList();
    }
    List<TabletMigration> result = new ArrayList<>();
    // Copy counts so we can update them as we propose migrations
    Map<TableId, Integer> tooMuchMap = tabletCountsPerTable(tooMuch.status);
    Map<TableId, Integer> tooLittleMap = tabletCountsPerTable(tooLittle.status);
    for (int i = 0; i < count; i++) {
        TableId table;
        Integer tooLittleCount;
        if (tableToBalance == null) {
            // find a table to migrate
            // look for an uneven table count
            int biggestDifference = 0;
            TableId biggestDifferenceTable = null;
            for (var tableEntry : tooMuchMap.entrySet()) {
                TableId tableID = tableEntry.getKey();
                tooLittleMap.putIfAbsent(tableID, 0);
                int diff = tableEntry.getValue() - tooLittleMap.get(tableID);
                if (diff > biggestDifference) {
                    biggestDifference = diff;
                    biggestDifferenceTable = tableID;
                }
            }
            if (biggestDifference < 2) {
                table = busiest(tooMuch.status.tableMap);
            } else {
                table = biggestDifferenceTable;
            }
        } else {
            // just balance the given table
            table = tableToBalance;
        }
        Map<KeyExtent, TabletStats> onlineTabletsForTable = donerTabletStats.get(table);
        try {
            if (onlineTabletsForTable == null) {
                onlineTabletsForTable = new HashMap<>();
                List<TabletStats> stats = getOnlineTabletsForTable(tooMuch.server, table);
                if (stats == null) {
                    log.warn("Unable to find tablets to move");
                    return result;
                }
                for (TabletStats stat : stats) onlineTabletsForTable.put(KeyExtent.fromThrift(stat.extent), stat);
                donerTabletStats.put(table, onlineTabletsForTable);
            }
        } catch (Exception ex) {
            log.error("Unable to select a tablet to move", ex);
            return result;
        }
        KeyExtent extent = selectTablet(onlineTabletsForTable);
        onlineTabletsForTable.remove(extent);
        if (extent == null)
            return result;
        tooMuchMap.put(table, tooMuchMap.get(table) - 1);
        /**
         * If a table grows from 1 tablet then tooLittleMap.get(table) can return a null, since there
         * is only one tabletserver that holds all of the tablets. Here we check to see if in fact
         * that is the case and if so set the value to 0.
         */
        tooLittleCount = tooLittleMap.get(table);
        if (tooLittleCount == null) {
            tooLittleCount = 0;
        }
        tooLittleMap.put(table, tooLittleCount + 1);
        tooMuch.count--;
        tooLittle.count++;
        result.add(new TabletMigration(extent, tooMuch.server, tooLittle.server));
    }
    return result;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TabletMigration(org.apache.accumulo.server.master.state.TabletMigration) TabletStats(org.apache.accumulo.core.tabletserver.thrift.TabletStats) ArrayList(java.util.ArrayList) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent)

Example 18 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class DefaultLoadBalancer method busiest.

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

Example 19 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class ProblemReport method decodeMetadataEntry.

public static ProblemReport decodeMetadataEntry(Entry<Key, Value> entry) throws IOException {
    TableId tableId = TableId.of(entry.getKey().getRow().toString().substring("~err_".length()));
    String problemType = entry.getKey().getColumnFamily().toString();
    String resource = entry.getKey().getColumnQualifier().toString();
    return new ProblemReport(tableId, ProblemType.valueOf(problemType), resource, entry.getValue().get());
}
Also used : TableId(org.apache.accumulo.core.data.TableId)

Example 20 with TableId

use of org.apache.accumulo.core.data.TableId in project accumulo by apache.

the class ReplicationUtil method getReplicationTargets.

public Set<ReplicationTarget> getReplicationTargets() {
    // The total set of configured targets
    final Set<ReplicationTarget> allConfiguredTargets = new HashSet<>();
    final Map<String, TableId> tableNameToId = context.getTableNameToIdMap();
    for (String table : tableNameToId.keySet()) {
        if (MetadataTable.NAME.equals(table) || RootTable.NAME.equals(table)) {
            continue;
        }
        TableId localId = tableNameToId.get(table);
        if (localId == null) {
            log.trace("Could not determine ID for {}", table);
            continue;
        }
        TableConfiguration tableConf = context.getTableConfiguration(localId);
        if (tableConf == null) {
            log.trace("Could not get configuration for table {} (it no longer exists)", table);
            continue;
        }
        for (Entry<String, String> prop : tableConf.getAllPropertiesWithPrefix(Property.TABLE_REPLICATION_TARGET).entrySet()) {
            String peerName = prop.getKey().substring(Property.TABLE_REPLICATION_TARGET.getKey().length());
            String remoteIdentifier = prop.getValue();
            ReplicationTarget target = new ReplicationTarget(peerName, remoteIdentifier, localId);
            allConfiguredTargets.add(target);
        }
    }
    return allConfiguredTargets;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) ReplicationTarget(org.apache.accumulo.core.replication.ReplicationTarget) TableConfiguration(org.apache.accumulo.server.conf.TableConfiguration) HashSet(java.util.HashSet)

Aggregations

TableId (org.apache.accumulo.core.data.TableId)169 Text (org.apache.hadoop.io.Text)64 HashMap (java.util.HashMap)55 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)55 ArrayList (java.util.ArrayList)45 Test (org.junit.Test)43 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)41 Map (java.util.Map)37 Key (org.apache.accumulo.core.data.Key)36 AccumuloClient (org.apache.accumulo.core.client.AccumuloClient)34 HashSet (java.util.HashSet)31 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)31 Value (org.apache.accumulo.core.data.Value)31 IOException (java.io.IOException)28 Scanner (org.apache.accumulo.core.client.Scanner)28 AccumuloException (org.apache.accumulo.core.client.AccumuloException)27 Mutation (org.apache.accumulo.core.data.Mutation)27 List (java.util.List)26 Range (org.apache.accumulo.core.data.Range)24 BatchWriter (org.apache.accumulo.core.client.BatchWriter)23