Search in sources :

Example 11 with NodeValueIndexCursor

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

the class NodeIndexTransactionStateTest method assertEntityAndValueForSeek.

@Override
void assertEntityAndValueForSeek(Set<Pair<Long, Value>> expected, KernelTransaction tx, IndexDescriptor index, boolean needsValues, Object anotherValueFoundByQuery, PropertyIndexQuery... queries) throws Exception {
    try (NodeValueIndexCursor nodes = tx.cursors().allocateNodeValueIndexCursor(tx.cursorContext(), tx.memoryTracker())) {
        IndexReadSession indexSession = tx.dataRead().indexReadSession(index);
        tx.dataRead().nodeIndexSeek(indexSession, nodes, unordered(needsValues), queries);
        assertEntityAndValue(expected, tx, needsValues, anotherValueFoundByQuery, new NodeCursorAdapter(nodes));
    }
}
Also used : NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

Example 12 with NodeValueIndexCursor

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

the class ManagedTestCursors method allocateFullAccessNodeValueIndexCursor.

@Override
public NodeValueIndexCursor allocateFullAccessNodeValueIndexCursor(CursorContext cursorContext, MemoryTracker memoryTracker) {
    NodeValueIndexCursor n = cursors.allocateFullAccessNodeValueIndexCursor(cursorContext, memoryTracker);
    allCursors.add(n);
    return n;
}
Also used : NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor)

Example 13 with NodeValueIndexCursor

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

the class IndexStatisticsTest method assertIndexedNodesMatchesStoreNodes.

private void assertIndexedNodesMatchesStoreNodes(IndexDescriptor index) throws Exception {
    int nodesInStore = 0;
    Label label = Label.label(PERSON_LABEL);
    try (Transaction transaction = db.beginTx()) {
        KernelTransaction ktx = ((InternalTransaction) transaction).kernelTransaction();
        List<String> mismatches = new ArrayList<>();
        int propertyKeyId = ktx.tokenRead().propertyKey(NAME_PROPERTY);
        IndexReadSession indexSession = ktx.dataRead().indexReadSession(index);
        try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
            // Node --> Index
            for (Node node : filter(n -> n.hasLabel(label) && n.hasProperty(NAME_PROPERTY), transaction.getAllNodes())) {
                nodesInStore++;
                String name = (String) node.getProperty(NAME_PROPERTY);
                ktx.dataRead().nodeIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.exact(propertyKeyId, name));
                boolean found = false;
                while (cursor.next()) {
                    long indexedNode = cursor.nodeReference();
                    if (indexedNode == node.getId()) {
                        if (found) {
                            mismatches.add("Index has multiple entries for " + name + " and " + indexedNode);
                        }
                        found = true;
                    }
                }
                if (!found) {
                    mismatches.add("Index is missing entry for " + name + " " + node);
                }
            }
            if (!mismatches.isEmpty()) {
                fail(String.join(format("%n"), mismatches));
            }
            // Node count == indexed node count
            ktx.dataRead().nodeIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.exists(propertyKeyId));
            int nodesInIndex = 0;
            while (cursor.next()) {
                nodesInIndex++;
            }
            assertEquals(nodesInStore, nodesInIndex);
        }
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) Node(org.neo4j.graphdb.Node) Label(org.neo4j.graphdb.Label) SchemaDescriptor.forLabel(org.neo4j.internal.schema.SchemaDescriptor.forLabel) ArrayList(java.util.ArrayList) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction)

Example 14 with NodeValueIndexCursor

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

the class NodeGetUniqueFromIndexSeekIT method shouldNotCompositeFindNonMatchingNode.

@Test
void shouldNotCompositeFindNonMatchingNode() throws Exception {
    // given
    IndexDescriptor index = createUniquenessConstraint(labelId, propertyId1, propertyId2);
    Value value1 = Values.of("value1");
    Value value2 = Values.of("value2");
    createNodeWithValues(Values.of("other_" + value1), Values.of("other_" + value2));
    // when looking for it
    KernelTransaction transaction = newTransaction();
    try (NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(transaction.cursorContext(), transaction.memoryTracker())) {
        long foundId = transaction.dataRead().lockingNodeUniqueIndexSeek(index, cursor, exact(propertyId1, value1), exact(propertyId2, value2));
        // then
        assertTrue(isNoSuchNode(foundId), "Non-matching created node was found");
    }
    commit();
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) Value(org.neo4j.values.storable.Value) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) Test(org.junit.jupiter.api.Test)

Example 15 with NodeValueIndexCursor

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

the class DefaultPooledCursorsTestBase method shouldReuseFullAccessNodeValueIndexCursor.

@Test
void shouldReuseFullAccessNodeValueIndexCursor() throws Exception {
    int prop = token.propertyKey("prop");
    IndexDescriptor indexDescriptor = tx.schemaRead().indexGetForName(NODE_PROP_INDEX_NAME);
    Predicates.awaitEx(() -> tx.schemaRead().indexGetState(indexDescriptor) == ONLINE, 1, MINUTES);
    IndexReadSession indexSession = tx.dataRead().indexReadSession(indexDescriptor);
    NodeValueIndexCursor c1 = cursors.allocateFullAccessNodeValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
    read.nodeIndexSeek(indexSession, c1, IndexQueryConstraints.unconstrained(), PropertyIndexQuery.exact(prop, "zero"));
    c1.close();
    NodeValueIndexCursor c2 = cursors.allocateFullAccessNodeValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
    assertThat(c1).isSameAs(c2);
    c2.close();
}
Also used : NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Aggregations

NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)42 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)25 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)20 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)20 Test (org.junit.jupiter.api.Test)18 Transaction (org.neo4j.graphdb.Transaction)16 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)16 ArrayList (java.util.ArrayList)9 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)9 MethodSource (org.junit.jupiter.params.provider.MethodSource)9 TokenRead (org.neo4j.internal.kernel.api.TokenRead)7 Read (org.neo4j.internal.kernel.api.Read)6 Value (org.neo4j.values.storable.Value)6 KernelException (org.neo4j.exceptions.KernelException)3 Node (org.neo4j.graphdb.Node)3 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)2 Label (org.neo4j.graphdb.Label)2 IndexQueryConstraints (org.neo4j.internal.kernel.api.IndexQueryConstraints)2 NodeIndexCursor (org.neo4j.internal.kernel.api.NodeIndexCursor)2 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)2