Search in sources :

Example 26 with NewIndexDescriptor

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

the class ConstraintIndexCreatorTest method shouldDropIndexInAnotherTransaction.

@Test
public void shouldDropIndexInAnotherTransaction() throws Exception {
    // given
    StubKernel kernel = new StubKernel();
    IndexingService indexingService = mock(IndexingService.class);
    NewIndexDescriptor index = NewIndexDescriptorFactory.uniqueForLabel(123, 456);
    PropertyAccessor propertyAccessor = mock(PropertyAccessor.class);
    ConstraintIndexCreator creator = new ConstraintIndexCreator(() -> kernel, indexingService, propertyAccessor, false);
    // when
    creator.dropUniquenessConstraintIndex(index);
    // then
    assertEquals(1, kernel.statements.size());
    verify(kernel.statements.get(0).txState()).indexDoDrop(index);
    verifyZeroInteractions(indexingService);
}
Also used : ConstraintIndexCreator(org.neo4j.kernel.impl.api.state.ConstraintIndexCreator) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) Test(org.junit.Test)

Example 27 with NewIndexDescriptor

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

the class IndexingServiceTest method shouldWaitForRecoveredUniquenessConstraintIndexesToBeFullyPopulated.

@Test
public void shouldWaitForRecoveredUniquenessConstraintIndexesToBeFullyPopulated() throws Exception {
    // I.e. when a uniqueness constraint is created, but database crashes before that schema record
    // ends up in the store, so that next start have no choice but to rebuild it.
    // GIVEN
    final DoubleLatch latch = new DoubleLatch();
    ControlledIndexPopulator populator = new ControlledIndexPopulator(latch);
    final AtomicLong indexId = new AtomicLong(-1);
    IndexingService.Monitor monitor = new IndexingService.MonitorAdapter() {

        @Override
        public void awaitingPopulationOfRecoveredIndex(long index, NewIndexDescriptor descriptor) {
            // When we see that we start to await the index to populate, notify the slow-as-heck
            // populator that it can actually go and complete its job.
            indexId.set(index);
            latch.startAndWaitForAllToStart();
        }
    };
    // leaving out the IndexRule here will have the index being populated from scratch
    IndexingService indexing = newIndexingServiceWithMockedDependencies(populator, accessor, withData(addNodeUpdate(0, "value", 1)), monitor);
    // WHEN initializing, i.e. preparing for recovery
    life.init();
    // simulating an index being created as part of applying recovered transactions
    long fakeOwningConstraintRuleId = 1;
    indexing.createIndexes(constraintIndexRule(2, labelId, propertyKeyId, PROVIDER_DESCRIPTOR, fakeOwningConstraintRuleId));
    // and then starting, i.e. considering recovery completed
    life.start();
    // THEN afterwards the index should be ONLINE
    assertEquals(2, indexId.get());
    assertEquals(ONLINE, indexing.getIndexProxy(indexId.get()).getState());
}
Also used : AtomicLong(java.util.concurrent.atomic.AtomicLong) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) DoubleLatch(org.neo4j.test.DoubleLatch) Test(org.junit.Test)

Example 28 with NewIndexDescriptor

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

the class IndexIT method shouldDisallowDroppingIndexThatDoesNotExist.

@Test
public void shouldDisallowDroppingIndexThatDoesNotExist() throws Exception {
    // given
    NewIndexDescriptor index;
    {
        SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
        index = statement.indexCreate(SchemaBoundary.map(descriptor));
        commit();
    }
    {
        SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
        statement.indexDrop(index);
        commit();
    }
    // when
    try {
        SchemaWriteOperations statement = schemaWriteOperationsInNewTransaction();
        statement.indexDrop(index);
        commit();
    }// then
     catch (SchemaKernelException e) {
        assertEquals("Unable to drop index on :label[" + labelId + "](property[" + propertyKeyId + "]): " + "No such INDEX ON :label[" + labelId + "](property[" + propertyKeyId + "]).", e.getMessage());
    }
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) SchemaWriteOperations(org.neo4j.kernel.api.SchemaWriteOperations) SchemaKernelException(org.neo4j.kernel.api.exceptions.schema.SchemaKernelException) Test(org.junit.Test) KernelIntegrationTest(org.neo4j.kernel.impl.api.integrationtest.KernelIntegrationTest)

Example 29 with NewIndexDescriptor

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

the class IndexPopulationJobTest method indexDescriptor.

private NewIndexDescriptor indexDescriptor(Label label, String propertyKey, boolean constraint) throws TransactionFailureException {
    try (KernelTransaction tx = kernel.newTransaction(KernelTransaction.Type.implicit, AnonymousContext.read());
        Statement statement = tx.acquireStatement()) {
        int labelId = statement.readOperations().labelGetForName(label.name());
        int propertyKeyId = statement.readOperations().propertyKeyGetForName(propertyKey);
        NewIndexDescriptor descriptor = constraint ? NewIndexDescriptorFactory.uniqueForLabel(labelId, propertyKeyId) : NewIndexDescriptorFactory.forLabel(labelId, propertyKeyId);
        tx.success();
        return descriptor;
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Statement(org.neo4j.kernel.api.Statement)

Example 30 with NewIndexDescriptor

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

the class IndexStatisticsTest method shouldProvideIndexStatisticsWhenIndexIsBuiltViaPopulationAndConcurrentAdditionsAndDeletions.

@Test
public void shouldProvideIndexStatisticsWhenIndexIsBuiltViaPopulationAndConcurrentAdditionsAndDeletions() throws Exception {
    // given some initial data
    long[] nodes = repeatCreateNamedPeopleFor(NAMES.length * CREATION_MULTIPLIER);
    int initialNodes = nodes.length;
    // when populating while creating
    NewIndexDescriptor index = createIndex("Person", "name");
    UpdatesTracker updatesTracker = executeCreationsAndDeletions(nodes, index, CREATION_MULTIPLIER);
    awaitOnline(index);
    // then
    int seenWhilePopulating = initialNodes + updatesTracker.createdDuringPopulation() - updatesTracker.deletedDuringPopulation();
    double expectedSelectivity = UNIQUE_NAMES / seenWhilePopulating;
    assertCorrectIndexSelectivity(expectedSelectivity, indexSelectivity(index));
    assertCorrectIndexSize(seenWhilePopulating, indexSize(index));
    int expectedIndexUpdates = updatesTracker.deletedAfterPopulation() + updatesTracker.createdAfterPopulation();
    assertCorrectIndexUpdates(expectedIndexUpdates, indexUpdates(index));
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) 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