use of com.netflix.astyanax.recipes.locks.ColumnPrefixDistributedRowLock in project titan by thinkaurelius.
the class AstyanaxRecipeLocker method writeSingleLock.
@Override
protected AstyanaxLockStatus writeSingleLock(KeyColumn lockID, StoreTransaction tx) throws TemporaryLockingException, PermanentLockingException {
long approxTimeNS = times.getApproxNSSinceEpoch();
ByteBuffer keyToLock = serializer.toLockKey(lockID.getKey(), lockID.getColumn()).asByteBuffer();
ColumnPrefixDistributedRowLock<ByteBuffer> lock = new ColumnPrefixDistributedRowLock<ByteBuffer>(lockKeyspace, lockColumnFamily, keyToLock).expireLockAfter(lockExpireNS, TimeUnit.NANOSECONDS).withConsistencyLevel(ConsistencyLevel.CL_QUORUM);
try {
lock.acquire();
log.debug("Locked {} in store {}", lockID, lockColumnFamily.getName());
return new AstyanaxLockStatus(approxTimeNS, TimeUnit.NANOSECONDS, lock);
} catch (StaleLockException e) {
// TODO handle gracefully?
throw new TemporaryLockingException(e);
} catch (BusyLockException e) {
// TODO handle gracefully?
throw new TemporaryLockingException(e);
} catch (Exception e) {
throw new PermanentLockingException(e);
}
}
Aggregations