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);
}
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);
}
}
}
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)));
}
Aggregations