Search in sources :

Example 21 with LongList

use of org.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.

the class ParallelNodeCursorTransactionStateTestBase method shouldScanAllNodesFromRandomlySizedWorkers.

@Test
void shouldScanAllNodesFromRandomlySizedWorkers() throws InterruptedException, TransactionFailureException, InvalidTransactionTypeKernelException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    int size = 128;
    LongArrayList ids = new LongArrayList();
    try (KernelTransaction tx = beginTransaction()) {
        Write write = tx.dataWrite();
        for (int i = 0; i < size; i++) {
            ids.add(write.nodeCreate());
        }
        Read read = tx.dataRead();
        Scan<NodeCursor> scan = read.allNodesScan();
        CursorFactory cursors = testSupport.kernelToTest().cursors();
        // when
        List<Future<LongList>> futures = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            futures.add(service.submit(randomBatchWorker(scan, () -> cursors.allocateNodeCursor(NULL), NODE_GET)));
        }
        // then
        List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
        TestUtils.assertDistinct(lists);
        LongList concat = TestUtils.concat(lists);
        assertEquals(ids.toSortedList(), concat.toSortedList());
        tx.rollback();
    } finally {
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
    }
}
Also used : Write(org.neo4j.internal.kernel.api.Write) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) ArrayList(java.util.ArrayList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) NodeCursor(org.neo4j.internal.kernel.api.NodeCursor) LongList(org.eclipse.collections.api.list.primitive.LongList) Read(org.neo4j.internal.kernel.api.Read) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) ExecutorService(java.util.concurrent.ExecutorService) Future(java.util.concurrent.Future) Test(org.junit.jupiter.api.Test)

Example 22 with LongList

use of org.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.

the class ParallelNodeLabelScanTestBase method shouldScanAllNodesFromMultipleThreads.

@Test
void shouldScanAllNodesFromMultipleThreads() throws InterruptedException, ExecutionException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    Scan<NodeLabelIndexCursor> scan = read.nodeLabelScan(BAR_LABEL);
    CursorFactory cursors = testSupport.kernelToTest().cursors();
    try {
        // when
        Supplier<NodeLabelIndexCursor> allocateCursor = () -> cursors.allocateNodeLabelIndexCursor(NULL);
        Future<LongList> future1 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, NUMBER_OF_NODES));
        Future<LongList> future2 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, NUMBER_OF_NODES));
        Future<LongList> future3 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, NUMBER_OF_NODES));
        Future<LongList> future4 = service.submit(singleBatchWorker(scan, allocateCursor, NODE_GET, NUMBER_OF_NODES));
        // then
        LongList ids1 = future1.get();
        LongList ids2 = future2.get();
        LongList ids3 = future3.get();
        LongList ids4 = future4.get();
        assertDistinct(ids1, ids2, ids3, ids4);
        assertEquals(BAR_NODES, LongSets.immutable.withAll(concat(ids1, ids2, ids3, ids4)));
    } finally {
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
    }
}
Also used : CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) ExecutorService(java.util.concurrent.ExecutorService) LongList(org.eclipse.collections.api.list.primitive.LongList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) Test(org.junit.jupiter.api.Test)

Example 23 with LongList

use of org.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.

the class ParallelNodeLabelScanTransactionStateTestBase method shouldScanAllNodesFromRandomlySizedWorkers.

@Test
void shouldScanAllNodesFromRandomlySizedWorkers() throws InterruptedException, KernelException {
    // given
    ExecutorService service = Executors.newFixedThreadPool(4);
    int size = 2000;
    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);
        CursorFactory cursors = testSupport.kernelToTest().cursors();
        // when
        List<Future<LongList>> futures = new ArrayList<>();
        for (int i = 0; i < 10; i++) {
            futures.add(service.submit(randomBatchWorker(scan, () -> cursors.allocateNodeLabelIndexCursor(tx.cursorContext()), NODE_GET)));
        }
        // then
        List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
        assertDistinct(lists);
        assertEquals(ids.toSortedList(), concat(lists).toSortedList());
        tx.rollback();
    } finally {
        service.shutdown();
        service.awaitTermination(1, TimeUnit.MINUTES);
    }
}
Also used : Read(org.neo4j.internal.kernel.api.Read) KernelTransaction(org.neo4j.kernel.api.KernelTransaction) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) ExecutorService(java.util.concurrent.ExecutorService) ArrayList(java.util.ArrayList) Future(java.util.concurrent.Future) LongList(org.eclipse.collections.api.list.primitive.LongList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) Test(org.junit.jupiter.api.Test)

Example 24 with LongList

use of org.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.

the class ParallelNodeLabelScanTransactionStateTestBase method parallelTxStateScanStressTest.

@Test
void parallelTxStateScanStressTest() throws KernelException, InterruptedException {
    int label = label("L");
    MutableLongSet existingNodes = LongSets.mutable.withAll(createNodesWithLabel(label, 1000));
    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 allNodes = LongSets.mutable.withAll(existingNodes);
            try (KernelTransaction tx = beginTransaction()) {
                int nodeInTx = random.nextInt(1000);
                allNodes.addAll(createNodesWithLabel(tx.dataWrite(), label, nodeInTx));
                Scan<NodeLabelIndexCursor> scan = tx.dataRead().nodeLabelScan(label);
                List<Future<LongList>> futures = new ArrayList<>(workers);
                for (int j = 0; j < workers; j++) {
                    futures.add(threadPool.submit(randomBatchWorker(scan, () -> cursors.allocateNodeLabelIndexCursor(tx.cursorContext()), NODE_GET)));
                }
                List<LongList> lists = futures.stream().map(TestUtils::unsafeGet).collect(Collectors.toList());
                assertDistinct(lists);
                LongList concat = concat(lists);
                assertEquals(allNodes, LongSets.immutable.withAll(concat), format("nodes=%d, seen=%d, all=%d", nodeInTx, concat.size(), allNodes.size()));
                assertEquals(allNodes.size(), concat.size(), format("nodes=%d", nodeInTx));
                tx.rollback();
            }
        }
    } finally {
        threadPool.shutdown();
        threadPool.awaitTermination(1, TimeUnit.MINUTES);
    }
}
Also used : KernelTransaction(org.neo4j.kernel.api.KernelTransaction) ArrayList(java.util.ArrayList) LongList(org.eclipse.collections.api.list.primitive.LongList) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) MutableLongSet(org.eclipse.collections.api.set.primitive.MutableLongSet) CursorFactory(org.neo4j.internal.kernel.api.CursorFactory) ExecutorService(java.util.concurrent.ExecutorService) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) Future(java.util.concurrent.Future) NodeLabelIndexCursor(org.neo4j.internal.kernel.api.NodeLabelIndexCursor) Test(org.junit.jupiter.api.Test)

Example 25 with LongList

use of org.eclipse.collections.api.list.primitive.LongList in project neo4j by neo4j.

the class IndexedIdGeneratorTest method shouldConcurrentlyAllocateAllIdsAroundReservedIds.

@Test
void shouldConcurrentlyAllocateAllIdsAroundReservedIds() throws IOException {
    // given
    idGenerator.start(NO_FREE_IDS, NULL);
    long startingId = IdValidator.INTEGER_MINUS_ONE - 100;
    idGenerator.setHighId(startingId);
    idGenerator.markHighestWrittenAtHighId();
    // when
    Race race = new Race();
    int threads = 8;
    int allocationsPerThread = 32;
    LongList[] allocatedIds = new LongList[threads];
    for (int i = 0; i < 8; i++) {
        LongArrayList list = new LongArrayList(32);
        allocatedIds[i] = list;
        race.addContestant(() -> {
            for (int j = 0; j < allocationsPerThread; j++) {
                list.add(idGenerator.nextId(NULL));
            }
        }, 1);
    }
    race.goUnchecked();
    // then
    MutableLongList allIds = new LongArrayList(allocationsPerThread * threads);
    Stream.of(allocatedIds).forEach(allIds::addAll);
    allIds = allIds.sortThis();
    assertEquals(allocationsPerThread * threads, allIds.size());
    MutableLongIterator allIdsIterator = allIds.longIterator();
    long nextExpected = startingId;
    while (allIdsIterator.hasNext()) {
        assertEquals(nextExpected, allIdsIterator.next());
        do {
            nextExpected++;
        } while (IdValidator.isReservedId(nextExpected));
    }
}
Also used : MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) LongArrayList(org.eclipse.collections.impl.list.mutable.primitive.LongArrayList) Race(org.neo4j.test.Race) MutableLongList(org.eclipse.collections.api.list.primitive.MutableLongList) LongList(org.eclipse.collections.api.list.primitive.LongList) MutableLongIterator(org.eclipse.collections.api.iterator.MutableLongIterator) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

LongList (org.eclipse.collections.api.list.primitive.LongList)29 Test (org.junit.jupiter.api.Test)23 ExecutorService (java.util.concurrent.ExecutorService)19 CursorFactory (org.neo4j.internal.kernel.api.CursorFactory)19 MutableLongList (org.eclipse.collections.api.list.primitive.MutableLongList)18 KernelTransaction (org.neo4j.kernel.api.KernelTransaction)12 ArrayList (java.util.ArrayList)11 LongArrayList (org.eclipse.collections.impl.list.mutable.primitive.LongArrayList)11 Future (java.util.concurrent.Future)9 Read (org.neo4j.internal.kernel.api.Read)8 Write (org.neo4j.internal.kernel.api.Write)8 NodeCursor (org.neo4j.internal.kernel.api.NodeCursor)6 RelationshipScanCursor (org.neo4j.internal.kernel.api.RelationshipScanCursor)6 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)5 NodeLabelIndexCursor (org.neo4j.internal.kernel.api.NodeLabelIndexCursor)5 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)3 MutableLongSet (org.eclipse.collections.api.set.primitive.MutableLongSet)3 BigDecimal (java.math.BigDecimal)2 BigInteger (java.math.BigInteger)2 List (java.util.List)2