Search in sources :

Example 1 with IgniteRandom

use of org.apache.ignite.internal.util.IgniteRandom in project ignite-3 by apache.

the class ItBplusTreeSelfTest method doTestMassiveRemove.

private void doTestMassiveRemove(final boolean canGetRow) throws Exception {
    final int threads = 64;
    final int keys = 3000;
    final AtomicLongArray rmvd = new AtomicLongArray(keys);
    final TestTree tree = createTestTree(canGetRow);
    // Put keys in reverse order to have a better balance in the tree (lower height).
    for (long i = keys - 1; i >= 0; i--) {
        tree.put(i);
    // println(tree.printTree());
    }
    assertEquals(keys, tree.size());
    tree.validateTree();
    info("Remove...");
    try {
        runMultiThreaded(() -> {
            Random rnd = new IgniteRandom();
            for (; ; ) {
                int idx = 0;
                boolean found = false;
                for (int i = 0, shift = rnd.nextInt(keys); i < keys; i++) {
                    idx = (i + shift) % keys;
                    if (rmvd.get(idx) == 0 && rmvd.compareAndSet(idx, 0, 1)) {
                        found = true;
                        break;
                    }
                }
                if (!found) {
                    break;
                }
                assertEquals(Long.valueOf(idx), tree.remove((long) idx));
                if (canGetRow) {
                    rmvdIds.add((long) idx);
                }
            }
            return null;
        }, threads, "remove");
        assertEquals(0, tree.size());
        tree.validateTree();
    } finally {
        rmvdIds.clear();
    }
}
Also used : Random(java.util.Random) IgniteRandom(org.apache.ignite.internal.util.IgniteRandom) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) AtomicLongArray(java.util.concurrent.atomic.AtomicLongArray) IgniteRandom(org.apache.ignite.internal.util.IgniteRandom)

Example 2 with IgniteRandom

use of org.apache.ignite.internal.util.IgniteRandom in project ignite-3 by apache.

the class ItBplusTreeSelfTest method doTestMassivePut.

private void doTestMassivePut(final boolean canGetRow) throws Exception {
    final int threads = 16;
    // We may fail to insert more on small pages size because of tree height.
    final int keys = 26;
    final TestTree tree = createTestTree(canGetRow);
    info("Put...");
    final AtomicLongArray k = new AtomicLongArray(keys);
    runMultiThreaded(() -> {
        Random rnd = new IgniteRandom();
        for (; ; ) {
            int idx = 0;
            boolean found = false;
            for (int i = 0, shift = rnd.nextInt(keys); i < keys; i++) {
                idx = (i + shift) % keys;
                if (k.get(idx) == 0 && k.compareAndSet(idx, 0, 1)) {
                    found = true;
                    break;
                }
            }
            if (!found) {
                break;
            }
            assertNull(tree.put((long) idx));
            assertNoLocks();
        }
        return null;
    }, threads, "put");
    assertEquals(keys, tree.size());
    tree.validateTree();
    IgniteCursor<Long> c = tree.find(null, null);
    long x = 0;
    while (c.next()) {
        assertEquals(Long.valueOf(x++), c.get());
    }
    assertEquals(keys, x);
    assertNoLocks();
}
Also used : Random(java.util.Random) IgniteRandom(org.apache.ignite.internal.util.IgniteRandom) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) AtomicLongArray(java.util.concurrent.atomic.AtomicLongArray) IgniteUtils.hexLong(org.apache.ignite.internal.util.IgniteUtils.hexLong) PageUtils.getLong(org.apache.ignite.internal.pagememory.util.PageUtils.getLong) AtomicLong(java.util.concurrent.atomic.AtomicLong) PageUtils.putLong(org.apache.ignite.internal.pagememory.util.PageUtils.putLong) IgniteRandom(org.apache.ignite.internal.util.IgniteRandom)

Aggregations

Random (java.util.Random)2 ThreadLocalRandom (java.util.concurrent.ThreadLocalRandom)2 AtomicLongArray (java.util.concurrent.atomic.AtomicLongArray)2 IgniteRandom (org.apache.ignite.internal.util.IgniteRandom)2 AtomicLong (java.util.concurrent.atomic.AtomicLong)1 PageUtils.getLong (org.apache.ignite.internal.pagememory.util.PageUtils.getLong)1 PageUtils.putLong (org.apache.ignite.internal.pagememory.util.PageUtils.putLong)1 IgniteUtils.hexLong (org.apache.ignite.internal.util.IgniteUtils.hexLong)1