Search in sources :

Example 21 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class NodeGetUniqueFromIndexSeekIT method shouldNotCompositeFindNonMatchingNode.

@Test
public void shouldNotCompositeFindNonMatchingNode() throws Exception {
    // given
    NewIndexDescriptor index = createUniquenessConstraint(labelId, propertyId1, propertyId2);
    String value1 = "value1";
    String value2 = "value2";
    createNodeWithValues("other_" + value1, "other_" + value2);
    // when looking for it
    ReadOperations readOperations = readOperationsInNewTransaction();
    long foundId = readOperations.nodeGetFromUniqueIndexSeek(index, exact(propertyId1, value1), exact(propertyId2, value2));
    commit();
    // then
    assertTrue("Non-matching created node was found", isNoSuchNode(foundId));
}
Also used : ReadOperations(org.neo4j.kernel.api.ReadOperations) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Test(org.junit.Test)

Example 22 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class LuceneSchemaIndexCorruptionTest method shouldRequestIndexPopulationFailingWithFileNotFoundException.

@Test
public void shouldRequestIndexPopulationFailingWithFileNotFoundException() throws Exception {
    // Given
    long faultyIndexId = 1;
    FileNotFoundException error = new FileNotFoundException("/some/path/somewhere");
    LuceneSchemaIndexProvider provider = newFaultySchemaIndexProvider(faultyIndexId, error);
    // When
    NewIndexDescriptor descriptor = NewIndexDescriptorFactory.forLabel(1, 1);
    InternalIndexState initialState = provider.getInitialState(faultyIndexId, descriptor);
    // Then
    assertThat(initialState, equalTo(InternalIndexState.POPULATING));
    logProvider.assertAtLeastOnce(loggedException(error));
}
Also used : InternalIndexState(org.neo4j.kernel.api.index.InternalIndexState) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) FileNotFoundException(java.io.FileNotFoundException) Test(org.junit.Test)

Example 23 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class IndexPopulationFlipRaceIT method verifyThatThereAreExactlyOneIndexEntryPerNodeInTheIndexes.

private void verifyThatThereAreExactlyOneIndexEntryPerNodeInTheIndexes(int i, Pair<long[], long[]> data) throws Exception {
    KernelAPI kernelAPI = db.getDependencyResolver().resolveDependency(KernelAPI.class);
    try (KernelTransaction tx = kernelAPI.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
        Statement statement = tx.acquireStatement()) {
        int labelAId = statement.readOperations().labelGetForName(labelA(i).name());
        int keyAId = statement.readOperations().propertyKeyGetForName(keyA(i));
        int labelBId = statement.readOperations().labelGetForName(labelB(i).name());
        int keyBId = statement.readOperations().propertyKeyGetForName(keyB(i));
        NewIndexDescriptor indexA = NewIndexDescriptorFactory.forLabel(labelAId, keyAId);
        NewIndexDescriptor indexB = NewIndexDescriptorFactory.forLabel(labelBId, keyBId);
        for (int j = 0; j < NODES_PER_INDEX; j++) {
            long nodeAId = data.first()[j];
            assertEquals(1, statement.readOperations().nodesCountIndexed(indexA, nodeAId, nodeAId));
            long nodeBId = data.other()[j];
            assertEquals(1, statement.readOperations().nodesCountIndexed(indexB, nodeBId, nodeBId));
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement) KernelAPI(org.neo4j.kernel.api.KernelAPI)

Example 24 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class ConstraintEnforcingEntityOperations method validateNoExistingNodeWithExactValues.

private void validateNoExistingNodeWithExactValues(KernelStatement state, UniquenessConstraintDescriptor constraint, ExactPredicate[] propertyValues, long modifiedNode) throws ConstraintValidationException {
    try {
        NewIndexDescriptor index = constraint.ownedIndexDescriptor();
        assertIndexOnline(state, index);
        int labelId = index.schema().getLabelId();
        state.locks().optimistic().acquireExclusive(state.lockTracer(), INDEX_ENTRY, indexEntryResourceId(labelId, propertyValues));
        long existing = entityReadOperations.nodeGetFromUniqueIndexSeek(state, index, propertyValues);
        if (existing != NO_SUCH_NODE && existing != modifiedNode) {
            throw new UniquePropertyValueValidationException(constraint, VALIDATION, new IndexEntryConflictException(existing, NO_SUCH_NODE, OrderedPropertyValues.of(propertyValues)));
        }
    } catch (IndexNotFoundKernelException | IndexBrokenKernelException | IndexNotApplicableKernelException e) {
        throw new UnableToValidateConstraintException(constraint, e);
    }
}
Also used : UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) IndexNotApplicableKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotApplicableKernelException) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) UnableToValidateConstraintException(org.neo4j.kernel.api.exceptions.schema.UnableToValidateConstraintException) IndexBrokenKernelException(org.neo4j.kernel.api.exceptions.schema.IndexBrokenKernelException) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)

Example 25 with NewIndexDescriptor

use of org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor in project neo4j by neo4j.

the class ConstraintIndexCreatorTest method shouldDropIndexIfPopulationFails.

@Test
public void shouldDropIndexIfPopulationFails() throws Exception {
    // given
    StatementOperationParts constraintCreationContext = mockedParts();
    KernelStatement state = mockedState();
    IndexingService indexingService = mock(IndexingService.class);
    StubKernel kernel = new StubKernel();
    when(constraintCreationContext.schemaReadOperations().indexGetCommittedId(state, index)).thenReturn(2468L);
    IndexProxy indexProxy = mock(IndexProxy.class);
    when(indexingService.getIndexProxy(2468L)).thenReturn(indexProxy);
    IndexEntryConflictException cause = new IndexEntryConflictException(2, 1, "a");
    doThrow(new IndexPopulationFailedKernelException(SchemaBoundary.map(descriptor), "some index", cause)).when(indexProxy).awaitStoreScanCompleted();
    PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, false);
    // when
    try {
        creator.createUniquenessConstraintIndex(state, constraintCreationContext.schemaReadOperations(), descriptor);
        fail("expected exception");
    }// then
     catch (UniquePropertyValueValidationException e) {
        assertEquals("Existing data does not satisfy CONSTRAINT ON ( label[123]:label[123] ) ASSERT label[123].property[456] IS UNIQUE.", e.getMessage());
    }
    assertEquals(2, kernel.statements.size());
    TransactionState tx1 = kernel.statements.get(0).txState();
    NewIndexDescriptor newIndex = NewIndexDescriptorFactory.uniqueForLabel(123, 456);
    verify(tx1).indexRuleDoAdd(newIndex);
    verifyNoMoreInteractions(tx1);
    verify(constraintCreationContext.schemaReadOperations()).indexGetCommittedId(state, index);
    verifyNoMoreInteractions(constraintCreationContext.schemaReadOperations());
    TransactionState tx2 = kernel.statements.get(1).txState();
    verify(tx2).indexDoDrop(newIndex);
    verifyNoMoreInteractions(tx2);
}
Also used : TransactionState(org.neo4j.kernel.api.txstate.TransactionState) ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) UniquePropertyValueValidationException(org.neo4j.kernel.api.exceptions.schema.UniquePropertyValueValidationException) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) StatementOperationParts(org.neo4j.kernel.impl.api.StatementOperationParts) KernelStatement(org.neo4j.kernel.impl.api.KernelStatement) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException) IndexProxy(org.neo4j.kernel.impl.api.index.IndexProxy) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) Test(org.junit.Test)

Aggregations

NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)99 Test (org.junit.Test)55 Statement (org.neo4j.kernel.api.Statement)24 ReadOperations (org.neo4j.kernel.api.ReadOperations)17 IndexNotFoundKernelException (org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException)10 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)9 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)9 InternalIndexState (org.neo4j.kernel.api.index.InternalIndexState)7 Transaction (org.neo4j.graphdb.Transaction)6 IndexDefinition (org.neo4j.graphdb.schema.IndexDefinition)5 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)5 SchemaRuleNotFoundException (org.neo4j.kernel.api.exceptions.schema.SchemaRuleNotFoundException)5 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)5 ArrayList (java.util.ArrayList)4 HashMap (java.util.HashMap)4 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)4 Label (org.neo4j.graphdb.Label)4 NotFoundException (org.neo4j.graphdb.NotFoundException)4 KernelException (org.neo4j.kernel.api.exceptions.KernelException)4 NodePropertyDescriptor (org.neo4j.kernel.api.schema.NodePropertyDescriptor)4