Search in sources :

Example 16 with StorageNodeCursor

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

the class StoreScanStageTest method shouldAbortScanOnStopped.

@Test
void shouldAbortScanOnStopped() {
    // given
    StubStorageCursors data = someData();
    EntityIdIterator entityIdIterator = new CursorEntityIdIterator<>(data.allocateNodeCursor(NULL));
    AtomicInteger numBatchesProcessed = new AtomicInteger();
    AtomicBoolean continueScanning = new AtomicBoolean(true);
    AbortingExternalUpdatesCheck externalUpdatesCheck = new AbortingExternalUpdatesCheck(1, continueScanning);
    var writer = new PropertyConsumer(() -> numBatchesProcessed.incrementAndGet());
    StoreScanStage<StorageNodeCursor> scan = new StoreScanStage(dbConfig, config, ct -> entityIdIterator, externalUpdatesCheck, continueScanning, data, new int[] { LABEL }, alwaysTrue(), writer, null, new NodeCursorBehaviour(data), id -> null, true, jobScheduler, PageCacheTracer.NULL, EmptyMemoryTracker.INSTANCE);
    // when
    runScan(scan);
    // then
    assertThat(numBatchesProcessed.get()).isEqualTo(2);
}
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 17 with StorageNodeCursor

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

the class NeoStoresTest method nodeAddProperty.

private StorageProperty nodeAddProperty(long nodeId, int key, Object value) {
    StorageProperty property = new PropertyKeyValue(key, Values.of(value));
    StorageProperty oldProperty = null;
    try (StorageNodeCursor nodeCursor = storageReader.allocateNodeCursor(NULL)) {
        nodeCursor.single(nodeId);
        if (nodeCursor.next()) {
            StorageProperty fetched = getProperty(key, nodeCursor.propertiesReference());
            if (fetched != null) {
                oldProperty = fetched;
            }
        }
    }
    if (oldProperty == null) {
        transactionState.nodeDoAddProperty(nodeId, key, property.value());
    } else {
        transactionState.nodeDoChangeProperty(nodeId, key, property.value());
    }
    return property;
}
Also used : PropertyKeyValue(org.neo4j.storageengine.api.PropertyKeyValue) StorageProperty(org.neo4j.storageengine.api.StorageProperty) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor)

Example 18 with StorageNodeCursor

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

the class TxStateTransactionDataSnapshot method takeSnapshot.

private void takeSnapshot(MemoryTracker memoryTracker) {
    var cursorContext = transaction.cursorContext();
    try (StorageNodeCursor node = store.allocateNodeCursor(cursorContext);
        StoragePropertyCursor properties = store.allocatePropertyCursor(cursorContext, memoryTracker)) {
        TokenRead tokenRead = transaction.tokenRead();
        snapshotRemovedNodes(memoryTracker, node, properties, tokenRead);
        snapshotRemovedRelationships(memoryTracker, properties, tokenRead);
        snapshotModifiedNodes(memoryTracker, node, properties, tokenRead);
        snapshotModifiedRelationships(memoryTracker, properties, tokenRead);
    } catch (PropertyKeyIdNotFoundKernelException e) {
        throw new IllegalStateException("An entity that does not exist was modified.", e);
    }
}
Also used : StoragePropertyCursor(org.neo4j.storageengine.api.StoragePropertyCursor) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) TokenRead(org.neo4j.internal.kernel.api.TokenRead) PropertyKeyIdNotFoundKernelException(org.neo4j.internal.kernel.api.exceptions.PropertyKeyIdNotFoundKernelException)

Example 19 with StorageNodeCursor

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

the class RecordStorageReaderLabelTest method labelsShouldNotLeakOutAsProperties.

@Test
void labelsShouldNotLeakOutAsProperties() throws Exception {
    // GIVEN
    long nodeId = createNode(map("name", "Node"), label1);
    int namePropertyKeyId = propertyKeyId("name");
    // WHEN THEN
    StorageNodeCursor nodeCursor = storageReader.allocateNodeCursor(NULL);
    StoragePropertyCursor propertyCursor = storageReader.allocatePropertyCursor(NULL, INSTANCE);
    nodeCursor.single(nodeId);
    assertTrue(nodeCursor.next());
    nodeCursor.properties(propertyCursor);
    assertTrue(propertyCursor.next());
    assertEquals(namePropertyKeyId, propertyCursor.propertyKey());
    assertFalse(propertyCursor.next());
}
Also used : StoragePropertyCursor(org.neo4j.storageengine.api.StoragePropertyCursor) StorageNodeCursor(org.neo4j.storageengine.api.StorageNodeCursor) Test(org.junit.jupiter.api.Test)

Example 20 with StorageNodeCursor

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

the class RecordStorageReaderRelTypesAndDegreeTest method testDegreeByDirectionAndTypeForDenseNodeWithPartiallyDeletedRelChains.

protected void testDegreeByDirectionAndTypeForDenseNodeWithPartiallyDeletedRelChains(boolean modifyInChain, boolean modifyOutChain, boolean modifyLoopChain) throws Exception {
    int inRelCount = randomRelCount();
    int outRelCount = randomRelCount();
    int loopRelCount = randomRelCount();
    long nodeId = createNode(inRelCount, outRelCount, loopRelCount);
    StorageNodeCursor cursor = newCursor(nodeId);
    if (modifyInChain) {
        markRandomRelsInGroupNotInUse(nodeId, IN);
    }
    if (modifyOutChain) {
        markRandomRelsInGroupNotInUse(nodeId, OUT);
    }
    if (modifyLoopChain) {
        markRandomRelsInGroupNotInUse(nodeId, LOOP);
    }
    assertEquals(0, degreeForDirectionAndType(cursor, OUTGOING, relTypeId(IN)));
    assertEquals(outRelCount, degreeForDirectionAndType(cursor, OUTGOING, relTypeId(OUT)));
    assertEquals(loopRelCount, degreeForDirectionAndType(cursor, OUTGOING, relTypeId(LOOP)));
    assertEquals(0, degreeForDirectionAndType(cursor, INCOMING, relTypeId(OUT)));
    assertEquals(inRelCount, degreeForDirectionAndType(cursor, INCOMING, relTypeId(IN)));
    assertEquals(loopRelCount, degreeForDirectionAndType(cursor, INCOMING, relTypeId(LOOP)));
    assertEquals(inRelCount, degreeForDirectionAndType(cursor, BOTH, relTypeId(IN)));
    assertEquals(outRelCount, degreeForDirectionAndType(cursor, BOTH, relTypeId(OUT)));
    assertEquals(loopRelCount, degreeForDirectionAndType(cursor, BOTH, relTypeId(LOOP)));
}
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