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);
}
}
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);
}
}
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();
}
}
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;
}
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());
}
Aggregations