use of org.apache.accumulo.core.dataImpl.thrift.TConditionalSession in project accumulo by apache.
the class ConditionalWriterImpl method reserveSessionID.
private SessionID reserveSessionID(HostAndPort location, TabletClientService.Iface client, TInfo tinfo) throws ThriftSecurityException, TException {
// avoid cost of repeatedly making RPC to create sessions, reuse sessions
synchronized (cachedSessionIDs) {
SessionID sid = cachedSessionIDs.get(location);
if (sid != null) {
if (sid.reserved)
throw new IllegalStateException();
if (sid.isActive()) {
sid.reserved = true;
return sid;
} else {
cachedSessionIDs.remove(location);
}
}
}
TConditionalSession tcs = client.startConditionalUpdate(tinfo, context.rpcCreds(), ByteBufferUtil.toByteBuffers(auths.getAuthorizations()), tableId.canonical(), DurabilityImpl.toThrift(durability), this.classLoaderContext);
synchronized (cachedSessionIDs) {
SessionID sid = new SessionID();
sid.reserved = true;
sid.sessionID = tcs.sessionId;
sid.lockId = tcs.tserverLock;
sid.ttl = tcs.ttl;
sid.location = location;
if (cachedSessionIDs.put(location, sid) != null)
throw new IllegalStateException();
return sid;
}
}
use of org.apache.accumulo.core.dataImpl.thrift.TConditionalSession 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