Search in sources :

Example 6 with TokenPredicate

use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.

the class NodeScanIT method trackPageCacheAccessOnNodeLabelScan.

@Test
void trackPageCacheAccessOnNodeLabelScan() throws KernelException {
    var testLabel = Label.label("testLabel");
    try (KernelTransaction tx = kernel.beginTransaction(IMPLICIT, read())) {
        var cursorContext = tx.cursorContext();
        assertThat(cursorContext.getCursorTracer().pins()).isZero();
        var label = tx.tokenRead().nodeLabel(testLabel.name());
        IndexDescriptor index = tx.schemaRead().index(SchemaDescriptor.forAnyEntityTokens(EntityType.NODE)).next();
        TokenReadSession tokenReadSession = tx.dataRead().tokenReadSession(index);
        try (NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(cursorContext)) {
            tx.dataRead().nodeLabelScan(tokenReadSession, cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(label));
            assertThat(cursorContext.getCursorTracer().pins()).isNotZero();
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TokenReadSession(org.neo4j.internal.kernel.api.TokenReadSession) TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) Test(org.junit.jupiter.api.Test)

Example 7 with TokenPredicate

use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.

the class KernelReadTracerTest method shouldTraceLabelScan.

@Test
void shouldTraceLabelScan() throws KernelException {
    // given
    TestKernelReadTracer tracer = new TestKernelReadTracer();
    int barId = token.labelGetOrCreateForName("Bar");
    List<TraceEvent> expectedEvents = new ArrayList<>();
    expectedEvents.add(OnLabelScan(barId));
    try (NodeLabelIndexCursor cursor = cursors.allocateNodeLabelIndexCursor(NULL)) {
        // when
        cursor.setTracer(tracer);
        read.nodeLabelScan(getTokenReadSession(tx, EntityType.NODE), cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(barId));
        while (cursor.next()) {
            expectedEvents.add(OnNode(cursor.nodeReference()));
        }
    }
    // then
    tracer.assertEvents(expectedEvents);
}
Also used : TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) ArrayList(java.util.ArrayList) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) TraceEvent(org.neo4j.kernel.impl.newapi.TestKernelReadTracer.TraceEvent) Test(org.junit.jupiter.api.Test)

Example 8 with TokenPredicate

use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.

the class NodeLabelTokenIndexCursorTest method shouldFindNodesByLabelInTx.

@Test
void shouldFindNodesByLabelInTx() throws Exception {
    long inStore;
    long deletedInTx;
    long createdInTx;
    try (KernelTransaction tx = beginTransaction()) {
        inStore = createNode(tx.dataWrite(), labelOne);
        createNode(tx.dataWrite(), labelTwo);
        deletedInTx = createNode(tx.dataWrite(), labelOne);
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        tx.dataWrite().nodeDelete(deletedInTx);
        createdInTx = createNode(tx.dataWrite(), labelOne);
        createNode(tx.dataWrite(), labelTwo);
        Read read = tx.dataRead();
        var session = getTokenReadSession(tx);
        try (NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
            MutableLongSet uniqueIds = new LongHashSet();
            // when
            read.nodeLabelScan(session, cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(labelOne));
            // then
            assertNodes(cursor, uniqueIds, inStore, createdInTx);
        }
    }
}
Also used : Read(org.neo4j.internal.kernel.api.Read) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LongHashSet(org.eclipse.collections.impl.set.mutable.primitive.LongHashSet) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) Test(org.junit.jupiter.api.Test)

Example 9 with TokenPredicate

use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.

the class NodeTransactionStateTestBase method shouldFindUpdatedNodeInInLabelScan.

@Test
void shouldFindUpdatedNodeInInLabelScan() throws Exception {
    // Given
    Node node = createNode();
    try (KernelTransaction tx = beginTransaction();
        NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
        // when
        int label = tx.tokenWrite().labelGetOrCreateForName("label");
        tx.dataWrite().nodeAddLabel(node.node, label);
        tx.dataRead().nodeLabelScan(getTokenReadSession(tx, EntityType.NODE), cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(label));
        // then
        assertTrue(cursor.next());
        assertEquals(node.node, cursor.nodeReference());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) Test(org.junit.jupiter.api.Test)

Example 10 with TokenPredicate

use of org.neo4j.internal.kernel.api.TokenPredicate in project neo4j by neo4j.

the class NodeTransactionStateTestBase method shouldNotFindDeletedNodeInLabelScan.

@Test
void shouldNotFindDeletedNodeInLabelScan() throws Exception {
    // Given
    Node node = createNode("label");
    try (KernelTransaction tx = beginTransaction();
        NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
        // when
        tx.dataWrite().nodeDelete(node.node);
        tx.dataRead().nodeLabelScan(getTokenReadSession(tx, EntityType.NODE), cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(node.labels[0]));
        // then
        assertFalse(cursor.next());
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) TokenPredicate(org.neo4j.internal.kernel.api.TokenPredicate) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) Test(org.junit.jupiter.api.Test)

Aggregations

TokenPredicate (org.neo4j.internal.kernel.api.TokenPredicate)32 Test (org.junit.jupiter.api.Test)16 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)13 NodeLabelIndexCursor (org.neo4j.internal.kernel.api.NodeLabelIndexCursor)11 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)6 KernelException (org.neo4j.exceptions.KernelException)5 IndexNotFoundKernelException (org.neo4j.internal.kernel.api.exceptions.schema.IndexNotFoundKernelException)5 SimpleEntityTokenClient (org.neo4j.storageengine.api.schema.SimpleEntityTokenClient)5 ArrayList (java.util.ArrayList)4 TokenReadSession (org.neo4j.internal.kernel.api.TokenReadSession)4 InvalidTransactionTypeKernelException (org.neo4j.internal.kernel.api.exceptions.InvalidTransactionTypeKernelException)4 SchemaKernelException (org.neo4j.internal.kernel.api.exceptions.schema.SchemaKernelException)4 QueryExecutionKernelException (org.neo4j.kernel.impl.query.QueryExecutionKernelException)4 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)2 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)2 Read (org.neo4j.internal.kernel.api.Read)2 RelationshipTypeIndexCursor (org.neo4j.internal.kernel.api.RelationshipTypeIndexCursor)2 CursorIterator (org.neo4j.kernel.impl.coreapi.internal.CursorIterator)2 TraceEvent (org.neo4j.kernel.impl.newapi.TestKernelReadTracer.TraceEvent)2 PrimitiveIterator (java.util.PrimitiveIterator)1