use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class ParallelRelationshipCursorTransactionStateTestBase method scanShouldNotSeeDeletedRelationships.
@Test
void scanShouldNotSeeDeletedRelationships() throws Exception {
int size = 100;
MutableLongSet created = LongSets.mutable.empty();
MutableLongSet deleted = LongSets.mutable.empty();
try (KernelTransaction tx = beginTransaction()) {
Write write = tx.dataWrite();
int type = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
for (int i = 0; i < size; i++) {
created.add(write.relationshipCreate(write.nodeCreate(), type, write.nodeCreate()));
deleted.add(write.relationshipCreate(write.nodeCreate(), type, write.nodeCreate()));
}
tx.commit();
}
try (KernelTransaction tx = beginTransaction()) {
deleted.each(new CheckedLongProcedure() {
@Override
public void safeValue(long item) throws Exception {
tx.dataWrite().relationshipDelete(item);
}
});
try (RelationshipScanCursor cursor = tx.cursors().allocateRelationshipScanCursor(NULL)) {
Scan<RelationshipScanCursor> scan = tx.dataRead().allRelationshipsScan();
MutableLongSet seen = LongSets.mutable.empty();
while (scan.reserveBatch(cursor, 17)) {
while (cursor.next()) {
long relationshipId = cursor.relationshipReference();
assertTrue(seen.add(relationshipId));
assertTrue(created.remove(relationshipId));
}
}
assertTrue(created.isEmpty());
}
}
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class ParallelRelationshipCursorTransactionStateTestBase method parallelTxStateScanStressTest.
@Test
void parallelTxStateScanStressTest() throws InterruptedException, KernelException {
LongSet existingRelationships = createRelationships(77);
int workers = Runtime.getRuntime().availableProcessors();
ExecutorService threadPool = Executors.newFixedThreadPool(workers);
CursorFactory cursors = testSupport.kernelToTest().cursors();
ThreadLocalRandom random = ThreadLocalRandom.current();
try {
for (int i = 0; i < 1000; i++) {
MutableLongSet allRels = LongSets.mutable.withAll(existingRelationships);
try (KernelTransaction tx = beginTransaction()) {
int relationshipsInTx = random.nextInt(100);
Write write = tx.dataWrite();
int type = tx.tokenWrite().relationshipTypeGetOrCreateForName("R");
for (int j = 0; j < relationshipsInTx; j++) {
allRels.add(write.relationshipCreate(write.nodeCreate(), type, write.nodeCreate()));
}
Scan<RelationshipScanCursor> scan = tx.dataRead().allRelationshipsScan();
List<Future<LongList>> futures = new ArrayList<>(workers);
for (int j = 0; j < workers; j++) {
futures.add(threadPool.submit(randomBatchWorker(scan, () -> cursors.allocateRelationshipScanCursor(NULL), REL_GET)));
}
List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
TestUtils.assertDistinct(lists);
LongList concat = TestUtils.concat(lists);
assertEquals(allRels, LongSets.immutable.withAll(concat), format("relationships=%d, seen=%d, all=%d", relationshipsInTx, concat.size(), allRels.size()));
assertEquals(allRels.size(), concat.size(), format("relationships=%d", relationshipsInTx));
tx.rollback();
}
}
} finally {
threadPool.shutdown();
threadPool.awaitTermination(1, TimeUnit.MINUTES);
}
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet 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.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class ParallelNodeCursorTransactionStateTestBase method scanShouldSeeAddedNodes.
@Test
void scanShouldSeeAddedNodes() throws Exception {
int size = 100;
MutableLongSet existing = createNodes(size);
MutableLongSet added = LongSets.mutable.empty();
try (KernelTransaction tx = beginTransaction()) {
for (int i = 0; i < size; i++) {
added.add(tx.dataWrite().nodeCreate());
}
try (NodeCursor cursor = tx.cursors().allocateNodeCursor(NULL)) {
Scan<NodeCursor> scan = tx.dataRead().allNodesScan();
MutableLongSet seen = LongSets.mutable.empty();
while (scan.reserveBatch(cursor, 17)) {
while (cursor.next()) {
long nodeId = cursor.nodeReference();
assertTrue(seen.add(nodeId));
assertTrue(existing.remove(nodeId) || added.remove(nodeId));
}
}
// make sure we have seen all nodes
assertTrue(existing.isEmpty());
assertTrue(added.isEmpty());
}
}
}
use of org.eclipse.collections.api.set.primitive.MutableLongSet in project neo4j by neo4j.
the class IdRangeMarkerTest method shouldIgnoreReservedIds.
@Test
void shouldIgnoreReservedIds() throws IOException {
// given
long reservedId = IdValidator.INTEGER_MINUS_ONE;
// when
MutableLongSet expectedIds = LongSets.mutable.empty();
try (IdRangeMarker marker = new IdRangeMarker(idsPerEntry, layout, tree.writer(NULL), mock(Lock.class), IdRangeMerger.DEFAULT, true, new AtomicBoolean(), 1, new AtomicLong(reservedId - 1), true, NO_MONITOR)) {
for (long id = reservedId - 1; id <= reservedId + 1; id++) {
marker.markDeleted(id);
if (id != reservedId) {
expectedIds.add(id);
}
}
}
// then
MutableLongSet deletedIdsInTree = LongSets.mutable.empty();
tree.visit(new GBPTreeVisitor.Adaptor<>() {
private IdRangeKey idRangeKey;
@Override
public void key(IdRangeKey idRangeKey, boolean isLeaf, long offloadId) {
this.idRangeKey = idRangeKey;
}
@Override
public void value(IdRange idRange) {
for (int i = 0; i < idsPerEntry; i++) {
if (idRange.getState(i) == DELETED) {
deletedIdsInTree.add(idRangeKey.getIdRangeIdx() * idsPerEntry + i);
}
}
}
}, NULL);
assertEquals(expectedIds, deletedIdsInTree);
}
Aggregations