use of org.neo4j.internal.kernel.api.NodeLabelIndexCursor in project neo4j by neo4j.
the class ParallelNodeLabelScanTransactionStateTestBase method scanShouldNotSeeDeletedNode.
@Test
void scanShouldNotSeeDeletedNode() throws Exception {
int size = 1000;
Set<Long> created = new HashSet<>(size);
Set<Long> deleted = new HashSet<>(size);
int label = label("L");
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
for (int i = 0; i < size; i++) {
long createId = write.nodeCreate();
long deleteId = write.nodeCreate();
write.nodeAddLabel(createId, label);
write.nodeAddLabel(deleteId, label);
created.add(createId);
deleted.add(deleteId);
}
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
for (long delete : deleted) {
tx.dataWrite().nodeDelete(delete);
}
try (NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
Scan<NodeLabelIndexCursor> scan = tx.dataRead().nodeLabelScan(label);
Set<Long> seen = new HashSet<>();
while (scan.reserveBatch(cursor, 128)) {
while (cursor.next()) {
long nodeId = cursor.nodeReference();
assertTrue(seen.add(nodeId));
assertTrue(created.remove(nodeId));
}
}
assertTrue(created.isEmpty());
}
}
}
use of org.neo4j.internal.kernel.api.NodeLabelIndexCursor in project neo4j by neo4j.
the class ParallelNodeLabelScanTransactionStateTestBase method shouldScanAllNodesFromMultipleThreads.
@Test
void shouldScanAllNodesFromMultipleThreads() throws InterruptedException, ExecutionException, KernelException {
// given
ExecutorService service = Executors.newFixedThreadPool(4);
CursorFactory cursors = testSupport.kernelToTest().cursors();
int size = 1024;
try (KernelTransaction tx = beginTransaction()) {
int label = tx.tokenWrite().labelGetOrCreateForName("L");
LongList ids = createNodesWithLabel(tx.dataWrite(), label, size);
Read read = tx.dataRead();
Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(label);
// when
Supplier<NodeLabelIndexCursor> allocateCursor = () -> cursors.allocateNodeLabelIndexCursor(tx.cursorContext());
Future<LongList> future1 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, size / 4));
Future<LongList> future2 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, size / 4));
Future<LongList> future3 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, size / 4));
Future<LongList> future4 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, size / 4));
// then
LongList ids1 = future1.get();
LongList ids2 = future2.get();
LongList ids3 = future3.get();
LongList ids4 = future4.get();
assertDistinct(ids1, ids2, ids3, ids4);
LongList concat = concat(ids1, ids2, ids3, ids4);
assertEquals(ids.toSortedList(), concat.toSortedList());
tx.rollback();
} finally {
service.shutdown();
service.awaitTermination(1, TimeUnit.MINUTES);
}
}
use of org.neo4j.internal.kernel.api.NodeLabelIndexCursor in project neo4j by neo4j.
the class KernelReadTracerTest method shouldTraceLabelScan.
@Test
void shouldTraceLabelScan() throws KernelException {
// given
TestKernelReadTracer tracer = new TestKernelReadTracer();
int barId = token.labelGetOrCreateForName("Bar");
List<TraceEvent> expectedEvents = new ArrayList<>();
expectedEvents.add(OnLabelScan(barId));
try (NodeLabelIndexCursor cursor = cursors.allocateNodeLabelIndexCursor(NULL)) {
// when
cursor.setTracer(tracer);
read.nodeLabelScan(getTokenReadSession(tx, EntityType.NODE), cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(barId));
while (cursor.next()) {
expectedEvents.add(OnNode(cursor.nodeReference()));
}
}
// then
tracer.assertEvents(expectedEvents);
}
use of org.neo4j.internal.kernel.api.NodeLabelIndexCursor in project neo4j by neo4j.
the class NodeLabelTokenIndexCursorTest method shouldFindNodesByLabelInTx.
@Test
void shouldFindNodesByLabelInTx() throws Exception {
long inStore;
long deletedInTx;
long createdInTx;
try (KernelTransaction tx = beginTransaction()) {
inStore = createNode(tx.dataWrite(), labelOne);
createNode(tx.dataWrite(), labelTwo);
deletedInTx = createNode(tx.dataWrite(), labelOne);
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
tx.dataWrite().nodeDelete(deletedInTx);
createdInTx = createNode(tx.dataWrite(), labelOne);
createNode(tx.dataWrite(), labelTwo);
Read read = tx.dataRead();
var session = getTokenReadSession(tx);
try (NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
MutableLongSet uniqueIds = new LongHashSet();
// when
read.nodeLabelScan(session, cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(labelOne));
// then
assertNodes(cursor, uniqueIds, inStore, createdInTx);
}
}
}
use of org.neo4j.internal.kernel.api.NodeLabelIndexCursor in project neo4j by neo4j.
the class NodeTransactionStateTestBase method shouldFindUpdatedNodeInInLabelScan.
@Test
void shouldFindUpdatedNodeInInLabelScan() throws Exception {
// Given
Node node = createNode();
try (KernelTransaction tx = beginTransaction();
NodeLabelIndexCursor cursor = tx.cursors().allocateNodeLabelIndexCursor(tx.cursorContext())) {
// when
int label = tx.tokenWrite().labelGetOrCreateForName("label");
tx.dataWrite().nodeAddLabel(node.node, label);
tx.dataRead().nodeLabelScan(getTokenReadSession(tx, EntityType.NODE), cursor, IndexQueryConstraints.unconstrained(), new TokenPredicate(label));
// then
assertTrue(cursor.next());
assertEquals(node.node, cursor.nodeReference());
}
}
Aggregations