Search in sources :

Example 21 with TKeyExtent

use of org.apache.accumulo.core.dataImpl.thrift.TKeyExtent in project accumulo by apache.

the class ThriftClientHandler method conditionalUpdate.

@Override
public List<TCMResult> conditionalUpdate(TInfo tinfo, long sessID, Map<TKeyExtent, List<TConditionalMutation>> mutations, List<String> symbols) throws NoSuchScanIDException, TException {
    ConditionalSession cs = (ConditionalSession) server.sessionManager.reserveSession(sessID);
    if (cs == null || cs.interruptFlag.get()) {
        throw new NoSuchScanIDException();
    }
    if (!cs.tableId.equals(MetadataTable.ID) && !cs.tableId.equals(RootTable.ID)) {
        try {
            server.resourceManager.waitUntilCommitsAreEnabled();
        } catch (HoldTimeoutException hte) {
            // Assumption is that the client has timed out and is gone. If that's not the case throw
            // an exception that will cause it to retry.
            log.debug("HoldTimeoutException during conditionalUpdate, reporting no such session");
            throw new NoSuchScanIDException();
        }
    }
    TableId tid = cs.tableId;
    long opid = writeTracker.startWrite(TabletType.type(new KeyExtent(tid, null, null)));
    try {
        // @formatter:off
        Map<KeyExtent, List<ServerConditionalMutation>> updates = mutations.entrySet().stream().collect(Collectors.toMap(entry -> KeyExtent.fromThrift(entry.getKey()), entry -> entry.getValue().stream().map(ServerConditionalMutation::new).collect(Collectors.toList())));
        // @formatter:on
        for (KeyExtent ke : updates.keySet()) {
            if (!ke.tableId().equals(tid)) {
                throw new IllegalArgumentException("Unexpected table id " + tid + " != " + ke.tableId());
            }
        }
        ArrayList<TCMResult> results = new ArrayList<>();
        Map<KeyExtent, List<ServerConditionalMutation>> deferred = conditionalUpdate(cs, updates, results, symbols);
        while (!deferred.isEmpty()) {
            deferred = conditionalUpdate(cs, deferred, results, symbols);
        }
        return results;
    } catch (IOException ioe) {
        throw new TException(ioe);
    } finally {
        writeTracker.finishWrite(opid);
        server.sessionManager.unreserveSession(sessID);
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) FileSystem(org.apache.hadoop.fs.FileSystem) TooManyFilesException(org.apache.accumulo.server.fs.TooManyFilesException) Text(org.apache.hadoop.io.Text) Collections2(com.google.common.collect.Collections2) ConstraintViolationSummary(org.apache.accumulo.core.data.ConstraintViolationSummary) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) Future(java.util.concurrent.Future) TSummaries(org.apache.accumulo.core.dataImpl.thrift.TSummaries) CompressedIterators(org.apache.accumulo.core.clientImpl.CompressedIterators) ExternalCompactionId(org.apache.accumulo.core.metadata.schema.ExternalCompactionId) ScanResult(org.apache.accumulo.core.dataImpl.thrift.ScanResult) Map(java.util.Map) RootTable(org.apache.accumulo.core.metadata.RootTable) MapFileInfo(org.apache.accumulo.core.dataImpl.thrift.MapFileInfo) BulkImportState(org.apache.accumulo.core.master.thrift.BulkImportState) NoSuchScanIDException(org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException) Property(org.apache.accumulo.core.conf.Property) VolumeManager(org.apache.accumulo.server.fs.VolumeManager) CancellationException(java.util.concurrent.CancellationException) Column(org.apache.accumulo.core.data.Column) TSummaryRequest(org.apache.accumulo.core.dataImpl.thrift.TSummaryRequest) TabletStats(org.apache.accumulo.core.tabletserver.thrift.TabletStats) PreparedMutations(org.apache.accumulo.tserver.tablet.PreparedMutations) TConditionalSession(org.apache.accumulo.core.dataImpl.thrift.TConditionalSession) Set(java.util.Set) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TCMStatus(org.apache.accumulo.core.dataImpl.thrift.TCMStatus) TCredentials(org.apache.accumulo.core.securityImpl.thrift.TCredentials) TExternalCompactionJob(org.apache.accumulo.core.tabletserver.thrift.TExternalCompactionJob) TSamplerConfiguration(org.apache.accumulo.core.tabletserver.thrift.TSamplerConfiguration) ScanDispatcher(org.apache.accumulo.core.spi.scan.ScanDispatcher) RowLock(org.apache.accumulo.tserver.RowLocks.RowLock) ServiceLock(org.apache.accumulo.fate.zookeeper.ServiceLock) UtilWaitThread.sleepUninterruptibly(org.apache.accumulo.fate.util.UtilWaitThread.sleepUninterruptibly) TRange(org.apache.accumulo.core.dataImpl.thrift.TRange) SamplerConfigurationImpl(org.apache.accumulo.core.sample.impl.SamplerConfigurationImpl) KVEntry(org.apache.accumulo.tserver.tablet.KVEntry) SummaryCollection(org.apache.accumulo.core.summary.SummaryCollection) MINUTES(java.util.concurrent.TimeUnit.MINUTES) Threads(org.apache.accumulo.core.util.threads.Threads) ZooUtil(org.apache.accumulo.fate.zookeeper.ZooUtil) DurabilityImpl(org.apache.accumulo.core.clientImpl.DurabilityImpl) ArrayList(java.util.ArrayList) MultiScanSession(org.apache.accumulo.tserver.session.MultiScanSession) TSampleNotPresentException(org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException) Gatherer(org.apache.accumulo.core.summary.Gatherer) ActiveCompaction(org.apache.accumulo.core.tabletserver.thrift.ActiveCompaction) LookupTask(org.apache.accumulo.tserver.scan.LookupTask) FSError(org.apache.hadoop.fs.FSError) Key(org.apache.accumulo.core.data.Key) FileSystemResolver(org.apache.accumulo.core.summary.Gatherer.FileSystemResolver) CommitSession(org.apache.accumulo.tserver.tablet.CommitSession) TabletFile(org.apache.accumulo.core.metadata.TabletFile) InitialScan(org.apache.accumulo.core.dataImpl.thrift.InitialScan) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) ServerMutation(org.apache.accumulo.server.data.ServerMutation) TConditionalMutation(org.apache.accumulo.core.dataImpl.thrift.TConditionalMutation) TColumn(org.apache.accumulo.core.dataImpl.thrift.TColumn) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) ConstraintViolationException(org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException) TException(org.apache.thrift.TException) IOException(java.io.IOException) Range(org.apache.accumulo.core.data.Range) ExecutionException(java.util.concurrent.ExecutionException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) ActiveScan(org.apache.accumulo.core.tabletserver.thrift.ActiveScan) TableId(org.apache.accumulo.core.data.TableId) FileCompactor(org.apache.accumulo.server.compaction.FileCompactor) NextBatchTask(org.apache.accumulo.tserver.scan.NextBatchTask) TabletServerStatus(org.apache.accumulo.core.master.thrift.TabletServerStatus) MultiScanResult(org.apache.accumulo.core.dataImpl.thrift.MultiScanResult) LoggerFactory(org.slf4j.LoggerFactory) TimeoutException(java.util.concurrent.TimeoutException) MetadataTable(org.apache.accumulo.core.metadata.MetadataTable) TabletLogger(org.apache.accumulo.core.logging.TabletLogger) TServerUtils(org.apache.accumulo.server.rpc.TServerUtils) Mutation(org.apache.accumulo.core.data.Mutation) TKeyValue(org.apache.accumulo.core.dataImpl.thrift.TKeyValue) IterInfo(org.apache.accumulo.core.dataImpl.thrift.IterInfo) ScanParameters(org.apache.accumulo.tserver.scan.ScanParameters) ByteBuffer(java.nio.ByteBuffer) BlockCache(org.apache.accumulo.core.spi.cache.BlockCache) ConditionalSession(org.apache.accumulo.tserver.session.ConditionalSession) TInfo(org.apache.accumulo.core.trace.thrift.TInfo) UpdateSession(org.apache.accumulo.tserver.session.UpdateSession) TCMResult(org.apache.accumulo.core.dataImpl.thrift.TCMResult) TabletClientService(org.apache.accumulo.core.tabletserver.thrift.TabletClientService) Path(org.apache.hadoop.fs.Path) TUnloadTabletGoal(org.apache.accumulo.core.tabletserver.thrift.TUnloadTabletGoal) SingleScanSession(org.apache.accumulo.tserver.session.SingleScanSession) ConditionChecker(org.apache.accumulo.tserver.ConditionCheckerContext.ConditionChecker) ServerConditionalMutation(org.apache.accumulo.tserver.data.ServerConditionalMutation) Span(io.opentelemetry.api.trace.Span) Collection(java.util.Collection) Durability(org.apache.accumulo.core.client.Durability) TransactionWatcher(org.apache.accumulo.server.zookeeper.TransactionWatcher) Collectors(java.util.stream.Collectors) TabletClosedException(org.apache.accumulo.tserver.tablet.TabletClosedException) List(java.util.List) TableConfiguration(org.apache.accumulo.server.conf.TableConfiguration) Pair(org.apache.accumulo.core.util.Pair) Entry(java.util.Map.Entry) NamespaceId(org.apache.accumulo.core.data.NamespaceId) TraceUtil(org.apache.accumulo.core.trace.TraceUtil) ByteBufferUtil(org.apache.accumulo.core.util.ByteBufferUtil) IterationInterruptedException(org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException) TRowRange(org.apache.accumulo.core.dataImpl.thrift.TRowRange) TCompactionQueueSummary(org.apache.accumulo.core.tabletserver.thrift.TCompactionQueueSummary) HashMap(java.util.HashMap) CompactionConfig(org.apache.accumulo.core.client.admin.CompactionConfig) HashSet(java.util.HashSet) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) SummarySession(org.apache.accumulo.tserver.session.SummarySession) Halt(org.apache.accumulo.core.util.Halt) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) InitialMultiScan(org.apache.accumulo.core.dataImpl.thrift.InitialMultiScan) TableOperationExceptionType(org.apache.accumulo.core.clientImpl.thrift.TableOperationExceptionType) ExecutorService(java.util.concurrent.ExecutorService) UpdateErrors(org.apache.accumulo.core.dataImpl.thrift.UpdateErrors) TMutation(org.apache.accumulo.core.dataImpl.thrift.TMutation) Logger(org.slf4j.Logger) Iterator(java.util.Iterator) SecurityErrorCode(org.apache.accumulo.core.clientImpl.thrift.SecurityErrorCode) Scope(io.opentelemetry.context.Scope) UTF_8(java.nio.charset.StandardCharsets.UTF_8) ClientServiceHandler(org.apache.accumulo.server.client.ClientServiceHandler) CompactionInfo(org.apache.accumulo.server.compaction.CompactionInfo) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) Constants(org.apache.accumulo.core.Constants) Authorizations(org.apache.accumulo.core.security.Authorizations) ScanBatch(org.apache.accumulo.tserver.tablet.ScanBatch) TimeUnit(java.util.concurrent.TimeUnit) Collectors.toList(java.util.stream.Collectors.toList) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) TabletType(org.apache.accumulo.core.clientImpl.TabletType) TDurability(org.apache.accumulo.core.tabletserver.thrift.TDurability) Tablet(org.apache.accumulo.tserver.tablet.Tablet) Cache(com.google.common.cache.Cache) Collections(java.util.Collections) TException(org.apache.thrift.TException) ArrayList(java.util.ArrayList) TConditionalSession(org.apache.accumulo.core.dataImpl.thrift.TConditionalSession) ConditionalSession(org.apache.accumulo.tserver.session.ConditionalSession) IOException(java.io.IOException) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) NoSuchScanIDException(org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException) TCMResult(org.apache.accumulo.core.dataImpl.thrift.TCMResult) ArrayList(java.util.ArrayList) List(java.util.List) Collectors.toList(java.util.stream.Collectors.toList)

Example 22 with TKeyExtent

use of org.apache.accumulo.core.dataImpl.thrift.TKeyExtent in project accumulo by apache.

the class ThriftClientHandler method update.

@Override
public void update(TInfo tinfo, TCredentials credentials, TKeyExtent tkeyExtent, TMutation tmutation, TDurability tdurability) throws NotServingTabletException, ConstraintViolationException, ThriftSecurityException {
    final TableId tableId = TableId.of(new String(tkeyExtent.getTable(), UTF_8));
    NamespaceId namespaceId = getNamespaceId(credentials, tableId);
    if (!security.canWrite(credentials, tableId, namespaceId)) {
        throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
    }
    final KeyExtent keyExtent = KeyExtent.fromThrift(tkeyExtent);
    final Tablet tablet = server.getOnlineTablet(KeyExtent.copyOf(keyExtent));
    if (tablet == null) {
        throw new NotServingTabletException(tkeyExtent);
    }
    Durability tabletDurability = tablet.getDurability();
    if (!keyExtent.isMeta()) {
        try {
            server.resourceManager.waitUntilCommitsAreEnabled();
        } catch (HoldTimeoutException hte) {
            // was a failure and it should retry.
            throw new NotServingTabletException(tkeyExtent);
        }
    }
    final long opid = writeTracker.startWrite(TabletType.type(keyExtent));
    try {
        final Mutation mutation = new ServerMutation(tmutation);
        final List<Mutation> mutations = Collections.singletonList(mutation);
        PreparedMutations prepared;
        Span span = TraceUtil.startSpan(this.getClass(), "update::prep");
        try (Scope scope = span.makeCurrent()) {
            prepared = tablet.prepareMutationsForCommit(new TservConstraintEnv(server.getContext(), security, credentials), mutations);
        } catch (Exception e) {
            TraceUtil.setException(span, e, true);
            throw e;
        } finally {
            span.end();
        }
        if (prepared.tabletClosed()) {
            throw new NotServingTabletException(tkeyExtent);
        } else if (!prepared.getViolators().isEmpty()) {
            throw new ConstraintViolationException(prepared.getViolations().asList().stream().map(ConstraintViolationSummary::toThrift).collect(Collectors.toList()));
        } else {
            CommitSession session = prepared.getCommitSession();
            Durability durability = DurabilityImpl.resolveDurabilty(DurabilityImpl.fromThrift(tdurability), tabletDurability);
            // Instead of always looping on true, skip completely when durability is NONE.
            while (durability != Durability.NONE) {
                try {
                    Span span2 = TraceUtil.startSpan(this.getClass(), "update::wal");
                    try (Scope scope = span2.makeCurrent()) {
                        server.logger.log(session, mutation, durability);
                    } catch (Exception e) {
                        TraceUtil.setException(span2, e, true);
                        throw e;
                    } finally {
                        span2.end();
                    }
                    break;
                } catch (IOException ex) {
                    log.warn("Error writing mutations to log", ex);
                }
            }
            Span span3 = TraceUtil.startSpan(this.getClass(), "update::commit");
            try (Scope scope = span3.makeCurrent()) {
                session.commit(mutations);
            } catch (Exception e) {
                TraceUtil.setException(span3, e, true);
                throw e;
            } finally {
                span3.end();
            }
        }
    } finally {
        writeTracker.finishWrite(opid);
    }
}
Also used : TableId(org.apache.accumulo.core.data.TableId) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) CommitSession(org.apache.accumulo.tserver.tablet.CommitSession) Durability(org.apache.accumulo.core.client.Durability) TDurability(org.apache.accumulo.core.tabletserver.thrift.TDurability) ServerMutation(org.apache.accumulo.server.data.ServerMutation) IOException(java.io.IOException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) Span(io.opentelemetry.api.trace.Span) TooManyFilesException(org.apache.accumulo.server.fs.TooManyFilesException) TableNotFoundException(org.apache.accumulo.core.client.TableNotFoundException) NoSuchScanIDException(org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException) CancellationException(java.util.concurrent.CancellationException) ThriftSecurityException(org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException) TSampleNotPresentException(org.apache.accumulo.core.tabletserver.thrift.TSampleNotPresentException) ConstraintViolationException(org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException) TException(org.apache.thrift.TException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) NoNodeException(org.apache.zookeeper.KeeperException.NoNodeException) TimeoutException(java.util.concurrent.TimeoutException) TabletClosedException(org.apache.accumulo.tserver.tablet.TabletClosedException) IterationInterruptedException(org.apache.accumulo.core.iteratorsImpl.system.IterationInterruptedException) NotServingTabletException(org.apache.accumulo.core.tabletserver.thrift.NotServingTabletException) AccumuloSecurityException(org.apache.accumulo.core.client.AccumuloSecurityException) SampleNotPresentException(org.apache.accumulo.core.client.SampleNotPresentException) ThriftTableOperationException(org.apache.accumulo.core.clientImpl.thrift.ThriftTableOperationException) Scope(io.opentelemetry.context.Scope) PreparedMutations(org.apache.accumulo.tserver.tablet.PreparedMutations) ConstraintViolationException(org.apache.accumulo.core.tabletserver.thrift.ConstraintViolationException) Tablet(org.apache.accumulo.tserver.tablet.Tablet) NamespaceId(org.apache.accumulo.core.data.NamespaceId) ServerMutation(org.apache.accumulo.server.data.ServerMutation) TConditionalMutation(org.apache.accumulo.core.dataImpl.thrift.TConditionalMutation) Mutation(org.apache.accumulo.core.data.Mutation) ServerConditionalMutation(org.apache.accumulo.tserver.data.ServerConditionalMutation) TMutation(org.apache.accumulo.core.dataImpl.thrift.TMutation)

Example 23 with TKeyExtent

use of org.apache.accumulo.core.dataImpl.thrift.TKeyExtent in project accumulo by apache.

the class ThriftClientHandler method applyUpdates.

@Override
public void applyUpdates(TInfo tinfo, long updateID, TKeyExtent tkeyExtent, List<TMutation> tmutations) {
    UpdateSession us = (UpdateSession) server.sessionManager.reserveSession(updateID);
    if (us == null) {
        return;
    }
    boolean reserved = true;
    try {
        KeyExtent keyExtent = KeyExtent.fromThrift(tkeyExtent);
        setUpdateTablet(us, keyExtent);
        if (us.currentTablet != null) {
            long additionalMutationSize = 0;
            List<Mutation> mutations = us.queuedMutations.get(us.currentTablet);
            for (TMutation tmutation : tmutations) {
                Mutation mutation = new ServerMutation(tmutation);
                mutations.add(mutation);
                additionalMutationSize += mutation.numBytes();
            }
            us.queuedMutationSize += additionalMutationSize;
            long totalQueued = server.updateTotalQueuedMutationSize(additionalMutationSize);
            long total = server.getConfiguration().getAsBytes(Property.TSERV_TOTAL_MUTATION_QUEUE_MAX);
            if (totalQueued > total) {
                try {
                    flush(us);
                } catch (HoldTimeoutException hte) {
                    // Assumption is that the client has timed out and is gone. If that's not the case,
                    // then removing the session should cause the client to fail
                    // in such a way that it retries.
                    log.debug("HoldTimeoutException during applyUpdates, removing session");
                    server.sessionManager.removeSession(updateID, true);
                    reserved = false;
                }
            }
        }
    } finally {
        if (reserved) {
            server.sessionManager.unreserveSession(us);
        }
    }
}
Also used : UpdateSession(org.apache.accumulo.tserver.session.UpdateSession) ServerMutation(org.apache.accumulo.server.data.ServerMutation) TMutation(org.apache.accumulo.core.dataImpl.thrift.TMutation) ServerMutation(org.apache.accumulo.server.data.ServerMutation) TConditionalMutation(org.apache.accumulo.core.dataImpl.thrift.TConditionalMutation) Mutation(org.apache.accumulo.core.data.Mutation) ServerConditionalMutation(org.apache.accumulo.tserver.data.ServerConditionalMutation) TMutation(org.apache.accumulo.core.dataImpl.thrift.TMutation) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent)

Aggregations

TKeyExtent (org.apache.accumulo.core.dataImpl.thrift.TKeyExtent)23 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)15 ThriftSecurityException (org.apache.accumulo.core.clientImpl.thrift.ThriftSecurityException)12 ArrayList (java.util.ArrayList)11 Tablet (org.apache.accumulo.tserver.tablet.Tablet)9 IOException (java.io.IOException)8 HashMap (java.util.HashMap)7 List (java.util.List)7 Map (java.util.Map)7 AccumuloSecurityException (org.apache.accumulo.core.client.AccumuloSecurityException)7 TableId (org.apache.accumulo.core.data.TableId)7 NoSuchScanIDException (org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException)7 TabletClientService (org.apache.accumulo.core.tabletserver.thrift.TabletClientService)7 HashSet (java.util.HashSet)6 SampleNotPresentException (org.apache.accumulo.core.client.SampleNotPresentException)6 TableNotFoundException (org.apache.accumulo.core.client.TableNotFoundException)6 Entry (java.util.Map.Entry)5 NamespaceId (org.apache.accumulo.core.data.NamespaceId)5 Range (org.apache.accumulo.core.data.Range)5 MultiScanResult (org.apache.accumulo.core.dataImpl.thrift.MultiScanResult)5