Search in sources :

Example 51 with IndexUpdater

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

the class MultipleIndexPopulatorUpdatesTest method updateForHigherNodeIgnoredWhenUsingFullNodeStoreScan.

@Test
public void updateForHigherNodeIgnoredWhenUsingFullNodeStoreScan() throws IndexPopulationFailedKernelException, IOException, IndexEntryConflictException {
    NeoStores neoStores = Mockito.mock(NeoStores.class);
    CountsTracker countsTracker = mock(CountsTracker.class);
    NodeStore nodeStore = mock(NodeStore.class);
    PropertyStore propertyStore = mock(PropertyStore.class);
    NodeRecord nodeRecord = getNodeRecord();
    PropertyRecord propertyRecord = getPropertyRecord();
    when(neoStores.getCounts()).thenReturn(countsTracker);
    when(neoStores.getNodeStore()).thenReturn(nodeStore);
    when(neoStores.getPropertyStore()).thenReturn(propertyStore);
    when(propertyStore.getPropertyRecordChain(anyInt())).thenReturn(Collections.singletonList(propertyRecord));
    when(countsTracker.nodeCount(anyInt(), any(Register.DoubleLongRegister.class))).thenReturn(Registers.newDoubleLongRegister(3, 3));
    when(nodeStore.getHighestPossibleIdInUse()).thenReturn(20L);
    when(nodeStore.newRecord()).thenReturn(nodeRecord);
    when(nodeStore.getRecord(anyInt(), eq(nodeRecord), any(RecordLoad.class))).thenAnswer(new SetNodeIdRecordAnswer(nodeRecord, 1));
    when(nodeStore.getRecord(eq(7L), eq(nodeRecord), any(RecordLoad.class))).thenAnswer(new SetNodeIdRecordAnswer(nodeRecord, 7));
    ProcessListenableNeoStoreIndexView storeView = new ProcessListenableNeoStoreIndexView(LockService.NO_LOCK_SERVICE, neoStores);
    MultipleIndexPopulator indexPopulator = new MultipleIndexPopulator(storeView, logProvider);
    storeView.setProcessListener(new NodeUpdateProcessListener(indexPopulator));
    IndexPopulator populator = createIndexPopulator();
    IndexUpdater indexUpdater = mock(IndexUpdater.class);
    when(populator.newPopulatingUpdater(storeView)).thenReturn(indexUpdater);
    addPopulator(indexPopulator, populator, 1, NewIndexDescriptorFactory.forLabel(1, 1));
    indexPopulator.create();
    StoreScan<IndexPopulationFailedKernelException> storeScan = indexPopulator.indexAllNodes();
    storeScan.run();
    Mockito.verify(indexUpdater, times(0)).process(any(IndexEntryUpdate.class));
}
Also used : IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException) RecordLoad(org.neo4j.kernel.impl.store.record.RecordLoad) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) NodeStore(org.neo4j.kernel.impl.store.NodeStore) PropertyRecord(org.neo4j.kernel.impl.store.record.PropertyRecord) NeoStores(org.neo4j.kernel.impl.store.NeoStores) CountsTracker(org.neo4j.kernel.impl.store.counts.CountsTracker) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) PropertyStore(org.neo4j.kernel.impl.store.PropertyStore) Test(org.junit.Test)

Example 52 with IndexUpdater

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

the class MultipleIndexPopulator method newPopulatingUpdater.

@VisibleForTesting
MultipleIndexUpdater newPopulatingUpdater(NodePropertyAccessor accessor, CursorContext cursorContext) {
    Map<SchemaDescriptor, Pair<IndexPopulation, IndexUpdater>> updaters = new HashMap<>();
    forEachPopulation(population -> {
        IndexUpdater updater = population.populator.newPopulatingUpdater(accessor, cursorContext);
        updaters.put(population.schema(), Pair.of(population, updater));
    }, cursorContext);
    return new MultipleIndexUpdater(this, updaters, logProvider, cursorContext);
}
Also used : SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) HashMap(java.util.HashMap) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Pair(org.neo4j.internal.helpers.collection.Pair) VisibleForTesting(org.neo4j.util.VisibleForTesting)

Example 53 with IndexUpdater

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

the class IndexUpdaterMap method close.

@Override
public void close() throws UnderlyingStorageException {
    Set<Pair<IndexDescriptor, UnderlyingStorageException>> exceptions = null;
    for (Map.Entry<IndexDescriptor, IndexUpdater> updaterEntry : updaterMap.entrySet()) {
        IndexUpdater updater = updaterEntry.getValue();
        try {
            updater.close();
        } catch (UncheckedIOException | IndexEntryConflictException e) {
            if (null == exceptions) {
                exceptions = new HashSet<>();
            }
            exceptions.add(Pair.of(updaterEntry.getKey(), new UnderlyingStorageException(e)));
        }
    }
    clear();
    if (null != exceptions) {
        throw new MultipleUnderlyingStorageExceptions(exceptions);
    }
}
Also used : UncheckedIOException(java.io.UncheckedIOException) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) UnderlyingStorageException(org.neo4j.exceptions.UnderlyingStorageException) Map(java.util.Map) HashMap(java.util.HashMap) IndexEntryConflictException(org.neo4j.kernel.api.exceptions.index.IndexEntryConflictException) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Pair(org.neo4j.internal.helpers.collection.Pair) HashSet(java.util.HashSet) MultipleUnderlyingStorageExceptions(org.neo4j.kernel.impl.store.MultipleUnderlyingStorageExceptions)

Example 54 with IndexUpdater

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

the class IndexingServiceTest method shouldBringIndexOnlineAndFlipOverToIndexAccessor.

@Test
void shouldBringIndexOnlineAndFlipOverToIndexAccessor() throws Exception {
    // given
    when(accessor.newUpdater(any(IndexUpdateMode.class), any(CursorContext.class))).thenReturn(updater);
    IndexingService indexingService = newIndexingServiceWithMockedDependencies(populator, accessor, withData());
    life.start();
    // when
    indexingService.createIndexes(AUTH_DISABLED, index);
    IndexProxy proxy = indexingService.getIndexProxy(index);
    waitForIndexesToComeOnline(indexingService, index);
    verify(populator, timeout(10000)).close(eq(true), any());
    try (IndexUpdater updater = proxy.newUpdater(IndexUpdateMode.ONLINE, NULL)) {
        updater.process(add(10, "foo"));
    }
    // then
    assertEquals(ONLINE, 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_IDEMPOTENT), any());
    order.verify(updater).process(add(10, "foo"));
    order.verify(updater).close();
}
Also used : InOrder(org.mockito.InOrder) CursorContext(org.neo4j.io.pagecache.context.CursorContext) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.jupiter.api.Test)

Example 55 with IndexUpdater

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

the class IndexingServiceTest method shouldRefreshIndexesOnStart.

@Test
void shouldRefreshIndexesOnStart() throws Exception {
    // given
    newIndexingServiceWithMockedDependencies(populator, accessor, withData(), index);
    IndexAccessor accessor = mock(IndexAccessor.class);
    IndexUpdater updater = mock(IndexUpdater.class);
    when(accessor.newValueReader()).thenReturn(ValueIndexReader.EMPTY);
    when(accessor.newUpdater(any(IndexUpdateMode.class), any(CursorContext.class))).thenReturn(updater);
    when(indexProvider.getOnlineAccessor(any(IndexDescriptor.class), any(IndexSamplingConfig.class), any(TokenNameLookup.class))).thenReturn(accessor);
    life.init();
    verify(accessor, never()).refresh();
    life.start();
    // Then
    verify(accessor).refresh();
}
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