use of org.apache.accumulo.tserver.session.ConditionalSession in project accumulo by apache.
the class ThriftClientHandler method invalidateConditionalUpdate.
@Override
public void invalidateConditionalUpdate(TInfo tinfo, long sessID) {
// this method should wait for any running conditional update to complete
// after this method returns a conditional update should not be able to start
ConditionalSession cs = (ConditionalSession) server.sessionManager.getSession(sessID);
if (cs != null) {
cs.interruptFlag.set(true);
}
cs = (ConditionalSession) server.sessionManager.reserveSession(sessID, true);
if (cs != null) {
server.sessionManager.removeSession(sessID, true);
}
}
use of org.apache.accumulo.tserver.session.ConditionalSession 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.tserver.session.ConditionalSession in project accumulo by apache.
the class ThriftClientHandler method startConditionalUpdate.
@Override
public TConditionalSession startConditionalUpdate(TInfo tinfo, TCredentials credentials, List<ByteBuffer> authorizations, String tableIdStr, TDurability tdurabilty, String classLoaderContext) throws ThriftSecurityException, TException {
TableId tableId = TableId.of(tableIdStr);
Authorizations userauths = null;
NamespaceId namespaceId = getNamespaceId(credentials, tableId);
if (!security.canConditionallyUpdate(credentials, tableId, namespaceId)) {
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.PERMISSION_DENIED);
}
userauths = security.getUserAuthorizations(credentials);
for (ByteBuffer auth : authorizations) {
if (!userauths.contains(ByteBufferUtil.toBytes(auth))) {
throw new ThriftSecurityException(credentials.getPrincipal(), SecurityErrorCode.BAD_AUTHORIZATIONS);
}
}
ConditionalSession cs = new ConditionalSession(credentials, new Authorizations(authorizations), tableId, DurabilityImpl.fromThrift(tdurabilty));
long sid = server.sessionManager.createSession(cs, false);
return new TConditionalSession(sid, server.getLockID(), server.sessionManager.getMaxIdleTime());
}
Aggregations