Search in sources :

Example 11 with OIndexException

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

the class OLocalHashTable20 method remove.

@Override
public V remove(K key) {
    final OAtomicOperation atomicOperation;
    try {
        atomicOperation = startAtomicOperation(true);
    } catch (IOException e) {
        throw OException.wrapException(new OIndexException("Error during hash table entry deletion"), e);
    }
    acquireExclusiveLock();
    try {
        checkNullSupport(key);
        int sizeDiff = 0;
        if (key != null) {
            key = keySerializer.preprocess(key, (Object[]) keyTypes);
            final long hashCode = keyHashFunction.hashCode(key);
            final BucketPath nodePath = getBucket(hashCode);
            final long bucketPointer = directory.getNodePointer(nodePath.nodeIndex, nodePath.itemIndex + nodePath.hashMapOffset);
            final long pageIndex = getPageIndex(bucketPointer);
            final int fileLevel = getFileLevel(bucketPointer);
            final V removed;
            final boolean found;
            final OCacheEntry cacheEntry = loadPageEntry(pageIndex, fileLevel, atomicOperation);
            cacheEntry.acquireExclusiveLock();
            try {
                final OHashIndexBucket<K, V> bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
                final int positionIndex = bucket.getIndex(hashCode, key);
                found = positionIndex >= 0;
                if (found) {
                    removed = bucket.deleteEntry(positionIndex).value;
                    sizeDiff--;
                    mergeBucketsAfterDeletion(nodePath, bucket, atomicOperation);
                } else
                    removed = null;
            } finally {
                cacheEntry.releaseExclusiveLock();
                releasePage(atomicOperation, cacheEntry);
            }
            if (found) {
                if (nodePath.parent != null) {
                    final int hashMapSize = 1 << nodePath.nodeLocalDepth;
                    final boolean allMapsContainSameBucket = checkAllMapsContainSameBucket(directory.getNode(nodePath.nodeIndex), hashMapSize);
                    if (allMapsContainSameBucket)
                        mergeNodeToParent(nodePath);
                }
                changeSize(sizeDiff, atomicOperation);
            }
            endAtomicOperation(false, null);
            return removed;
        } else {
            if (getFilledUpTo(atomicOperation, nullBucketFileId) == 0) {
                endAtomicOperation(false, null);
                return null;
            }
            V removed = null;
            OCacheEntry cacheEntry = loadPage(atomicOperation, nullBucketFileId, 0, false);
            if (cacheEntry == null)
                cacheEntry = addPage(atomicOperation, nullBucketFileId);
            cacheEntry.acquireExclusiveLock();
            try {
                final ONullBucket<V> nullBucket = new ONullBucket<V>(cacheEntry, getChanges(atomicOperation, cacheEntry), valueSerializer, false);
                removed = nullBucket.getValue();
                if (removed != null) {
                    nullBucket.removeValue();
                    sizeDiff--;
                }
            } finally {
                cacheEntry.releaseExclusiveLock();
                releasePage(atomicOperation, cacheEntry);
            }
            changeSize(sizeDiff, atomicOperation);
            endAtomicOperation(false, null);
            return removed;
        }
    } catch (IOException e) {
        rollback();
        throw OException.wrapException(new OIndexException("Error during index removal"), e);
    } catch (Exception e) {
        rollback();
        throw OException.wrapException(new OStorageException("Error during index removal"), e);
    } finally {
        releaseExclusiveLock();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OIndexException(com.orientechnologies.orient.core.index.OIndexException) IOException(java.io.IOException) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OIndexEngineException(com.orientechnologies.orient.core.index.OIndexEngineException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Example 12 with OIndexException

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

the class OLocalHashTable20 method setKeySerializer.

@Override
public void setKeySerializer(OBinarySerializer<K> keySerializer) {
    final OAtomicOperation atomicOperation;
    try {
        atomicOperation = startAtomicOperation(true);
    } catch (IOException e) {
        throw OException.wrapException(new OIndexException("Error during hash set serializer for index keys"), e);
    }
    acquireExclusiveLock();
    try {
        this.keySerializer = keySerializer;
        OCacheEntry hashStateEntry = loadPage(atomicOperation, fileStateId, hashStateEntryIndex, true);
        hashStateEntry.acquireExclusiveLock();
        try {
            OHashIndexFileLevelMetadataPage metadataPage = new OHashIndexFileLevelMetadataPage(hashStateEntry, getChanges(atomicOperation, hashStateEntry), false);
            metadataPage.setKeySerializerId(keySerializer.getId());
        } finally {
            hashStateEntry.releaseExclusiveLock();
            releasePage(atomicOperation, hashStateEntry);
        }
        endAtomicOperation(false, null);
    } catch (IOException e) {
        rollback();
        throw OException.wrapException(new OIndexException("Cannot set serializer for index keys"), e);
    } catch (Exception e) {
        rollback();
        throw OException.wrapException(new OStorageException("Cannot set serializer for index keys"), 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) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) IOException(java.io.IOException) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OIndexEngineException(com.orientechnologies.orient.core.index.OIndexEngineException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Example 13 with OIndexException

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

the class OLocalHashTable20 method delete.

@Override
public void delete() {
    final OAtomicOperation atomicOperation;
    try {
        atomicOperation = startAtomicOperation(false);
    } catch (IOException e) {
        throw OException.wrapException(new OIndexException("Error during hash table deletion"), e);
    }
    acquireExclusiveLock();
    try {
        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)) {
                    deleteFile(atomicOperation, metadataPage.getFileId(i));
                }
            }
        } finally {
            releasePage(atomicOperation, hashStateEntry);
        }
        directory.delete();
        deleteFile(atomicOperation, fileStateId);
        if (nullKeyIsSupported)
            deleteFile(atomicOperation, nullBucketFileId);
        endAtomicOperation(false, null);
    } catch (IOException e) {
        rollback();
        throw OException.wrapException(new OIndexException("Exception during index deletion"), e);
    } catch (Exception e) {
        rollback();
        throw OException.wrapException(new OIndexException("Exception during index deletion"), 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) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OException(com.orientechnologies.common.exception.OException) IOException(java.io.IOException) OIndexEngineException(com.orientechnologies.orient.core.index.OIndexEngineException) OStorageException(com.orientechnologies.orient.core.exception.OStorageException)

Example 14 with OIndexException

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

the class OLocalHashTable method clear.

@Override
public void clear() {
    startOperation();
    try {
        final OAtomicOperation atomicOperation;
        try {
            atomicOperation = startAtomicOperation(true);
        } catch (IOException e) {
            throw OException.wrapException(new OIndexException("Error during hash table clear"), e);
        }
        acquireExclusiveLock();
        try {
            if (nullKeyIsSupported)
                truncateFile(atomicOperation, nullBucketFileId);
            initHashTreeState(atomicOperation);
            endAtomicOperation(false, null);
        } catch (IOException e) {
            rollback(e);
            throw OException.wrapException(new OLocalHashTableException("Error during hash table clear", this), e);
        } catch (Exception e) {
            rollback(e);
            throw OException.wrapException(new OLocalHashTableException("Error during hash table clear", this), e);
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OIndexException(com.orientechnologies.orient.core.index.OIndexException) OLocalHashTableException(com.orientechnologies.orient.core.exception.OLocalHashTableException) IOException(java.io.IOException) 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 15 with OIndexException

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

the class OLocalHashTable method remove.

@Override
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 OIndexException("Error during hash table entry deletion"), e);
        }
        acquireExclusiveLock();
        try {
            checkNullSupport(key);
            int sizeDiff = 0;
            if (key != null) {
                key = keySerializer.preprocess(key, (Object[]) keyTypes);
                final long hashCode = keyHashFunction.hashCode(key);
                final OHashTable.BucketPath nodePath = getBucket(hashCode);
                final long bucketPointer = directory.getNodePointer(nodePath.nodeIndex, nodePath.itemIndex + nodePath.hashMapOffset);
                final long pageIndex = getPageIndex(bucketPointer);
                final V removed;
                final boolean found;
                final OCacheEntry cacheEntry = loadPage(atomicOperation, fileId, pageIndex, false);
                cacheEntry.acquireExclusiveLock();
                try {
                    final OHashIndexBucket<K, V> bucket = new OHashIndexBucket<K, V>(cacheEntry, keySerializer, valueSerializer, keyTypes, getChanges(atomicOperation, cacheEntry));
                    final int positionIndex = bucket.getIndex(hashCode, key);
                    found = positionIndex >= 0;
                    if (found) {
                        removed = bucket.deleteEntry(positionIndex).value;
                        sizeDiff--;
                    } else
                        removed = null;
                } finally {
                    cacheEntry.releaseExclusiveLock();
                    releasePage(atomicOperation, cacheEntry);
                }
                if (found) {
                    if (nodePath.parent != null) {
                        final int hashMapSize = 1 << nodePath.nodeLocalDepth;
                        final boolean allMapsContainSameBucket = checkAllMapsContainSameBucket(directory.getNode(nodePath.nodeIndex), hashMapSize);
                        if (allMapsContainSameBucket)
                            mergeNodeToParent(nodePath);
                    }
                    changeSize(sizeDiff, atomicOperation);
                }
                endAtomicOperation(false, null);
                return removed;
            } else {
                if (getFilledUpTo(atomicOperation, nullBucketFileId) == 0) {
                    endAtomicOperation(false, null);
                    return null;
                }
                V removed = null;
                OCacheEntry cacheEntry = loadPage(atomicOperation, nullBucketFileId, 0, false);
                if (cacheEntry == null)
                    cacheEntry = addPage(atomicOperation, nullBucketFileId);
                cacheEntry.acquireExclusiveLock();
                try {
                    final ONullBucket<V> nullBucket = new ONullBucket<V>(cacheEntry, getChanges(atomicOperation, cacheEntry), valueSerializer, false);
                    removed = nullBucket.getValue();
                    if (removed != null) {
                        nullBucket.removeValue();
                        sizeDiff--;
                    }
                } finally {
                    cacheEntry.releaseExclusiveLock();
                    releasePage(atomicOperation, cacheEntry);
                }
                changeSize(sizeDiff, atomicOperation);
                endAtomicOperation(false, null);
                return removed;
            }
        } catch (IOException e) {
            rollback(e);
            throw OException.wrapException(new OIndexException("Error during index removal"), e);
        } catch (Exception e) {
            rollback(e);
            throw OException.wrapException(new OStorageException("Error during index removal"), e);
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        if (statistic != null)
            statistic.stopIndexEntryDeletionTimer();
        completeOperation();
    }
}
Also used : OAtomicOperation(com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation) OIndexException(com.orientechnologies.orient.core.index.OIndexException) IOException(java.io.IOException) 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) OCacheEntry(com.orientechnologies.orient.core.storage.cache.OCacheEntry) OStorageException(com.orientechnologies.orient.core.exception.OStorageException) OSessionStoragePerformanceStatistic(com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)

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