Search in sources :

Example 86 with OAtomicOperation

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

the class OLocalHashTable20 method close.

@Override
public void close() {
    acquireExclusiveLock();
    try {
        flush();
        OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
        directory.close();
        final OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, hashStateEntryIndex, true);
        try {
            for (int i = 0; i < HASH_CODE_SIZE; i++) {
                OHashIndexFileLevelMetadataPage metadataPage = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
                if (!metadataPage.isRemoved(i)) {
                    readCache.closeFile(metadataPage.getFileId(i), true, writeCache);
                }
            }
        } finally {
            releasePage(atomicOperation, hashStateEntry);
        }
        readCache.closeFile(fileStateId, true, writeCache);
    } catch (IOException e) {
        throw OException.wrapException(new OIndexException("Error during hash table close"), e);
    } finally {
        releaseExclusiveLock();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OIndexException(com.orientechnologies.orient.core.index.OIndexException) IOException(java.io.IOException)

Example 87 with OAtomicOperation

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

the class OLocalHashTable20 method higherEntries.

@Override
public OHashIndexBucket.Entry<K, V>[] higherEntries(K key, int limit) {
    atomicOperationsManager.acquireReadLock(this);
    try {
        acquireSharedLock();
        try {
            final OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
            key = keySerializer.preprocess(key, (Object[]) keyTypes);
            final long hashCode = keyHashFunction.hashCode(key);
            BucketPath bucketPath = getBucket(hashCode);
            long bucketPointer = directory.getNodePointer(bucketPath.nodeIndex, bucketPath.itemIndex + bucketPath.hashMapOffset);
            int fileLevel = getFileLevel(bucketPointer);
            long pageIndex = getPageIndex(bucketPointer);
            OCacheEntry cacheEntry = loadPageEntry(pageIndex, fileLevel, atomicOperation);
            try {
                OHashIndexBucket<K, V> bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
                while (bucket.size() == 0 || comparator.compare(bucket.getKey(bucket.size() - 1), key) <= 0) {
                    bucketPath = nextBucketToFind(bucketPath, bucket.getDepth());
                    if (bucketPath == null)
                        return OCommonConst.EMPTY_BUCKET_ENTRY_ARRAY;
                    releasePage(atomicOperation, cacheEntry);
                    final long nextPointer = directory.getNodePointer(bucketPath.nodeIndex, bucketPath.itemIndex + bucketPath.hashMapOffset);
                    fileLevel = getFileLevel(nextPointer);
                    pageIndex = getPageIndex(nextPointer);
                    cacheEntry = loadPageEntry(pageIndex, fileLevel, atomicOperation);
                    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 + 1;
                else
                    startIndex = -index - 1;
                final int endIndex;
                if (limit <= 0)
                    endIndex = bucket.size();
                else
                    endIndex = Math.min(bucket.size(), startIndex + limit);
                return convertBucketToEntries(bucket, startIndex, endIndex);
            } finally {
                releasePage(atomicOperation, cacheEntry);
            }
        } finally {
            releaseSharedLock();
        }
    } catch (IOException ioe) {
        throw OException.wrapException(new OIndexException("Exception during data retrieval"), ioe);
    } finally {
        atomicOperationsManager.releaseReadLock(this);
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OIndexException(com.orientechnologies.orient.core.index.OIndexException) IOException(java.io.IOException)

Example 88 with OAtomicOperation

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

the class OSBTree method iterateEntriesMinor.

public OSBTreeCursor<K, V> iterateEntriesMinor(K key, boolean inclusive, boolean ascSortOrder) {
    final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
    startOperation();
    if (statistic != null)
        statistic.startIndexEntryReadTimer();
    try {
        atomicOperationsManager.acquireReadLock(this);
        try {
            acquireSharedLock();
            try {
                OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
                if (!ascSortOrder)
                    return iterateEntriesMinorDesc(key, inclusive, atomicOperation);
                return iterateEntriesMinorAsc(key, inclusive, atomicOperation);
            } finally {
                releaseSharedLock();
            }
        } catch (IOException ioe) {
            throw OException.wrapException(new OSBTreeException("Error during iteration of minor values for key " + key + " in sbtree " + getName(), this), ioe);
        } finally {
            atomicOperationsManager.releaseReadLock(this);
        }
    } finally {
        if (statistic != null)
            statistic.stopIndexEntryReadTimer();
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) IOException(java.io.IOException) OSessionStoragePerformanceStatistic(com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)

Example 89 with OAtomicOperation

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

the class OSBTree method remove.

public V remove(K key) {
    final OSessionStoragePerformanceStatistic statistic = performanceStatisticManager.getSessionPerformanceStatistic();
    startOperation();
    if (statistic != null)
        statistic.startIndexEntryDeletionTimer();
    try {
        final OAtomicOperation atomicOperation;
        try {
            atomicOperation = startAtomicOperation(true);
        } catch (IOException e) {
            throw OException.wrapException(new OSBTreeException("Error during sbtree entrie remove", this), e);
        }
        acquireExclusiveLock();
        try {
            V removedValue;
            if (key != null) {
                key = keySerializer.preprocess(key, (Object[]) keyTypes);
                BucketSearchResult bucketSearchResult = findBucket(key, atomicOperation);
                if (bucketSearchResult.itemIndex < 0) {
                    endAtomicOperation(false, null);
                    return null;
                }
                OCacheEntry keyBucketCacheEntry = loadPage(atomicOperation, fileId, bucketSearchResult.getLastPathItem(), false);
                keyBucketCacheEntry.acquireExclusiveLock();
                try {
                    OSBTreeBucket<K, V> keyBucket = new OSBTreeBucket<K, V>(keyBucketCacheEntry, keySerializer, keyTypes, valueSerializer, getChanges(atomicOperation, keyBucketCacheEntry));
                    final OSBTreeValue<V> removed = keyBucket.getEntry(bucketSearchResult.itemIndex).value;
                    final V value = readValue(removed, atomicOperation);
                    long removedValueLink = keyBucket.remove(bucketSearchResult.itemIndex);
                    if (removedValueLink >= 0)
                        removeLinkedValue(removedValueLink, atomicOperation);
                    setSize(size() - 1, atomicOperation);
                    removedValue = value;
                } finally {
                    keyBucketCacheEntry.releaseExclusiveLock();
                    releasePage(atomicOperation, keyBucketCacheEntry);
                }
            } else {
                if (getFilledUpTo(atomicOperation, nullBucketFileId) == 0) {
                    endAtomicOperation(false, null);
                    return null;
                }
                OCacheEntry nullCacheEntry = loadPage(atomicOperation, nullBucketFileId, 0, false);
                nullCacheEntry.acquireExclusiveLock();
                try {
                    ONullBucket<V> nullBucket = new ONullBucket<V>(nullCacheEntry, getChanges(atomicOperation, nullCacheEntry), valueSerializer, false);
                    OSBTreeValue<V> treeValue = nullBucket.getValue();
                    if (treeValue != null) {
                        removedValue = readValue(treeValue, atomicOperation);
                        nullBucket.removeValue();
                    } else
                        removedValue = null;
                } finally {
                    nullCacheEntry.releaseExclusiveLock();
                    releasePage(atomicOperation, nullCacheEntry);
                }
                if (removedValue != null)
                    setSize(size() - 1, atomicOperation);
            }
            endAtomicOperation(false, null);
            return removedValue;
        } catch (IOException e) {
            rollback(e);
            throw OException.wrapException(new OSBTreeException("Error during removing key " + key + " from sbtree " + getName(), this), e);
        } catch (RuntimeException e) {
            rollback(e);
            throw e;
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        if (statistic != null)
            statistic.stopIndexEntryDeletionTimer();
        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 90 with OAtomicOperation

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

the class OSBTree method create.

public void create(OBinarySerializer<K> keySerializer, OBinarySerializer<V> valueSerializer, OType[] keyTypes, int keySize, boolean nullPointerSupport) {
    assert keySerializer != null;
    startOperation();
    try {
        final OAtomicOperation atomicOperation;
        try {
            atomicOperation = startAtomicOperation(false);
        } catch (IOException e) {
            throw OException.wrapException(new OSBTreeException("Error during sbtree creation", this), e);
        }
        acquireExclusiveLock();
        try {
            this.keySize = keySize;
            if (keyTypes != null)
                this.keyTypes = Arrays.copyOf(keyTypes, keyTypes.length);
            else
                this.keyTypes = null;
            this.keySerializer = keySerializer;
            this.valueSerializer = valueSerializer;
            this.nullPointerSupport = nullPointerSupport;
            fileId = addFile(atomicOperation, getFullName());
            if (nullPointerSupport)
                nullBucketFileId = addFile(atomicOperation, getName() + nullFileExtension);
            OCacheEntry rootCacheEntry = addPage(atomicOperation, fileId);
            rootCacheEntry.acquireExclusiveLock();
            try {
                OSBTreeBucket<K, V> rootBucket = new OSBTreeBucket<K, V>(rootCacheEntry, true, keySerializer, keyTypes, valueSerializer, getChanges(atomicOperation, rootCacheEntry));
                rootBucket.setTreeSize(0);
            } finally {
                rootCacheEntry.releaseExclusiveLock();
                releasePage(atomicOperation, rootCacheEntry);
            }
            endAtomicOperation(false, null);
        } catch (IOException e) {
            try {
                endAtomicOperation(true, e);
            } catch (IOException e1) {
                OLogManager.instance().error(this, "Error during sbtree data rollback", e1);
            }
            throw OException.wrapException(new OSBTreeException("Error creation of sbtree with name " + getName(), this), e);
        } catch (RuntimeException e) {
            try {
                endAtomicOperation(true, e);
            } catch (IOException e1) {
                OLogManager.instance().error(this, "Error during sbtree data rollback", e1);
            }
            throw e;
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        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)

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