Search in sources :

Example 21 with IndexSample

use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.

the class MultipleIndexPopulatorTest method testStopPopulation.

@Test
void testStopPopulation() throws FlipFailedKernelException {
    IndexPopulator indexPopulator1 = createIndexPopulator();
    IndexPopulator indexPopulator2 = createIndexPopulator();
    addPopulator(indexPopulator1, 1);
    addPopulator(indexPopulator2, 2);
    multipleIndexPopulator.stop(NULL);
    verify(indexStatisticsStore, times(2)).replaceStats(anyLong(), eq(new IndexSample(0, 0, 0)));
    verify(indexPopulator1).close(false, NULL);
    verify(indexPopulator2).close(false, NULL);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexSample(org.neo4j.kernel.api.index.IndexSample) Test(org.junit.jupiter.api.Test)

Example 22 with IndexSample

use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.

the class MultipleIndexPopulatorTest method createIndexPopulator.

private static IndexPopulator createIndexPopulator() {
    IndexPopulator populator = mock(IndexPopulator.class);
    when(populator.sample(any(CursorContext.class))).thenReturn(new IndexSample());
    return populator;
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexSample(org.neo4j.kernel.api.index.IndexSample) CursorContext(org.neo4j.io.pagecache.context.CursorContext)

Example 23 with IndexSample

use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.

the class MultipleIndexPopulatorTest method shouldVerifyConstraintsBeforeFlippingIfToldTo.

@Test
void shouldVerifyConstraintsBeforeFlippingIfToldTo() throws IndexEntryConflictException {
    // given
    IndexProxyFactory indexProxyFactory = mock(IndexProxyFactory.class);
    FailedIndexProxyFactory failedIndexProxyFactory = mock(FailedIndexProxyFactory.class);
    FlippableIndexProxy flipper = new FlippableIndexProxy();
    flipper.setFlipTarget(indexProxyFactory);
    IndexPopulator indexPopulator = createIndexPopulator();
    addPopulator(indexPopulator, 1, flipper, failedIndexProxyFactory);
    when(indexPopulator.sample(any(CursorContext.class))).thenReturn(new IndexSample());
    // when
    multipleIndexPopulator.createStoreScan(PageCacheTracer.NULL);
    multipleIndexPopulator.flipAfterStoreScan(true, NULL);
    // then
    verify(indexPopulator).verifyDeferredConstraints(any(NodePropertyAccessor.class));
    verify(indexPopulator).close(true, NULL);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexSample(org.neo4j.kernel.api.index.IndexSample) CursorContext(org.neo4j.io.pagecache.context.CursorContext) NodePropertyAccessor(org.neo4j.storageengine.api.NodePropertyAccessor) Test(org.junit.jupiter.api.Test)

Example 24 with IndexSample

use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.

the class IndexingServiceTest method shouldNotLoseIndexDescriptorDueToOtherSimilarIndexDuringRecovery.

/*
     * See comments in IndexingService#createIndex
     */
@Test
void shouldNotLoseIndexDescriptorDueToOtherSimilarIndexDuringRecovery() throws Exception {
    // GIVEN
    long nodeId = 0;
    long otherIndexId = 2;
    Update update = addNodeUpdate(nodeId, "value");
    when(indexStatisticsStore.indexSample(anyLong())).thenReturn(new IndexSample(100, 42, 42));
    // For some reason the usual accessor returned null from newUpdater, even when told to return the updater
    // so spying on a real object instead.
    IndexAccessor accessor = spy(new TrackingIndexAccessor());
    IndexingService indexing = newIndexingServiceWithMockedDependencies(populator, accessor, withData(update), index);
    when(indexProvider.getInitialState(index, NULL)).thenReturn(ONLINE);
    life.init();
    // WHEN dropping another index, which happens to have the same label/property... while recovering
    IndexDescriptor otherIndex = prototype.withName("index_" + otherIndexId).materialise(otherIndexId);
    indexing.createIndexes(AUTH_DISABLED, otherIndex);
    indexing.dropIndex(otherIndex);
    // and WHEN finally creating our index again (at a later point in recovery)
    indexing.createIndexes(AUTH_DISABLED, index);
    reset(accessor);
    indexing.applyUpdates(nodeIdsAsIndexUpdates(nodeId), NULL);
    // and WHEN starting, i.e. completing recovery
    life.start();
    verify(accessor).newUpdater(eq(RECOVERY), any(CursorContext.class));
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) CursorContext(org.neo4j.io.pagecache.context.CursorContext) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 25 with IndexSample

use of org.neo4j.kernel.api.index.IndexSample in project neo4j by neo4j.

the class IndexingServiceTest method shouldLogDeprecatedIndexesOnStart.

@Test
void shouldLogDeprecatedIndexesOnStart() throws Exception {
    // given two indexes per available index provider
    int id = 1;
    List<IndexDescriptor> indexDescriptors = new ArrayList<>();
    IndexProvider[] indexProviders = new IndexProvider[indexProviderDescriptors.length];
    for (int i = 0; i < indexProviderDescriptors.length; i++) {
        IndexProviderDescriptor indexProviderDescriptor = indexProviderDescriptors[i];
        IndexProvider indexProvider = mockIndexProviderWithAccessor(indexProviderDescriptor);
        indexProviders[i] = indexProvider;
        // Two indexes per provider
        for (int j = 0; j < 2; j++) {
            IndexDescriptor index = storeIndex(id, 1, id, indexProviderDescriptor);
            indexDescriptors.add(index);
            when(indexProvider.getInitialState(eq(index), any())).thenReturn(ONLINE);
            id++;
        }
    }
    Config config = Config.defaults(default_schema_provider, nativeBtree10Descriptor.name());
    DependencyResolver dependencies = buildIndexDependencies(indexProviders);
    DefaultIndexProviderMap providerMap = new DefaultIndexProviderMap(dependencies, config);
    providerMap.init();
    when(indexStatisticsStore.indexSample(anyLong())).thenReturn(new IndexSample(1, 1, 1));
    IndexingService indexingService = IndexingServiceFactory.createIndexingService(config, mock(JobScheduler.class), providerMap, storeViewFactory, nameLookup, indexDescriptors, internalLogProvider, userLogProvider, IndexingService.NO_MONITOR, schemaState, indexStatisticsStore, PageCacheTracer.NULL, INSTANCE, "", writable());
    // when starting IndexingService
    indexingService.init();
    for (IndexProviderDescriptor indexProviderDescriptor : indexProviderDescriptors) {
        onBothLogProviders(logProvider -> assertThat(logProvider).doesNotContainMessage(indexProviderDescriptor.name()));
    }
    userLogProvider.clear();
    indexingService.start();
    // then we should see log messages about deprecated providers if any
    for (IndexProviderDescriptor indexProviderDescriptor : indexProviderDescriptors) {
        if (isDeprecated(indexProviderDescriptor)) {
            assertThat(userLogProvider).containsMessages("Deprecated index providers in use:", indexProviderDescriptor.name() + " (2 indexes)", "Use procedure 'db.indexes()' to see what indexes use which index provider.");
        } else {
            onBothLogProviders(logProvider -> assertThat(logProvider).doesNotContainMessage(indexProviderDescriptor.name()));
        }
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) Config(org.neo4j.configuration.Config) IndexConfig(org.neo4j.internal.schema.IndexConfig) ArrayList(java.util.ArrayList) IndexProviderDescriptor(org.neo4j.internal.schema.IndexProviderDescriptor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) DependencyResolver(org.neo4j.common.DependencyResolver) IndexProvider(org.neo4j.kernel.api.index.IndexProvider) DefaultIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultIndexProviderMap) IndexSample(org.neo4j.kernel.api.index.IndexSample) Test(org.junit.jupiter.api.Test)

Aggregations

IndexSample (org.neo4j.kernel.api.index.IndexSample)56 Test (org.junit.jupiter.api.Test)43 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)14 CursorContext (org.neo4j.io.pagecache.context.CursorContext)13 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)10 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)8 IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)8 NodePropertyAccessor (org.neo4j.storageengine.api.NodePropertyAccessor)8 IndexProvider (org.neo4j.kernel.api.index.IndexProvider)7 IndexSampler (org.neo4j.kernel.api.index.IndexSampler)7 ArrayList (java.util.ArrayList)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)6 Config (org.neo4j.configuration.Config)6 Transaction (org.neo4j.graphdb.Transaction)6 IOException (java.io.IOException)5 Path (java.nio.file.Path)4 Arrays.asList (java.util.Arrays.asList)4 HashSet (java.util.HashSet)4 Set (java.util.Set)4 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)4