Search in sources :

Example 96 with TableId

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

the class Compactor method cancel.

@Override
public void cancel(TInfo tinfo, TCredentials credentials, String externalCompactionId) throws TException {
    TableId tableId = JOB_HOLDER.getTableId();
    try {
        NamespaceId nsId = getContext().getNamespaceId(tableId);
        if (!security.canCompact(credentials, tableId, nsId)) {
            throw new AccumuloSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED).asThriftException();
        }
    } catch (TableNotFoundException e) {
        throw new ThriftTableOperationException(tableId.canonical(), null, TableOperation.COMPACT_CANCEL, TableOperationExceptionType.NOTFOUND, e.getMessage());
    }
    cancel(externalCompactionId);
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) NamespaceId(org.apache.accumulo.core.data.NamespaceId)

Example 97 with TableId

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

the class GarbageCollectionAlgorithm method cleanUpDeletedTableDirs.

private void cleanUpDeletedTableDirs(GarbageCollectionEnvironment gce, SortedMap<String, String> candidateMap) throws IOException {
    HashSet<TableId> tableIdsWithDeletes = new HashSet<>();
    // find the table ids that had dirs deleted
    for (String delete : candidateMap.keySet()) {
        String[] tokens = delete.split("/");
        if (tokens.length == 2) {
            // its a directory
            TableId tableId = TableId.of(delete.split("/")[0]);
            tableIdsWithDeletes.add(tableId);
        }
    }
    Set<TableId> tableIdsInZookeeper = gce.getTableIDs();
    tableIdsWithDeletes.removeAll(tableIdsInZookeeper);
    for (TableId delTableId : tableIdsWithDeletes) {
        gce.deleteTableDirIfEmpty(delTableId);
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) HashSet(java.util.HashSet)

Example 98 with TableId

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

the class TableOperationsImpl method compact.

@Override
public void compact(String tableName, CompactionConfig config) throws AccumuloSecurityException, TableNotFoundException, AccumuloException {
    EXISTING_TABLE_NAME.validate(tableName);
    // Ensure compaction iterators exist on a tabletserver
    final String skviName = SortedKeyValueIterator.class.getName();
    for (IteratorSetting setting : config.getIterators()) {
        String iteratorClass = setting.getIteratorClass();
        if (!testClassLoad(tableName, iteratorClass, skviName)) {
            throw new AccumuloException("TabletServer could not load iterator class " + iteratorClass);
        }
    }
    ensureStrategyCanLoad(tableName, config);
    if (!UserCompactionUtils.isDefault(config.getConfigurer())) {
        if (!testClassLoad(tableName, config.getConfigurer().getClassName(), CompactionConfigurer.class.getName())) {
            throw new AccumuloException("TabletServer could not load " + CompactionConfigurer.class.getSimpleName() + " class " + config.getConfigurer().getClassName());
        }
    }
    if (!UserCompactionUtils.isDefault(config.getSelector())) {
        if (!testClassLoad(tableName, config.getSelector().getClassName(), CompactionSelector.class.getName())) {
            throw new AccumuloException("TabletServer could not load " + CompactionSelector.class.getSimpleName() + " class " + config.getSelector().getClassName());
        }
    }
    TableId tableId = context.getTableId(tableName);
    Text start = config.getStartRow();
    Text end = config.getEndRow();
    if (config.getFlush())
        _flush(tableId, start, end, true);
    List<ByteBuffer> args = Arrays.asList(ByteBuffer.wrap(tableId.canonical().getBytes(UTF_8)), ByteBuffer.wrap(UserCompactionUtils.encode(config)));
    Map<String, String> opts = new HashMap<>();
    try {
        doFateOperation(FateOperation.TABLE_COMPACT, args, opts, tableName, config.getWait());
    } catch (TableExistsException | NamespaceExistsException e) {
        // should not happen
        throw new AssertionError(e);
    } catch (NamespaceNotFoundException e) {
        throw new TableNotFoundException(null, tableName, "Namespace not found", e);
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) AccumuloException(org.apache.accumulo.core.client.AccumuloException) HashMap(java.util.HashMap) Text(org.apache.hadoop.io.Text) ByteBuffer(java.nio.ByteBuffer) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) IteratorSetting(org.apache.accumulo.core.client.IteratorSetting) TableExistsException(org.apache.accumulo.core.client.TableExistsException)

Example 99 with TableId

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

the class TableOperationsImpl method summaries.

@Override
public SummaryRetriever summaries(String tableName) {
    EXISTING_TABLE_NAME.validate(tableName);
    return new SummaryRetriever() {

        private Text startRow = null;

        private Text endRow = null;

        private List<TSummarizerConfiguration> summariesToFetch = Collections.emptyList();

        private String summarizerClassRegex;

        private boolean flush = false;

        @Override
        public SummaryRetriever startRow(Text startRow) {
            Objects.requireNonNull(startRow);
            if (endRow != null) {
                Preconditions.checkArgument(startRow.compareTo(endRow) < 0, "Start row must be less than end row : %s >= %s", startRow, endRow);
            }
            this.startRow = startRow;
            return this;
        }

        @Override
        public SummaryRetriever startRow(CharSequence startRow) {
            return startRow(new Text(startRow.toString()));
        }

        @Override
        public List<Summary> retrieve() throws AccumuloException, AccumuloSecurityException, TableNotFoundException {
            TableId tableId = context.getTableId(tableName);
            context.requireNotOffline(tableId, tableName);
            TRowRange range = new TRowRange(TextUtil.getByteBuffer(startRow), TextUtil.getByteBuffer(endRow));
            TSummaryRequest request = new TSummaryRequest(tableId.canonical(), range, summariesToFetch, summarizerClassRegex);
            if (flush) {
                _flush(tableId, startRow, endRow, true);
            }
            TSummaries ret = ServerClient.execute(context, new TabletClientService.Client.Factory(), client -> {
                TSummaries tsr = client.startGetSummaries(TraceUtil.traceInfo(), context.rpcCreds(), request);
                while (!tsr.finished) {
                    tsr = client.contiuneGetSummaries(TraceUtil.traceInfo(), tsr.sessionId);
                }
                return tsr;
            });
            return new SummaryCollection(ret).getSummaries();
        }

        @Override
        public SummaryRetriever endRow(Text endRow) {
            Objects.requireNonNull(endRow);
            if (startRow != null) {
                Preconditions.checkArgument(startRow.compareTo(endRow) < 0, "Start row must be less than end row : %s >= %s", startRow, endRow);
            }
            this.endRow = endRow;
            return this;
        }

        @Override
        public SummaryRetriever endRow(CharSequence endRow) {
            return endRow(new Text(endRow.toString()));
        }

        @Override
        public SummaryRetriever withConfiguration(Collection<SummarizerConfiguration> configs) {
            Objects.requireNonNull(configs);
            summariesToFetch = configs.stream().map(SummarizerConfigurationUtil::toThrift).collect(Collectors.toList());
            return this;
        }

        @Override
        public SummaryRetriever withConfiguration(SummarizerConfiguration... config) {
            Objects.requireNonNull(config);
            return withConfiguration(Arrays.asList(config));
        }

        @Override
        public SummaryRetriever withMatchingConfiguration(String regex) {
            Objects.requireNonNull(regex);
            // Do a sanity check here to make sure that regex compiles, instead of having it fail on a
            // tserver.
            Pattern.compile(regex);
            this.summarizerClassRegex = regex;
            return this;
        }

        @Override
        public SummaryRetriever flush(boolean b) {
            this.flush = b;
            return this;
        }
    };
}
Also used : TableId(org.apache.accumulo.core.data.TableId) Text(org.apache.hadoop.io.Text) SummarizerConfigurationUtil(org.apache.accumulo.core.summary.SummarizerConfigurationUtil) SummaryRetriever(org.apache.accumulo.core.client.admin.SummaryRetriever) TSummaryRequest(org.apache.accumulo.core.dataImpl.thrift.TSummaryRequest) TSummaries(org.apache.accumulo.core.dataImpl.thrift.TSummaries) Summary(org.apache.accumulo.core.client.summary.Summary) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection) Collection(java.util.Collection) ArrayList(java.util.ArrayList) List(java.util.List) LinkedList(java.util.LinkedList) Client(org.apache.accumulo.core.clientImpl.thrift.ClientService.Client) TRowRange(org.apache.accumulo.core.dataImpl.thrift.TRowRange) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) TSummarizerConfiguration(org.apache.accumulo.core.dataImpl.thrift.TSummarizerConfiguration)

Example 100 with TableId

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

the class TableOperationsImpl method addSplits.

@Override
public void addSplits(String tableName, SortedSet<Text> partitionKeys) throws TableNotFoundException, AccumuloException, AccumuloSecurityException {
    EXISTING_TABLE_NAME.validate(tableName);
    TableId tableId = context.getTableId(tableName);
    List<Text> splits = new ArrayList<>(partitionKeys);
    // should be sorted because we copied from a sorted set, but that makes
    // assumptions about how the copy was done so resort to be sure.
    Collections.sort(splits);
    CountDownLatch latch = new CountDownLatch(splits.size());
    AtomicReference<Exception> exception = new AtomicReference<>(null);
    ExecutorService executor = ThreadPools.createFixedThreadPool(16, "addSplits", false);
    try {
        executor.execute(new SplitTask(new SplitEnv(tableName, tableId, executor, latch, exception), splits));
        while (!latch.await(100, MILLISECONDS)) {
            if (exception.get() != null) {
                executor.shutdownNow();
                Throwable excep = exception.get();
                // user would only have the stack trace for the background thread.
                if (excep instanceof TableNotFoundException) {
                    TableNotFoundException tnfe = (TableNotFoundException) excep;
                    throw new TableNotFoundException(tableId.canonical(), tableName, "Table not found by background thread", tnfe);
                } else if (excep instanceof TableOfflineException) {
                    log.debug("TableOfflineException occurred in background thread. Throwing new exception", excep);
                    throw new TableOfflineException(tableId, tableName);
                } else if (excep instanceof AccumuloSecurityException) {
                    // base == background accumulo security exception
                    AccumuloSecurityException base = (AccumuloSecurityException) excep;
                    throw new AccumuloSecurityException(base.getUser(), base.asThriftException().getCode(), base.getTableInfo(), excep);
                } else if (excep instanceof AccumuloServerException) {
                    throw new AccumuloServerException((AccumuloServerException) excep);
                } else if (excep instanceof Error) {
                    throw new Error(excep);
                } else {
                    throw new AccumuloException(excep);
                }
            }
        }
    } catch (InterruptedException e) {
        throw new RuntimeException(e);
    } finally {
        executor.shutdown();
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) AccumuloException(org.apache.accumulo.core.client.AccumuloException) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) ArrayList(java.util.ArrayList) LocalityGroupConfigurationError(org.apache.accumulo.core.util.LocalityGroupUtil.LocalityGroupConfigurationError) Text(org.apache.hadoop.io.Text) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) TableOfflineException(org.apache.accumulo.core.client.TableOfflineException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NamespaceNotFoundException(org.apache.accumulo.core.client.NamespaceNotFoundException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TableExistsException(org.apache.accumulo.core.client.TableExistsException) TException(org.apache.thrift.TException) IOException(java.io.IOException) TTransportException(org.apache.thrift.transport.TTransportException) NamespaceExistsException(org.apache.accumulo.core.client.NamespaceExistsException) FileNotFoundException(java.io.FileNotFoundException) ThriftNotActiveServiceException(org.apache.accumulo.core.clientImpl.thrift.ThriftNotActiveServiceException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) TApplicationException(org.apache.thrift.TApplicationException) AccumuloException(org.apache.accumulo.core.client.AccumuloException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ExecutorService(java.util.concurrent.ExecutorService) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException)

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