use of org.neo4j.internal.kernel.api.NodeLabelIndexCursor in project neo4j by neo4j.
the class NodeScanIT method trackPageCacheAccessOnNodeLabelScan.
@Test
void trackPageCacheAccessOnNodeLabelScan() throws KernelException {
var testLabel = Label.label("testLabel");
try (KernelTransaction tx = kernel.beginTransaction(IMPLICIT, read())) {
var cursorContext = tx.cursorContext();
assertThat(cursorContext.getCursorTracer().pins()).isZero();
var label = tx.tokenRead().nodeLabel(testLabel.name());
IndexDescriptor index = tx.schemaRead().index(SchemaDescriptor.forAnyEntityTokens(EntityType.NODE)).next();
TokenReadSession tokenReadSession = tx.dataRead().tokenReadSession(index);
try (NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(cursorContext)) {
tx.dataRead().nodeLabelScan(tokenReadSession, cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(label));
assertThat(cursorContext.getCursorTracer().pins()).isNotZero();
}
}
}
use of org.neo4j.internal.kernel.api.NodeLabelIndexCursor in project neo4j by neo4j.
the class ParallelNodeLabelScanTestBase method shouldScanAllNodesFromRandomlySizedWorkers.
@Test
void shouldScanAllNodesFromRandomlySizedWorkers() throws InterruptedException {
// given
ExecutorService service = Executors.newFixedThreadPool(4);
Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(FOO_LABEL);
CursorFactory cursors = testSupport.kernelToTest().cursors();
try {
// when
List<Future<LongList>> futures = new ArrayList<>();
for (int i = 0; i < 10; i++) {
futures.add(service.submit(randomBatchWorker(scan, () -> cursors.allocateNodeLabelIndexCursor(NULL), NODE_GET)));
}
// then
List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
assertDistinct(lists);
assertEquals(FOO_NODES, LongSets.immutable.withAll(concat(lists)));
} finally {
service.shutdown();
service.awaitTermination(1, TimeUnit.MINUTES);
}
}
use of org.neo4j.internal.kernel.api.NodeLabelIndexCursor in project neo4j by neo4j.
the class ParallelNodeLabelScanTestBase method shouldScanASubsetOfNodes.
@Test
void shouldScanASubsetOfNodes() {
try (NodeLabelIndexCursor nodes = cursors.allocateNodeLabelIndexCursor(NULL)) {
for (int label : ALL_LABELS) {
Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(label);
assertTrue(scan.reserveBatch(nodes, 11));
MutableLongList found = LongLists.mutable.empty();
while (nodes.next()) {
found.add(nodes.nodeReference());
}
assertThat(found.size()).isGreaterThan(0);
if (label == FOO_LABEL) {
assertTrue(FOO_NODES.containsAll(found));
assertTrue(found.noneSatisfy(f -> BAR_NODES.contains(f)));
} else if (label == BAR_LABEL) {
assertTrue(BAR_NODES.containsAll(found));
assertTrue(found.noneSatisfy(f -> FOO_NODES.contains(f)));
} else {
fail();
}
}
}
}
use of org.neo4j.internal.kernel.api.NodeLabelIndexCursor in project neo4j by neo4j.
the class ParallelNodeLabelScanTestBase method shouldHandleSizeHintOverflow.
@Test
void shouldHandleSizeHintOverflow() {
try (NodeLabelIndexCursor nodes = cursors.allocateNodeLabelIndexCursor(NULL)) {
// when
Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(FOO_LABEL);
assertTrue(scan.reserveBatch(nodes, NUMBER_OF_NODES * 2));
MutableLongList ids = LongLists.mutable.empty();
while (nodes.next()) {
ids.add(nodes.nodeReference());
}
assertEquals(FOO_NODES.size(), ids.size());
assertTrue(FOO_NODES.containsAll(ids));
assertTrue(ids.noneSatisfy(f -> BAR_NODES.contains(f)));
}
}
use of org.neo4j.internal.kernel.api.NodeLabelIndexCursor in project neo4j by neo4j.
the class ParallelNodeLabelScanTransactionStateTestBase method scanShouldSeeAddedNodes.
@Test
void scanShouldSeeAddedNodes() throws Exception {
int size = 64;
int label = label("L");
MutableLongSet existing = LongSets.mutable.withAll(createNodesWithLabel(label, size));
try (KernelTransaction tx = beginTransaction()) {
MutableLongSet added = LongSets.mutable.withAll(createNodesWithLabel(tx.dataWrite(), label, size));
try (NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
Scan<NodeLabelIndexCursor> scan = tx.dataRead().nodeLabelScan(label);
Set<Long> seen = new HashSet<>();
while (scan.reserveBatch(cursor, 64)) {
while (cursor.next()) {
long nodeId = cursor.nodeReference();
assertTrue(seen.add(nodeId), format("%d was seen multiple times", nodeId));
assertTrue(existing.remove(nodeId) || added.remove(nodeId));
}
}
// make sure we have seen all nodes
assertTrue(existing.isEmpty());
assertTrue(added.isEmpty());
}
}
}
Aggregations