Search in sources :

Example 11 with PageLockListener

use of org.apache.ignite.internal.processors.cache.persistence.tree.util.PageLockListener in project ignite by apache.

the class SharedPageLockTrackerTest method doTestTakeDumpByTime.

/**
 */
private void doTestTakeDumpByTime(int pagesCnt, int structuresCnt, int dumpTime, int threads) throws IgniteCheckedException, InterruptedException {
    SharedPageLockTracker sharedPageLockTracker = new SharedPageLockTracker();
    List<PageMeta> pageMetas = new CopyOnWriteArrayList<>();
    int id = 1;
    for (int i = 0; i < pagesCnt; i++) pageMetas.add(new PageMeta((id++) % structuresCnt, id++, id++, id++));
    List<PageLockListener> pageLsnrs = new ArrayList<>();
    for (int i = 0; i < structuresCnt; i++) pageLsnrs.add(sharedPageLockTracker.registerStructure("my-structure-" + i));
    AtomicBoolean stop = new AtomicBoolean();
    CountDownLatch awaitThreadStartLatch = new CountDownLatch(threads);
    IgniteInternalFuture f = GridTestUtils.runMultiThreadedAsync(() -> {
        List<PageLockListener> locks = new ArrayList<>(pageLsnrs);
        List<PageMeta> pages = new ArrayList<>();
        pages.addAll(pageMetas);
        boolean latchDown = false;
        while (!stop.get()) {
            Collections.shuffle(locks);
            Collections.shuffle(pages);
            for (PageLockListener lsnr : locks) {
                for (PageMeta pageMeta : pages) {
                    awaitRandom(5);
                    lsnr.onBeforeReadLock(pageMeta.structureId, pageMeta.pageId, pageMeta.page);
                    awaitRandom(5);
                    lsnr.onReadLock(pageMeta.structureId, pageMeta.pageId, pageMeta.page, pageMeta.pageAddr);
                }
            }
            Collections.reverse(locks);
            Collections.reverse(pages);
            for (PageLockListener lsnr : locks) {
                for (PageMeta pageMeta : pages) {
                    awaitRandom(5);
                    lsnr.onReadUnlock(pageMeta.structureId, pageMeta.pageId, pageMeta.page, pageMeta.pageAddr);
                }
            }
            if (!latchDown) {
                awaitThreadStartLatch.countDown();
                latchDown = true;
            }
        }
    }, threads, "PageLocker");
    IgniteInternalFuture dumpFut = GridTestUtils.runAsync(() -> {
        try {
            awaitThreadStartLatch.await();
        } catch (InterruptedException e) {
            // Ignore.
            return;
        }
        while (!stop.get()) {
            awaitRandom(20);
            SharedPageLockTrackerDump dump = sharedPageLockTracker.dump();
            assertEquals(threads, dump.threadPageLockStates.size());
            assertEquals(0, dump.threadPageLockStates.stream().filter(e -> e.invalidContext != null).count());
        }
    });
    Thread.sleep(dumpTime);
    stop.set(true);
    f.get();
    dumpFut.get();
}
Also used : ArrayList(java.util.ArrayList) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList) PageLockListener(org.apache.ignite.internal.processors.cache.persistence.tree.util.PageLockListener) CountDownLatch(java.util.concurrent.CountDownLatch) IgniteInternalFuture(org.apache.ignite.internal.IgniteInternalFuture) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) CopyOnWriteArrayList(java.util.concurrent.CopyOnWriteArrayList)

Aggregations

PageLockListener (org.apache.ignite.internal.processors.cache.persistence.tree.util.PageLockListener)11 Test (org.junit.Test)6 CountDownLatch (java.util.concurrent.CountDownLatch)5 ArrayList (java.util.ArrayList)4 CopyOnWriteArrayList (java.util.concurrent.CopyOnWriteArrayList)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)3 IgniteInternalFuture (org.apache.ignite.internal.IgniteInternalFuture)3 AtomicReference (java.util.concurrent.atomic.AtomicReference)2 IgniteCheckedException (org.apache.ignite.IgniteCheckedException)2 SharedPageLockTracker (org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.SharedPageLockTracker)2 SharedPageLockTrackerDump (org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.SharedPageLockTrackerDump)2 ListeningTestLogger (org.apache.ignite.testframework.ListeningTestLogger)2 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)2 Path (java.nio.file.Path)1 Arrays (java.util.Arrays)1 Collection (java.util.Collection)1 Collections (java.util.Collections)1 List (java.util.List)1 Map (java.util.Map)1 Random (java.util.Random)1