Search in sources :

Example 26 with StorageNodeCursor

use of org.neo4j.storageengine.api.StorageNodeCursor in project neo4j by neo4j.

the class GenerateIndexUpdatesStepTest method allNodeIds.

private static long[] allNodeIds(StubStorageCursors data) {
    try (StorageNodeCursor cursor = data.allocateNodeCursor(NULL)) {
        cursor.scan();
        MutableLongList ids = LongLists.mutable.empty();
        while (cursor.next()) {
            ids.add(cursor.entityReference());
        }
        return ids.toArray();
    }
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor)

Example 27 with StorageNodeCursor

use of org.neo4j.storageengine.api.StorageNodeCursor in project neo4j by neo4j.

the class GenerateIndexUpdatesStepTest method shouldGenerateEntityPropertyUpdatesForRelevantPropertyTokens.

@ValueSource(booleans = { true, false })
@ParameterizedTest
void shouldGenerateEntityPropertyUpdatesForRelevantPropertyTokens(boolean alsoWrite) throws Exception {
    // given
    StubStorageCursors data = new StubStorageCursors();
    int numNodes = 10;
    MutableLongSet relevantNodeIds = LongSets.mutable.empty();
    for (int i = 0; i < numNodes; i++) {
        StubStorageCursors.NodeData node = data.withNode(i).labels(LABEL);
        Map<String, Value> properties = new HashMap<>();
        properties.put(KEY, stringValue("name_" + i));
        if (i % 2 == 0) {
            properties.put(OTHER_KEY, intValue(i));
            relevantNodeIds.add(i);
        }
        node.properties(properties);
    }
    int otherKeyId = data.propertyKeyTokenHolder().getIdByName(OTHER_KEY);
    TestPropertyScanConsumer scanConsumer = new TestPropertyScanConsumer();
    GenerateIndexUpdatesStep<StorageNodeCursor> step = new GenerateIndexUpdatesStep(new SimpleStageControl(), DEFAULT, data, pid -> pid == otherKeyId, new NodeCursorBehaviour(data), new int[] { LABEL }, scanConsumer, null, NO_LOCKING, 1, mebiBytes(1), alsoWrite, PageCacheTracer.NULL, INSTANCE);
    // when
    CapturingBatchSender<GeneratedIndexUpdates> sender = new CapturingBatchSender<>();
    step.process(allNodeIds(data), sender, NULL);
    // then
    if (alsoWrite) {
        for (TestPropertyScanConsumer.Record update : scanConsumer.batches.get(0)) {
            assertThat(relevantNodeIds.remove(update.getEntityId())).isTrue();
        }
    } else {
        GeneratedIndexUpdates updates = sender.batches.get(0);
        updates.completeBatch();
        for (TestPropertyScanConsumer.Record update : scanConsumer.batches.get(0)) {
            assertThat(relevantNodeIds.remove(update.getEntityId())).isTrue();
        }
    }
    assertThat(relevantNodeIds.isEmpty()).isTrue();
}
Also used : SimpleStageControl(org.neo4j.internal.batchimport.staging.SimpleStageControl) HashMap(java.util.HashMap) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) Value(org.neo4j.values.storable.Value) Values.stringValue(org.neo4j.values.storable.Values.stringValue) Values.intValue(org.neo4j.values.storable.Values.intValue) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) GeneratedIndexUpdates(org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 28 with StorageNodeCursor

use of org.neo4j.storageengine.api.StorageNodeCursor in project neo4j by neo4j.

the class StoreScanStageTest method shouldApplyExternalUpdatesIfThereAreSuch.

@Test
void shouldApplyExternalUpdatesIfThereAreSuch() {
    // given
    StubStorageCursors data = someData();
    EntityIdIterator entityIdIterator = new CursorEntityIdIterator<>(data.allocateNodeCursor(NULL));
    AtomicInteger numBatchesProcessed = new AtomicInteger();
    ControlledExternalUpdatesCheck externalUpdatesCheck = new ControlledExternalUpdatesCheck(config.batchSize(), 2, numBatchesProcessed);
    var writer = new PropertyConsumer(() -> numBatchesProcessed.incrementAndGet());
    StoreScanStage<StorageNodeCursor> scan = new StoreScanStage(dbConfig, config, ct -> entityIdIterator, externalUpdatesCheck, new AtomicBoolean(true), data, new int[] { LABEL }, alwaysTrue(), writer, null, new NodeCursorBehaviour(data), id -> null, true, jobScheduler, PageCacheTracer.NULL, EmptyMemoryTracker.INSTANCE);
    // when
    runScan(scan);
    // then
    assertThat(externalUpdatesCheck.applyCallCount).isEqualTo(1);
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CursorEntityIdIterator(org.neo4j.kernel.impl.transaction.state.storeview.PropertyAwareEntityStoreScan.CursorEntityIdIterator) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) StubStorageCursors(org.neo4j.storageengine.api.StubStorageCursors) CursorEntityIdIterator(org.neo4j.kernel.impl.transaction.state.storeview.PropertyAwareEntityStoreScan.CursorEntityIdIterator) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 29 with StorageNodeCursor

use of org.neo4j.storageengine.api.StorageNodeCursor in project neo4j by neo4j.

the class NeoStoresTest method allocateNodeCursor.

private StorageNodeCursor allocateNodeCursor(long nodeId) {
    StorageNodeCursor nodeCursor = storageReader.allocateNodeCursor(NULL);
    nodeCursor.single(nodeId);
    return nodeCursor;
}
Also used : StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor)

Aggregations

StorageNodeCursor (org.neo4j.storageengine.api.StorageNodeCursor)29 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 StubStorageCursors (org.neo4j.storageengine.api.StubStorageCursors)12 Test (org.junit.jupiter.api.Test)8 ValueSource (org.junit.jupiter.params.provider.ValueSource)7 SimpleStageControl (org.neo4j.internal.batchimport.staging.SimpleStageControl)7 GeneratedIndexUpdates (org.neo4j.kernel.impl.transaction.state.storeview.GenerateIndexUpdatesStep.GeneratedIndexUpdates)7 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)5 CursorEntityIdIterator (org.neo4j.kernel.impl.transaction.state.storeview.PropertyAwareEntityStoreScan.CursorEntityIdIterator)5 StoragePropertyCursor (org.neo4j.storageengine.api.StoragePropertyCursor)5 HashSet (java.util.HashSet)4 Value (org.neo4j.values.storable.Value)3 HashMap (java.util.HashMap)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)2 EntityUpdates (org.neo4j.storageengine.api.EntityUpdates)2 Values.intValue (org.neo4j.values.storable.Values.intValue)2 Values.stringValue (org.neo4j.values.storable.Values.stringValue)2 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)1