Search in sources :

Example 26 with OIndexException

use of com.orientechnologies.orient.core.index.OIndexException 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 27 with OIndexException

use of com.orientechnologies.orient.core.index.OIndexException 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 28 with OIndexException

use of com.orientechnologies.orient.core.index.OIndexException in project orientdb by orientechnologies.

the class OLocalHashTable20 method lowerEntries.

@Override
public OHashIndexBucket.Entry<K, V>[] lowerEntries(K key) {
    atomicOperationsManager.acquireReadLock(this);
    try {
        acquireSharedLock();
        try {
            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);
            OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
            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(0), key) >= 0) {
                    final BucketPath prevBucketPath = prevBucketToFind(bucketPath, bucket.getDepth());
                    if (prevBucketPath == null)
                        return OCommonConst.EMPTY_BUCKET_ENTRY_ARRAY;
                    releasePage(atomicOperation, cacheEntry);
                    final long prevPointer = directory.getNodePointer(prevBucketPath.nodeIndex, prevBucketPath.itemIndex + prevBucketPath.hashMapOffset);
                    fileLevel = getFileLevel(prevPointer);
                    pageIndex = getPageIndex(prevPointer);
                    cacheEntry = loadPageEntry(pageIndex, fileLevel, atomicOperation);
                    bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
                    bucketPath = prevBucketPath;
                }
                final int startIndex = 0;
                final int index = bucket.getIndex(hashCode, key);
                final int endIndex;
                if (index >= 0)
                    endIndex = index;
                else
                    endIndex = -index - 1;
                return convertBucketToEntries(bucket, startIndex, endIndex);
            } finally {
                releasePage(atomicOperation, cacheEntry);
            }
        } finally {
            releaseSharedLock();
        }
    } catch (IOException ioe) {
        throw OException.wrapException(new OIndexException("Exception during data read"), 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 29 with OIndexException

use of com.orientechnologies.orient.core.index.OIndexException in project orientdb by orientechnologies.

the class OLocalHashTable20 method firstEntry.

@Override
public OHashIndexBucket.Entry<K, V> firstEntry() {
    atomicOperationsManager.acquireReadLock(this);
    try {
        acquireSharedLock();
        try {
            BucketPath bucketPath = getBucket(HASH_CODE_MIN_VALUE);
            long bucketPointer = directory.getNodePointer(bucketPath.nodeIndex, bucketPath.itemIndex);
            int fileLevel = getFileLevel(bucketPointer);
            long pageIndex = getPageIndex(bucketPointer);
            OAtomicOperation atomicOperation = atomicOperationsManager.getCurrentOperation();
            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) {
                    bucketPath = nextBucketToFind(bucketPath, bucket.getDepth());
                    if (bucketPath == null)
                        return null;
                    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));
                }
                return bucket.getEntry(0);
            } finally {
                releasePage(atomicOperation, cacheEntry);
            }
        } finally {
            releaseSharedLock();
        }
    } catch (IOException ioe) {
        throw OException.wrapException(new OIndexException("Exception during data read"), 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 30 with OIndexException

use of com.orientechnologies.orient.core.index.OIndexException in project orientdb by orientechnologies.

the class OLuceneAnalyzerFactory method buildAnalyzer.

private Analyzer buildAnalyzer(String analyzerFQN) {
    try {
        final Class classAnalyzer = Class.forName(analyzerFQN);
        final Constructor constructor = classAnalyzer.getConstructor();
        return (Analyzer) constructor.newInstance();
    } catch (ClassNotFoundException e) {
        throw OException.wrapException(new OIndexException("Analyzer: " + analyzerFQN + " not found"), e);
    } catch (NoSuchMethodException e) {
        Class classAnalyzer = null;
        try {
            classAnalyzer = Class.forName(analyzerFQN);
            return (Analyzer) classAnalyzer.newInstance();
        } catch (Throwable e1) {
            throw OException.wrapException(new OIndexException("Couldn't instantiate analyzer:  public constructor  not found"), e);
        }
    } catch (Exception e) {
        OLogManager.instance().error(this, "Error on getting analyzer for Lucene index", e);
    }
    return new StandardAnalyzer();
}
Also used : OIndexException(com.orientechnologies.orient.core.index.OIndexException) Constructor(java.lang.reflect.Constructor) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) StandardAnalyzer(org.apache.lucene.analysis.standard.StandardAnalyzer) Analyzer(org.apache.lucene.analysis.Analyzer) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OException(com.orientechnologies.common.exception.OException)

Aggregations

OIndexException (com.orientechnologies.orient.core.index.OIndexException)31 IOException (java.io.IOException)27 OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)26 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)23 OException (com.orientechnologies.common.exception.OException)16 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)14 OIndexEngineException (com.orientechnologies.orient.core.index.OIndexEngineException)8 OLocalHashTableException (com.orientechnologies.orient.core.exception.OLocalHashTableException)6 OTooBigIndexKeyException (com.orientechnologies.orient.core.exception.OTooBigIndexKeyException)6 OSessionStoragePerformanceStatistic (com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)3 Constructor (java.lang.reflect.Constructor)2 Analyzer (org.apache.lucene.analysis.Analyzer)2 StandardAnalyzer (org.apache.lucene.analysis.standard.StandardAnalyzer)2 OIOException (com.orientechnologies.common.io.OIOException)1 OLuceneQueryContext (com.orientechnologies.lucene.query.OLuceneQueryContext)1 OIndexEngine (com.orientechnologies.orient.core.index.OIndexEngine)1 OHashTableIndexEngine (com.orientechnologies.orient.core.index.engine.OHashTableIndexEngine)1 ORemoteIndexEngine (com.orientechnologies.orient.core.index.engine.ORemoteIndexEngine)1 OClass (com.orientechnologies.orient.core.metadata.schema.OClass)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1