use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OLocalHashTable method lastEntry.
@Override
public OHashIndexBucket.Entry<K, V> lastEntry() {
startOperation();
try {
atomicOperationsManager.acquireReadLock(this);
try {
acquireSharedLock();
try {
OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
OHashTable.BucketPath bucketPath = getBucket(HASH_CODE_MAX_VALUE);
long bucketPointer = directory.getNodePointer(bucketPath.nodeIndex, bucketPath.itemIndex + bucketPath.hashMapOffset);
long pageIndex = getPageIndex(bucketPointer);
OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false);
cacheEntry.acquireSharedLock();
try {
OHashIndexBucket<K, V> bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
while (bucket.size() == 0) {
final OHashTable.BucketPath prevBucketPath = prevBucketToFind(bucketPath, bucket.getDepth());
if (prevBucketPath == null)
return null;
cacheEntry.releaseSharedLock();
releasePage(atomicOperation, cacheEntry);
final long prevPointer = directory.getNodePointer(prevBucketPath.nodeIndex, prevBucketPath.itemIndex + prevBucketPath.hashMapOffset);
pageIndex = getPageIndex(prevPointer);
cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false);
cacheEntry.acquireSharedLock();
bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
bucketPath = prevBucketPath;
}
return bucket.getEntry(bucket.size() - 1);
} finally {
cacheEntry.releaseSharedLock();
releasePage(atomicOperation, cacheEntry);
}
} finally {
releaseSharedLock();
}
} catch (IOException ioe) {
throw OException.wrapException(new OLocalHashTableException("Exception during data read", this), ioe);
} finally {
atomicOperationsManager.releaseReadLock(this);
}
} finally {
completeOperation();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OLocalHashTable method ceilingEntries.
@Override
public OHashIndexBucket.Entry<K, V>[] ceilingEntries(K key) {
startOperation();
try {
atomicOperationsManager.acquireReadLock(this);
try {
acquireSharedLock();
try {
OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
key = keySerializer.preprocess(key, (Object[]) keyTypes);
final long hashCode = keyHashFunction.hashCode(key);
OHashTable.BucketPath bucketPath = getBucket(hashCode);
long bucketPointer = directory.getNodePointer(bucketPath.nodeIndex, bucketPath.itemIndex + bucketPath.hashMapOffset);
long pageIndex = getPageIndex(bucketPointer);
OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false);
cacheEntry.acquireSharedLock();
try {
OHashIndexBucket<K, V> bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
while (bucket.size() == 0) {
bucketPath = nextBucketToFind(bucketPath, bucket.getDepth());
if (bucketPath == null)
return OCommonConst.EMPTY_BUCKET_ENTRY_ARRAY;
cacheEntry.releaseSharedLock();
releasePage(atomicOperation, cacheEntry);
final long nextPointer = directory.getNodePointer(bucketPath.nodeIndex, bucketPath.itemIndex + bucketPath.hashMapOffset);
pageIndex = getPageIndex(nextPointer);
cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false);
cacheEntry.acquireSharedLock();
bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
}
final int index = bucket.getIndex(hashCode, key);
final int startIndex;
if (index >= 0)
startIndex = index;
else
startIndex = -index - 1;
final int endIndex = bucket.size();
return convertBucketToEntries(bucket, startIndex, endIndex);
} finally {
cacheEntry.releaseSharedLock();
releasePage(atomicOperation, cacheEntry);
}
} finally {
releaseSharedLock();
}
} catch (IOException ioe) {
throw OException.wrapException(new OLocalHashTableException("Error during data retrieval", this), ioe);
} finally {
atomicOperationsManager.releaseReadLock(this);
}
} finally {
completeOperation();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OSBTreeBonsaiLocal method loadEntriesMajor.
/**
* Load all entries with key greater then specified key.
*
* @param key defines
* @param inclusive if true entry with given key is included
* @param ascSortOrder
* @param listener
*/
@Override
public void loadEntriesMajor(K key, boolean inclusive, boolean ascSortOrder, RangeResultListener<K, V> listener) {
final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
int readEntries = 0;
startOperation();
if (statistic != null)
statistic.startRidBagEntryReadTimer();
try {
if (!ascSortOrder)
throw new IllegalStateException("Descending sort order is not supported.");
atomicOperationsManager.acquireReadLock(this);
try {
final Lock lock = FILE_LOCK_MANAGER.acquireSharedLock(fileId);
try {
OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
BucketSearchResult bucketSearchResult = findBucket(key, atomicOperation);
OBonsaiBucketPointer bucketPointer = bucketSearchResult.getLastPathItem();
int index;
if (bucketSearchResult.itemIndex >= 0) {
index = inclusive ? bucketSearchResult.itemIndex : bucketSearchResult.itemIndex + 1;
} else {
index = -bucketSearchResult.itemIndex - 1;
}
do {
final OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, bucketPointer.getPageIndex(), false);
cacheEntry.acquireSharedLock();
try {
OSBTreeBonsaiBucket<K, V> bucket = new OSBTreeBonsaiBucket<K, V>(cacheEntry, bucketPointer.getPageOffset(), keySerializer, valueSerializer, getChanges(atomicOperation, cacheEntry), this);
int bucketSize = bucket.size();
for (int i = index; i < bucketSize; i++) {
if (!listener.addResult(bucket.getEntry(i))) {
readEntries++;
return;
}
}
bucketPointer = bucket.getRightSibling();
index = 0;
} finally {
cacheEntry.releaseSharedLock();
releasePage(atomicOperation, cacheEntry);
}
} while (bucketPointer.getPageIndex() >= 0);
} finally {
lock.unlock();
}
} catch (IOException ioe) {
throw OException.wrapException(new OSBTreeBonsaiLocalException("Error during fetch of major values for key " + key + " in sbtree " + getName(), this), ioe);
} finally {
atomicOperationsManager.releaseReadLock(this);
}
} finally {
if (statistic != null)
statistic.stopRidBagEntryReadTimer(readEntries);
completeOperation();
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OAbstractPaginatedStorage method lockRidBags.
private void lockRidBags(final TreeMap<Integer, OCluster> clusters, final TreeMap<String, OTransactionIndexChanges> indexes) {
final OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
for (Integer clusterId : clusters.keySet()) atomicOperationsManager.acquireExclusiveLockTillOperationComplete(atomicOperation, OSBTreeCollectionManagerAbstract.generateLockName(clusterId));
for (Map.Entry<String, OTransactionIndexChanges> entry : indexes.entrySet()) {
final String indexName = entry.getKey();
final OIndexInternal<?> index = entry.getValue().getAssociatedIndex();
if (!index.isUnique())
atomicOperationsManager.acquireExclusiveLockTillOperationComplete(atomicOperation, OIndexRIDContainerSBTree.generateLockName(indexName));
}
}
use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.
the class OIndexAbstract method removeValuesContainer.
private void removeValuesContainer() {
if (valueContainerAlgorithm.equals(ODefaultIndexFactory.SBTREEBONSAI_VALUE_CONTAINER)) {
final OAtomicOperation atomicOperation = storage.getAtomicOperationsManager().getCurrentOperation();
final OReadCache readCache = storage.getReadCache();
final OWriteCache writeCache = storage.getWriteCache();
if (atomicOperation == null) {
try {
final String fileName = getName() + OIndexRIDContainer.INDEX_FILE_EXTENSION;
if (writeCache.exists(fileName)) {
final long fileId = writeCache.loadFile(fileName);
readCache.deleteFile(fileId, writeCache);
}
} catch (IOException e) {
OLogManager.instance().error(this, "Cannot delete file for value containers", e);
}
} else {
try {
final String fileName = getName() + OIndexRIDContainer.INDEX_FILE_EXTENSION;
if (atomicOperation.isFileExists(fileName)) {
final long fileId = atomicOperation.loadFile(fileName);
atomicOperation.deleteFile(fileId);
}
} catch (IOException e) {
OLogManager.instance().error(this, "Cannot delete file for value containers", e);
}
}
}
}
Aggregations