Search in sources :

Example 31 with IndexPopulator

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

the class BatchingMultipleIndexPopulatorTest method pendingBatchesFlushedAfterStoreScan.

@Test
public void pendingBatchesFlushedAfterStoreScan() throws Exception {
    NodeUpdates update1 = nodeUpdates(1, propertyId, "foo", labelId);
    NodeUpdates update2 = nodeUpdates(2, propertyId, "bar", labelId);
    NodeUpdates update3 = nodeUpdates(3, propertyId, "baz", labelId);
    NodeUpdates update42 = nodeUpdates(4, 42, "42", 42);
    IndexStoreView storeView = newStoreView(update1, update2, update3, update42);
    BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(storeView, sameThreadExecutor(), NullLogProvider.getInstance());
    IndexPopulator populator1 = addPopulator(batchingPopulator, index1);
    IndexPopulator populator42 = addPopulator(batchingPopulator, index42);
    batchingPopulator.indexAllNodes().run();
    verify(populator1).add(Arrays.asList(forIndex(update1, index1), forIndex(update2, index1), forIndex(update3, index1)));
    verify(populator42).add(singletonList(forIndex(update42, index42)));
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) NeoStoreIndexStoreView(org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView) Test(org.junit.Test)

Example 32 with IndexPopulator

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

the class BatchingMultipleIndexPopulatorTest method populateFromQueuePopulatesWhenThresholdReached.

@Test
public void populateFromQueuePopulatesWhenThresholdReached() throws Exception {
    setProperty(QUEUE_THRESHOLD_NAME, 2);
    NeoStores neoStores = mock(NeoStores.class);
    NodeStore nodeStore = mock(NodeStore.class);
    when(neoStores.getNodeStore()).thenReturn(nodeStore);
    NeoStoreIndexStoreView storeView = new NeoStoreIndexStoreView(LockService.NO_LOCK_SERVICE, neoStores);
    BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(storeView, mock(ExecutorService.class), NullLogProvider.getInstance());
    IndexPopulator populator1 = addPopulator(batchingPopulator, index1);
    IndexUpdater updater1 = mock(IndexUpdater.class);
    when(populator1.newPopulatingUpdater(any())).thenReturn(updater1);
    IndexPopulator populator2 = addPopulator(batchingPopulator, index42);
    IndexUpdater updater2 = mock(IndexUpdater.class);
    when(populator2.newPopulatingUpdater(any())).thenReturn(updater2);
    batchingPopulator.indexAllNodes();
    IndexEntryUpdate update1 = IndexEntryUpdate.add(1, index1.schema(), "foo");
    IndexEntryUpdate update2 = IndexEntryUpdate.add(2, index42.schema(), "bar");
    IndexEntryUpdate update3 = IndexEntryUpdate.add(3, index1.schema(), "baz");
    batchingPopulator.queue(update1);
    batchingPopulator.queue(update2);
    batchingPopulator.queue(update3);
    batchingPopulator.populateFromQueue(42);
    verify(updater1).process(update1);
    verify(updater1).process(update3);
    verify(updater2).process(update2);
}
Also used : NeoStoreIndexStoreView(org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) NodeStore(org.neo4j.kernel.impl.store.NodeStore) NeoStores(org.neo4j.kernel.impl.store.NeoStores) ExecutorService(java.util.concurrent.ExecutorService) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.Test)

Example 33 with IndexPopulator

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

the class IndexPopulationJobTest method shouldPopulateIndexWithOneNode.

@Test
public void shouldPopulateIndexWithOneNode() throws Exception {
    // GIVEN
    String value = "Taylor";
    long nodeId = createNode(map(name, value), FIRST);
    IndexPopulator populator = spy(inMemoryPopulator(false));
    IndexPopulationJob job = newIndexPopulationJob(populator, new FlippableIndexProxy(), false);
    LabelSchemaDescriptor descriptor = SchemaDescriptorFactory.forLabel(0, 0);
    // WHEN
    job.run();
    // THEN
    IndexEntryUpdate update = IndexEntryUpdate.add(nodeId, descriptor, value);
    verify(populator).create();
    verify(populator).configureSampling(true);
    verify(populator).includeSample(update);
    verify(populator).add(anyListOf(IndexEntryUpdate.class));
    verify(populator).sampleResult();
    verify(populator).close(true);
    verifyNoMoreInteractions(populator);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) LabelSchemaDescriptor(org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor) Test(org.junit.Test)

Example 34 with IndexPopulator

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

the class IndexRecoveryIT method shouldBeAbleToRecoverAndUpdateOnlineIndex.

@Test
public void shouldBeAbleToRecoverAndUpdateOnlineIndex() throws Exception {
    // Given
    startDb();
    IndexPopulator populator = mock(IndexPopulator.class);
    when(mockedIndexProvider.getPopulator(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(populator);
    when(populator.sampleResult()).thenReturn(new IndexSample());
    IndexAccessor mockedAccessor = mock(IndexAccessor.class);
    when(mockedAccessor.newUpdater(any(IndexUpdateMode.class))).thenReturn(SwallowingIndexUpdater.INSTANCE);
    when(mockedIndexProvider.getOnlineAccessor(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(mockedAccessor);
    createIndexAndAwaitPopulation(myLabel);
    // rotate logs
    rotateLogsAndCheckPoint();
    // make updates
    Set<IndexEntryUpdate> expectedUpdates = createSomeBananas(myLabel);
    // And Given
    killDb();
    when(mockedIndexProvider.getInitialState(anyLong(), any(NewIndexDescriptor.class))).thenReturn(InternalIndexState.ONLINE);
    GatheringIndexWriter writer = new GatheringIndexWriter();
    when(mockedIndexProvider.getOnlineAccessor(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(writer);
    // When
    startDb();
    // Then
    assertThat(getIndexes(db, myLabel), inTx(db, hasSize(1)));
    assertThat(getIndexes(db, myLabel), inTx(db, haveState(db, Schema.IndexState.ONLINE)));
    verify(mockedIndexProvider, times(1)).getPopulator(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class));
    // once when we create the index, and once when we restart the db
    int onlineAccessorInvocationCount = 2;
    verify(mockedIndexProvider, times(onlineAccessorInvocationCount)).getOnlineAccessor(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class));
    assertEquals(expectedUpdates, writer.batchedUpdates);
    for (IndexEntryUpdate update : writer.batchedUpdates) {
        assertTrue(writer.recoveredNodes.contains(update.getEntityId()));
    }
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) IndexSample(org.neo4j.storageengine.api.schema.IndexSample) IndexAccessor(org.neo4j.kernel.api.index.IndexAccessor) Test(org.junit.Test)

Example 35 with IndexPopulator

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

the class IndexPopulationJobTest method shouldTransitionToFailedStateIfPopulationJobCrashes.

@Test
public void shouldTransitionToFailedStateIfPopulationJobCrashes() throws Exception {
    // GIVEN
    IndexPopulator failingPopulator = mock(IndexPopulator.class);
    doThrow(new RuntimeException("BORK BORK")).when(failingPopulator).add(any());
    FlippableIndexProxy index = new FlippableIndexProxy();
    createNode(map(name, "Taylor"), FIRST);
    IndexPopulationJob job = newIndexPopulationJob(failingPopulator, index, false);
    // WHEN
    job.run();
    // THEN
    assertThat(index.getState(), equalTo(InternalIndexState.FAILED));
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) Test(org.junit.Test)

Aggregations

IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)45 Test (org.junit.Test)37 IndexEntryUpdate (org.neo4j.kernel.api.index.IndexEntryUpdate)11 PropertyAccessor (org.neo4j.kernel.api.index.PropertyAccessor)8 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)7 IndexSamplingConfig (org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig)7 NeoStoreIndexStoreView (org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView)7 NodeUpdates (org.neo4j.kernel.api.index.NodeUpdates)6 SchemaIndexProvider (org.neo4j.kernel.api.index.SchemaIndexProvider)6 NewIndexDescriptor (org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)6 BatchInserter (org.neo4j.unsafe.batchinsert.BatchInserter)5 ExecutorService (java.util.concurrent.ExecutorService)3 LabelSchemaDescriptor (org.neo4j.kernel.api.schema_new.LabelSchemaDescriptor)3 IndexPopulation (org.neo4j.kernel.impl.api.index.MultipleIndexPopulator.IndexPopulation)3 NeoStores (org.neo4j.kernel.impl.store.NeoStores)3 NodeStore (org.neo4j.kernel.impl.store.NodeStore)3 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)3 AssertableLogProvider (org.neo4j.logging.AssertableLogProvider)3 IntPredicate (java.util.function.IntPredicate)2 NodeLabelUpdate (org.neo4j.kernel.api.labelscan.NodeLabelUpdate)2