Search in sources :

Example 21 with NodeUpdates

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

the class NeoStoreIndexStoreViewTest method processAllNodeProperties.

@Test
public void processAllNodeProperties() throws Exception {
    CopyUpdateVisitor propertyUpdateVisitor = new CopyUpdateVisitor();
    StoreViewNodeStoreScan storeViewNodeStoreScan = new StoreViewNodeStoreScan(neoStores.getNodeStore(), locks, neoStores.getPropertyStore(), null, propertyUpdateVisitor, new int[] { labelId }, id -> true);
    NodeRecord nodeRecord = new NodeRecord(-1);
    neoStores.getNodeStore().getRecord(1L, nodeRecord, RecordLoad.FORCE);
    storeViewNodeStoreScan.process(nodeRecord);
    NodeUpdates propertyUpdates = propertyUpdateVisitor.getPropertyUpdates();
    assertNotNull("Visitor should containts container with updates.", propertyUpdates);
    assert propertyUpdates.forIndex(SchemaDescriptorFactory.forLabel(0, 0)).isPresent();
    assert propertyUpdates.forIndex(SchemaDescriptorFactory.forLabel(0, 1)).isPresent();
    assert propertyUpdates.forIndex(SchemaDescriptorFactory.forLabel(0, 0, 1)).isPresent();
    assert !propertyUpdates.forIndex(SchemaDescriptorFactory.forLabel(1, 1)).isPresent();
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) NodeRecord(org.neo4j.kernel.impl.store.record.NodeRecord) Test(org.junit.Test)

Example 22 with NodeUpdates

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

the class MultiIndexPopulationConcurrentUpdatesIT method applyConcurrentDeletesToPopulatedIndex.

@Test
public void applyConcurrentDeletesToPopulatedIndex() throws Throwable {
    List<NodeUpdates> updates = new ArrayList<>(2);
    updates.add(NodeUpdates.forNode(0, id(COUNTRY_LABEL)).removed(propertyId, "Sweden").build());
    updates.add(NodeUpdates.forNode(3, id(COLOR_LABEL)).removed(propertyId, "green").build());
    launchCustomIndexPopulation(labelsNameIdMap, propertyId, updates);
    waitAndActivateIndexes(labelsNameIdMap, propertyId);
    try (Transaction ignored = embeddedDatabase.beginTx()) {
        Integer countryLabelId = labelsNameIdMap.get(COUNTRY_LABEL);
        Integer colorLabelId = labelsNameIdMap.get(COLOR_LABEL);
        try (IndexReader indexReader = getIndexReader(propertyId, countryLabelId)) {
            assertEquals("Should be removed by concurrent remove.", 0, indexReader.countIndexedNodes(0, "Sweden"));
        }
        try (IndexReader indexReader = getIndexReader(propertyId, colorLabelId)) {
            assertEquals("Should be removed by concurrent remove.", 0, indexReader.countIndexedNodes(3, "green"));
        }
    }
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) Transaction(org.neo4j.graphdb.Transaction) ArrayList(java.util.ArrayList) IndexReader(org.neo4j.storageengine.api.schema.IndexReader) Test(org.junit.Test)

Example 23 with NodeUpdates

use of org.neo4j.kernel.api.index.NodeUpdates 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)

Example 24 with NodeUpdates

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

the class BatchingMultipleIndexPopulatorTest method newStoreView.

@SuppressWarnings("unchecked")
private static IndexStoreView newStoreView(NodeUpdates... updates) {
    IndexStoreView storeView = mock(IndexStoreView.class);
    when(storeView.visitNodes(any(), any(), any(), any(), anyBoolean())).thenAnswer(invocation -> {
        Object visitorArg = invocation.getArguments()[2];
        Visitor<NodeUpdates, IndexPopulationFailedKernelException> visitor = (Visitor<NodeUpdates, IndexPopulationFailedKernelException>) visitorArg;
        return new IndexEntryUpdateScan(updates, visitor);
    });
    return storeView;
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) Visitor(org.neo4j.helpers.collection.Visitor) NeoStoreIndexStoreView(org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException)

Example 25 with NodeUpdates

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

the class IndexPopulationJobTest method shouldBeAbleToCancelPopulationJob.

@Test
public void shouldBeAbleToCancelPopulationJob() throws Exception {
    // GIVEN
    createNode(map(name, "Mattias"), FIRST);
    IndexPopulator populator = mock(IndexPopulator.class);
    FlippableIndexProxy index = mock(FlippableIndexProxy.class);
    IndexStoreView storeView = mock(IndexStoreView.class);
    ControlledStoreScan storeScan = new ControlledStoreScan();
    when(storeView.visitNodes(any(int[].class), any(IntPredicate.class), Matchers.<Visitor<NodeUpdates, RuntimeException>>any(), Matchers.<Visitor<NodeLabelUpdate, RuntimeException>>any(), anyBoolean())).thenReturn(storeScan);
    final IndexPopulationJob job = newIndexPopulationJob(populator, index, storeView, NullLogProvider.getInstance(), false);
    OtherThreadExecutor<Void> populationJobRunner = cleanup.add(new OtherThreadExecutor<>("Population job test runner", null));
    Future<Void> runFuture = populationJobRunner.executeDontWait(state -> {
        job.run();
        return null;
    });
    storeScan.latch.waitForAllToStart();
    job.cancel().get();
    storeScan.latch.waitForAllToFinish();
    // WHEN
    runFuture.get();
    // THEN
    verify(populator, times(1)).close(false);
    verify(index, times(0)).flip(Matchers.any(), Matchers.any());
}
Also used : IntPredicate(java.util.function.IntPredicate) NodeLabelUpdate(org.neo4j.kernel.api.labelscan.NodeLabelUpdate) NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) IndexPopulator(org.neo4j.kernel.api.index.IndexPopulator) Test(org.junit.Test)

Aggregations

NodeUpdates (org.neo4j.kernel.api.index.NodeUpdates)28 Test (org.junit.Test)25 NeoStores (org.neo4j.kernel.impl.store.NeoStores)9 PropertyRecord (org.neo4j.kernel.impl.store.record.PropertyRecord)8 DefinedProperty (org.neo4j.kernel.api.properties.DefinedProperty)5 NeoStoreIndexStoreView (org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView)5 ArrayList (java.util.ArrayList)4 IndexPopulator (org.neo4j.kernel.api.index.IndexPopulator)4 Transaction (org.neo4j.graphdb.Transaction)3 NodeRecord (org.neo4j.kernel.impl.store.record.NodeRecord)3 Collection (java.util.Collection)2 Visitor (org.neo4j.helpers.collection.Visitor)2 KernelException (org.neo4j.kernel.api.exceptions.KernelException)2 NodeLabelUpdate (org.neo4j.kernel.api.labelscan.NodeLabelUpdate)2 PropertyBlock (org.neo4j.kernel.impl.store.record.PropertyBlock)2 IndexReader (org.neo4j.storageengine.api.schema.IndexReader)2 File (java.io.File)1 IOException (java.io.IOException)1 PrintStream (java.io.PrintStream)1 Boolean.parseBoolean (java.lang.Boolean.parseBoolean)1