Search in sources :

Example 76 with OAtomicOperation

use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.

the class OSBTreeBonsaiLocal method get.

@Override
public V get(K key) {
    final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
    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 bucketSearchResult = findBucket(key, atomicOperation);
                if (bucketSearchResult.itemIndex < 0)
                    return null;
                OBonsaiBucketPointer bucketPointer = bucketSearchResult.getLastPathItem();
                OCacheEntry keyBucketCacheEntry = loadPage(atomicOperation, fileId, bucketPointer.getPageIndex(), false);
                keyBucketCacheEntry.acquireSharedLock();
                try {
                    OSBTreeBonsaiBucket<K, V> keyBucket = new OSBTreeBonsaiBucket<K, V>(keyBucketCacheEntry, bucketPointer.getPageOffset(), keySerializer, valueSerializer, getChanges(atomicOperation, keyBucketCacheEntry), this);
                    return keyBucket.getEntry(bucketSearchResult.itemIndex).value;
                } finally {
                    keyBucketCacheEntry.releaseSharedLock();
                    releasePage(atomicOperation, keyBucketCacheEntry);
                }
            } finally {
                lock.unlock();
            }
        } catch (IOException e) {
            throw OException.wrapException(new OSBTreeBonsaiLocalException("Error during retrieving  of sbtree with name " + getName(), this), e);
        } finally {
            atomicOperationsManager.releaseReadLock(this);
        }
    } finally {
        if (statistic != null)
            statistic.stopRidBagEntryReadTimer(1);
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OSBTreeBonsaiLocalException(com.orientechnologies.orient.core.exception.OSBTreeBonsaiLocalException) IOException(java.io.IOException) OSessionStoragePerformanceStatistic(com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic) Lock(java.util.concurrent.locks.Lock)

Example 77 with OAtomicOperation

use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.

the class OSBTreeBonsaiLocal method delete.

/**
   * Deletes a whole tree. Puts all its pages to free list for further reusage.
   */
@Override
public void delete() {
    startOperation();
    try {
        final OAtomicOperation atomicOperation;
        try {
            atomicOperation = startAtomicOperation(false);
        } catch (IOException e) {
            throw OException.wrapException(new OSBTreeBonsaiLocalException("Error during sbtree deletion", this), e);
        }
        final Lock lock = FILE_LOCK_MANAGER.acquireExclusiveLock(fileId);
        try {
            final Queue<OBonsaiBucketPointer> subTreesToDelete = new LinkedList<OBonsaiBucketPointer>();
            subTreesToDelete.add(rootBucketPointer);
            recycleSubTrees(subTreesToDelete, atomicOperation);
            endAtomicOperation(false, null);
        } catch (Exception e) {
            rollback(e);
            throw OException.wrapException(new OSBTreeBonsaiLocalException("Error during delete of sbtree with name " + getName(), this), e);
        } finally {
            lock.unlock();
        }
    } finally {
        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) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OSBTreeBonsaiLocalException(com.orientechnologies.orient.core.exception.OSBTreeBonsaiLocalException) Lock(java.util.concurrent.locks.Lock)

Example 78 with OAtomicOperation

use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.

the class OSBTreeBonsaiLocal method lastKey.

@Override
public K lastKey() {
    final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
    startOperation();
    if (statistic != null)
        statistic.startRidBagEntryReadTimer();
    try {
        atomicOperationsManager.acquireReadLock(this);
        try {
            final Lock lock = FILE_LOCK_MANAGER.acquireSharedLock(fileId);
            try {
                LinkedList<PagePathItemUnit> path = new LinkedList<PagePathItemUnit>();
                OBonsaiBucketPointer bucketPointer = rootBucketPointer;
                OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
                OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, bucketPointer.getPageIndex(), false);
                cacheEntry.acquireSharedLock();
                OSBTreeBonsaiBucket<K, V> bucket = new OSBTreeBonsaiBucket<K, V>(cacheEntry, bucketPointer.getPageOffset(), keySerializer, valueSerializer, getChanges(atomicOperation, cacheEntry), this);
                int itemIndex = bucket.size() - 1;
                try {
                    while (true) {
                        if (bucket.isLeaf()) {
                            if (bucket.isEmpty()) {
                                if (path.isEmpty()) {
                                    return null;
                                } else {
                                    PagePathItemUnit pagePathItemUnit = path.removeLast();
                                    bucketPointer = pagePathItemUnit.bucketPointer;
                                    itemIndex = pagePathItemUnit.itemIndex - 1;
                                }
                            } else {
                                return bucket.getKey(bucket.size() - 1);
                            }
                        } else {
                            if (itemIndex < -1) {
                                if (!path.isEmpty()) {
                                    PagePathItemUnit pagePathItemUnit = path.removeLast();
                                    bucketPointer = pagePathItemUnit.bucketPointer;
                                    itemIndex = pagePathItemUnit.itemIndex - 1;
                                } else
                                    return null;
                            } else {
                                path.add(new PagePathItemUnit(bucketPointer, itemIndex));
                                if (itemIndex > -1) {
                                    OSBTreeBonsaiBucket.SBTreeEntry<K, V> entry = bucket.getEntry(itemIndex);
                                    bucketPointer = entry.rightChild;
                                } else {
                                    OSBTreeBonsaiBucket.SBTreeEntry<K, V> entry = bucket.getEntry(0);
                                    bucketPointer = entry.leftChild;
                                }
                                itemIndex = OSBTreeBonsaiBucket.MAX_BUCKET_SIZE_BYTES + 1;
                            }
                        }
                        cacheEntry.releaseSharedLock();
                        releasePage(atomicOperation, cacheEntry);
                        cacheEntry = loadPage(atomicOperation, fileId, bucketPointer.getPageIndex(), false);
                        cacheEntry.acquireSharedLock();
                        bucket = new OSBTreeBonsaiBucket<K, V>(cacheEntry, bucketPointer.getPageOffset(), keySerializer, valueSerializer, getChanges(atomicOperation, cacheEntry), this);
                        if (itemIndex == OSBTreeBonsaiBucket.MAX_BUCKET_SIZE_BYTES + 1)
                            itemIndex = bucket.size() - 1;
                    }
                } finally {
                    cacheEntry.releaseSharedLock();
                    releasePage(atomicOperation, cacheEntry);
                }
            } finally {
                lock.unlock();
            }
        } catch (IOException e) {
            throw OException.wrapException(new OSBTreeBonsaiLocalException("Error during finding first key in sbtree [" + getName() + "]", this), e);
        } finally {
            atomicOperationsManager.releaseReadLock(this);
        }
    } finally {
        if (statistic != null)
            statistic.stopRidBagEntryReadTimer(1);
        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 79 with OAtomicOperation

use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.

the class OSBTreeBonsaiLocal method loadEntriesMinor.

@Override
public void loadEntriesMinor(K key, boolean inclusive, RangeResultListener<K, V> listener) {
    final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
    startOperation();
    int readEntries = 0;
    if (statistic != null)
        statistic.startRidBagEntryReadTimer();
    try {
        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 - 2;
                }
                boolean firstBucket = true;
                do {
                    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 (!firstBucket)
                            index = bucket.size() - 1;
                        for (int i = index; i >= 0; i--) {
                            if (!listener.addResult(bucket.getEntry(i))) {
                                readEntries++;
                                return;
                            }
                        }
                        bucketPointer = bucket.getLeftSibling();
                        firstBucket = false;
                    } 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 minor 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 80 with OAtomicOperation

use of com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation in project orientdb by orientechnologies.

the class OSBTreeBonsaiLocal method create.

public void create(OBinarySerializer<K> keySerializer, OBinarySerializer<V> valueSerializer) {
    startOperation();
    try {
        final OAtomicOperation atomicOperation;
        try {
            atomicOperation = startAtomicOperation(false);
        } catch (IOException e) {
            throw OException.wrapException(new OSBTreeBonsaiLocalException("Error during sbtree creation", this), e);
        }
        Lock lock = FILE_LOCK_MANAGER.acquireExclusiveLock(-1l);
        try {
            this.keySerializer = keySerializer;
            this.valueSerializer = valueSerializer;
            if (isFileExists(atomicOperation, getFullName()))
                this.fileId = openFile(atomicOperation, getFullName());
            else
                this.fileId = addFile(atomicOperation, getFullName());
            initAfterCreate(atomicOperation);
            endAtomicOperation(false, null);
        } catch (IOException e) {
            rollback(e);
            throw OException.wrapException(new OSBTreeBonsaiLocalException("Error creation of sbtree with name" + getName(), this), e);
        } catch (Exception e) {
            rollback(e);
            throw OException.wrapException(new OSBTreeBonsaiLocalException("Error creation of sbtree with name" + getName(), this), e);
        } finally {
            lock.unlock();
        }
    } finally {
        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) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OSBTreeBonsaiLocalException(com.orientechnologies.orient.core.exception.OSBTreeBonsaiLocalException) Lock(java.util.concurrent.locks.Lock)

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