Search in sources :

Example 36 with IndexUpdater

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

the class FullCheckTokenIndexIT method updateNodeLabelIndex.

void updateNodeLabelIndex(GraphDatabaseAPI database, IndexDescriptor index) throws IOException, IndexEntryConflictException {
    DependencyResolver dependencyResolver = database.getDependencyResolver();
    IndexingService indexingService = dependencyResolver.resolveDependency(IndexingService.class);
    IndexAccessors.IndexAccessorLookup indexAccessorLookup = new LookupAccessorsFromRunningDb(indexingService);
    IndexAccessor accessor = indexAccessorLookup.apply(index);
    try (IndexUpdater indexUpdater = accessor.newUpdater(IndexUpdateMode.ONLINE, CursorContext.NULL)) {
        indexUpdater.process(IndexEntryUpdate.change(100, index, new long[0], new long[] { 1 }));
    }
}
Also used : LookupAccessorsFromRunningDb(org.neo4j.consistency.LookupAccessorsFromRunningDb) IndexAccessors(org.neo4j.consistency.checking.index.IndexAccessors) IndexingService(org.neo4j.kernel.impl.api.index.IndexingService) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) DependencyResolver(org.neo4j.common.DependencyResolver)

Example 37 with IndexUpdater

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

the class IndexingServiceTest method shouldDeliverUpdatesThatOccurDuringPopulationToPopulator.

@SuppressWarnings("unchecked")
@Test
void shouldDeliverUpdatesThatOccurDuringPopulationToPopulator() throws Exception {
    // given
    when(populator.newPopulatingUpdater(eq(propertyAccessor), any())).thenReturn(updater);
    CountDownLatch populationLatch = new CountDownLatch(1);
    Barrier.Control populationStartBarrier = new Barrier.Control();
    IndexingService.Monitor monitor = new IndexingService.MonitorAdapter() {

        @Override
        public void indexPopulationScanStarting() {
            populationStartBarrier.reached();
        }

        @Override
        public void indexPopulationScanComplete() {
            try {
                populationLatch.await();
            } catch (InterruptedException e) {
                Thread.currentThread().interrupt();
                throw new RuntimeException("Index population monitor was interrupted", e);
            }
        }
    };
    IndexingService indexingService = newIndexingServiceWithMockedDependencies(populator, accessor, withData(addNodeUpdate(1, "value1")), monitor);
    life.start();
    // when
    indexingService.createIndexes(AUTH_DISABLED, index);
    IndexProxy proxy = indexingService.getIndexProxy(index);
    assertEquals(POPULATING, proxy.getState());
    populationStartBarrier.await();
    populationStartBarrier.release();
    IndexEntryUpdate<?> value2 = add(2, "value2");
    try (IndexUpdater updater = proxy.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
        updater.process(value2);
    }
    populationLatch.countDown();
    waitForIndexesToComeOnline(indexingService, index);
    verify(populator).close(eq(true), any());
    // then
    assertEquals(ONLINE, proxy.getState());
    InOrder order = inOrder(populator, accessor, updater);
    order.verify(populator).create();
    order.verify(populator).includeSample(add(1, "value1"));
    order.verify(populator, times(1)).add(any(Collection.class), any(CursorContext.class));
    order.verify(populator).scanCompleted(any(PhaseTracker.class), any(IndexPopulator.PopulationWorkScheduler.class), any(CursorContext.class));
    order.verify(populator).newPopulatingUpdater(eq(propertyAccessor), any());
    order.verify(populator).includeSample(any());
    order.verify(updater).process(any());
    order.verify(updater).close();
    order.verify(populator).sample(any());
    order.verify(populator).close(eq(true), any());
    verifyNoMoreInteractions(updater);
    verifyNoMoreInteractions(populator);
    verifyNoInteractions(accessor);
}
Also used : InOrder(org.mockito.InOrder) Barrier(org.neo4j.test.Barrier) CursorContext(org.neo4j.io.pagecache.context.CursorContext) CountDownLatch(java.util.concurrent.CountDownLatch) Iterators.asCollection(org.neo4j.internal.helpers.collection.Iterators.asCollection) Collection(java.util.Collection) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 38 with IndexUpdater

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

the class IndexingServiceTest method shouldIncrementIndexUpdatesAfterStartingExistingOnlineIndexProxy.

@Test
public void shouldIncrementIndexUpdatesAfterStartingExistingOnlineIndexProxy() throws Exception {
    // given
    long indexId = 10;
    IndexDescriptor indexDescriptor = uniqueIndex.materialise(indexId);
    IndexingService indexingService = newIndexingServiceWithMockedDependencies(populator, accessor, withData(), indexDescriptor);
    life.start();
    // when
    IndexProxy proxy = indexingService.getIndexProxy(indexDescriptor);
    try (IndexUpdater updater = proxy.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
        updater.process(IndexEntryUpdate.add(123, indexDescriptor, stringValue("some value")));
    }
    // then
    verify(indexStatisticsStore).incrementIndexUpdates(indexId, 1L);
}
Also used : IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 39 with IndexUpdater

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

the class IndexingServiceTest method shouldStillReportInternalIndexStateAsPopulatingWhenConstraintIndexIsDonePopulating.

@Test
void shouldStillReportInternalIndexStateAsPopulatingWhenConstraintIndexIsDonePopulating() throws Exception {
    // given
    when(accessor.newUpdater(any(IndexUpdateMode.class), any(CursorContext.class))).thenReturn(updater);
    ValueIndexReader indexReader = mock(ValueIndexReader.class);
    when(accessor.newValueReader()).thenReturn(indexReader);
    doAnswer(new NodeIdsIndexReaderQueryAnswer(index)).when(indexReader).query(any(), any(), any(), any());
    IndexingService indexingService = newIndexingServiceWithMockedDependencies(populator, accessor, withData());
    life.start();
    // when
    IndexDescriptor index = constraintIndexRule(0, labelId, propertyKeyId, PROVIDER_DESCRIPTOR);
    indexingService.createIndexes(AUTH_DISABLED, index);
    IndexProxy proxy = indexingService.getIndexProxy(index);
    // don't wait for index to come ONLINE here since we're testing that it doesn't
    verify(populator, timeout(20000)).close(eq(true), any());
    try (IndexUpdater updater = proxy.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
        updater.process(add(10, "foo"));
    }
    // then
    assertEquals(POPULATING, proxy.getState());
    InOrder order = inOrder(populator, accessor, updater);
    order.verify(populator).create();
    order.verify(populator).close(eq(true), any());
    order.verify(accessor).newUpdater(eq(IndexUpdateMode.ONLINE), any());
    order.verify(updater).process(add(10, "foo"));
    order.verify(updater).close();
}
Also used : NodeIdsIndexReaderQueryAnswer(org.neo4j.kernel.impl.index.schema.NodeIdsIndexReaderQueryAnswer) InOrder(org.mockito.InOrder) CursorContext(org.neo4j.io.pagecache.context.CursorContext) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) ValueIndexReader(org.neo4j.kernel.api.index.ValueIndexReader) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 40 with IndexUpdater

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

the class IndexingServiceTest method closingOfValidatedUpdatesShouldCloseUpdaters.

@Test
void closingOfValidatedUpdatesShouldCloseUpdaters() throws Exception {
    // Given
    long indexId1 = 1;
    long indexId2 = 2;
    int labelId1 = 24;
    int labelId2 = 42;
    IndexDescriptor index1 = storeIndex(indexId1, labelId1, propertyKeyId, PROVIDER_DESCRIPTOR);
    IndexDescriptor index2 = storeIndex(indexId2, labelId2, propertyKeyId, PROVIDER_DESCRIPTOR);
    IndexingService indexing = newIndexingServiceWithMockedDependencies(populator, accessor, withData());
    IndexAccessor accessor1 = mock(IndexAccessor.class);
    IndexUpdater updater1 = mock(IndexUpdater.class);
    when(accessor1.newUpdater(any(IndexUpdateMode.class), any(CursorContext.class))).thenReturn(updater1);
    IndexAccessor accessor2 = mock(IndexAccessor.class);
    IndexUpdater updater2 = mock(IndexUpdater.class);
    when(accessor2.newUpdater(any(IndexUpdateMode.class), any(CursorContext.class))).thenReturn(updater2);
    when(indexProvider.getOnlineAccessor(eq(index1), any(IndexSamplingConfig.class), any(TokenNameLookup.class))).thenReturn(accessor1);
    when(indexProvider.getOnlineAccessor(eq(index2), any(IndexSamplingConfig.class), any(TokenNameLookup.class))).thenReturn(accessor2);
    life.start();
    indexing.createIndexes(AUTH_DISABLED, index1);
    indexing.createIndexes(AUTH_DISABLED, index2);
    waitForIndexesToComeOnline(indexing, index1, index2);
    verify(populator, timeout(10000).times(2)).close(eq(true), any());
    // When
    indexing.applyUpdates(asList(add(1, "foo", index1), add(2, "bar", index2)), NULL);
    // Then
    verify(updater1).close();
    verify(updater2).close();
}
Also used : TokenNameLookup(org.neo4j.common.TokenNameLookup) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) CursorContext(org.neo4j.io.pagecache.context.CursorContext) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Aggregations

IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)94 Test (org.junit.jupiter.api.Test)61 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)22 ValueIndexEntryUpdate (org.neo4j.storageengine.api.ValueIndexEntryUpdate)13 IndexAccessor (org.neo4j.kernel.api.index.IndexAccessor)12 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)9 Value (org.neo4j.values.storable.Value)9 ConsistencySummaryStatistics (org.neo4j.consistency.report.ConsistencySummaryStatistics)7 CursorContext (org.neo4j.io.pagecache.context.CursorContext)7 IndexEntryUpdate (org.neo4j.storageengine.api.IndexEntryUpdate)6 SwallowingIndexUpdater (org.neo4j.kernel.impl.api.index.SwallowingIndexUpdater)5 ArrayList (java.util.ArrayList)4 Test (org.junit.Test)4 Transaction (org.neo4j.graphdb.Transaction)4 IndexEntryConflictException (org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException)4 SchemaIndexTestHelper.mockIndexProxy (org.neo4j.kernel.impl.api.index.SchemaIndexTestHelper.mockIndexProxy)4 NodePropertyAccessor (org.neo4j.storageengine.api.NodePropertyAccessor)4 HashMap (java.util.HashMap)3 EnumSource (org.junit.jupiter.params.provider.EnumSource)3