Search in sources :

Example 26 with IndexSample

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

the class IndexingServiceTest method shouldSnapshotOnlineIndexes.

@Test
void shouldSnapshotOnlineIndexes() throws Exception {
    // GIVEN
    int indexId = 1;
    int indexId2 = 2;
    IndexDescriptor rule1 = storeIndex(indexId, 2, 3, PROVIDER_DESCRIPTOR);
    IndexDescriptor rule2 = storeIndex(indexId2, 4, 5, PROVIDER_DESCRIPTOR);
    IndexAccessor indexAccessor = mock(IndexAccessor.class);
    IndexingService indexing = newIndexingServiceWithMockedDependencies(mock(IndexPopulator.class), indexAccessor, new DataUpdates(), rule1, rule2);
    Path theFile = Path.of("Blah");
    when(indexAccessor.snapshotFiles()).thenAnswer(newResourceIterator(theFile));
    when(indexProvider.getInitialState(rule1, NULL)).thenReturn(ONLINE);
    when(indexProvider.getInitialState(rule2, NULL)).thenReturn(ONLINE);
    when(indexStatisticsStore.indexSample(anyLong())).thenReturn(new IndexSample(100L, 32L, 32L));
    life.start();
    // WHEN
    ResourceIterator<Path> files = indexing.snapshotIndexFiles();
    // THEN
    // We get a snapshot per online index
    assertThat(asCollection(files)).isEqualTo(asCollection(iterator(theFile, theFile)));
}
Also used : Path(java.nio.file.Path) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexSample(org.neo4j.kernel.api.index.IndexSample) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 27 with IndexSample

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

the class IndexingServiceTest method shouldNotSnapshotPopulatingIndexes.

@Test
void shouldNotSnapshotPopulatingIndexes() throws Exception {
    // GIVEN
    CountDownLatch populatorLatch = new CountDownLatch(1);
    IndexAccessor indexAccessor = mock(IndexAccessor.class);
    int indexId = 1;
    int indexId2 = 2;
    IndexDescriptor index1 = storeIndex(indexId, 2, 3, PROVIDER_DESCRIPTOR);
    IndexDescriptor index2 = storeIndex(indexId2, 4, 5, PROVIDER_DESCRIPTOR);
    IndexingService indexing = newIndexingServiceWithMockedDependencies(populator, indexAccessor, new DataUpdates(), index1, index2);
    Path theFile = Path.of("Blah");
    doAnswer(waitForLatch(populatorLatch)).when(populator).create();
    when(indexAccessor.snapshotFiles()).thenAnswer(newResourceIterator(theFile));
    when(indexProvider.getInitialState(eq(index1), any())).thenReturn(POPULATING);
    when(indexProvider.getInitialState(eq(index2), any())).thenReturn(ONLINE);
    when(indexStatisticsStore.indexSample(anyLong())).thenReturn(new IndexSample(100, 32, 32));
    life.start();
    // WHEN
    ResourceIterator<Path> files = indexing.snapshotIndexFiles();
    // only now, after the snapshot, is the population job allowed to finish
    populatorLatch.countDown();
    waitForIndexesToComeOnline(indexing, index1, index2);
    // THEN
    // We get a snapshot from the online index, but no snapshot from the populating one
    assertThat(asCollection(files)).isEqualTo(asCollection(iterator(theFile)));
}
Also used : Path(java.nio.file.Path) IndexSample(org.neo4j.kernel.api.index.IndexSample) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) CountDownLatch(java.util.concurrent.CountDownLatch) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 28 with IndexSample

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

the class FusionIndexIT method shouldKeepIndexSamplesUpdated.

@Test
void shouldKeepIndexSamplesUpdated() {
    // Given
    createIndex();
    assertThat(indexSample()).isEqualTo(new IndexSample(0, 0, 0, 0));
    // When
    try (Transaction tx = db.beginTx()) {
        tx.createNode(label).setProperty(propKey, numberValue);
        tx.createNode(label).setProperty(propKey, stringValue);
        tx.createNode(label).setProperty(propKey, spatialValue);
        tx.createNode(label).setProperty(propKey, temporalValue);
        tx.commit();
    }
    // Then
    assertEventually(this::indexSample, equalityCondition(new IndexSample(4, 4, 4)), 1, MINUTES);
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.jupiter.api.Test)

Example 29 with IndexSample

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

the class IndexingServiceTest method shouldLogIndexStateOnStart.

@Test
void shouldLogIndexStateOnStart() throws Throwable {
    // given
    IndexProvider provider = mockIndexProviderWithAccessor(PROVIDER_DESCRIPTOR);
    Config config = Config.defaults(default_schema_provider, PROVIDER_DESCRIPTOR.name());
    DefaultIndexProviderMap providerMap = new DefaultIndexProviderMap(buildIndexDependencies(provider, fulltextProvider()), config);
    providerMap.init();
    IndexDescriptor onlineIndex = storeIndex(1, 1, 1, PROVIDER_DESCRIPTOR);
    IndexDescriptor populatingIndex = storeIndex(2, 1, 2, PROVIDER_DESCRIPTOR);
    IndexDescriptor failedIndex = storeIndex(3, 2, 2, PROVIDER_DESCRIPTOR);
    IndexingService indexingService = IndexingServiceFactory.createIndexingService(config, mock(JobScheduler.class), providerMap, storeViewFactory, nameLookup, asList(onlineIndex, populatingIndex, failedIndex), internalLogProvider, userLogProvider, IndexingService.NO_MONITOR, schemaState, indexStatisticsStore, PageCacheTracer.NULL, INSTANCE, "", writable());
    when(provider.getInitialState(eq(onlineIndex), any())).thenReturn(ONLINE);
    when(provider.getInitialState(eq(populatingIndex), any())).thenReturn(POPULATING);
    when(provider.getInitialState(eq(failedIndex), any())).thenReturn(FAILED);
    indexingService.init();
    nameLookup.label(1, "LabelOne");
    nameLookup.label(2, "LabelTwo");
    nameLookup.propertyKey(1, "propertyOne");
    nameLookup.propertyKey(2, "propertyTwo");
    when(indexStatisticsStore.indexSample(anyLong())).thenReturn(new IndexSample(100L, 32L, 32L));
    internalLogProvider.clear();
    // when
    indexingService.start();
    // then
    verify(provider).getPopulationFailure(eq(failedIndex), any());
    assertThat(internalLogProvider).forLevel(DEBUG).containsMessages("IndexingService.start: index 1 on (:LabelOne {propertyOne}) is ONLINE", "IndexingService.start: index 2 on (:LabelOne {propertyTwo}) is POPULATING", "IndexingService.start: index 3 on (:LabelTwo {propertyTwo}) is FAILED");
}
Also used : IndexProvider(org.neo4j.kernel.api.index.IndexProvider) DefaultIndexProviderMap(org.neo4j.kernel.impl.transaction.state.DefaultIndexProviderMap) JobScheduler(org.neo4j.scheduler.JobScheduler) IndexSample(org.neo4j.kernel.api.index.IndexSample) Config(org.neo4j.configuration.Config) IndexConfig(org.neo4j.internal.schema.IndexConfig) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 30 with IndexSample

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

the class IndexingServiceTest method shouldNotLoseIndexDescriptorDueToOtherVerySimilarIndexDuringRecovery.

@Test
void shouldNotLoseIndexDescriptorDueToOtherVerySimilarIndexDuringRecovery() throws Exception {
    // GIVEN
    AtomicReference<BinaryLatch> populationStartLatch = latchedIndexPopulation();
    long nodeId = 0;
    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();
    populationStartLatch.getAndSet(new BinaryLatch()).release();
    // WHEN dropping another index, which happens to be identical to the existing one except for different index config... while recovering
    IndexConfig indexConfig = index.getIndexConfig().withIfAbsent("a", Values.booleanValue(true));
    IndexDescriptor otherIndex = index.withIndexConfig(indexConfig);
    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();
    IndexProxy indexProxy = indexing.getIndexProxy(index);
    try {
        assertNull(indexProxy.getDescriptor().getIndexConfig().get("a"));
        // The existing online index got nuked during recovery.
        assertThat(indexProxy.getState()).isEqualTo(POPULATING);
    } finally {
        populationStartLatch.get().release();
    }
}
Also used : IndexSample(org.neo4j.kernel.api.index.IndexSample) IndexConfig(org.neo4j.internal.schema.IndexConfig) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) IndexEntryUpdate(org.neo4j.storageengine.api.IndexEntryUpdate) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) BinaryLatch(org.neo4j.util.concurrent.BinaryLatch) 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