Search in sources :

Example 1 with OInvalidIndexEngineIdException

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

the class OIndexAbstract method contains.

public boolean contains(Object key) {
    key = getCollatingValue(key);
    final ODatabase database = getDatabase();
    final boolean txIsActive = database.getTransaction().isActive();
    if (!txIsActive)
        keyLockManager.acquireSharedLock(key);
    try {
        acquireSharedLock();
        try {
            assert indexId >= 0;
            while (true) try {
                return storage.indexContainsKey(indexId, key);
            } catch (OInvalidIndexEngineIdException e) {
                doReloadIndexEngine();
            }
        } finally {
            releaseSharedLock();
        }
    } finally {
        if (!txIsActive)
            keyLockManager.releaseSharedLock(key);
    }
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase)

Example 2 with OInvalidIndexEngineIdException

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

the class OIndexAbstract method create.

/**
   * Creates the index.
   *
   * @param clusterIndexName Cluster name where to place the TreeMap
   * @param clustersToIndex
   * @param rebuild
   * @param progressListener
   * @param valueSerializer
   */
public OIndexInternal<?> create(final OIndexDefinition indexDefinition, final String clusterIndexName, final Set<String> clustersToIndex, boolean rebuild, final OProgressListener progressListener, final OBinarySerializer valueSerializer) {
    acquireExclusiveLock();
    try {
        configuration = indexConfigurationInstance(new ODocument().setTrackingChanges(false));
        this.indexDefinition = indexDefinition;
        if (clustersToIndex != null)
            this.clustersToIndex = new HashSet<String>(clustersToIndex);
        else
            this.clustersToIndex = new HashSet<String>();
        // do not remove this, it is needed to remove index garbage if such one exists
        try {
            removeValuesContainer();
        } catch (Exception e) {
            OLogManager.instance().error(this, "Error during deletion of index '%s'", name);
        }
        final Boolean durableInNonTxMode = isDurableInNonTxMode();
        indexId = storage.addIndexEngine(name, algorithm, type, indexDefinition, valueSerializer, isAutomatic(), durableInNonTxMode, version, getEngineProperties(), clustersToIndex, metadata);
        assert indexId >= 0;
        onIndexEngineChange(indexId);
        if (rebuild)
            fillIndex(progressListener);
        updateConfiguration();
    } catch (Exception e) {
        OLogManager.instance().error(this, "Exception during index '%s' creation", e, name);
        while (true) try {
            if (indexId >= 0)
                storage.deleteIndexEngine(indexId);
            break;
        } catch (OInvalidIndexEngineIdException ex) {
            doReloadIndexEngine();
        } catch (Exception ex) {
            OLogManager.instance().error(this, "Exception during index '%s' deletion", ex, name);
        }
        if (e instanceof OIndexException)
            throw (OIndexException) e;
        throw OException.wrapException(new OIndexException("Cannot create the index '" + name + "'"), e);
    } finally {
        releaseExclusiveLock();
    }
    return this;
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) OConfigurationException(com.orientechnologies.orient.core.exception.OConfigurationException) OException(com.orientechnologies.common.exception.OException) OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) OCommandExecutionException(com.orientechnologies.orient.core.exception.OCommandExecutionException) IOException(java.io.IOException) InvocationTargetException(java.lang.reflect.InvocationTargetException) OTooBigIndexKeyException(com.orientechnologies.orient.core.exception.OTooBigIndexKeyException) ODocument(com.orientechnologies.orient.core.record.impl.ODocument)

Example 3 with OInvalidIndexEngineIdException

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

the class OIndexAbstract method remove.

public boolean remove(Object key) {
    key = getCollatingValue(key);
    final ODatabase database = getDatabase();
    final boolean txIsActive = database.getTransaction().isActive();
    if (!txIsActive)
        keyLockManager.acquireExclusiveLock(key);
    try {
        acquireSharedLock();
        try {
            while (true) try {
                return storage.removeKeyFromIndex(indexId, key);
            } catch (OInvalidIndexEngineIdException e) {
                doReloadIndexEngine();
            }
        } finally {
            releaseSharedLock();
        }
    } finally {
        if (!txIsActive)
            keyLockManager.releaseExclusiveLock(key);
    }
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase)

Example 4 with OInvalidIndexEngineIdException

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

the class OIndexMultiValues method remove.

@Override
public boolean remove(Object key, final OIdentifiable value) {
    key = getCollatingValue(key);
    final ODatabase database = getDatabase();
    final boolean txIsActive = database.getTransaction().isActive();
    if (!txIsActive)
        keyLockManager.acquireExclusiveLock(key);
    try {
        acquireSharedLock();
        try {
            Set<OIdentifiable> values = null;
            while (true) {
                try {
                    values = (Set<OIdentifiable>) storage.getIndexValue(indexId, key);
                    break;
                } catch (OInvalidIndexEngineIdException e) {
                    doReloadIndexEngine();
                }
            }
            if (values == null) {
                return false;
            }
            final OModifiableBoolean removed = new OModifiableBoolean(false);
            final Callable<Object> creator = new EntityRemover(value, removed, values);
            while (true) try {
                storage.updateIndexEntry(indexId, key, creator);
                break;
            } catch (OInvalidIndexEngineIdException e) {
                doReloadIndexEngine();
            }
            return removed.getValue();
        } finally {
            releaseSharedLock();
        }
    } finally {
        if (!txIsActive)
            keyLockManager.releaseExclusiveLock(key);
    }
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable) OModifiableBoolean(com.orientechnologies.common.types.OModifiableBoolean)

Example 5 with OInvalidIndexEngineIdException

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

the class OIndexMultiValues method get.

public Set<OIdentifiable> get(Object key) {
    key = getCollatingValue(key);
    final ODatabase database = getDatabase();
    final boolean txIsActive = database.getTransaction().isActive();
    if (!txIsActive)
        keyLockManager.acquireSharedLock(key);
    try {
        acquireSharedLock();
        try {
            Set<OIdentifiable> values;
            while (true) {
                try {
                    values = (Set<OIdentifiable>) storage.getIndexValue(indexId, key);
                    break;
                } catch (OInvalidIndexEngineIdException e) {
                    doReloadIndexEngine();
                }
            }
            if (values == null)
                return Collections.emptySet();
            return Collections.unmodifiableSet(values);
        } finally {
            releaseSharedLock();
        }
    } finally {
        if (!txIsActive)
            keyLockManager.releaseSharedLock(key);
    }
}
Also used : OInvalidIndexEngineIdException(com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException) ODatabase(com.orientechnologies.orient.core.db.ODatabase) OIdentifiable(com.orientechnologies.orient.core.db.record.OIdentifiable)

Aggregations

OInvalidIndexEngineIdException (com.orientechnologies.orient.core.exception.OInvalidIndexEngineIdException)20 ODatabase (com.orientechnologies.orient.core.db.ODatabase)13 OIdentifiable (com.orientechnologies.orient.core.db.record.OIdentifiable)9 OLuceneIndexEngine (com.orientechnologies.lucene.engine.OLuceneIndexEngine)4 OIndexEngine (com.orientechnologies.orient.core.index.OIndexEngine)4 OIndexEngineCallback (com.orientechnologies.orient.core.storage.impl.local.OIndexEngineCallback)3 OTransaction (com.orientechnologies.orient.core.tx.OTransaction)3 IOException (java.io.IOException)3 OException (com.orientechnologies.common.exception.OException)2 OModifiableBoolean (com.orientechnologies.common.types.OModifiableBoolean)2 OLuceneTxChanges (com.orientechnologies.lucene.tx.OLuceneTxChanges)2 OIndexRIDContainer (com.orientechnologies.orient.core.db.record.ridbag.sbtree.OIndexRIDContainer)2 ODocument (com.orientechnologies.orient.core.record.impl.ODocument)2 OLuceneTxOperations (com.orientechnologies.lucene.OLuceneTxOperations)1 OCommandExecutionException (com.orientechnologies.orient.core.exception.OCommandExecutionException)1 OConfigurationException (com.orientechnologies.orient.core.exception.OConfigurationException)1 OTooBigIndexKeyException (com.orientechnologies.orient.core.exception.OTooBigIndexKeyException)1 ORID (com.orientechnologies.orient.core.id.ORID)1 OIndexException (com.orientechnologies.orient.core.index.OIndexException)1 OEmptyIterator (com.orientechnologies.orient.core.iterator.OEmptyIterator)1