Search in sources :

Example 1 with IndexUpdates

use of org.neo4j.kernel.impl.transaction.state.IndexUpdates 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 2 with IndexUpdates

use of org.neo4j.kernel.impl.transaction.state.IndexUpdates in project neo4j by neo4j.

the class IndexingService method applyRecoveredUpdates.

private void applyRecoveredUpdates() throws IOException, IndexEntryConflictException {
    if (log.isDebugEnabled()) {
        log.debug("Applying recovered updates: " + recoveredNodeIds);
    }
    monitor.applyingRecoveredData(recoveredNodeIds);
    if (!recoveredNodeIds.isEmpty()) {
        try (IndexUpdaterMap updaterMap = indexMapRef.createIndexUpdaterMap(IndexUpdateMode.RECOVERY)) {
            for (IndexUpdater updater : updaterMap) {
                updater.remove(recoveredNodeIds);
            }
            IndexUpdates updates = readRecoveredUpdatesFromStore();
            apply(updates, IndexUpdateMode.RECOVERY);
            monitor.appliedRecoveredData(updates);
        }
    }
    recoveredNodeIds.clear();
}
Also used : DirectIndexUpdates(org.neo4j.kernel.impl.transaction.state.DirectIndexUpdates) IndexUpdates(org.neo4j.kernel.impl.transaction.state.IndexUpdates) IndexUpdater(org.neo4j.kernel.api.index.IndexUpdater)

Aggregations

DirectIndexUpdates (org.neo4j.kernel.impl.transaction.state.DirectIndexUpdates)2 IndexUpdates (org.neo4j.kernel.impl.transaction.state.IndexUpdates)2 Collection (java.util.Collection)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 Test (org.junit.Test)1 PrimitiveLongSet (org.neo4j.collection.primitive.PrimitiveLongSet)1 BoundedIterable (org.neo4j.helpers.collection.BoundedIterable)1 Iterators.asCollection (org.neo4j.helpers.collection.Iterators.asCollection)1 IndexUpdater (org.neo4j.kernel.api.index.IndexUpdater)1 NodeUpdates (org.neo4j.kernel.api.index.NodeUpdates)1