Search in sources :

Example 1 with UpdateSession

use of org.apache.accumulo.tserver.session.UpdateSession in project accumulo by apache.

the class ThriftClientHandler method startUpdate.

@Override
public long startUpdate(TInfo tinfo, TCredentials credentials, TDurability tdurabilty) throws ThriftSecurityException {
    // Make sure user is real
    Durability durability = DurabilityImpl.fromThrift(tdurabilty);
    security.authenticateUser(credentials, credentials);
    server.updateMetrics.addPermissionErrors(0);
    UpdateSession us = new UpdateSession(new TservConstraintEnv(server.getContext(), security, credentials), credentials, durability);
    return server.sessionManager.createSession(us, false);
}
Also used : UpdateSession(org.apache.accumulo.tserver.session.UpdateSession) Durability(org.apache.accumulo.core.client.Durability) TDurability(org.apache.accumulo.core.tabletserver.thrift.TDurability)

Example 2 with UpdateSession

use of org.apache.accumulo.tserver.session.UpdateSession 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)

Example 3 with UpdateSession

use of org.apache.accumulo.tserver.session.UpdateSession in project accumulo by apache.

the class ThriftClientHandler method closeUpdate.

@Override
public UpdateErrors closeUpdate(TInfo tinfo, long updateID) throws NoSuchScanIDException {
    final UpdateSession us = (UpdateSession) server.sessionManager.removeSession(updateID);
    if (us == null) {
        throw new NoSuchScanIDException();
    }
    // clients may or may not see data from an update session while
    // it is in progress, however when the update session is closed
    // want to ensure that reads wait for the write to finish
    long opid = writeTracker.startWrite(us.queuedMutations.keySet());
    try {
        flush(us);
    } catch (HoldTimeoutException e) {
        // 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 closeUpdate, reporting no such session");
        throw new NoSuchScanIDException();
    } finally {
        writeTracker.finishWrite(opid);
    }
    if (log.isTraceEnabled()) {
        log.trace(String.format("UpSess %s %,d in %.3fs, at=[%s] ft=%.3fs(pt=%.3fs lt=%.3fs ct=%.3fs)", TServerUtils.clientAddress.get(), us.totalUpdates, (System.currentTimeMillis() - us.startTime) / 1000.0, us.authTimes, us.flushTime / 1000.0, us.prepareTimes.sum() / 1000.0, us.walogTimes.sum() / 1000.0, us.commitTimes.sum() / 1000.0));
    }
    if (!us.failures.isEmpty()) {
        Entry<KeyExtent, Long> first = us.failures.entrySet().iterator().next();
        log.debug(String.format("Failures: %d, first extent %s successful commits: %d", us.failures.size(), first.getKey().toString(), first.getValue()));
    }
    List<ConstraintViolationSummary> violations = us.violations.asList();
    if (!violations.isEmpty()) {
        ConstraintViolationSummary first = us.violations.asList().iterator().next();
        log.debug(String.format("Violations: %d, first %s occurs %d", violations.size(), first.violationDescription, first.numberOfViolatingMutations));
    }
    if (!us.authFailures.isEmpty()) {
        KeyExtent first = us.authFailures.keySet().iterator().next();
        log.debug(String.format("Authentication Failures: %d, first %s", us.authFailures.size(), first.toString()));
    }
    return new UpdateErrors(us.failures.entrySet().stream().collect(Collectors.toMap(e -> e.getKey().toThrift(), Entry::getValue)), violations.stream().map(ConstraintViolationSummary::toThrift).collect(Collectors.toList()), us.authFailures.entrySet().stream().collect(Collectors.toMap(e -> e.getKey().toThrift(), Entry::getValue)));
}
Also used : KVEntry(org.apache.accumulo.tserver.tablet.KVEntry) Entry(java.util.Map.Entry) UpdateErrors(org.apache.accumulo.core.dataImpl.thrift.UpdateErrors) UpdateSession(org.apache.accumulo.tserver.session.UpdateSession) ConstraintViolationSummary(org.apache.accumulo.core.data.ConstraintViolationSummary) TKeyExtent(org.apache.accumulo.core.dataImpl.thrift.TKeyExtent) KeyExtent(org.apache.accumulo.core.dataImpl.KeyExtent) NoSuchScanIDException(org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException)

Aggregations

UpdateSession (org.apache.accumulo.tserver.session.UpdateSession)3 KeyExtent (org.apache.accumulo.core.dataImpl.KeyExtent)2 TKeyExtent (org.apache.accumulo.core.dataImpl.thrift.TKeyExtent)2 Entry (java.util.Map.Entry)1 Durability (org.apache.accumulo.core.client.Durability)1 ConstraintViolationSummary (org.apache.accumulo.core.data.ConstraintViolationSummary)1 Mutation (org.apache.accumulo.core.data.Mutation)1 TConditionalMutation (org.apache.accumulo.core.dataImpl.thrift.TConditionalMutation)1 TMutation (org.apache.accumulo.core.dataImpl.thrift.TMutation)1 UpdateErrors (org.apache.accumulo.core.dataImpl.thrift.UpdateErrors)1 NoSuchScanIDException (org.apache.accumulo.core.tabletserver.thrift.NoSuchScanIDException)1 TDurability (org.apache.accumulo.core.tabletserver.thrift.TDurability)1 ServerMutation (org.apache.accumulo.server.data.ServerMutation)1 ServerConditionalMutation (org.apache.accumulo.tserver.data.ServerConditionalMutation)1 KVEntry (org.apache.accumulo.tserver.tablet.KVEntry)1