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