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;
}
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());
}
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());
}
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());
}
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();
}
}
Aggregations