Search in sources :

Example 26 with IndexPopulator

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

the class FullCheckIntegrationTest method shouldNotReportIndexInconsistenciesIfIndexIsFailed.

@Test
public void shouldNotReportIndexInconsistenciesIfIndexIsFailed() throws Exception {
    // this test fails all indexes, and then destroys a record and makes sure we only get a failure for
    // the label scan store but not for any index
    // given
    DirectStoreAccess storeAccess = fixture.directStoreAccess();
    // fail all indexes
    Iterator<IndexRule> rules = new SchemaStorage(storeAccess.nativeStores().getSchemaStore()).indexesGetAll();
    while (rules.hasNext()) {
        IndexRule rule = rules.next();
        IndexSamplingConfig samplingConfig = new IndexSamplingConfig(Config.empty());
        IndexPopulator populator = storeAccess.indexes().getPopulator(rule.getId(), rule.getIndexDescriptor(), samplingConfig);
        populator.markAsFailed("Oh noes! I was a shiny index and then I was failed");
        populator.close(false);
    }
    for (Long indexedNodeId : indexedNodes) {
        storeAccess.nativeStores().getNodeStore().updateRecord(notInUse(new NodeRecord(indexedNodeId, false, -1, -1)));
    }
    // when
    ConsistencySummaryStatistics stats = check();
    // then
    on(stats).verify(RecordType.LABEL_SCAN_DOCUMENT, 1).verify(RecordType.COUNTS, 3).andThatsAllFolks();
}
Also used : IndexRule(org.neo4j.kernel.impl.store.record.IndexRule) SchemaRuleUtil.constraintIndexRule(org.neo4j.consistency.checking.SchemaRuleUtil.constraintIndexRule) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) SchemaStorage(org.neo4j.kernel.impl.store.SchemaStorage) DirectStoreAccess(org.neo4j.kernel.api.direct.DirectStoreAccess) AtomicLong(java.util.concurrent.atomic.AtomicLong) ConsistencySummaryStatistics(org.neo4j.consistency.report.ConsistencySummaryStatistics) Test(org.junit.Test)

Example 27 with IndexPopulator

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

the class BatchInsertTest method dbWithIndexAndSingleIndexedNode.

private long dbWithIndexAndSingleIndexedNode() throws Exception {
    IndexPopulator populator = mock(IndexPopulator.class);
    SchemaIndexProvider provider = mock(SchemaIndexProvider.class);
    when(provider.getProviderDescriptor()).thenReturn(InMemoryIndexProviderFactory.PROVIDER_DESCRIPTOR);
    when(provider.getPopulator(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(populator);
    BatchInserter inserter = newBatchInserterWithSchemaIndexProvider(singleInstanceSchemaIndexProviderFactory(InMemoryIndexProviderFactory.KEY, provider));
    inserter.createDeferredSchemaIndex(label("Hacker")).on("handle").create();
    long nodeId = inserter.createNode(map("handle", "Jakewins"), label("Hacker"));
    inserter.shutdown();
    return nodeId;
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor)

Example 28 with IndexPopulator

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

the class BatchInsertTest method shouldRunConstraintPopulationJobAtShutdown.

@Test
public void shouldRunConstraintPopulationJobAtShutdown() throws Throwable {
    // GIVEN
    IndexPopulator populator = mock(IndexPopulator.class);
    SchemaIndexProvider provider = mock(SchemaIndexProvider.class);
    when(provider.getProviderDescriptor()).thenReturn(InMemoryIndexProviderFactory.PROVIDER_DESCRIPTOR);
    when(provider.getPopulator(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class))).thenReturn(populator);
    BatchInserter inserter = newBatchInserterWithSchemaIndexProvider(singleInstanceSchemaIndexProviderFactory(InMemoryIndexProviderFactory.KEY, provider));
    inserter.createDeferredConstraint(label("Hacker")).assertPropertyIsUnique("handle").create();
    long nodeId = inserter.createNode(map("handle", "Jakewins"), label("Hacker"));
    // WHEN
    inserter.shutdown();
    // THEN
    verify(provider).init();
    verify(provider).start();
    verify(provider).getPopulator(anyLong(), any(NewIndexDescriptor.class), any(IndexSamplingConfig.class));
    verify(populator).create();
    verify(populator).add(singletonList(IndexEntryUpdate.add(nodeId, internalUniqueIndex.schema(), "Jakewins")));
    verify(populator).verifyDeferredConstraints(any(PropertyAccessor.class));
    verify(populator).close(true);
    verify(provider).stop();
    verify(provider).shutdown();
    verifyNoMoreInteractions(populator);
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexSamplingConfig(org.neo4j.kernel.impl.api.index.sampling.IndexSamplingConfig) BatchInserter(org.neo4j.unsafe.batchinsert.BatchInserter) SchemaIndexProvider(org.neo4j.kernel.api.index.SchemaIndexProvider) NewIndexDescriptor(org.neo4j.kernel.api.schema_new.index.NewIndexDescriptor) PropertyAccessor(org.neo4j.kernel.api.index.PropertyAccessor) Test(org.junit.Test)

Example 29 with IndexPopulator

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

the class BatchingMultipleIndexPopulatorTest method populateFromQueueDoesNothingIfThresholdNotReached.

@Test
public void populateFromQueueDoesNothingIfThresholdNotReached() throws Exception {
    setProperty(QUEUE_THRESHOLD_NAME, 5);
    BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(mock(IndexStoreView.class), mock(ExecutorService.class), NullLogProvider.getInstance());
    IndexPopulator populator = addPopulator(batchingPopulator, index1);
    IndexUpdater updater = mock(IndexUpdater.class);
    when(populator.newPopulatingUpdater(any())).thenReturn(updater);
    IndexEntryUpdate update1 = IndexEntryUpdate.add(1, index1.schema(), "foo");
    IndexEntryUpdate update2 = IndexEntryUpdate.add(2, index1.schema(), "bar");
    batchingPopulator.queue(update1);
    batchingPopulator.queue(update2);
    batchingPopulator.populateFromQueueBatched(42);
    verify(updater, never()).process(any());
    verify(populator, never()).newPopulatingUpdater(any());
}
Also used : IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) IndexEntryUpdate(org.neo4j.kernel.api.index.IndexEntryUpdate) NeoStoreIndexStoreView(org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView) ExecutorService(java.util.concurrent.ExecutorService) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater) Test(org.junit.Test)

Example 30 with IndexPopulator

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

the class BatchingMultipleIndexPopulatorTest method populatorMarkedAsFailedAndUpdatesNotAdded.

@Test
public void populatorMarkedAsFailedAndUpdatesNotAdded() throws Exception {
    setProperty(BATCH_SIZE_NAME, 2);
    NodeUpdates update1 = nodeUpdates(1, propertyId, "aaa", labelId);
    NodeUpdates update2 = nodeUpdates(1, propertyId, "bbb", labelId);
    NodeUpdates update3 = nodeUpdates(1, propertyId, "ccc", labelId);
    NodeUpdates update4 = nodeUpdates(1, propertyId, "ddd", labelId);
    NodeUpdates update5 = nodeUpdates(1, propertyId, "eee", labelId);
    IndexStoreView storeView = newStoreView(update1, update2, update3, update4, update5);
    RuntimeException batchFlushError = new RuntimeException("Batch failed");
    BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(storeView, sameThreadExecutor(), NullLogProvider.getInstance());
    IndexPopulator populator = addPopulator(batchingPopulator, index1);
    doThrow(batchFlushError).when(populator).add(Arrays.asList(forIndex(update3, index1), forIndex(update4, index1)));
    batchingPopulator.indexAllNodes().run();
    verify(populator).add(Arrays.asList(forIndex(update1, index1), forIndex(update2, index1)));
    verify(populator).add(Arrays.asList(forIndex(update3, index1), forIndex(update4, index1)));
    verify(populator).markAsFailed(failure(batchFlushError).asString());
    verify(populator, never()).add(singletonList(forIndex(update5, index1)));
}
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)

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