Search in sources :

Example 71 with TableId

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

the class SecurityOperation method _hasTablePermission.

/**
 * Checks if a user has a table permission<br>
 * This cannot check if a system user has permission.
 *
 * @return true if a user exists and has permission; false otherwise
 */
protected boolean _hasTablePermission(String user, TableId table, TablePermission permission, boolean useCached) throws ThriftSecurityException {
    targetUserExists(user);
    @SuppressWarnings("deprecation") TableId replicationTableId = org.apache.accumulo.core.replication.ReplicationTable.ID;
    if ((table.equals(MetadataTable.ID) || table.equals(RootTable.ID) || table.equals(replicationTableId)) && permission.equals(TablePermission.READ))
        return true;
    try {
        if (useCached)
            return permHandle.hasCachedTablePermission(user, table.canonical(), permission);
        return permHandle.hasTablePermission(user, table.canonical(), permission);
    } catch (TableNotFoundException e) {
        throw new ThriftSecurityException(user, SecurityErrorCode.TABLE_DOESNT_EXIST);
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)

Example 72 with TableId

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

the class TabletServerResource method doCurrentOperations.

private List<CurrentOperations> doCurrentOperations(List<TabletStats> tsStats) throws Exception {
    List<CurrentOperations> currentOperations = new ArrayList<>();
    for (TabletStats info : tsStats) {
        if (info.extent == null) {
            historical = info;
            continue;
        }
        total.numEntries += info.numEntries;
        ActionStatsUpdator.update(total.minors, info.minors);
        ActionStatsUpdator.update(total.majors, info.majors);
        KeyExtent extent = KeyExtent.fromThrift(info.extent);
        TableId tableId = extent.tableId();
        String displayExtent = String.format("[%s]", extent.obscured());
        String tableName = monitor.getContext().getPrintableTableInfoFromId(tableId);
        currentOperations.add(new CurrentOperations(tableName, tableId, displayExtent, info.numEntries, info.ingestRate, info.queryRate, info.minors.num != 0 ? info.minors.elapsed / info.minors.num : null, stddev(info.minors.elapsed, info.minors.num, info.minors.sumDev), info.minors.elapsed != 0 ? info.minors.count / info.minors.elapsed : null, info.majors.num != 0 ? info.majors.elapsed / info.majors.num : null, stddev(info.majors.elapsed, info.majors.num, info.majors.sumDev), info.majors.elapsed != 0 ? info.majors.count / info.majors.elapsed : null));
    }
    return currentOperations;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) TabletStats(org.apache.accumulo.core.tabletserver.thrift.TabletStats) ArrayList(java.util.ArrayList) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent)

Example 73 with TableId

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

the class ProblemsResource method getDetails.

/**
 * Generates a list of the problem details as a JSON object
 *
 * @return problem details list
 */
@GET
@Path("details")
public ProblemDetail getDetails() {
    ProblemDetail problems = new ProblemDetail();
    if (monitor.getProblemException() == null) {
        for (Entry<TableId, Map<ProblemType, Integer>> entry : monitor.getProblemSummary().entrySet()) {
            ArrayList<ProblemReport> problemReports = new ArrayList<>();
            Iterator<ProblemReport> iter = entry.getKey() == null ? ProblemReports.getInstance(monitor.getContext()).iterator() : ProblemReports.getInstance(monitor.getContext()).iterator(entry.getKey());
            while (iter.hasNext()) {
                problemReports.add(iter.next());
            }
            for (ProblemReport pr : problemReports) {
                String tableName = monitor.getContext().getPrintableTableInfoFromId(pr.getTableId());
                problems.addProblemDetail(new ProblemDetailInformation(tableName, entry.getKey(), pr.getProblemType().name(), pr.getServer(), pr.getTime(), pr.getResource(), pr.getException()));
            }
        }
    }
    return problems;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) ProblemReport(org.apache.accumulo.server.problems.ProblemReport) ArrayList(java.util.ArrayList) Map(java.util.Map) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Example 74 with TableId

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

the class CompactableUtils method selectFiles.

static Set<StoredTabletFile> selectFiles(Tablet tablet, SortedMap<StoredTabletFile, DataFileValue> datafiles, PluginConfig selectorConfig) {
    CompactionSelector selector = newInstance(tablet.getTableConfiguration(), selectorConfig.getClassName(), CompactionSelector.class);
    final ServiceEnvironment senv = new ServiceEnvironmentImpl(tablet.getContext());
    selector.init(new CompactionSelector.InitParameters() {

        @Override
        public Map<String, String> getOptions() {
            return selectorConfig.getOptions();
        }

        @Override
        public PluginEnvironment getEnvironment() {
            return senv;
        }

        @Override
        public TableId getTableId() {
            return tablet.getExtent().tableId();
        }
    });
    Selection selection = selector.select(new CompactionSelector.SelectionParameters() {

        @Override
        public PluginEnvironment getEnvironment() {
            return senv;
        }

        @Override
        public Collection<CompactableFile> getAvailableFiles() {
            return Collections2.transform(datafiles.entrySet(), e -> new CompactableFileImpl(e.getKey(), e.getValue()));
        }

        @Override
        public Collection<Summary> getSummaries(Collection<CompactableFile> files, Predicate<SummarizerConfiguration> summarySelector) {
            var context = tablet.getContext();
            var tsrm = tablet.getTabletResources().getTabletServerResourceManager();
            SummaryCollection sc = new SummaryCollection();
            SummarizerFactory factory = new SummarizerFactory(tablet.getTableConfiguration());
            for (CompactableFile cf : files) {
                var file = CompactableFileImpl.toStoredTabletFile(cf);
                FileSystem fs = context.getVolumeManager().getFileSystemByPath(file.getPath());
                Configuration conf = context.getHadoopConf();
                SummaryCollection fsc = SummaryReader.load(fs, conf, factory, file.getPath(), summarySelector, tsrm.getSummaryCache(), tsrm.getIndexCache(), tsrm.getFileLenCache(), context.getCryptoService()).getSummaries(Collections.singletonList(new Gatherer.RowRange(tablet.getExtent())));
                sc.merge(fsc, factory);
            }
            return sc.getSummaries();
        }

        @Override
        public TableId getTableId() {
            return tablet.getExtent().tableId();
        }

        @Override
        public Optional<SortedKeyValueIterator<Key, Value>> getSample(CompactableFile file, SamplerConfiguration sc) {
            try {
                FileOperations fileFactory = FileOperations.getInstance();
                Path path = new Path(file.getUri());
                FileSystem ns = tablet.getTabletServer().getVolumeManager().getFileSystemByPath(path);
                var fiter = fileFactory.newReaderBuilder().forFile(path.toString(), ns, ns.getConf(), tablet.getContext().getCryptoService()).withTableConfiguration(tablet.getTableConfiguration()).seekToBeginning().build();
                return Optional.ofNullable(fiter.getSample(new SamplerConfigurationImpl(sc)));
            } catch (IOException e) {
                throw new UncheckedIOException(e);
            }
        }
    });
    return selection.getFilesToCompact().stream().map(CompactableFileImpl::toStoredTabletFile).collect(Collectors.toSet());
}
Also used : PluginEnvironment(org.apache.accumulo.core.client.PluginEnvironment) TableId(org.apache.accumulo.core.data.TableId) TableId(org.apache.accumulo.core.data.TableId) FileCompactor(org.apache.accumulo.server.compaction.FileCompactor) FileSystem(org.apache.hadoop.fs.FileSystem) LoggerFactory(org.slf4j.LoggerFactory) Collections2(com.google.common.collect.Collections2) MetadataTableUtil(org.apache.accumulo.server.util.MetadataTableUtil) Selection(org.apache.accumulo.core.client.admin.compaction.CompactionSelector.Selection) PluginConfig(org.apache.accumulo.core.client.admin.PluginConfig) CompactableFile(org.apache.accumulo.core.client.admin.compaction.CompactableFile) BlockCache(org.apache.accumulo.core.spi.cache.BlockCache) ConfigurationTypeHelper(org.apache.accumulo.core.conf.ConfigurationTypeHelper) ClassLoaderUtil(org.apache.accumulo.core.classloader.ClassLoaderUtil) FileOperations(org.apache.accumulo.core.file.FileOperations) Map(java.util.Map) Configuration(org.apache.hadoop.conf.Configuration) Path(org.apache.hadoop.fs.Path) CompactionStrategyConfigUtil(org.apache.accumulo.core.clientImpl.CompactionStrategyConfigUtil) Value(org.apache.accumulo.core.data.Value) SamplerConfiguration(org.apache.accumulo.core.client.sample.SamplerConfiguration) Property(org.apache.accumulo.core.conf.Property) CompactionEnv(org.apache.accumulo.server.compaction.FileCompactor.CompactionEnv) VolumeManager(org.apache.accumulo.server.fs.VolumeManager) Predicate(java.util.function.Predicate) Collection(java.util.Collection) MajorCompactionReason(org.apache.accumulo.tserver.compaction.MajorCompactionReason) FileSKVIterator(org.apache.accumulo.core.file.FileSKVIterator) Set(java.util.Set) SummaryReader(org.apache.accumulo.core.summary.SummaryReader) Collectors(java.util.stream.Collectors) UncheckedIOException(java.io.UncheckedIOException) CompactionStrategyConfig(org.apache.accumulo.core.client.admin.CompactionStrategyConfig) TableConfiguration(org.apache.accumulo.server.conf.TableConfiguration) CompactionSelector(org.apache.accumulo.core.client.admin.compaction.CompactionSelector) Pair(org.apache.accumulo.core.util.Pair) ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) Optional(java.util.Optional) ConfigurationCopy(org.apache.accumulo.core.conf.ConfigurationCopy) CacheBuilder(com.google.common.cache.CacheBuilder) SortedMap(java.util.SortedMap) SummarizerFactory(org.apache.accumulo.core.summary.SummarizerFactory) CompactionPlan(org.apache.accumulo.tserver.compaction.CompactionPlan) DataFileValue(org.apache.accumulo.core.metadata.schema.DataFileValue) SamplerConfigurationImpl(org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl) CompactionHelper(org.apache.accumulo.tserver.tablet.CompactableImpl.CompactionHelper) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection) HashMap(java.util.HashMap) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) SortedKeyValueIterator(org.apache.accumulo.core.iterators.SortedKeyValueIterator) PluginEnvironment(org.apache.accumulo.core.client.PluginEnvironment) HashSet(java.util.HashSet) StoredTabletFile(org.apache.accumulo.core.metadata.StoredTabletFile) Gatherer(org.apache.accumulo.core.summary.Gatherer) CompactionKind(org.apache.accumulo.core.spi.compaction.CompactionKind) Key(org.apache.accumulo.core.data.Key) ServiceEnvironmentImpl(org.apache.accumulo.server.ServiceEnvironmentImpl) TabletFile(org.apache.accumulo.core.metadata.TabletFile) CompactionStats(org.apache.accumulo.server.compaction.CompactionStats) Summary(org.apache.accumulo.core.client.summary.Summary) CompactionCanceledException(org.apache.accumulo.server.compaction.FileCompactor.CompactionCanceledException) Logger(org.slf4j.Logger) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) MajorCompactionRequest(org.apache.accumulo.tserver.compaction.MajorCompactionRequest) IOException(java.io.IOException) CompactionConfigurer(org.apache.accumulo.core.client.admin.compaction.CompactionConfigurer) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) WriteParameters(org.apache.accumulo.tserver.compaction.WriteParameters) ExecutionException(java.util.concurrent.ExecutionException) CompactionJob(org.apache.accumulo.core.spi.compaction.CompactionJob) Preconditions(com.google.common.base.Preconditions) CompactionStrategy(org.apache.accumulo.tserver.compaction.CompactionStrategy) Cache(com.google.common.cache.Cache) Collections(java.util.Collections) UserCompactionUtils(org.apache.accumulo.core.clientImpl.UserCompactionUtils) CompactableFileImpl(org.apache.accumulo.core.metadata.CompactableFileImpl) Gatherer(org.apache.accumulo.core.summary.Gatherer) Configuration(org.apache.hadoop.conf.Configuration) SamplerConfiguration(org.apache.accumulo.core.client.sample.SamplerConfiguration) TableConfiguration(org.apache.accumulo.server.conf.TableConfiguration) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration) Selection(org.apache.accumulo.core.client.admin.compaction.CompactionSelector.Selection) SamplerConfigurationImpl(org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl) SamplerConfiguration(org.apache.accumulo.core.client.sample.SamplerConfiguration) FileOperations(org.apache.accumulo.core.file.FileOperations) SummarizerFactory(org.apache.accumulo.core.summary.SummarizerFactory) UncheckedIOException(java.io.UncheckedIOException) ServiceEnvironment(org.apache.accumulo.core.spi.common.ServiceEnvironment) FileSystem(org.apache.hadoop.fs.FileSystem) SummarizerConfiguration(org.apache.accumulo.core.client.summary.SummarizerConfiguration) Path(org.apache.hadoop.fs.Path) CompactableFileImpl(org.apache.accumulo.core.metadata.CompactableFileImpl) CompactableFile(org.apache.accumulo.core.client.admin.compaction.CompactableFile) Optional(java.util.Optional) ServiceEnvironmentImpl(org.apache.accumulo.server.ServiceEnvironmentImpl) UncheckedIOException(java.io.UncheckedIOException) IOException(java.io.IOException) CompactionSelector(org.apache.accumulo.core.client.admin.compaction.CompactionSelector) Value(org.apache.accumulo.core.data.Value) DataFileValue(org.apache.accumulo.core.metadata.schema.DataFileValue) Collection(java.util.Collection) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection) Map(java.util.Map) SortedMap(java.util.SortedMap) HashMap(java.util.HashMap) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection) Key(org.apache.accumulo.core.data.Key)

Example 75 with TableId

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

the class ReplicationServicerHandler method replicateLog.

@Override
public long replicateLog(String tableIdStr, WalEdits data, TCredentials tcreds) throws TException {
    TableId tableId = TableId.of(tableIdStr);
    log.debug("Got replication request to tableID {} with {} edits", tableId, data.getEditsSize());
    tabletServer.getSecurityOperation().authenticateUser(tabletServer.getContext().rpcCreds(), tcreds);
    String tableName;
    try {
        tableName = tabletServer.getContext().getTableName(tableId);
    } catch (TableNotFoundException e) {
        log.error("Could not find table with id {}", tableId);
        throw new RemoteReplicationException(RemoteReplicationErrorCode.TABLE_DOES_NOT_EXIST, "Table with id " + tableId + " does not exist");
    }
    AccumuloConfiguration conf = tabletServer.getConfiguration();
    Map<String, String> replicationHandlers = conf.getAllPropertiesWithPrefix(Property.TSERV_REPLICATION_REPLAYERS);
    String propertyForHandlerTable = Property.TSERV_REPLICATION_REPLAYERS.getKey() + tableId;
    String handlerClassForTable = replicationHandlers.get(propertyForHandlerTable);
    if (handlerClassForTable == null) {
        if (!replicationHandlers.isEmpty()) {
            log.debug("Could not find replication replayer for {}", tableId);
        }
        handlerClassForTable = conf.get(Property.TSERV_REPLICATION_DEFAULT_HANDLER);
    }
    log.debug("Using {} replication replayer for table {}", handlerClassForTable, tableId);
    // Get class for replayer
    Class<? extends AccumuloReplicationReplayer> clz;
    try {
        Class<?> untypedClz = Class.forName(handlerClassForTable);
        clz = untypedClz.asSubclass(AccumuloReplicationReplayer.class);
    } catch (ClassNotFoundException e) {
        log.error("Could not instantiate replayer class {}", handlerClassForTable, e);
        throw new RemoteReplicationException(RemoteReplicationErrorCode.CANNOT_INSTANTIATE_REPLAYER, "Could not instantiate replayer class " + handlerClassForTable);
    }
    // Create an instance
    AccumuloReplicationReplayer replayer;
    try {
        replayer = clz.getDeclaredConstructor().newInstance();
    } catch (ReflectiveOperationException e1) {
        log.error("Could not instantiate replayer class {}", clz.getName());
        throw new RemoteReplicationException(RemoteReplicationErrorCode.CANNOT_INSTANTIATE_REPLAYER, "Could not instantiate replayer class" + clz.getName());
    }
    long entriesReplicated;
    try {
        entriesReplicated = replayer.replicateLog(tabletServer.getContext(), tableName, data);
    } catch (AccumuloException | AccumuloSecurityException e) {
        log.error("Could not get connection", e);
        throw new RemoteReplicationException(RemoteReplicationErrorCode.CANNOT_AUTHENTICATE, "Cannot get connection as " + tabletServer.getContext().getCredentials().getPrincipal());
    }
    log.debug("Replicated {} mutations to {}", entriesReplicated, tableName);
    return entriesReplicated;
}
Also used : TableId(org.apache.accumulo.core.data.TableId) AccumuloException(org.apache.accumulo.core.client.AccumuloException) RemoteReplicationException(org.apache.accumulo.core.replication.thrift.RemoteReplicationException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) AccumuloReplicationReplayer(org.apache.accumulo.core.replication.AccumuloReplicationReplayer) AccumuloConfiguration(org.apache.accumulo.core.conf.AccumuloConfiguration)

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