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