Search in sources :

Example 61 with TableId

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);
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Gatherer(org.apache.accumulo.core.summary.Gatherer) ExecutorService(java.util.concurrent.ExecutorService) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) NamespaceId(org.apache.accumulo.core.data.NamespaceId) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection)

Example 62 with TableId

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;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TabletStats(org.apache.accumulo.core.tabletserver.thrift.TabletStats) ArrayList(java.util.ArrayList) Text(org.apache.hadoop.io.Text) Tablet(org.apache.accumulo.tserver.tablet.Tablet) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent)

Example 63 with TableId

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;
}
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 64 with TableId

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);
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TabletMetadata(org.apache.accumulo.core.metadata.schema.TabletMetadata) Text(org.apache.hadoop.io.Text) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) Test(org.junit.Test)

Example 65 with TableId

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;
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) Scanner(org.apache.accumulo.core.client.Scanner) MutableInt(org.apache.commons.lang3.mutable.MutableInt) Value(org.apache.accumulo.core.data.Value) Key(org.apache.accumulo.core.data.Key) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance)

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