Search in sources :

Example 6 with IndexNotFoundKernelException

use of org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException in project neo4j by neo4j.

the class IndexProcedures method resampleIndex.

public void resampleIndex(String indexSpecification) throws ProcedureException {
    IndexSpecifier index = parse(indexSpecification);
    int labelId = getLabelId(index.label());
    int propertyKeyId = getPropertyKeyId(index.property());
    //TODO: Support composite indexes
    try {
        triggerSampling(getIndex(labelId, propertyKeyId, index));
    } catch (IndexNotFoundKernelException e) {
        throw new ProcedureException(e.status(), e.getMessage(), e);
    }
}
Also used : IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) ProcedureException(org.neo4j.kernel.api.exceptions.ProcedureException)

Example 7 with IndexNotFoundKernelException

use of org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException in project neo4j by neo4j.

the class ConstraintIndexCreator method createUniquenessConstraintIndex.

/**
     * You MUST hold a schema write lock before you call this method.
     * However the schema write lock is temporarily released while populating the index backing the constraint.
     * It goes a little like this:
     * <ol>
     * <li>Prerequisite: Getting here means that there's an open schema transaction which has acquired the
     * SCHEMA WRITE lock.</li>
     * <li>Index schema rule which is backing the constraint is created in a nested mini-transaction
     * which doesn't acquire any locking, merely adds tx state and commits so that the index rule is applied
     * to the store, which triggers the index population</li>
     * <li>Release the SCHEMA WRITE lock</li>
     * <li>Await index population to complete</li>
     * <li>Acquire the SCHEMA WRITE lock (effectively blocking concurrent transactions changing
     * data related to this constraint, and it so happens, most other transactions as well) and verify
     * the uniqueness of the built index</li>
     * <li>Leave this method, knowing that the uniqueness constraint rule will be added to tx state
     * and this tx committed, which will create the uniqueness constraint</li>
     * </ol>
     */
public long createUniquenessConstraintIndex(KernelStatement state, SchemaReadOperations schema, LabelSchemaDescriptor descriptor) throws TransactionFailureException, CreateConstraintFailureException, DropIndexFailureException, UniquePropertyValueValidationException {
    UniquenessConstraintDescriptor constraint = ConstraintDescriptorFactory.uniqueForSchema(descriptor);
    NewIndexDescriptor index = createConstraintIndex(descriptor);
    boolean success = false;
    boolean reacquiredSchemaLock = false;
    Client locks = state.locks().pessimistic();
    try {
        long indexId = schema.indexGetCommittedId(state, index);
        // Release the SCHEMA WRITE lock during index population.
        // At this point the integrity of the constraint to be created was checked
        // while holding the lock and the index rule backing the soon-to-be-created constraint
        // has been created. Now it's just the population left, which can take a long time
        releaseSchemaLock(locks);
        awaitConstrainIndexPopulation(constraint, indexId);
        // Index population was successful, but at this point we don't know if the uniqueness constraint holds.
        // Acquire SCHEMA WRITE lock and verify the constraints here in this user transaction
        // and if everything checks out then it will be held until after the constraint has been
        // created and activated.
        acquireSchemaLock(state, locks);
        reacquiredSchemaLock = true;
        indexingService.getIndexProxy(indexId).verifyDeferredConstraints(propertyAccessor);
        success = true;
        return indexId;
    } catch (SchemaRuleNotFoundException | IndexNotFoundKernelException e) {
        throw new IllegalStateException(String.format("Index (%s) that we just created does not exist.", descriptor));
    } catch (IndexEntryConflictException e) {
        throw new UniquePropertyValueValidationException(constraint, VERIFICATION, e);
    } catch (InterruptedException | IOException e) {
        throw new CreateConstraintFailureException(constraint, e);
    } finally {
        if (!success) {
            if (!reacquiredSchemaLock) {
                acquireSchemaLock(state, locks);
            }
            dropUniquenessConstraintIndex(index);
        }
    }
}
Also used : UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) SchemaRuleNotFoundException(org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) IOException(java.io.IOException) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) UniquenessConstraintDescriptor(org.neo4j.kernel.api.schema_new.constaints.UniquenessConstraintDescriptor) Client(org.neo4j.kernel.impl.locking.Locks.Client) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) CreateConstraintFailureException(org.neo4j.kernel.api.exceptions.schema.CreateConstraintFailureException)

Example 8 with IndexNotFoundKernelException

use of org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException in project neo4j by neo4j.

the class NeoStoreTransactionApplierTest method shouldApplyUpdateIndexRuleSchemaRuleCommandToTheStoreThrowingIndexProblem.

@Test
public void shouldApplyUpdateIndexRuleSchemaRuleCommandToTheStoreThrowingIndexProblem() throws IOException, IndexNotFoundKernelException, IndexPopulationFailedKernelException, IndexActivationFailedKernelException {
    // given
    final BatchTransactionApplier applier = newIndexApplier();
    doThrow(new IndexNotFoundKernelException("")).when(indexingService).activateIndex(anyLong());
    final DynamicRecord record = DynamicRecord.dynamicRecord(21, true);
    final Collection<DynamicRecord> recordsAfter = Arrays.asList(record);
    final IndexRule rule = constraintIndexRule(0, 1, 2, new SchemaIndexProvider.Descriptor("K", "X.Y"), 42L);
    final Command.SchemaRuleCommand command = new Command.SchemaRuleCommand(Collections.<DynamicRecord>emptyList(), recordsAfter, rule);
    // when
    try {
        apply(applier, command::handle, transactionToApply);
        fail("should have thrown");
    } catch (Exception e) {
        // then
        assertTrue(e.getCause() instanceof IndexNotFoundKernelException);
    }
}
Also used : DynamicRecord(org.neo4j.kernel.impl.store.record.DynamicRecord) IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) RelationshipTypeTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.RelationshipTypeTokenCommand) LabelTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.LabelTokenCommand) PropertyKeyTokenCommand(org.neo4j.kernel.impl.transaction.command.Command.PropertyKeyTokenCommand) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) BatchTransactionApplier(org.neo4j.kernel.impl.api.BatchTransactionApplier) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException) IOException(java.io.IOException) IndexActivationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexActivationFailedKernelException) Test(org.junit.Test)

Example 9 with IndexNotFoundKernelException

use of org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException in project neo4j by neo4j.

the class DatabaseCompositeIndexAccessorTest method shouldStopSamplingWhenIndexIsDropped.

@Test
public void shouldStopSamplingWhenIndexIsDropped() throws Exception {
    // given
    updateAndCommit(asList(add(nodeId, values), add(nodeId2, values2)));
    // when
    // needs to be acquired before drop() is called
    IndexReader indexReader = accessor.newReader();
    IndexSampler indexSampler = indexReader.createSampler();
    Future<Void> drop = threading.executeAndAwait(new IOFunction<Void, Void>() {

        @Override
        public Void apply(Void nothing) throws IOException {
            accessor.drop();
            return nothing;
        }
    }, null, waitingWhileIn(TaskCoordinator.class, "awaitCompletion"), 3, SECONDS);
    try (IndexReader reader = indexReader) /* do not inline! */
    {
        indexSampler.sampleIndex();
        fail("expected exception");
    } catch (IndexNotFoundKernelException e) {
        assertEquals("Index dropped while sampling.", e.getMessage());
    } finally {
        drop.get();
    }
}
Also used : IndexReader(org.neo4j.storageengine.api.schema.IndexReader) TaskCoordinator(org.neo4j.helpers.TaskCoordinator) IOException(java.io.IOException) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) IndexSampler(org.neo4j.storageengine.api.schema.IndexSampler) Test(org.junit.Test)

Example 10 with IndexNotFoundKernelException

use of org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException in project neo4j by neo4j.

the class DatabaseIndexAccessorTest method shouldStopSamplingWhenIndexIsDropped.

@Test
public void shouldStopSamplingWhenIndexIsDropped() throws Exception {
    // given
    updateAndCommit(asList(add(nodeId, value), add(nodeId2, value2)));
    // when
    // needs to be acquired before drop() is called
    IndexReader indexReader = accessor.newReader();
    IndexSampler indexSampler = indexReader.createSampler();
    Future<Void> drop = threading.executeAndAwait((IOFunction<Void, Void>) nothing -> {
        accessor.drop();
        return nothing;
    }, null, waitingWhileIn(TaskCoordinator.class, "awaitCompletion"), 3, SECONDS);
    try (IndexReader reader = indexReader) /* do not inline! */
    {
        indexSampler.sampleIndex();
        fail("expected exception");
    } catch (IndexNotFoundKernelException e) {
        assertEquals("Index dropped while sampling.", e.getMessage());
    } finally {
        drop.get();
    }
}
Also used : DirectoryFactory(org.neo4j.kernel.api.impl.index.storage.DirectoryFactory) Arrays(java.util.Arrays) EphemeralFileSystemRule(org.neo4j.test.rule.fs.EphemeralFileSystemRule) Iterators.asSet(org.neo4j.helpers.collection.Iterators.asSet) RunWith(org.junit.runner.RunWith) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) PrimitiveLongIterator(org.neo4j.collection.primitive.PrimitiveLongIterator) TaskCoordinator(org.neo4j.helpers.TaskCoordinator) Assert.assertThat(org.junit.Assert.assertThat) Future(java.util.concurrent.Future) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) IndexQuery.exact(org.neo4j.kernel.api.schema_new.IndexQuery.exact) Assert.fail(org.junit.Assert.fail) IndexUpdateMode(org.neo4j.kernel.impl.api.index.IndexUpdateMode) ClassRule(org.junit.ClassRule) Parameterized(org.junit.runners.Parameterized) Before(org.junit.Before) PrimitiveLongCollections(org.neo4j.collection.primitive.PrimitiveLongCollections) IndexQuery(org.neo4j.kernel.api.schema_new.IndexQuery) Collection(java.util.Collection) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) NewIndexDescriptorFactory(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptorFactory) Test(org.junit.Test) IOException(java.io.IOException) IndexQuery.range(org.neo4j.kernel.api.schema_new.IndexQuery.range) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IOFunction(org.neo4j.function.IOFunction) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) File(java.io.File) List(java.util.List) Rule(org.junit.Rule) ThreadingRule(org.neo4j.test.rule.concurrent.ThreadingRule) IndexSampler(org.neo4j.storageengine.api.schema.IndexSampler) Iterators.emptySetOf(org.neo4j.helpers.collection.Iterators.emptySetOf) ThreadingRule.waitingWhileIn(org.neo4j.test.rule.concurrent.ThreadingRule.waitingWhileIn) SECONDS(java.util.concurrent.TimeUnit.SECONDS) Assert.assertEquals(org.junit.Assert.assertEquals) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) TaskCoordinator(org.neo4j.helpers.TaskCoordinator) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) IndexSampler(org.neo4j.storageengine.api.schema.IndexSampler) Test(org.junit.Test)

Aggregations

IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)10 IOException (java.io.IOException)5 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)4 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)4 Test (org.junit.Test)3 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)3 IndexSampler (org.neo4j.storageengine.api.schema.IndexSampler)3 List (java.util.List)2 TaskCoordinator (org.neo4j.helpers.TaskCoordinator)2 Iterators.asSet (org.neo4j.helpers.collection.Iterators.asSet)2 Statement (org.neo4j.kernel.api.Statement)2 ProcedureException (org.neo4j.kernel.api.exceptions.ProcedureException)2 IndexNotApplicableKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException)2 IndexingService (org.neo4j.kernel.impl.api.index.IndexingService)2 File (java.io.File)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 Arrays.asList (java.util.Arrays.asList)1 Collection (java.util.Collection)1 Comparator (java.util.Comparator)1