use of org.apache.accumulo.core.data.TableId in project accumulo by apache.
the class ThriftClientHandler method startGetSummaries.
@Override
public TSummaries startGetSummaries(TInfo tinfo, TCredentials credentials, TSummaryRequest request) throws ThriftSecurityException, ThriftTableOperationException, TException {
NamespaceId namespaceId;
TableId tableId = TableId.of(request.getTableId());
try {
namespaceId = server.getContext().getNamespaceId(tableId);
} catch (TableNotFoundException e1) {
throw new ThriftTableOperationException(tableId.canonical(), null, null, TableOperationExceptionType.NOTFOUND, null);
}
if (!security.canGetSummaries(credentials, tableId, namespaceId)) {
throw new AccumuloSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED).asThriftException();
}
ExecutorService es = server.resourceManager.getSummaryPartitionExecutor();
Future<SummaryCollection> future = new Gatherer(server.getContext(), request, context.getTableConfiguration(tableId), context.getCryptoService()).gather(es);
return startSummaryOperation(credentials, future);
}
use of org.apache.accumulo.core.data.TableId in project accumulo by apache.
the class ThriftClientHandler method getTabletStats.
@Override
public List<TabletStats> getTabletStats(TInfo tinfo, TCredentials credentials, String tableId) {
List<TabletStats> result = new ArrayList<>();
TableId text = TableId.of(tableId);
KeyExtent start = new KeyExtent(text, new Text(), null);
for (Entry<KeyExtent, Tablet> entry : server.getOnlineTablets().tailMap(start).entrySet()) {
KeyExtent ke = entry.getKey();
if (ke.tableId().compareTo(text) == 0) {
Tablet tablet = entry.getValue();
TabletStats stats = tablet.getTabletStats();
stats.extent = ke.toThrift();
stats.ingestRate = tablet.ingestRate();
stats.queryRate = tablet.queryRate();
stats.splitCreationTime = tablet.getSplitCreationTime();
stats.numEntries = tablet.getNumEntries();
result.add(stats);
}
}
return result;
}
use of org.apache.accumulo.core.data.TableId 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;
}
use of org.apache.accumulo.core.data.TableId in project accumulo by apache.
the class ListTabletsCommandTest method builderTest.
@Test
public void builderTest() {
TableId id = TableId.of("123");
Text startRow = new Text("a");
Text endRow = new Text("z");
KeyExtent ke = new KeyExtent(id, endRow, startRow);
TabletMetadata.Location loc = new TabletMetadata.Location("localhost", "", TabletMetadata.LocationType.CURRENT);
ListTabletsCommand.TabletRowInfo.Factory factory = new ListTabletsCommand.TabletRowInfo.Factory("aName", ke).numFiles(1).numWalLogs(2).numEntries(3).size(4).status(TabletState.HOSTED.toString()).location(loc).tableExists(true);
ListTabletsCommand.TabletRowInfo info = factory.build();
assertEquals("aName", info.tableName);
assertEquals(1, info.numFiles);
assertEquals(2, info.numWalLogs);
assertEquals("3", info.getNumEntries(false));
assertEquals(3, info.numEntries);
assertEquals("4", info.getSize(false));
assertEquals(4, info.size);
assertEquals("HOSTED", info.status);
assertEquals("CURRENT:localhost", info.location);
assertEquals(TableId.of("123"), info.tableId);
assertEquals(startRow + " " + endRow, info.getTablet());
assertTrue(info.tableExists);
}
use of org.apache.accumulo.core.data.TableId in project accumulo by apache.
the class RegexGroupBalanceIT method getCounts.
private Table<String, String, MutableInt> getCounts(AccumuloClient client, String tablename) throws TableNotFoundException {
try (Scanner s = client.createScanner(MetadataTable.NAME, Authorizations.EMPTY)) {
s.fetchColumnFamily(CurrentLocationColumnFamily.NAME);
TableId tableId = TableId.of(client.tableOperations().tableIdMap().get(tablename));
s.setRange(TabletsSection.getRange(tableId));
Table<String, String, MutableInt> groupLocationCounts = HashBasedTable.create();
for (Entry<Key, Value> entry : s) {
String group = entry.getKey().getRow().toString();
if (group.endsWith("<")) {
group = "03";
} else {
group = group.substring(tableId.canonical().length() + 1).substring(0, 2);
}
String loc = new TServerInstance(entry.getValue(), entry.getKey().getColumnQualifier()).getHostPortSession();
MutableInt count = groupLocationCounts.get(group, loc);
if (count == null) {
count = new MutableInt(0);
groupLocationCounts.put(group, loc, count);
}
count.increment();
}
return groupLocationCounts;
}
}
Aggregations