Search in sources :

Example 6 with NodeUpdates

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

the class MultiIndexPopulationConcurrentUpdatesIT method applyConcurrentAddsToPopulatedIndex.

@Test
public void applyConcurrentAddsToPopulatedIndex() throws Throwable {
    List<NodeUpdates> updates = new ArrayList<>(2);
    updates.add(NodeUpdates.forNode(6, id(COUNTRY_LABEL)).added(propertyId, "Denmark").build());
    updates.add(NodeUpdates.forNode(7, id(CAR_LABEL)).added(propertyId, "BMW").build());
    launchCustomIndexPopulation(labelsNameIdMap, propertyId, updates);
    waitAndActivateIndexes(labelsNameIdMap, propertyId);
    try (Transaction ignored = embeddedDatabase.beginTx()) {
        Integer countryLabelId = labelsNameIdMap.get(COUNTRY_LABEL);
        Integer carLabelId = labelsNameIdMap.get(CAR_LABEL);
        try (IndexReader indexReader = getIndexReader(propertyId, countryLabelId)) {
            assertEquals("Should be added by concurrent add.", 1, indexReader.countIndexedNodes(6, "Denmark"));
        }
        try (IndexReader indexReader = getIndexReader(propertyId, carLabelId)) {
            assertEquals("Should be added by concurrent add.", 1, indexReader.countIndexedNodes(7, "BMW"));
        }
    }
}
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 7 with NodeUpdates

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

the class BatchingMultipleIndexPopulatorTest method batchIsFlushedWhenThresholdReached.

@Test
public void batchIsFlushedWhenThresholdReached() throws Exception {
    setProperty(BATCH_SIZE_NAME, 2);
    NodeUpdates update1 = nodeUpdates(1, propertyId, "foo", labelId);
    NodeUpdates update2 = nodeUpdates(2, propertyId, "bar", labelId);
    NodeUpdates update3 = nodeUpdates(3, propertyId, "baz", labelId);
    IndexStoreView storeView = newStoreView(update1, update2, update3);
    BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(storeView, sameThreadExecutor(), NullLogProvider.getInstance());
    IndexPopulator populator = addPopulator(batchingPopulator, index1);
    batchingPopulator.indexAllNodes().run();
    verify(populator).add(Arrays.asList(forIndex(update1, index1), forIndex(update2, index1)));
    verify(populator).add(singletonList(forIndex(update3, 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 8 with NodeUpdates

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

the class IndexingServiceTest method recoveredUpdatesShouldBeApplied.

@SuppressWarnings("unchecked")
@Test
public void recoveredUpdatesShouldBeApplied() throws Exception {
    // Given
    final long nodeId1 = 1;
    final long nodeId2 = 2;
    final PrimitiveLongSet nodeIds = setOf(nodeId1, nodeId2);
    final NodeUpdates nodeUpdate1 = addNodeUpdate(nodeId1, "foo");
    final NodeUpdates nodeUpdate2 = addNodeUpdate(nodeId2, "bar");
    final Set<NodeUpdates> nodeUpdates = asSet(nodeUpdate1, nodeUpdate2);
    final AtomicBoolean applyingRecoveredDataCalled = new AtomicBoolean();
    final AtomicBoolean appliedRecoveredDataCalled = new AtomicBoolean();
    // Mockito not used here because it does not work well with mutable objects (set of recovered node ids in
    // this case, which is cleared at the end of recovery).
    // See https://code.google.com/p/mockito/issues/detail?id=126 and
    // https://groups.google.com/forum/#!topic/mockito/_A4BpsEAY9s
    IndexingService.Monitor monitor = new IndexingService.MonitorAdapter() {

        @Override
        public void applyingRecoveredData(PrimitiveLongSet recoveredNodeIds) {
            assertEquals(nodeIds, recoveredNodeIds);
            applyingRecoveredDataCalled.set(true);
        }

        @Override
        public void appliedRecoveredData(Iterable<NodeUpdates> updates) {
            assertEquals(nodeUpdates, Iterables.asSet(updates));
            appliedRecoveredDataCalled.set(true);
        }
    };
    IndexingService indexing = newIndexingServiceWithMockedDependencies(populator, accessor, withData(), monitor);
    doAnswer(nodeUpdatesAnswer(nodeUpdate1)).when(storeView).nodeAsUpdates(eq(nodeId1), any(Collection.class));
    doAnswer(nodeUpdatesAnswer(nodeUpdate2)).when(storeView).nodeAsUpdates(eq(nodeId2), any(Collection.class));
    // When
    life.init();
    IndexUpdates updates = nodeIdsAsIndexUpdates(nodeIds);
    indexing.apply(updates);
    life.start();
    // Then
    assertTrue("applyingRecoveredData was not called", applyingRecoveredDataCalled.get());
    assertTrue("appliedRecoveredData was not called", appliedRecoveredDataCalled.get());
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DirectIndexUpdates(org.neo4j.kernel.impl.transaction.state.DirectIndexUpdates) IndexUpdates(org.neo4j.kernel.impl.transaction.state.IndexUpdates) PrimitiveLongSet(org.neo4j.collection.primitive.PrimitiveLongSet) BoundedIterable(org.neo4j.helpers.collection.BoundedIterable) Iterators.asCollection(org.neo4j.helpers.collection.Iterators.asCollection) Collection(java.util.Collection) Test(org.junit.Test)

Example 9 with NodeUpdates

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

the class BatchingMultipleIndexPopulatorTest method executorShutdownAfterStoreScanCompletes.

@Test
public void executorShutdownAfterStoreScanCompletes() throws Exception {
    NodeUpdates update = nodeUpdates(1, propertyId, "foo", labelId);
    IndexStoreView storeView = newStoreView(update);
    ExecutorService executor = mock(ExecutorService.class);
    when(executor.awaitTermination(anyLong(), any())).thenReturn(true);
    BatchingMultipleIndexPopulator batchingPopulator = new BatchingMultipleIndexPopulator(storeView, executor, NullLogProvider.getInstance());
    StoreScan<IndexPopulationFailedKernelException> storeScan = batchingPopulator.indexAllNodes();
    verify(executor, never()).shutdown();
    storeScan.run();
    verify(executor).shutdown();
    verify(executor).awaitTermination(anyLong(), any());
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) NeoStoreIndexStoreView(org.neo4j.kernel.impl.transaction.state.storeview.NeoStoreIndexStoreView) IndexPopulationFailedKernelException(org.neo4j.kernel.api.exceptions.index.IndexPopulationFailedKernelException) ExecutorService(java.util.concurrent.ExecutorService) Test(org.junit.Test)

Example 10 with NodeUpdates

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

the class TransactionRecordStateTest method shouldConvertMixedLabelAdditionAndSetPropertyToNodePropertyUpdates.

@Test
public void shouldConvertMixedLabelAdditionAndSetPropertyToNodePropertyUpdates() throws Exception {
    // GIVEN
    NeoStores neoStores = neoStoresRule.open();
    long nodeId = 0;
    TransactionRecordState recordState = newTransactionRecordState(neoStores);
    recordState.nodeCreate(nodeId);
    recordState.nodeAddProperty(nodeId, propertyId1, value1);
    addLabelsToNode(recordState, nodeId, oneLabelId);
    apply(neoStores, recordState);
    // WHEN
    recordState = newTransactionRecordState(neoStores);
    recordState.nodeAddProperty(nodeId, propertyId2, value2);
    addLabelsToNode(recordState, nodeId, secondLabelId);
    Iterable<NodeUpdates> indexUpdates = indexUpdatesOf(neoStores, recordState);
    // THEN
    NodeUpdates expected = NodeUpdates.forNode(nodeId, oneLabelId, bothLabelIds).added(propertyId2, value2).buildWithExistingProperties(Property.stringProperty(propertyId1, value1));
    assertEquals(expected, Iterables.single(indexUpdates));
}
Also used : NodeUpdates(org.neo4j.kernel.api.index.NodeUpdates) NeoStores(org.neo4j.kernel.impl.store.NeoStores) 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