Search in sources :

Example 6 with OLocalHashTableException

use of com.orientechnologies.orient.core.exception.OLocalHashTableException 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 7 with OLocalHashTableException

use of com.orientechnologies.orient.core.exception.OLocalHashTableException 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 8 with OLocalHashTableException

use of com.orientechnologies.orient.core.exception.OLocalHashTableException in project orientdb by orientechnologies.

the class OLocalHashTable method higherEntries.

@Override
public OHashIndexBucket.Entry<K, V>[] higherEntries(K key, int limit) {
    startOperation();
    try {
        atomicOperationsManager.acquireReadLock(this);
        try {
            acquireSharedLock();
            try {
                final 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 || comparator.compare(bucket.getKey(bucket.size() - 1), key) <= 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 + 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 {
                    cacheEntry.releaseSharedLock();
                    releasePage(atomicOperation, cacheEntry);
                }
            } finally {
                releaseSharedLock();
            }
        } catch (IOException ioe) {
            throw OException.wrapException(new OLocalHashTableException("Exception 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 9 with OLocalHashTableException

use of com.orientechnologies.orient.core.exception.OLocalHashTableException in project orientdb by orientechnologies.

the class OLocalHashTable method firstEntry.

@Override
public OHashIndexBucket.Entry<K, V> firstEntry() {
    startOperation();
    try {
        atomicOperationsManager.acquireReadLock(this);
        try {
            acquireSharedLock();
            try {
                OHashTable.BucketPath bucketPath = getBucket(HASH_CODE_MIN_VALUE);
                long bucketPointer = directory.getNodePointer(bucketPath.nodeIndex, bucketPath.itemIndex);
                long pageIndex = getPageIndex(bucketPointer);
                OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
                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 null;
                        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));
                    }
                    return bucket.getEntry(0);
                } 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 10 with OLocalHashTableException

use of com.orientechnologies.orient.core.exception.OLocalHashTableException in project orientdb by orientechnologies.

the class OLocalHashTable method load.

@Override
public void load(String name, OType[] keyTypes, boolean nullKeyIsSupported) {
    startOperation();
    try {
        acquireExclusiveLock();
        try {
            if (keyTypes != null)
                this.keyTypes = Arrays.copyOf(keyTypes, keyTypes.length);
            else
                this.keyTypes = null;
            this.nullKeyIsSupported = nullKeyIsSupported;
            OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
            fileStateId = openFile(atomicOperation, name + metadataConfigurationFileExtension);
            final OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, 0, true);
            hashStateEntryIndex = hashStateEntry.getPageIndex();
            directory = new OHashTableDirectory(treeStateFileExtension, name, getFullName(), durableInNonTxMode, storage);
            directory.open();
            pinPage(atomicOperation, hashStateEntry);
            hashStateEntry.acquireSharedLock();
            try {
                OHashIndexFileLevelMetadataPage page = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
                OBinarySerializerFactory serializerFactory = OBinarySerializerFactory.create(storage.getConfiguration().binaryFormatVersion);
                keySerializer = (OBinarySerializer<K>) serializerFactory.getObjectSerializer(page.getKeySerializerId());
                valueSerializer = (OBinarySerializer<V>) serializerFactory.getObjectSerializer(page.getValueSerializerId());
            } finally {
                hashStateEntry.releaseSharedLock();
                releasePage(atomicOperation, hashStateEntry);
            }
            if (nullKeyIsSupported)
                nullBucketFileId = openFile(atomicOperation, name + nullBucketFileExtension);
            fileId = openFile(atomicOperation, getFullName());
        } catch (IOException e) {
            throw OException.wrapException(new OLocalHashTableException("Exception during hash table loading", this), 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) OLocalHashTableException(com.orientechnologies.orient.core.exception.OLocalHashTableException) IOException(java.io.IOException) OBinarySerializerFactory(com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory)

Aggregations

OLocalHashTableException (com.orientechnologies.orient.core.exception.OLocalHashTableException)11 OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)11 IOException (java.io.IOException)11 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)8 OException (com.orientechnologies.common.exception.OException)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 OBinarySerializerFactory (com.orientechnologies.orient.core.serialization.serializer.binary.OBinarySerializerFactory)1