Search in sources :

Example 96 with Lock

use of java.util.concurrent.locks.Lock in project orientdb by orientechnologies.

the class OAbstractPaginatedStorage method updateRecord.

@Override
public OStorageOperationResult<Integer> updateRecord(final ORecordId rid, final boolean updateContent, final byte[] content, final int version, final byte recordType, final int mode, final ORecordCallback<Integer> callback) {
    checkOpeness();
    checkLowDiskSpaceFullCheckpointRequestsAndBackgroundDataFlushExceptions();
    final OCluster cluster = getClusterById(rid.getClusterId());
    final OStorageOperationResult<Integer> result;
    if (transaction.get() != null) {
        result = doUpdateRecord(rid, updateContent, content, version, recordType, callback, cluster);
    } else {
        stateLock.acquireReadLock();
        try {
            // GET THE SHARED LOCK AND GET AN EXCLUSIVE LOCK AGAINST THE RECORD
            final Lock lock = recordVersionManager.acquireExclusiveLock(rid);
            try {
                checkOpeness();
                // UPDATE IT
                result = doUpdateRecord(rid, updateContent, content, version, recordType, callback, cluster);
            } finally {
                lock.unlock();
            }
        } finally {
            stateLock.releaseReadLock();
        }
    }
    return result;
}
Also used : AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Lock(java.util.concurrent.locks.Lock)

Example 97 with Lock

use of java.util.concurrent.locks.Lock in project orientdb by orientechnologies.

the class OneEntryPerKeyLockManagerNullKeysTest method testNullKeyShared.

@Test
public void testNullKeyShared() {
    manager.acquireSharedLock(null);
    final Lock lock = manager.acquireSharedLock(null);
    assertEquals(2, wrapper(lock).getLockCount());
    lock.unlock();
    assertEquals(1, wrapper(lock).getLockCount());
    manager.releaseSharedLock(null);
    assertEquals(0, wrapper(lock).getLockCount());
}
Also used : Lock(java.util.concurrent.locks.Lock) Test(org.junit.Test)

Example 98 with Lock

use of java.util.concurrent.locks.Lock in project orientdb by orientechnologies.

the class OneEntryPerKeyLockManagerNullKeysTest method testNullKeyExclusive.

@Test
public void testNullKeyExclusive() {
    manager.acquireExclusiveLock(null);
    final Lock lock = manager.acquireExclusiveLock(null);
    assertEquals(2, wrapper(lock).getLockCount());
    lock.unlock();
    assertEquals(1, wrapper(lock).getLockCount());
    manager.releaseExclusiveLock(null);
    assertEquals(0, wrapper(lock).getLockCount());
}
Also used : Lock(java.util.concurrent.locks.Lock) Test(org.junit.Test)

Example 99 with Lock

use of java.util.concurrent.locks.Lock in project orientdb by orientechnologies.

the class OneEntryPerKeyLockManagerNullKeysTest method testNullKeysInCollectionBatch.

@Test
public void testNullKeysInCollectionBatch() {
    final List<String> keys = new ArrayList<String>();
    keys.add(null);
    keys.add("key");
    keys.add(null);
    final Lock[] locks = manager.acquireExclusiveLocksInBatch(keys);
    assertEquals(keys.size(), locks.length);
    assertEquals(2, wrapper(locks[0]).getLockCount());
    assertEquals(2, wrapper(locks[1]).getLockCount());
    assertEquals(1, wrapper(locks[2]).getLockCount());
    for (Lock lock : locks) lock.unlock();
    assertEquals(0, wrapper(locks[0]).getLockCount());
    assertEquals(0, wrapper(locks[1]).getLockCount());
    assertEquals(0, wrapper(locks[2]).getLockCount());
}
Also used : ArrayList(java.util.ArrayList) Lock(java.util.concurrent.locks.Lock) Test(org.junit.Test)

Example 100 with Lock

use of java.util.concurrent.locks.Lock in project orientdb by orientechnologies.

the class O2QCache method deleteFile.

@Override
public void deleteFile(long fileId, OWriteCache writeCache) throws IOException {
    fileId = OAbstractWriteCache.checkFileIdCompatibility(writeCache.getId(), fileId);
    Lock fileLock;
    cacheLock.acquireReadLock();
    try {
        fileLock = fileLockManager.acquireExclusiveLock(fileId);
        try {
            clearFile(fileId);
            filePages.remove(fileId);
            writeCache.deleteFile(fileId);
        } finally {
            fileLockManager.releaseExclusiveLock(fileId);
        }
    } finally {
        cacheLock.releaseReadLock();
    }
}
Also used : Lock(java.util.concurrent.locks.Lock)

Aggregations

Lock (java.util.concurrent.locks.Lock)717 ReentrantReadWriteLock (java.util.concurrent.locks.ReentrantReadWriteLock)171 ReadWriteLock (java.util.concurrent.locks.ReadWriteLock)144 ReentrantLock (java.util.concurrent.locks.ReentrantLock)96 Test (org.junit.Test)57 ArrayList (java.util.ArrayList)41 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)36 IOException (java.io.IOException)33 CountDownLatch (java.util.concurrent.CountDownLatch)30 HashMap (java.util.HashMap)22 Triple (org.apache.clerezza.commons.rdf.Triple)21 Map (java.util.Map)20 Ignite (org.apache.ignite.Ignite)17 Condition (java.util.concurrent.locks.Condition)15 OSBTreeBonsaiLocalException (com.orientechnologies.orient.core.exception.OSBTreeBonsaiLocalException)13 OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)13 HashSet (java.util.HashSet)13 BlankNodeOrIRI (org.apache.clerezza.commons.rdf.BlankNodeOrIRI)13 AtomicLong (java.util.concurrent.atomic.AtomicLong)12 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)11