Search in sources :

Example 1 with OTooBigIndexKeyException

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

the class OSBTree method put.

@SuppressWarnings("unchecked")
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 OSBTreeException("Error during sbtree entrie put", this), e);
        }
        acquireExclusiveLock();
        try {
            checkNullSupport(key);
            if (key != null) {
                final int keySize = keySerializer.getObjectSize(key, (Object[]) keyTypes);
                final int valueSize = valueSerializer.getObjectSize(value);
                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());
                final boolean createLinkToTheValue = valueSize > MAX_EMBEDDED_VALUE_SIZE;
                key = keySerializer.preprocess(key, (Object[]) keyTypes);
                long valueLink = -1;
                if (createLinkToTheValue)
                    valueLink = createLinkToTheValue(value, atomicOperation);
                final OSBTreeValue<V> treeValue = new OSBTreeValue<V>(createLinkToTheValue, valueLink, createLinkToTheValue ? null : value);
                BucketSearchResult bucketSearchResult = findBucket(key, atomicOperation);
                OCacheEntry keyBucketCacheEntry = loadPage(atomicOperation, fileId, bucketSearchResult.getLastPathItem(), false);
                keyBucketCacheEntry.acquireExclusiveLock();
                OSBTreeBucket<K, V> keyBucket = new OSBTreeBucket<K, V>(keyBucketCacheEntry, keySerializer, keyTypes, valueSerializer, getChanges(atomicOperation, keyBucketCacheEntry));
                if (validator != null) {
                    // assuming validation throws by default
                    boolean failure = true;
                    boolean ignored = false;
                    try {
                        final V oldValue = bucketSearchResult.itemIndex > -1 ? readValue(keyBucket.getValue(bucketSearchResult.itemIndex), atomicOperation) : null;
                        final Object result = validator.validate(key, oldValue, value);
                        if (result == OIndexEngine.Validator.IGNORE) {
                            ignored = true;
                            failure = false;
                            return false;
                        }
                        value = (V) result;
                        failure = false;
                    } finally {
                        if (failure || ignored) {
                            keyBucketCacheEntry.releaseExclusiveLock();
                            releasePage(atomicOperation, keyBucketCacheEntry);
                        }
                        if (// in case of a failure atomic operation will be ended in a usual way below
                        ignored)
                            endAtomicOperation(false, null);
                    }
                }
                int insertionIndex;
                int sizeDiff;
                if (bucketSearchResult.itemIndex >= 0) {
                    int updateResult = keyBucket.updateValue(bucketSearchResult.itemIndex, treeValue);
                    if (updateResult >= 0) {
                        keyBucketCacheEntry.releaseExclusiveLock();
                        releasePage(atomicOperation, keyBucketCacheEntry);
                        endAtomicOperation(false, null);
                        return true;
                    } else {
                        assert updateResult == -1;
                        long removedLinkedValue = keyBucket.remove(bucketSearchResult.itemIndex);
                        if (removedLinkedValue >= 0)
                            removeLinkedValue(removedLinkedValue, atomicOperation);
                        insertionIndex = bucketSearchResult.itemIndex;
                        sizeDiff = 0;
                    }
                } else {
                    insertionIndex = -bucketSearchResult.itemIndex - 1;
                    sizeDiff = 1;
                }
                while (!keyBucket.addEntry(insertionIndex, new OSBTreeBucket.SBTreeEntry<K, V>(-1, -1, key, treeValue), true)) {
                    keyBucketCacheEntry.releaseExclusiveLock();
                    releasePage(atomicOperation, keyBucketCacheEntry);
                    bucketSearchResult = splitBucket(bucketSearchResult.path, insertionIndex, key, atomicOperation);
                    insertionIndex = bucketSearchResult.itemIndex;
                    keyBucketCacheEntry = loadPage(atomicOperation, fileId, bucketSearchResult.getLastPathItem(), false);
                    keyBucketCacheEntry.acquireExclusiveLock();
                    keyBucket = new OSBTreeBucket<K, V>(keyBucketCacheEntry, keySerializer, keyTypes, valueSerializer, getChanges(atomicOperation, keyBucketCacheEntry));
                }
                keyBucketCacheEntry.releaseExclusiveLock();
                releasePage(atomicOperation, keyBucketCacheEntry);
                if (sizeDiff != 0)
                    setSize(size() + sizeDiff, atomicOperation);
            } else {
                OCacheEntry cacheEntry;
                boolean isNew = false;
                if (getFilledUpTo(atomicOperation, nullBucketFileId) == 0) {
                    cacheEntry = addPage(atomicOperation, nullBucketFileId);
                    isNew = true;
                } else
                    cacheEntry = loadPage(atomicOperation, nullBucketFileId, 0, false);
                final int valueSize = valueSerializer.getObjectSize(value);
                final boolean createLinkToTheValue = valueSize > MAX_EMBEDDED_VALUE_SIZE;
                long valueLink = -1;
                if (createLinkToTheValue)
                    valueLink = createLinkToTheValue(value, atomicOperation);
                final OSBTreeValue<V> treeValue = new OSBTreeValue<V>(createLinkToTheValue, valueLink, createLinkToTheValue ? null : value);
                int sizeDiff = 0;
                boolean ignored = false;
                cacheEntry.acquireExclusiveLock();
                try {
                    final ONullBucket<V> nullBucket = new ONullBucket<V>(cacheEntry, getChanges(atomicOperation, cacheEntry), valueSerializer, isNew);
                    final OSBTreeValue<V> oldValue = nullBucket.getValue();
                    if (validator != null) {
                        final V oldValueValue = oldValue == null ? null : readValue(oldValue, atomicOperation);
                        final Object result = validator.validate(null, oldValueValue, value);
                        if (result == OIndexEngine.Validator.IGNORE) {
                            ignored = true;
                            return false;
                        }
                        value = (V) result;
                    }
                    if (oldValue != null)
                        sizeDiff = -1;
                    nullBucket.setValue(treeValue);
                } finally {
                    cacheEntry.releaseExclusiveLock();
                    releasePage(atomicOperation, cacheEntry);
                    if (ignored)
                        endAtomicOperation(false, null);
                }
                sizeDiff++;
                setSize(size() + sizeDiff, atomicOperation);
            }
            endAtomicOperation(false, null);
            return true;
        } catch (IOException e) {
            rollback(e);
            throw OException.wrapException(new OSBTreeException("Error during index update with key " + key + " and value " + value, this), e);
        } catch (RuntimeException e) {
            rollback(e);
            throw e;
        } finally {
            releaseExclusiveLock();
        }
    } finally {
        if (statistic != null)
            statistic.stopIndexEntryUpdateTimer();
        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) OTooBigIndexKeyException(com.orientechnologies.orient.core.exception.OTooBigIndexKeyException)

Example 2 with OTooBigIndexKeyException

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

the class OIndexAbstract method indexCluster.

protected long[] indexCluster(final String clusterName, final OProgressListener iProgressListener, long documentNum, long documentIndexed, long documentTotal) {
    try {
        for (final ORecord record : getDatabase().browseCluster(clusterName)) {
            if (Thread.interrupted())
                throw new OCommandExecutionException("The index rebuild has been interrupted");
            if (record instanceof ODocument) {
                final ODocument doc = (ODocument) record;
                if (indexDefinition == null)
                    throw new OConfigurationException("Index '" + name + "' cannot be rebuilt because has no a valid definition (" + indexDefinition + ")");
                final Object fieldValue = indexDefinition.getDocumentValueToIndex(doc);
                if (fieldValue != null || !indexDefinition.isNullValuesIgnored()) {
                    try {
                        populateIndex(doc, fieldValue);
                    } catch (OTooBigIndexKeyException e) {
                        OLogManager.instance().error(this, "Exception during index rebuild. Exception was caused by following key/ value pair - key %s, value %s." + " Rebuild will continue from this point", e, fieldValue, doc.getIdentity());
                    } catch (OIndexException e) {
                        OLogManager.instance().error(this, "Exception during index rebuild. Exception was caused by following key/ value pair - key %s, value %s." + " Rebuild will continue from this point", e, fieldValue, doc.getIdentity());
                    }
                    ++documentIndexed;
                }
            }
            documentNum++;
            if (iProgressListener != null)
                iProgressListener.onProgress(this, documentNum, (float) (documentNum * 100.0 / documentTotal));
        }
    } catch (NoSuchElementException e) {
    // END OF CLUSTER REACHED, IGNORE IT
    }
    return new long[] { documentNum, documentIndexed };
}
Also used : OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) ORecord(com.orientechnologies.orient.core.record.ORecord) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) OTooBigIndexKeyException(com.orientechnologies.orient.core.exception.OTooBigIndexKeyException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 3 with OTooBigIndexKeyException

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

Aggregations

OTooBigIndexKeyException (com.orientechnologies.orient.core.exception.OTooBigIndexKeyException)3 OAtomicOperation (com.orientechnologies.orient.core.storage.impl.local.paginated.atomicoperations.OAtomicOperation)2 OSessionStoragePerformanceStatistic (com.orientechnologies.orient.core.storage.impl.local.statistic.OSessionStoragePerformanceStatistic)2 IOException (java.io.IOException)2 OException (com.orientechnologies.common.exception.OException)1 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)1 OLocalHashTableException (com.orientechnologies.orient.core.exception.OLocalHashTableException)1 OStorageException (com.orientechnologies.orient.core.exception.OStorageException)1 OIndexException (com.orientechnologies.orient.core.index.OIndexException)1 ORecord (com.orientechnologies.orient.core.record.ORecord)1 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)1 OCacheEntry (com.orientechnologies.orient.core.storage.cache.OCacheEntry)1