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));
}
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;
}
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;
}
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());
}
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;
}
Aggregations