Search in sources :

Example 56 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class NodeEntityTest method traceNodePageCacheAccessOnRelationshipTypeAndDegreeCount.

@Test
void traceNodePageCacheAccessOnRelationshipTypeAndDegreeCount() {
    long sourceId;
    var relationshipType = RelationshipType.withName("connection");
    try (Transaction tx = db.beginTx()) {
        var source = tx.createNode();
        createDenseNodeWithShortIncomingChain(tx, source, relationshipType);
        sourceId = source.getId();
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        var cursorContext = ((InternalTransaction) tx).kernelTransaction().cursorContext();
        PageCursorTracer cursorTracer = cursorContext.getCursorTracer();
        var source = tx.getNodeById(sourceId);
        cursorTracer.reportEvents();
        assertZeroTracer(cursorContext);
        source.getDegree(relationshipType, Direction.INCOMING);
        assertThat(cursorTracer.hits()).isEqualTo(3);
        assertThat(cursorTracer.unpins()).isEqualTo(0);
        assertThat(cursorTracer.pins()).isEqualTo(3);
    }
}
Also used : PageCursorTracer(org.neo4j.io.pagecache.tracing.cursor.PageCursorTracer) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) Test(org.junit.jupiter.api.Test)

Example 57 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class KernelIT method schemaStateContains.

private boolean schemaStateContains(String key) {
    try (Transaction tx = db.beginTx()) {
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        final AtomicBoolean result = new AtomicBoolean(true);
        ktx.schemaRead().schemaStateGetOrCreate(key, s -> {
            result.set(false);
            return null;
        });
        tx.commit();
        return result.get();
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Transaction(org.neo4j.graphdb.Transaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction)

Example 58 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class KernelIT method getOrCreateSchemaState.

private void getOrCreateSchemaState(Transaction tx, String key, final String maybeSetThisState) {
    KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
    ktx.schemaRead().schemaStateGetOrCreate(key, s -> maybeSetThisState);
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction)

Example 59 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class ManyMergesStressTest method shouldWorkFine.

@Test
void shouldWorkFine() {
    GraphDatabaseQueryService graph = new GraphDatabaseCypherService(db);
    Label person = Label.label("Person");
    try (Transaction tx = db.beginTx()) {
        // THIS USED TO CAUSE OUT OF FILE HANDLES
        // (maybe look at:  http://stackoverflow.com/questions/6210348/too-many-open-files-error-on-lucene)
        tx.schema().indexFor(person).on("id").create();
        // THIS SHOULD ALSO WORK
        tx.schema().constraintFor(person).assertPropertyIsUnique("id").create();
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        tx.schema().indexFor(person).on("name").create();
        tx.commit();
    }
    try (Transaction tx = db.beginTx()) {
        tx.schema().awaitIndexesOnline(2, TimeUnit.MINUTES);
        tx.commit();
    }
    for (int count = 0; count < TRIES; count++) {
        Pair<String, String> stringPair = getRandomName();
        String ident = stringPair.first();
        String name = stringPair.other();
        String id = Long.toString(Math.abs(random.nextLong()));
        String query = format("MERGE (%s:Person {id: %s}) ON CREATE SET %s.name = \"%s\";", ident, id, ident, name);
        try (InternalTransaction tx = graph.beginTransaction(KernelTransaction.Type.IMPLICIT, LoginContext.AUTH_DISABLED)) {
            Result result = tx.execute(query);
            result.close();
            tx.commit();
        }
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) Transaction(org.neo4j.graphdb.Transaction) GraphDatabaseQueryService(org.neo4j.kernel.GraphDatabaseQueryService) Label(org.neo4j.graphdb.Label) GraphDatabaseCypherService(org.neo4j.cypher.internal.javacompat.GraphDatabaseCypherService) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Result(org.neo4j.graphdb.Result) Test(org.junit.jupiter.api.Test)

Example 60 with InternalTransaction

use of org.neo4j.kernel.impl.coreapi.InternalTransaction in project neo4j by neo4j.

the class ReadTracingIT method tracePageCacheAccessOnNodeIndexScan.

@Test
void tracePageCacheAccessOnNodeIndexScan() throws KernelException {
    createNodeConstraint();
    createMatchingNode();
    try (InternalTransaction transaction = (InternalTransaction) database.beginTx()) {
        var kernelTransaction = transaction.kernelTransaction();
        var dataRead = kernelTransaction.dataRead();
        var indexDescriptor = kernelTransaction.schemaRead().indexGetForName(indexName);
        var cursorContext = kernelTransaction.cursorContext();
        assertZeroCursor(cursorContext);
        var indexSession = dataRead.indexReadSession(indexDescriptor);
        try (var cursor = kernelTransaction.cursors().allocateNodeValueIndexCursor(kernelTransaction.cursorContext(), kernelTransaction.memoryTracker())) {
            dataRead.nodeIndexScan(indexSession, cursor, unconstrained());
            consumeCursor(cursor);
        }
        assertOneCursor(cursorContext);
        assertThat(cursorContext.getCursorTracer().faults()).isZero();
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Test(org.junit.jupiter.api.Test)

Aggregations

InternalTransaction (org.neo4j.kernel.impl.coreapi.InternalTransaction)126 Transaction (org.neo4j.graphdb.Transaction)58 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)53 Test (org.junit.jupiter.api.Test)46 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)20 MethodSource (org.junit.jupiter.params.provider.MethodSource)18 Node (org.neo4j.graphdb.Node)16 NodeValueIndexCursor (org.neo4j.internal.kernel.api.NodeValueIndexCursor)15 ArrayList (java.util.ArrayList)13 Test (org.junit.Test)12 Result (org.neo4j.graphdb.Result)12 TokenRead (org.neo4j.internal.kernel.api.TokenRead)11 IndexDescriptor (org.neo4j.internal.schema.IndexDescriptor)10 IndexReadSession (org.neo4j.internal.kernel.api.IndexReadSession)8 ExecutingQuery (org.neo4j.kernel.api.query.ExecutingQuery)7 Relationship (org.neo4j.graphdb.Relationship)6 GraphDatabaseQueryService (org.neo4j.kernel.GraphDatabaseQueryService)6 GraphDatabaseFacade (org.neo4j.kernel.impl.factory.GraphDatabaseFacade)6 GraphDatabaseAPI (org.neo4j.kernel.internal.GraphDatabaseAPI)6 ReturnsDeepStubs (org.mockito.internal.stubbing.defaultanswers.ReturnsDeepStubs)5