Search in sources :

Example 11 with NamespaceId

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

the class ManagerClientServiceHandler method alterTableProperty.

private void alterTableProperty(TCredentials c, String tableName, String property, String value, TableOperation op) throws ThriftSecurityException, ThriftTableOperationException {
    final TableId tableId = ClientServiceHandler.checkTableId(manager.getContext(), tableName, op);
    NamespaceId namespaceId = getNamespaceIdFromTableId(op, tableId);
    if (!manager.security.canAlterTable(c, tableId, namespaceId))
        throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
    try {
        if (value == null || value.isEmpty()) {
            TablePropUtil.removeTableProperty(manager.getContext(), tableId, property);
        } else if (!TablePropUtil.setTableProperty(manager.getContext(), tableId, property, value)) {
            throw new Exception("Invalid table property.");
        }
    } catch (KeeperException.NoNodeException e) {
        // race condition... table no longer exists? This call will throw an exception if the table
        // was deleted:
        ClientServiceHandler.checkTableId(manager.getContext(), tableName, op);
        log.info("Error altering table property", e);
        throw new ThriftTableOperationException(tableId.canonical(), tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property");
    } catch (Exception e) {
        log.error("Problem altering table property", e);
        throw new ThriftTableOperationException(tableId.canonical(), tableName, op, TableOperationExceptionType.OTHER, "Problem altering table property");
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) NamespaceId(org.apache.accumulo.core.data.NamespaceId) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) InvalidProtocolBufferException(com.google.protobuf.InvalidProtocolBufferException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TabletDeletedException(org.apache.accumulo.core.metadata.schema.TabletDeletedException) KeeperException(org.apache.zookeeper.KeeperException) TException(org.apache.thrift.TException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) KeeperException(org.apache.zookeeper.KeeperException)

Example 12 with NamespaceId

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

the class ManagerClientServiceHandler method waitForFlush.

@Override
public void waitForFlush(TInfo tinfo, TCredentials c, String tableIdStr, ByteBuffer startRowBB, ByteBuffer endRowBB, long flushID, long maxLoops) throws ThriftSecurityException, ThriftTableOperationException {
    TableId tableId = TableId.of(tableIdStr);
    NamespaceId namespaceId = getNamespaceIdFromTableId(TableOperation.FLUSH, tableId);
    if (!manager.security.canFlush(c, tableId, namespaceId))
        throw new ThriftSecurityException(c.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
    Text startRow = ByteBufferUtil.toText(startRowBB);
    Text endRow = ByteBufferUtil.toText(endRowBB);
    if (endRow != null && startRow != null && startRow.compareTo(endRow) >= 0)
        throw new ThriftTableOperationException(tableId.canonical(), null, TableOperation.FLUSH, TableOperationExceptionType.BAD_RANGE, "start row must be less than end row");
    Set<TServerInstance> serversToFlush = new HashSet<>(manager.tserverSet.getCurrentServers());
    for (long l = 0; l < maxLoops; l++) {
        for (TServerInstance instance : serversToFlush) {
            try {
                final TServerConnection server = manager.tserverSet.getConnection(instance);
                if (server != null)
                    server.flush(manager.managerLock, tableId, ByteBufferUtil.toBytes(startRowBB), ByteBufferUtil.toBytes(endRowBB));
            } catch (TException ex) {
                Manager.log.error(ex.toString());
            }
        }
        if (tableId.equals(RootTable.ID))
            // this code does not properly handle the root tablet. See #798
            break;
        if (l == maxLoops - 1)
            break;
        sleepUninterruptibly(50, TimeUnit.MILLISECONDS);
        serversToFlush.clear();
        try (TabletsMetadata tablets = TabletsMetadata.builder(manager.getContext()).forTable(tableId).overlapping(startRow, endRow).fetch(FLUSH_ID, LOCATION, LOGS, PREV_ROW).build()) {
            int tabletsToWaitFor = 0;
            int tabletCount = 0;
            for (TabletMetadata tablet : tablets) {
                int logs = tablet.getLogs().size();
                // when tablet is not online and has no logs, there is no reason to wait for it
                if ((tablet.hasCurrent() || logs > 0) && tablet.getFlushId().orElse(-1) < flushID) {
                    tabletsToWaitFor++;
                    if (tablet.hasCurrent())
                        serversToFlush.add(tablet.getLocation());
                }
                tabletCount++;
            }
            if (tabletsToWaitFor == 0)
                break;
            if (tabletCount == 0 && !manager.getContext().tableNodeExists(tableId))
                throw new ThriftTableOperationException(tableId.canonical(), null, TableOperation.FLUSH, TableOperationExceptionType.NOTFOUND, null);
        } catch (TabletDeletedException e) {
            Manager.log.debug("Failed to scan {} table to wait for flush {}", MetadataTable.NAME, tableId, e);
        }
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TException(org.apache.thrift.TException) Text(org.apache.hadoop.io.Text) TabletDeletedException(org.apache.accumulo.core.metadata.schema.TabletDeletedException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TServerInstance(org.apache.accumulo.core.metadata.TServerInstance) TServerConnection(org.apache.accumulo.server.manager.LiveTServerSet.TServerConnection) TabletsMetadata(org.apache.accumulo.core.metadata.schema.TabletsMetadata) TabletMetadata(org.apache.accumulo.core.metadata.schema.TabletMetadata) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) NamespaceId(org.apache.accumulo.core.data.NamespaceId) HashSet(java.util.HashSet)

Example 13 with NamespaceId

use of org.apache.accumulo.core.data.NamespaceId 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 14 with NamespaceId

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

the class ListTabletsCommand method populateTables.

/**
 * Process the command line for table names using table option, table name pattern, or default to
 * current table.
 *
 * @param cl
 *          command line
 * @param shellState
 *          shell state
 * @return set of table names.
 * @throws NamespaceNotFoundException
 *           if the namespace option is specified and namespace does not exist
 */
private Set<TableInfo> populateTables(final CommandLine cl, final Shell shellState) throws NamespaceNotFoundException {
    final TableOperations tableOps = shellState.getAccumuloClient().tableOperations();
    var tableIdMap = tableOps.tableIdMap();
    Set<TableInfo> tableSet = new TreeSet<>();
    if (cl.hasOption(optTablePattern.getOpt())) {
        Pattern tablePattern = Pattern.compile(cl.getOptionValue(optTablePattern.getOpt()));
        for (String table : tableOps.list()) {
            if (tablePattern.matcher(table).matches()) {
                TableId id = TableId.of(tableIdMap.get(table));
                tableSet.add(new TableInfo(table, id));
            }
        }
        return tableSet;
    }
    if (cl.hasOption(optNamespace.getOpt())) {
        String nsName = cl.getOptionValue(optNamespace.getOpt());
        NamespaceId namespaceId = Namespaces.getNamespaceId(shellState.getContext(), nsName);
        List<String> tables = Namespaces.getTableNames(shellState.getContext(), namespaceId);
        tables.forEach(name -> {
            String tableIdString = tableIdMap.get(name);
            if (tableIdString != null) {
                TableId id = TableId.of(tableIdString);
                tableSet.add(new TableInfo(name, id));
            } else {
                log.warn("Table not found: {}", name);
            }
        });
        return tableSet;
    }
    if (cl.hasOption(ShellOptions.tableOption)) {
        String table = cl.getOptionValue(ShellOptions.tableOption);
        String idString = tableIdMap.get(table);
        if (idString != null) {
            TableId id = TableId.of(idString);
            tableSet.add(new TableInfo(table, id));
        } else {
            log.warn("Table not found: {}", table);
        }
        return tableSet;
    }
    // If we didn't get any tables, and we have a table selected, add the current table
    String table = shellState.getTableName();
    if (!table.isEmpty()) {
        TableId id = TableId.of(tableIdMap.get(table));
        tableSet.add(new TableInfo(table, id));
        return tableSet;
    }
    return Collections.emptySet();
}
Also used : TableId(org.apache.accumulo.core.data.TableId) Pattern(java.util.regex.Pattern) TableOperations(org.apache.accumulo.core.client.admin.TableOperations) TreeSet(java.util.TreeSet) NamespaceId(org.apache.accumulo.core.data.NamespaceId)

Example 15 with NamespaceId

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

the class ThriftClientHandler method startScan.

@Override
public InitialScan startScan(TInfo tinfo, TCredentials credentials, TKeyExtent textent, TRange range, List<TColumn> columns, int batchSize, List<IterInfo> ssiList, Map<String, Map<String, String>> ssio, List<ByteBuffer> authorizations, boolean waitForWrites, boolean isolated, long readaheadThreshold, TSamplerConfiguration tSamplerConfig, long batchTimeOut, String contextArg, Map<String, String> executionHints) throws NotServingTabletException, ThriftSecurityException, org.apache.accumulo.core.tabletserver.thrift.TooManyFilesException, TSampleNotPresentException {
    TableId tableId = TableId.of(new String(textent.getTable(), UTF_8));
    NamespaceId namespaceId;
    try {
        namespaceId = server.getContext().getNamespaceId(tableId);
    } catch (TableNotFoundException e1) {
        throw new NotServingTabletException(textent);
    }
    if (!security.canScan(credentials, tableId, namespaceId, range, columns, ssiList, ssio, authorizations)) {
        throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
    }
    if (!security.authenticatedUserHasAuthorizations(credentials, authorizations)) {
        throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.BAD_AUTHORIZATIONS);
    }
    final KeyExtent extent = KeyExtent.fromThrift(textent);
    // metadata
    if (waitForWrites) {
        writeTracker.waitForWrites(TabletType.type(extent));
    }
    Tablet tablet = server.getOnlineTablet(extent);
    if (tablet == null) {
        throw new NotServingTabletException(textent);
    }
    HashSet<Column> columnSet = new HashSet<>();
    for (TColumn tcolumn : columns) {
        columnSet.add(new Column(tcolumn));
    }
    ScanParameters scanParams = new ScanParameters(batchSize, new Authorizations(authorizations), columnSet, ssiList, ssio, isolated, SamplerConfigurationImpl.fromThrift(tSamplerConfig), batchTimeOut, contextArg);
    final SingleScanSession scanSession = new SingleScanSession(credentials, extent, scanParams, readaheadThreshold, executionHints);
    scanSession.scanner = tablet.createScanner(new Range(range), scanParams, scanSession.interruptFlag);
    long sid = server.sessionManager.createSession(scanSession, true);
    ScanResult scanResult;
    try {
        scanResult = continueScan(tinfo, sid, scanSession);
    } catch (NoSuchScanIDException e) {
        log.error("The impossible happened", e);
        throw new RuntimeException();
    } finally {
        server.sessionManager.unreserveSession(sid);
    }
    return new InitialScan(sid, scanResult);
}
Also used : TableId(org.apache.accumulo.core.data.TableId) Authorizations(org.apache.accumulo.core.security.Authorizations) ScanResult(org.apache.accumulo.core.dataImpl.thrift.ScanResult) MultiScanResult(org.apache.accumulo.core.dataImpl.thrift.MultiScanResult) TColumn(org.apache.accumulo.core.dataImpl.thrift.TColumn) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) TRange(org.apache.accumulo.core.dataImpl.thrift.TRange) Range(org.apache.accumulo.core.data.Range) TRowRange(org.apache.accumulo.core.dataImpl.thrift.TRowRange) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) InitialScan(org.apache.accumulo.core.dataImpl.thrift.InitialScan) NoSuchScanIDException(org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Column(org.apache.accumulo.core.data.Column) TColumn(org.apache.accumulo.core.dataImpl.thrift.TColumn) ScanParameters(org.apache.accumulo.tserver.scan.ScanParameters) Tablet(org.apache.accumulo.tserver.tablet.Tablet) NamespaceId(org.apache.accumulo.core.data.NamespaceId) SingleScanSession(org.apache.accumulo.tserver.session.SingleScanSession) HashSet(java.util.HashSet)

Aggregations

NamespaceId (org.apache.accumulo.core.data.NamespaceId)32 TableId (org.apache.accumulo.core.data.TableId)20 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)16 ThriftTableOperationException (org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException)12 ThriftSecurityException (org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)11 TException (org.apache.thrift.TException)9 IOException (java.io.IOException)7 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)7 HashSet (java.util.HashSet)6 NamespaceNotFoundException (org.apache.accumulo.core.client.NamespaceNotFoundException)5 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)5 TKeyExtent (org.apache.accumulo.core.dataImpl.thrift.TKeyExtent)5 NoNodeException (org.apache.zookeeper.KeeperException.NoNodeException)5 ByteBuffer (java.nio.ByteBuffer)4 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 TreeSet (java.util.TreeSet)4 Authorizations (org.apache.accumulo.core.security.Authorizations)4 NotServingTabletException (org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException)4 ZooReaderWriter (org.apache.accumulo.fate.zookeeper.ZooReaderWriter)4