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