Search in sources :

Example 1 with ReentrantTransactionLock

use of org.janusgraph.graphdb.transaction.lock.ReentrantTransactionLock in project janusgraph by JanusGraph.

the class StandardJanusGraphTx method getLock.

private TransactionLock getLock(final LockTuple la) {
    if (config.isSingleThreaded())
        return FakeLock.INSTANCE;
    Map<LockTuple, TransactionLock> result = uniqueLocks;
    if (result == UNINITIALIZED_LOCKS) {
        Preconditions.checkArgument(!config.isSingleThreaded());
        synchronized (this) {
            result = uniqueLocks;
            if (result == UNINITIALIZED_LOCKS)
                uniqueLocks = result = new ConcurrentHashMap<>();
        }
    }
    // TODO: clean out no longer used locks from uniqueLocks when it grows to large (use ReadWriteLock to protect against race conditions)
    TransactionLock lock = new ReentrantTransactionLock();
    TransactionLock existingLock = result.putIfAbsent(la, lock);
    return (existingLock == null) ? lock : existingLock;
}
Also used : LockTuple(org.janusgraph.graphdb.transaction.lock.LockTuple) IndexLockTuple(org.janusgraph.graphdb.transaction.lock.IndexLockTuple) ReentrantTransactionLock(org.janusgraph.graphdb.transaction.lock.ReentrantTransactionLock) TransactionLock(org.janusgraph.graphdb.transaction.lock.TransactionLock) ReentrantTransactionLock(org.janusgraph.graphdb.transaction.lock.ReentrantTransactionLock)

Aggregations

IndexLockTuple (org.janusgraph.graphdb.transaction.lock.IndexLockTuple)1 LockTuple (org.janusgraph.graphdb.transaction.lock.LockTuple)1 ReentrantTransactionLock (org.janusgraph.graphdb.transaction.lock.ReentrantTransactionLock)1 TransactionLock (org.janusgraph.graphdb.transaction.lock.TransactionLock)1