Search in sources :

Example 51 with IndexReadSession

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

the class CompositeStringLengthValidationIT method shouldHandleCompositeSizesCloseToTheLimit.

@Test
void shouldHandleCompositeSizesCloseToTheLimit() throws KernelException {
    String firstSlot = random.nextAlphaNumericString(firstSlotLength, firstSlotLength);
    String secondSlot = random.nextAlphaNumericString(secondSlotLength, secondSlotLength);
    // given
    IndexDescriptor index = createIndex(KEY, KEY2);
    Node node;
    try (Transaction tx = db.beginTx()) {
        node = tx.createNode(LABEL);
        node.setProperty(KEY, firstSlot);
        node.setProperty(KEY2, secondSlot);
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        int propertyKeyId1 = ktx.tokenRead().propertyKey(KEY);
        int propertyKeyId2 = ktx.tokenRead().propertyKey(KEY2);
        try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
            IndexReadSession indexReadSession = ktx.dataRead().indexReadSession(index);
            ktx.dataRead().nodeIndexSeek(indexReadSession, cursor, unconstrained(), PropertyIndexQuery.exact(propertyKeyId1, firstSlot), PropertyIndexQuery.exact(propertyKeyId2, secondSlot));
            assertTrue(cursor.next());
            assertEquals(node.getId(), cursor.nodeReference());
            assertFalse(cursor.next());
        }
        tx.commit();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) Node(org.neo4j.graphdb.Node) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 52 with IndexReadSession

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

the class LuceneFulltextTestSupport method assertQueryFindsNodeIdsInOrder.

void assertQueryFindsNodeIdsInOrder(KernelTransaction ktx, String indexName, String query, long... ids) throws Exception {
    IndexDescriptor index = ktx.schemaRead().indexGetForName(indexName);
    IndexReadSession indexSession = ktx.dataRead().indexReadSession(index);
    try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
        int num = 0;
        float score = Float.MAX_VALUE;
        ktx.dataRead().nodeIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.fulltextSearch(query));
        while (cursor.next()) {
            long nextId = cursor.nodeReference();
            float nextScore = cursor.score();
            assertThat(nextScore).isLessThanOrEqualTo(score);
            score = nextScore;
            assertEquals(ids[num], nextId, format("Result returned node id %d, expected %d", nextId, ids[num]));
            num++;
        }
        assertEquals(ids.length, num, "Number of results differ from expected");
    }
}
Also used : NodeValueIndexCursor(org.neo4j.internal.kernel.api.NodeValueIndexCursor) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession)

Example 53 with IndexReadSession

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

the class DefaultPooledCursorsTestBase method shouldReuseNodeValueIndexCursor.

@Test
void shouldReuseNodeValueIndexCursor() 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.allocateNodeValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
    read.nodeIndexSeek(indexSession, c1, IndexQueryConstraints.unconstrained(), PropertyIndexQuery.exact(prop, "zero"));
    c1.close();
    NodeValueIndexCursor c2 = cursors.allocateNodeValueIndexCursor(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)

Example 54 with IndexReadSession

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

the class DefaultPooledCursorsTestBase method shouldReuseRelationshipIndexCursors.

@Test
void shouldReuseRelationshipIndexCursors() throws Exception {
    // given
    int connection;
    int name;
    String indexName = "myIndex";
    IndexDescriptor index;
    try (KernelTransaction tx = beginTransaction()) {
        connection = tx.tokenWrite().relationshipTypeGetOrCreateForName("Connection");
        name = tx.tokenWrite().propertyKeyGetOrCreateForName("name");
        tx.commit();
    }
    try (KernelTransaction tx = beginTransaction()) {
        SchemaDescriptor schema = SchemaDescriptor.fulltext(EntityType.RELATIONSHIP, array(connection), array(name));
        IndexPrototype prototype = IndexPrototype.forSchema(schema, DESCRIPTOR).withName(indexName).withIndexType(IndexType.FULLTEXT);
        index = tx.schemaWrite().indexCreate(prototype);
        tx.commit();
    }
    Predicates.awaitEx(() -> tx.schemaRead().indexGetState(index) == ONLINE, 1, MINUTES);
    RelationshipValueIndexCursor c1 = cursors.allocateRelationshipValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
    IndexReadSession indexSession = tx.dataRead().indexReadSession(index);
    read.relationshipIndexSeek(indexSession, c1, IndexQueryConstraints.unconstrained(), PropertyIndexQuery.fulltextSearch("hello"));
    c1.close();
    RelationshipValueIndexCursor c2 = cursors.allocateRelationshipValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
    assertThat(c1).isSameAs(c2);
    c2.close();
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) SchemaDescriptor(org.neo4j.internal.schema.SchemaDescriptor) RelationshipValueIndexCursor(org.neo4j.internal.kernel.api.RelationshipValueIndexCursor) IndexPrototype(org.neo4j.internal.schema.IndexPrototype) IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Example 55 with IndexReadSession

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

the class KernelAPIParallelRelationshipValueIndexScanStressIT method shouldDoParallelIndexScans.

@Test
void shouldDoParallelIndexScans() throws Throwable {
    // Given
    try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
        createRelationships(tx, N_RELS, "TYPE1", "prop");
        createRelationships(tx, N_RELS, "TYPE2", "prop");
        createRelationships(tx, N_RELS, "TYPE3", "prop");
        tx.commit();
    }
    IndexDescriptor index1;
    IndexDescriptor index2;
    IndexDescriptor index3;
    try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
        index1 = unwrap(tx.schema().indexFor(RelationshipType.withName("TYPE1")).on("prop").create());
        index2 = unwrap(tx.schema().indexFor(RelationshipType.withName("TYPE2")).on("prop").create());
        index3 = unwrap(tx.schema().indexFor(RelationshipType.withName("TYPE3")).on("prop").create());
        tx.commit();
    }
    try (org.neo4j.graphdb.Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexesOnline(10, MINUTES);
        tx.commit();
    }
    // when & then
    IndexReadSession[] indexes = new IndexReadSession[3];
    try (KernelTransaction tx = kernel.beginTransaction(EXPLICIT, LoginContext.AUTH_DISABLED)) {
        indexes[0] = indexReadSession(tx, index1);
        indexes[1] = indexReadSession(tx, index2);
        indexes[2] = indexReadSession(tx, index3);
        tx.commit();
    }
    KernelAPIParallelStress.parallelStressInTx(kernel, N_THREADS, tx -> tx.cursors().allocateRelationshipValueIndexCursor(tx.cursorContext(), tx.memoryTracker()), (read, cursor) -> indexSeek(read, cursor, indexes[random.nextInt(indexes.length)]));
}
Also used : IndexDescriptor(org.neo4j.internal.schema.IndexDescriptor) IndexReadSession(org.neo4j.internal.kernel.api.IndexReadSession) Test(org.junit.jupiter.api.Test)

Aggregations

IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)93 Test (org.junit.jupiter.api.Test)62 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)47 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)22 NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)20 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)17 LongHashSet (org.eclipse.collections.impl.set.mutable.primitive.LongHashSet)15 ArrayList (java.util.ArrayList)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)12 EnumSource (org.junit.jupiter.params.provider.EnumSource)12 RelationshipValueIndexCursor (org.neo4j.internal.kernel.api.RelationshipValueIndexCursor)12 IndexValueCapability (org.neo4j.internal.schema.IndexValueCapability)12 Pair (org.neo4j.internal.helpers.collection.Pair)11 InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)10 Transaction (org.neo4j.graphdb.Transaction)9 IndexQueryConstraints (org.neo4j.internal.kernel.api.IndexQueryConstraints)9 IndexOrderCapability (org.neo4j.internal.schema.IndexOrderCapability)7 Read (org.neo4j.internal.kernel.api.Read)6 TokenRead (org.neo4j.internal.kernel.api.TokenRead)6 PropertyIndexQuery (org.neo4j.internal.kernel.api.PropertyIndexQuery)5