Search in sources :

Example 36 with InternalTransaction

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

the class TransactionTracingIT method tracePageCacheAccessOnFindNodes.

@Test
void tracePageCacheAccessOnFindNodes() {
    var marker = Label.label("marker");
    var type = withName("connection");
    try (Transaction transaction = database.beginTx()) {
        for (int i = 0; i < ENTITY_COUNT; i++) {
            var source = transaction.createNode(marker);
            source.createRelationshipTo(transaction.createNode(), type);
        }
        transaction.commit();
    }
    try (InternalTransaction transaction = (InternalTransaction) database.beginTx()) {
        var cursorContext = transaction.kernelTransaction().cursorContext();
        assertZeroCursor(cursorContext);
        softly.assertThat(Iterators.count(transaction.findNodes(marker))).as("Number of expected nodes").isEqualTo(ENTITY_COUNT);
        softly.assertThat(cursorContext.getCursorTracer().pins()).as("Number of cursor pins").isEqualTo(1);
        softly.assertThat(cursorContext.getCursorTracer().unpins()).as("Number of cursor unpins").isEqualTo(1);
        softly.assertThat(cursorContext.getCursorTracer().hits()).as("Number of cursor hits").isEqualTo(1);
    }
}
Also used : InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Test(org.junit.jupiter.api.Test)

Example 37 with InternalTransaction

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

the class MyCoreAPI method makeNode.

public long makeNode(Transaction tx, String label) throws ProcedureException {
    try {
        KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
        long nodeId = ktx.dataWrite().nodeCreate();
        int labelId = ktx.tokenWrite().labelGetOrCreateForName(label);
        ktx.dataWrite().nodeAddLabel(nodeId, labelId);
        return nodeId;
    } catch (Exception e) {
        log.error("Failed to create node: " + e.getMessage());
        throw new ProcedureException(Status.Procedure.ProcedureCallFailed, "Failed to create node: " + e.getMessage(), e);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) ProcedureException(org.neo4j.internal.kernel.api.exceptions.ProcedureException)

Example 38 with InternalTransaction

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

the class MultiIndexPopulationConcurrentUpdatesIT method launchCustomIndexPopulation.

private void launchCustomIndexPopulation(GraphDatabaseSettings.SchemaIndex schemaIndex, Map<String, Integer> labelNameIdMap, int propertyId, Runnable customAction) throws Throwable {
    RecordStorageEngine storageEngine = getStorageEngine();
    try (Transaction transaction = db.beginTx()) {
        Config config = Config.defaults();
        KernelTransaction ktx = ((InternalTransaction) transaction).kernelTransaction();
        JobScheduler scheduler = getJobScheduler();
        NullLogProvider nullLogProvider = NullLogProvider.getInstance();
        IndexStoreViewFactory indexStoreViewFactory = mock(IndexStoreViewFactory.class);
        when(indexStoreViewFactory.createTokenIndexStoreView(any())).thenAnswer(invocation -> dynamicIndexStoreViewWrapper(customAction, storageEngine::newReader, invocation.getArgument(0), config, scheduler));
        IndexProviderMap providerMap = getIndexProviderMap();
        indexService = IndexingServiceFactory.createIndexingService(config, scheduler, providerMap, indexStoreViewFactory, ktx.tokenRead(), initialSchemaRulesLoader(storageEngine), nullLogProvider, nullLogProvider, IndexingService.NO_MONITOR, getSchemaState(), mock(IndexStatisticsStore.class), PageCacheTracer.NULL, INSTANCE, "", writable());
        indexService.start();
        rules = createIndexRules(schemaIndex, labelNameIdMap, propertyId);
        schemaCache = new SchemaCache(new StandardConstraintSemantics(), providerMap);
        schemaCache.load(iterable(rules));
        indexService.createIndexes(AUTH_DISABLED, rules);
        transaction.commit();
    }
}
Also used : JobScheduler(org.neo4j.scheduler.JobScheduler) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) Transaction(org.neo4j.graphdb.Transaction) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) RecordStorageEngine(org.neo4j.internal.recordstorage.RecordStorageEngine) Config(org.neo4j.configuration.Config) NullLogProvider(org.neo4j.logging.NullLogProvider) SchemaCache(org.neo4j.internal.recordstorage.SchemaCache) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) IndexProviderMap(org.neo4j.kernel.impl.api.index.IndexProviderMap) StandardConstraintSemantics(org.neo4j.kernel.impl.constraints.StandardConstraintSemantics) IndexStoreViewFactory(org.neo4j.kernel.impl.transaction.state.storeview.IndexStoreViewFactory)

Example 39 with InternalTransaction

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

the class MultiIndexPopulationConcurrentUpdatesIT method getLabelIdsByName.

private Map<String, Integer> getLabelIdsByName(Transaction tx, String... names) {
    Map<String, Integer> labelNameIdMap = new HashMap<>();
    KernelTransaction ktx = ((InternalTransaction) tx).kernelTransaction();
    TokenRead tokenRead = ktx.tokenRead();
    for (String name : names) {
        labelNameIdMap.put(name, tokenRead.nodeLabel(name));
    }
    return labelNameIdMap;
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) HashMap(java.util.HashMap) InternalTransaction(org.neo4j.kernel.impl.coreapi.InternalTransaction) TokenRead(org.neo4j.internal.kernel.api.TokenRead)

Example 40 with InternalTransaction

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

the class Neo4jTransactionalContextTest method shouldBeTopLevelWithImplicitTx.

@Test
void shouldBeTopLevelWithImplicitTx() {
    InternalTransaction tx = mock(InternalTransaction.class);
    when(tx.transactionType()).thenReturn(KernelTransaction.Type.IMPLICIT);
    Neo4jTransactionalContext context = newContext(tx);
    assertTrue(context.isTopLevelTx());
}
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