Search in sources :

Example 51 with OAtomicOperation

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();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLocalHashTableException(com.orientechnologies.orient.core.exception.OLocalHashTableException) IOException(java.io.IOException)

Example 52 with OAtomicOperation

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();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OLocalHashTableException(com.orientechnologies.orient.core.exception.OLocalHashTableException) IOException(java.io.IOException)

Example 53 with OAtomicOperation

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();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OSBTreeBonsaiLocalException(com.orientechnologies.orient.core.exception.OSBTreeBonsaiLocalException) IOException(java.io.IOException) Lock(java.util.concurrent.locks.Lock) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OSessionStoragePerformanceStatistic(com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)

Example 54 with OAtomicOperation

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));
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) AtomicInteger(java.util.concurrent.atomic.AtomicInteger)

Example 55 with OAtomicOperation

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);
            }
        }
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OWriteCache(com.orientechnologies.orient.core.storage.cache.OWriteCache) OReadCache(com.orientechnologies.orient.core.storage.cache.OReadCache) IOException(java.io.IOException)

Aggregations

OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)118 IOException (java.io.IOException)94 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)76 OException (com.orientechnologies.common.exception.OException)42 OIndexException (com.orientechnologies.orient.core.index.OIndexException)28 OSessionStoragePerformanceStatistic (com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)25 OLocalHashTableException (com.orientechnologies.orient.core.exception.OLocalHashTableException)16 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)16 OSBTreeBonsaiLocalException (com.orientechnologies.orient.core.exception.OSBTreeBonsaiLocalException)13 Lock (java.util.concurrent.locks.Lock)13 OHashTableDirectoryException (com.orientechnologies.orient.core.exception.OHashTableDirectoryException)11 OTooBigIndexKeyException (com.orientechnologies.orient.core.exception.OTooBigIndexKeyException)11 OPaginatedClusterException (com.orientechnologies.orient.core.exception.OPaginatedClusterException)9 OIndexEngineException (com.orientechnologies.orient.core.index.OIndexEngineException)9 OClusterPositionMapException (com.orientechnologies.orient.core.exception.OClusterPositionMapException)8 ORecordId (com.orientechnologies.orient.core.id.ORecordId)7 ORecordNotFoundException (com.orientechnologies.orient.core.exception.ORecordNotFoundException)6 OReadCache (com.orientechnologies.orient.core.storage.cache.OReadCache)2 OWriteCache (com.orientechnologies.orient.core.storage.cache.OWriteCache)2 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)1