Search in sources :

Example 16 with OSessionStoragePerformanceStatistic

use of com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic in project orientdb by orientechnologies.

the class OSBTree method firstKey.

public K firstKey() {
    final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
    startOperation();
    if (statistic != null)
        statistic.startIndexEntryReadTimer();
    try {
        atomicOperationsManager.acquireReadLock(this);
        try {
            acquireSharedLock();
            try {
                OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
                final BucketSearchResult searchResult = firstItem(atomicOperation);
                if (searchResult == null)
                    return null;
                final OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, searchResult.getLastPathItem(), false);
                cacheEntry.acquireSharedLock();
                try {
                    OSBTreeBucket<K, V> bucket = new OSBTreeBucket<K, V>(cacheEntry, keySerializer, keyTypes, valueSerializer, getChanges(atomicOperation, cacheEntry));
                    return bucket.getKey(searchResult.itemIndex);
                } finally {
                    cacheEntry.releaseSharedLock();
                    releasePage(atomicOperation, cacheEntry);
                }
            } finally {
                releaseSharedLock();
            }
        } catch (IOException e) {
            throw OException.wrapException(new OSBTreeException("Error during finding first key in sbtree [" + getName() + "]", this), e);
        } finally {
            atomicOperationsManager.releaseReadLock(this);
        }
    } finally {
        if (statistic != null)
            statistic.stopIndexEntryReadTimer();
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) IOException(java.io.IOException) OSessionStoragePerformanceStatistic(com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)

Example 17 with OSessionStoragePerformanceStatistic

use of com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic in project orientdb by orientechnologies.

the class OSBTree method lastKey.

public K lastKey() {
    final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
    startOperation();
    if (statistic != null)
        statistic.startIndexEntryReadTimer();
    try {
        atomicOperationsManager.acquireReadLock(this);
        try {
            acquireSharedLock();
            try {
                OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
                final BucketSearchResult searchResult = lastItem(atomicOperation);
                if (searchResult == null)
                    return null;
                final OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, searchResult.getLastPathItem(), false);
                cacheEntry.acquireSharedLock();
                try {
                    OSBTreeBucket<K, V> bucket = new OSBTreeBucket<K, V>(cacheEntry, keySerializer, keyTypes, valueSerializer, getChanges(atomicOperation, cacheEntry));
                    return bucket.getKey(searchResult.itemIndex);
                } finally {
                    cacheEntry.releaseSharedLock();
                    releasePage(atomicOperation, cacheEntry);
                }
            } finally {
                releaseSharedLock();
            }
        } catch (IOException e) {
            throw OException.wrapException(new OSBTreeException("Error during finding last key in sbtree [" + getName() + "]", this), e);
        } finally {
            atomicOperationsManager.releaseReadLock(this);
        }
    } finally {
        if (statistic != null)
            statistic.stopIndexEntryReadTimer();
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) IOException(java.io.IOException) OSessionStoragePerformanceStatistic(com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)

Example 18 with OSessionStoragePerformanceStatistic

use of com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic in project orientdb by orientechnologies.

the class OSBTree method get.

public V get(K key) {
    final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
    startOperation();
    if (statistic != null)
        statistic.startIndexEntryReadTimer();
    try {
        atomicOperationsManager.acquireReadLock(this);
        try {
            acquireSharedLock();
            try {
                checkNullSupport(key);
                OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
                if (key != null) {
                    key = keySerializer.preprocess(key, (Object[]) keyTypes);
                    BucketSearchResult bucketSearchResult = findBucket(key, atomicOperation);
                    if (bucketSearchResult.itemIndex < 0)
                        return null;
                    long pageIndex = bucketSearchResult.getLastPathItem();
                    OCacheEntry keyBucketCacheEntry = loadPage(atomicOperation, fileId, pageIndex, false);
                    keyBucketCacheEntry.acquireSharedLock();
                    try {
                        OSBTreeBucket<K, V> keyBucket = new OSBTreeBucket<K, V>(keyBucketCacheEntry, keySerializer, keyTypes, valueSerializer, getChanges(atomicOperation, keyBucketCacheEntry));
                        OSBTreeBucket.SBTreeEntry<K, V> treeEntry = keyBucket.getEntry(bucketSearchResult.itemIndex);
                        return readValue(treeEntry.value, atomicOperation);
                    } finally {
                        keyBucketCacheEntry.releaseSharedLock();
                        releasePage(atomicOperation, keyBucketCacheEntry);
                    }
                } else {
                    if (getFilledUpTo(atomicOperation, nullBucketFileId) == 0)
                        return null;
                    final OCacheEntry nullBucketCacheEntry = loadPage(atomicOperation, nullBucketFileId, 0, false);
                    nullBucketCacheEntry.acquireSharedLock();
                    try {
                        final ONullBucket<V> nullBucket = new ONullBucket<V>(nullBucketCacheEntry, getChanges(atomicOperation, nullBucketCacheEntry), valueSerializer, false);
                        final OSBTreeValue<V> treeValue = nullBucket.getValue();
                        if (treeValue == null)
                            return null;
                        return readValue(treeValue, atomicOperation);
                    } finally {
                        nullBucketCacheEntry.releaseSharedLock();
                        releasePage(atomicOperation, nullBucketCacheEntry);
                    }
                }
            } finally {
                releaseSharedLock();
            }
        } catch (IOException e) {
            throw OException.wrapException(new OSBTreeException("Error during retrieving  of sbtree with name " + getName(), this), e);
        } finally {
            atomicOperationsManager.releaseReadLock(this);
        }
    } finally {
        if (statistic != null)
            statistic.startIndexEntryReadTimer();
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) IOException(java.io.IOException) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OSessionStoragePerformanceStatistic(com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)

Example 19 with OSessionStoragePerformanceStatistic

use of com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic in project orientdb by orientechnologies.

the class OSBTreeBonsaiLocal method loadEntriesBetween.

@Override
public void loadEntriesBetween(K keyFrom, boolean fromInclusive, K keyTo, boolean toInclusive, RangeResultListener<K, V> listener) {
    final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
    int readEntries = 0;
    startOperation();
    if (statistic != null)
        statistic.startRidBagEntryReadTimer();
    try {
        atomicOperationsManager.acquireReadLock(this);
        try {
            final Lock lock = FILE_LOCK_MANAGER.acquireSharedLock(fileId);
            try {
                OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
                BucketSearchResult bucketSearchResultFrom = findBucket(keyFrom, atomicOperation);
                OBonsaiBucketPointer bucketPointerFrom = bucketSearchResultFrom.getLastPathItem();
                int indexFrom;
                if (bucketSearchResultFrom.itemIndex >= 0) {
                    indexFrom = fromInclusive ? bucketSearchResultFrom.itemIndex : bucketSearchResultFrom.itemIndex + 1;
                } else {
                    indexFrom = -bucketSearchResultFrom.itemIndex - 1;
                }
                BucketSearchResult bucketSearchResultTo = findBucket(keyTo, atomicOperation);
                OBonsaiBucketPointer bucketPointerTo = bucketSearchResultTo.getLastPathItem();
                int indexTo;
                if (bucketSearchResultTo.itemIndex >= 0) {
                    indexTo = toInclusive ? bucketSearchResultTo.itemIndex : bucketSearchResultTo.itemIndex - 1;
                } else {
                    indexTo = -bucketSearchResultTo.itemIndex - 2;
                }
                int startIndex = indexFrom;
                int endIndex;
                OBonsaiBucketPointer bucketPointer = bucketPointerFrom;
                resultsLoop: while (true) {
                    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);
                        if (!bucketPointer.equals(bucketPointerTo))
                            endIndex = bucket.size() - 1;
                        else
                            endIndex = indexTo;
                        for (int i = startIndex; i <= endIndex; i++) {
                            if (!listener.addResult(bucket.getEntry(i))) {
                                readEntries++;
                                break resultsLoop;
                            }
                        }
                        if (bucketPointer.equals(bucketPointerTo))
                            break;
                        bucketPointer = bucket.getRightSibling();
                        if (bucketPointer.getPageIndex() < 0)
                            break;
                    } finally {
                        cacheEntry.releaseSharedLock();
                        releasePage(atomicOperation, cacheEntry);
                    }
                    startIndex = 0;
                }
            } finally {
                lock.unlock();
            }
        } catch (IOException ioe) {
            throw OException.wrapException(new OSBTreeBonsaiLocalException("Error during fetch of values between key " + keyFrom + " and key " + keyTo + " 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 20 with OSessionStoragePerformanceStatistic

use of com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic in project orientdb by orientechnologies.

the class OSBTreeBonsaiLocal method remove.

@Override
public V remove(K key) {
    final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
    startOperation();
    if (statistic != null)
        statistic.startRidBagEntryDeletionTimer();
    try {
        final OAtomicOperation atomicOperation;
        try {
            atomicOperation = startAtomicOperation(true);
        } catch (IOException e) {
            throw OException.wrapException(new OSBTreeBonsaiLocalException("Error during sbtree entrie removal", this), e);
        }
        Lock lock = FILE_LOCK_MANAGER.acquireExclusiveLock(fileId);
        try {
            BucketSearchResult bucketSearchResult = findBucket(key, atomicOperation);
            if (bucketSearchResult.itemIndex < 0) {
                endAtomicOperation(false, null);
                return null;
            }
            OBonsaiBucketPointer bucketPointer = bucketSearchResult.getLastPathItem();
            OCacheEntry keyBucketCacheEntry = loadPage(atomicOperation, fileId, bucketPointer.getPageIndex(), false);
            final V removed;
            keyBucketCacheEntry.acquireExclusiveLock();
            try {
                OSBTreeBonsaiBucket<K, V> keyBucket = new OSBTreeBonsaiBucket<K, V>(keyBucketCacheEntry, bucketPointer.getPageOffset(), keySerializer, valueSerializer, getChanges(atomicOperation, keyBucketCacheEntry), this);
                removed = keyBucket.getEntry(bucketSearchResult.itemIndex).value;
                keyBucket.remove(bucketSearchResult.itemIndex);
            } finally {
                keyBucketCacheEntry.releaseExclusiveLock();
                releasePage(atomicOperation, keyBucketCacheEntry);
            }
            setSize(size() - 1, atomicOperation);
            endAtomicOperation(false, null);
            return removed;
        } catch (IOException e) {
            rollback(e);
            throw OException.wrapException(new OSBTreeBonsaiLocalException("Error during removing key " + key + " from sbtree " + getName(), this), e);
        } catch (RuntimeException e) {
            rollback(e);
            throw e;
        } finally {
            lock.unlock();
        }
    } finally {
        if (statistic != null)
            statistic.stopRidBagEntryDeletionTimer();
        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)

Aggregations

OSessionStoragePerformanceStatistic (com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)47 OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)25 IOException (java.io.IOException)23 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)20 Lock (java.util.concurrent.locks.Lock)11 OSBTreeBonsaiLocalException (com.orientechnologies.orient.core.exception.OSBTreeBonsaiLocalException)9 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)7 ORawPair (com.orientechnologies.common.util.ORawPair)5 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)5 OException (com.orientechnologies.common.exception.OException)4 ORecordId (com.orientechnologies.orient.core.id.ORecordId)4 OPaginatedClusterException (com.orientechnologies.orient.core.exception.OPaginatedClusterException)3 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)3 OTooBigIndexKeyException (com.orientechnologies.orient.core.exception.OTooBigIndexKeyException)3 OIndexException (com.orientechnologies.orient.core.index.OIndexException)3 OLocalHashTableException (com.orientechnologies.orient.core.exception.OLocalHashTableException)2 OStorage (com.orientechnologies.orient.core.storage.OStorage)2 OAbstractPaginatedStorage (com.orientechnologies.orient.core.storage.impl.local.OAbstractPaginatedStorage)2 ODatabaseDocumentInternal (com.orientechnologies.orient.core.db.ODatabaseDocumentInternal)1 OAllCacheEntriesAreUsedException (com.orientechnologies.orient.core.exception.OAllCacheEntriesAreUsedException)1