Search in sources :

Example 26 with OSessionStoragePerformanceStatistic

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

the class OLocalHashTable method put.

private boolean put(K key, V value, OIndexEngine.Validator<K, V> validator) {
    final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
    startOperation();
    if (statistic != null)
        statistic.startIndexEntryUpdateTimer();
    try {
        final OAtomicOperation atomicOperation;
        try {
            atomicOperation = startAtomicOperation(true);
        } catch (IOException e) {
            throw OException.wrapException(new OIndexException("Error during hash table entry put"), e);
        }
        acquireExclusiveLock();
        try {
            checkNullSupport(key);
            if (key != null) {
                final int keySize = keySerializer.getObjectSize(key, (Object[]) keyTypes);
                if (keySize > MAX_KEY_SIZE)
                    throw new OTooBigIndexKeyException("Key size is more than allowed, operation was canceled. Current key size " + keySize + ", allowed  " + MAX_KEY_SIZE, getName());
            }
            key = keySerializer.preprocess(key, (Object[]) keyTypes);
            final boolean putResult = doPut(key, value, validator, atomicOperation);
            endAtomicOperation(false, null);
            return putResult;
        } catch (IOException e) {
            rollback(e);
            throw OException.wrapException(new OIndexException("Error during index update"), e);
        } catch (Exception e) {
            rollback(e);
            throw OException.wrapException(new OStorageException("Error during index update"), e);
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        if (statistic != null)
            statistic.stopIndexEntryUpdateTimer();
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) IOException(java.io.IOException) OSessionStoragePerformanceStatistic(com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic) OTooBigIndexKeyException(com.orientechnologies.orient.core.exception.OTooBigIndexKeyException) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OLocalHashTableException(com.orientechnologies.orient.core.exception.OLocalHashTableException) OTooBigIndexKeyException(com.orientechnologies.orient.core.exception.OTooBigIndexKeyException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Example 27 with OSessionStoragePerformanceStatistic

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

the class OSBTreeBonsaiLocal method load.

public boolean load(OBonsaiBucketPointer rootBucketPointer) {
    OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
    startOperation();
    if (statistic != null)
        statistic.startRidBagEntryLoadTimer();
    try {
        Lock lock = FILE_LOCK_MANAGER.acquireExclusiveLock(fileId);
        try {
            this.rootBucketPointer = rootBucketPointer;
            final OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
            this.fileId = openFile(atomicOperation, getFullName());
            OCacheEntry rootCacheEntry = loadPage(atomicOperation, this.fileId, this.rootBucketPointer.getPageIndex(), false);
            rootCacheEntry.acquireSharedLock();
            try {
                OSBTreeBonsaiBucket<K, V> rootBucket = new OSBTreeBonsaiBucket<K, V>(rootCacheEntry, this.rootBucketPointer.getPageOffset(), keySerializer, valueSerializer, getChanges(atomicOperation, rootCacheEntry), this);
                keySerializer = (OBinarySerializer<K>) storage.getComponentsFactory().binarySerializerFactory.getObjectSerializer(rootBucket.getKeySerializerId());
                valueSerializer = (OBinarySerializer<V>) storage.getComponentsFactory().binarySerializerFactory.getObjectSerializer(rootBucket.getValueSerializerId());
                return !rootBucket.isDeleted();
            } finally {
                rootCacheEntry.releaseSharedLock();
                releasePage(atomicOperation, rootCacheEntry);
            }
        } catch (IOException e) {
            throw OException.wrapException(new OSBTreeBonsaiLocalException("Exception during loading of sbtree " + fileId, this), e);
        } finally {
            lock.unlock();
        }
    } finally {
        if (statistic != null)
            statistic.stopRidBagEntryLoadTimer();
        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 28 with OSessionStoragePerformanceStatistic

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

the class OSBTreeBonsaiLocal method put.

@Override
public boolean put(K key, V value) {
    final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
    startOperation();
    if (statistic != null)
        statistic.startRidBagEntryUpdateTimer();
    try {
        final OAtomicOperation atomicOperation;
        try {
            atomicOperation = startAtomicOperation(true);
        } catch (IOException e) {
            throw OException.wrapException(new OSBTreeBonsaiLocalException("Error during sbtree entrie put", this), e);
        }
        final Lock lock = FILE_LOCK_MANAGER.acquireExclusiveLock(fileId);
        try {
            BucketSearchResult bucketSearchResult = findBucket(key, atomicOperation);
            OBonsaiBucketPointer bucketPointer = bucketSearchResult.getLastPathItem();
            OCacheEntry keyBucketCacheEntry = loadPage(atomicOperation, fileId, bucketPointer.getPageIndex(), false);
            keyBucketCacheEntry.acquireExclusiveLock();
            OSBTreeBonsaiBucket<K, V> keyBucket = new OSBTreeBonsaiBucket<K, V>(keyBucketCacheEntry, bucketPointer.getPageOffset(), keySerializer, valueSerializer, getChanges(atomicOperation, keyBucketCacheEntry), this);
            final boolean itemFound = bucketSearchResult.itemIndex >= 0;
            boolean result = true;
            if (itemFound) {
                final int updateResult = keyBucket.updateValue(bucketSearchResult.itemIndex, value);
                assert updateResult == 0 || updateResult == 1;
                result = updateResult != 0;
            } else {
                int insertionIndex = -bucketSearchResult.itemIndex - 1;
                while (!keyBucket.addEntry(insertionIndex, new OSBTreeBonsaiBucket.SBTreeEntry<K, V>(OBonsaiBucketPointer.NULL, OBonsaiBucketPointer.NULL, key, value), true)) {
                    keyBucketCacheEntry.releaseExclusiveLock();
                    releasePage(atomicOperation, keyBucketCacheEntry);
                    bucketSearchResult = splitBucket(bucketSearchResult.path, insertionIndex, key, atomicOperation);
                    bucketPointer = bucketSearchResult.getLastPathItem();
                    insertionIndex = bucketSearchResult.itemIndex;
                    keyBucketCacheEntry = loadPage(atomicOperation, fileId, bucketSearchResult.getLastPathItem().getPageIndex(), false);
                    keyBucketCacheEntry.acquireExclusiveLock();
                    keyBucket = new OSBTreeBonsaiBucket<K, V>(keyBucketCacheEntry, bucketPointer.getPageOffset(), keySerializer, valueSerializer, getChanges(atomicOperation, keyBucketCacheEntry), this);
                }
            }
            keyBucketCacheEntry.releaseExclusiveLock();
            releasePage(atomicOperation, keyBucketCacheEntry);
            if (!itemFound)
                setSize(size() + 1, atomicOperation);
            endAtomicOperation(false, null);
            return result;
        } catch (IOException e) {
            rollback(e);
            throw OException.wrapException(new OSBTreeBonsaiLocalException("Error during index update with key " + key + " and value " + value, this), e);
        } finally {
            lock.unlock();
        }
    } finally {
        if (statistic != null)
            statistic.stopRidBagEntryUpdateTimer();
        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 29 with OSessionStoragePerformanceStatistic

use of com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic 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 30 with OSessionStoragePerformanceStatistic

use of com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic 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)

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