use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class NodeIndexTransactionStateTest method assertEntityAndValueForSeek.
@Override
void assertEntityAndValueForSeek(Set<Pair<Long, Value>> expected, KernelTransaction tx, IndexDescriptor index, boolean needsValues, Object anotherValueFoundByQuery, PropertyIndexQuery... queries) throws Exception {
try (NodeValueIndexCursor nodes = tx.cursors().allocateNodeValueIndexCursor(tx.cursorContext(), tx.memoryTracker())) {
IndexReadSession indexSession = tx.dataRead().indexReadSession(index);
tx.dataRead().nodeIndexSeek(indexSession, nodes, unordered(needsValues), queries);
assertEntityAndValue(expected, tx, needsValues, anotherValueFoundByQuery, new NodeCursorAdapter(nodes));
}
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class ManagedTestCursors method allocateFullAccessNodeValueIndexCursor.
@Override
public NodeValueIndexCursor allocateFullAccessNodeValueIndexCursor(CursorContext cursorContext, MemoryTracker memoryTracker) {
NodeValueIndexCursor n = cursors.allocateFullAccessNodeValueIndexCursor(cursorContext, memoryTracker);
allCursors.add(n);
return n;
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class IndexStatisticsTest method assertIndexedNodesMatchesStoreNodes.
private void assertIndexedNodesMatchesStoreNodes(IndexDescriptor index) throws Exception {
int nodesInStore = 0;
Label label = Label.label(PERSON_LABEL);
try (Transaction transaction = db.beginTx()) {
KernelTransaction ktx = ((InternalTransaction) transaction).kernelTransaction();
List<String> mismatches = new ArrayList<>();
int propertyKeyId = ktx.tokenRead().propertyKey(NAME_PROPERTY);
IndexReadSession indexSession = ktx.dataRead().indexReadSession(index);
try (NodeValueIndexCursor cursor = ktx.cursors().allocateNodeValueIndexCursor(ktx.cursorContext(), ktx.memoryTracker())) {
// Node --> Index
for (Node node : filter(n -> n.hasLabel(label) && n.hasProperty(NAME_PROPERTY), transaction.getAllNodes())) {
nodesInStore++;
String name = (String) node.getProperty(NAME_PROPERTY);
ktx.dataRead().nodeIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.exact(propertyKeyId, name));
boolean found = false;
while (cursor.next()) {
long indexedNode = cursor.nodeReference();
if (indexedNode == node.getId()) {
if (found) {
mismatches.add("Index has multiple entries for " + name + " and " + indexedNode);
}
found = true;
}
}
if (!found) {
mismatches.add("Index is missing entry for " + name + " " + node);
}
}
if (!mismatches.isEmpty()) {
fail(String.join(format("%n"), mismatches));
}
// Node count == indexed node count
ktx.dataRead().nodeIndexSeek(indexSession, cursor, unconstrained(), PropertyIndexQuery.exists(propertyKeyId));
int nodesInIndex = 0;
while (cursor.next()) {
nodesInIndex++;
}
assertEquals(nodesInStore, nodesInIndex);
}
}
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class NodeGetUniqueFromIndexSeekIT method shouldNotCompositeFindNonMatchingNode.
@Test
void shouldNotCompositeFindNonMatchingNode() throws Exception {
// given
IndexDescriptor index = createUniquenessConstraint(labelId, propertyId1, propertyId2);
Value value1 = Values.of("value1");
Value value2 = Values.of("value2");
createNodeWithValues(Values.of("other_" + value1), Values.of("other_" + value2));
// when looking for it
KernelTransaction transaction = newTransaction();
try (NodeValueIndexCursor cursor = transaction.cursors().allocateNodeValueIndexCursor(transaction.cursorContext(), transaction.memoryTracker())) {
long foundId = transaction.dataRead().lockingNodeUniqueIndexSeek(index, cursor, exact(propertyId1, value1), exact(propertyId2, value2));
// then
assertTrue(isNoSuchNode(foundId), "Non-matching created node was found");
}
commit();
}
use of org.neo4j.internal.kernel.api.NodeValueIndexCursor in project neo4j by neo4j.
the class DefaultPooledCursorsTestBase method shouldReuseFullAccessNodeValueIndexCursor.
@Test
void shouldReuseFullAccessNodeValueIndexCursor() 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.allocateFullAccessNodeValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
read.nodeIndexSeek(indexSession, c1, IndexQueryConstraints.unconstrained(), PropertyIndexQuery.exact(prop, "zero"));
c1.close();
NodeValueIndexCursor c2 = cursors.allocateFullAccessNodeValueIndexCursor(NULL, EmptyMemoryTracker.INSTANCE);
assertThat(c1).isSameAs(c2);
c2.close();
}
Aggregations