Search in sources :

Example 31 with NewIndexDescriptor

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

the class IndexStatisticsTest method shouldWorkWhileHavingHeavyConcurrentUpdates.

@Test
public void shouldWorkWhileHavingHeavyConcurrentUpdates() throws Exception {
    // given some initial data
    final long[] nodes = repeatCreateNamedPeopleFor(NAMES.length * CREATION_MULTIPLIER);
    int initialNodes = nodes.length;
    int threads = 5;
    ExecutorService executorService = Executors.newFixedThreadPool(threads);
    // when populating while creating
    final NewIndexDescriptor index = createIndex("Person", "name");
    final Collection<Callable<UpdatesTracker>> jobs = new ArrayList<>(threads);
    for (int i = 0; i < threads; i++) {
        jobs.add(new Callable<UpdatesTracker>() {

            @Override
            public UpdatesTracker call() throws Exception {
                return executeCreationsDeletionsAndUpdates(nodes, index, CREATION_MULTIPLIER);
            }
        });
    }
    List<Future<UpdatesTracker>> futures = executorService.invokeAll(jobs);
    // sum result into empty result
    UpdatesTracker result = new UpdatesTracker();
    result.notifyPopulationCompleted();
    for (Future<UpdatesTracker> future : futures) {
        result.add(future.get());
    }
    awaitOnline(index);
    executorService.awaitTermination(1, TimeUnit.SECONDS);
    executorService.shutdown();
    // then
    int tolerance = MISSED_UPDATES_TOLERANCE * threads;
    double doubleTolerance = DOUBLE_ERROR_TOLERANCE * threads;
    int seenWhilePopulating = initialNodes + result.createdDuringPopulation() - result.deletedDuringPopulation();
    double expectedSelectivity = UNIQUE_NAMES / seenWhilePopulating;
    assertCorrectIndexSelectivity(expectedSelectivity, indexSelectivity(index), doubleTolerance);
    assertCorrectIndexSize("Tracker had " + result, seenWhilePopulating, indexSize(index), tolerance);
    int expectedIndexUpdates = result.deletedAfterPopulation() + result.createdAfterPopulation();
    assertCorrectIndexUpdates("Tracker had " + result, expectedIndexUpdates, indexUpdates(index), tolerance);
}
Also used : ArrayList(java.util.ArrayList) Callable(java.util.concurrent.Callable) IndexNotFoundKernelException(org.neo4j.kernel.api.exceptions.index.IndexNotFoundKernelException) EntityNotFoundException(org.neo4j.kernel.api.exceptions.EntityNotFoundException) KernelException(org.neo4j.kernel.api.exceptions.KernelException) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Test(org.junit.Test)

Example 32 with NewIndexDescriptor

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

the class IndexStatisticsIT method shouldRecoverIndexCountsBySamplingThemOnStartup.

@Test
public void shouldRecoverIndexCountsBySamplingThemOnStartup() {
    // given some aliens in a database
    createAliens();
    // that have been indexed
    awaitIndexOnline(indexAliensBySpecimen());
    // where ALIEN and SPECIMEN are both the first ids of their kind
    NewIndexDescriptor index = NewIndexDescriptorFactory.forLabel(labelId(ALIEN), pkId(SPECIMEN));
    SchemaStorage storage = new SchemaStorage(neoStores().getSchemaStore());
    long indexId = storage.indexGetForSchema(index).getId();
    // for which we don't have index counts
    resetIndexCounts(indexId);
    // when we shutdown the database and restart it
    restart();
    // then we should have re-sampled the index
    CountsTracker tracker = neoStores().getCounts();
    assertEqualRegisters("Unexpected updates and size for the index", newDoubleLongRegister(0, 32), tracker.indexUpdatesAndSize(indexId, newDoubleLongRegister()));
    assertEqualRegisters("Unexpected sampling result", newDoubleLongRegister(16, 32), tracker.indexSample(indexId, newDoubleLongRegister()));
    // and also
    assertLogExistsForRecoveryOn(":Alien(specimen)");
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) Test(org.junit.Test)

Example 33 with NewIndexDescriptor

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

the class IndexStatisticsTest method shouldProvideIndexSelectivityWhenThereAreManyDuplicates.

@Test
public void shouldProvideIndexSelectivityWhenThereAreManyDuplicates() throws Exception {
    // given some initial data
    int created = repeatCreateNamedPeopleFor(NAMES.length * CREATION_MULTIPLIER).length;
    // when
    NewIndexDescriptor index = awaitOnline(createIndex("Person", "name"));
    // then
    double expectedSelectivity = UNIQUE_NAMES / created;
    assertCorrectIndexSelectivity(expectedSelectivity, indexSelectivity(index));
    assertCorrectIndexSize(created, indexSize(index));
    assertEquals(0L, indexUpdates(index));
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Test(org.junit.Test)

Example 34 with NewIndexDescriptor

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

the class IndexStatisticsTest method createIndex.

private NewIndexDescriptor createIndex(String labelName, String propertyKeyName) throws KernelException {
    try (Transaction tx = db.beginTx()) {
        Statement statement = bridge.get();
        int labelId = statement.tokenWriteOperations().labelGetOrCreateForName(labelName);
        int propertyKeyId = statement.tokenWriteOperations().propertyKeyGetOrCreateForName(propertyKeyName);
        LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(labelId, propertyKeyId);
        NewIndexDescriptor index = statement.schemaWriteOperations().indexCreate(descriptor);
        tx.success();
        return index;
    }
}
Also used : NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) Transaction(org.neo4j.graphdb.Transaction) Statement(org.neo4j.kernel.api.Statement) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)

Example 35 with NewIndexDescriptor

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

the class IndexStatisticsTest method shouldProvideIndexStatisticsWhenIndexIsBuiltViaPopulationAndConcurrentAdditionsAndChanges.

@Test
public void shouldProvideIndexStatisticsWhenIndexIsBuiltViaPopulationAndConcurrentAdditionsAndChanges() 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 = executeCreationsAndUpdates(nodes, index, CREATION_MULTIPLIER);
    awaitOnline(index);
    // then
    int seenWhilePopulating = initialNodes + updatesTracker.createdDuringPopulation();
    double expectedSelectivity = UNIQUE_NAMES / seenWhilePopulating;
    assertCorrectIndexSelectivity(expectedSelectivity, indexSelectivity(index));
    assertCorrectIndexSize(seenWhilePopulating, indexSize(index));
    assertCorrectIndexUpdates(updatesTracker.createdAfterPopulation(), 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