Search in sources :

Example 6 with PageLockListener

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

the class ToStringDumpHelperTest method toStringSharedPageLockTrackerTest.

/**
 */
@Test
public void toStringSharedPageLockTrackerTest() throws Exception {
    SharedPageLockTracker pageLockTracker = new SharedPageLockTracker();
    PageLockListener tracker = pageLockTracker.registerStructure("dummy");
    tracker.onReadLock(1, 2, 3, 4);
    tracker.onReadUnlock(1, 2, 3, 4);
    Thread asyncLockUnlock = new Thread(() -> tracker.onReadLock(4, 32, 1, 64), "async-lock-unlock");
    asyncLockUnlock.start();
    asyncLockUnlock.join();
    long threadIdInLog = asyncLockUnlock.getId();
    SharedPageLockTrackerDump pageLockDump = pageLockTracker.dump();
    // Hack to have same timestamp in test.
    for (ThreadPageLockState state : pageLockDump.threadPageLockStates) GridTestUtils.setFieldValue(state.pageLockDump, PageLockDump.class, "time", TIME);
    assertNotNull(pageLockDump);
    String dumpStr = ToStringDumpHelper.toStringDump(pageLockDump);
    String expectedLog = "Page locks dump:" + U.nl() + U.nl() + "Thread=[name=async-lock-unlock, id=" + threadIdInLog + "], state=TERMINATED" + U.nl() + "Locked pages = [32[0000000000000020](r=1|w=0)]" + U.nl() + "Locked pages log: name=async-lock-unlock time=(1596173397167, " + ToStringDumpHelper.DATE_FMT.format(Instant.ofEpochMilli(TIME)) + ")" + U.nl() + "L=1 -> Read lock pageId=32, structureId=dummy [pageIdHex=0000000000000020, partId=0, pageIdx=32, flags=00000000]" + U.nl() + U.nl() + U.nl() + U.nl();
    assertEquals(expectedLog, dumpStr);
}
Also used : ThreadPageLockState(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.ThreadPageLockState) SharedPageLockTracker(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.SharedPageLockTracker) PageLockDump(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockDump) SharedPageLockTrackerDump(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.SharedPageLockTrackerDump) PageLockListener(org.apache.ignite.internal.processors.cache.persistence.tree.util.PageLockListener) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 7 with PageLockListener

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

the class PageLockTrackerManagerTest method testMemoryCalculation0.

/**
 * @param type Tracker type.
 */
public void testMemoryCalculation0(int type) throws Exception {
    System.out.println(">>> Calculation mempory tracker type:" + type);
    int timeOutWorkerInterval = 10_000;
    System.setProperty("IGNITE_PAGE_LOCK_TRACKER_TYPE", String.valueOf(type));
    System.setProperty("IGNITE_PAGE_LOCK_TRACKER_CHECK_INTERVAL", String.valueOf(timeOutWorkerInterval));
    try {
        PageLockTrackerManager mgr = new PageLockTrackerManager(new ListeningTestLogger());
        mgr.start();
        printOverhead(mgr);
        long heapOverhead0 = mgr.getHeapOverhead();
        long offHeapOverhead0 = mgr.getOffHeapOverhead();
        long totalOverhead0 = mgr.getTotalOverhead();
        Assert.assertTrue(heapOverhead0 > 0);
        Assert.assertTrue(offHeapOverhead0 >= 0);
        Assert.assertEquals(heapOverhead0 + offHeapOverhead0, totalOverhead0);
        PageLockListener pls = mgr.createPageLockTracker("test");
        printOverhead(mgr);
        long heapOverhead1 = mgr.getHeapOverhead();
        long offHeapOverhead1 = mgr.getOffHeapOverhead();
        long totalOverhead1 = mgr.getTotalOverhead();
        Assert.assertTrue(heapOverhead1 > 0);
        Assert.assertTrue(offHeapOverhead1 >= 0);
        Assert.assertTrue(heapOverhead1 > heapOverhead0);
        Assert.assertTrue(offHeapOverhead1 >= offHeapOverhead0);
        Assert.assertEquals(heapOverhead1 + offHeapOverhead1, totalOverhead1);
        int threads = 2_000;
        int cacheId = 1;
        long pageId = 2;
        long page = 3;
        long pageAdder = 4;
        List<Thread> threadsList = new ArrayList<>(threads);
        String threadNamePreffix = "my-thread-";
        CountDownLatch startThreadsLatch = new CountDownLatch(threads);
        CountDownLatch finishThreadsLatch = new CountDownLatch(1);
        for (int i = 0; i < threads; i++) {
            Thread th = new Thread(() -> {
                startThreadsLatch.countDown();
                pls.onBeforeReadLock(cacheId, pageId, page);
                pls.onReadLock(cacheId, pageId, page, pageAdder);
                pls.onReadUnlock(cacheId, pageId, page, pageAdder);
                try {
                    finishThreadsLatch.await();
                } catch (InterruptedException ignored) {
                // No-op.
                }
            });
            th.setName(threadNamePreffix + i);
            threadsList.add(th);
            th.start();
            System.out.println(">>> start thread:" + th.getName());
        }
        startThreadsLatch.await();
        printOverhead(mgr);
        long heapOverhead2 = mgr.getHeapOverhead();
        long offHeapOverhead2 = mgr.getOffHeapOverhead();
        long totalOverhead2 = mgr.getTotalOverhead();
        Assert.assertTrue(heapOverhead2 > heapOverhead1);
        Assert.assertTrue(offHeapOverhead2 >= offHeapOverhead1);
        Assert.assertEquals(heapOverhead2 + offHeapOverhead2, totalOverhead2);
        finishThreadsLatch.countDown();
        threadsList.forEach(th -> {
            try {
                System.out.println(">>> await thread:" + th.getName());
                th.join();
            } catch (InterruptedException ignored) {
            // No-op.
            }
        });
        // Await cleanup worker interval.
        U.sleep(2 * timeOutWorkerInterval);
        printOverhead(mgr);
        long heapOverhead3 = mgr.getHeapOverhead();
        long offHeapOverhead3 = mgr.getOffHeapOverhead();
        long totalOverhead3 = mgr.getTotalOverhead();
        Assert.assertTrue(heapOverhead3 > 0);
        Assert.assertTrue(offHeapOverhead3 >= 0);
        Assert.assertTrue(heapOverhead3 < heapOverhead2);
        Assert.assertTrue(offHeapOverhead3 <= offHeapOverhead2);
        Assert.assertEquals(heapOverhead3 + offHeapOverhead3, totalOverhead3);
        mgr.stop();
    } finally {
        System.clearProperty("IGNITE_PAGE_LOCK_TRACKER_TYPE");
        System.clearProperty("IGNITE_PAGE_LOCK_TRACKER_CHECK_INTERVAL");
    }
}
Also used : ArrayList(java.util.ArrayList) ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) PageLockListener(org.apache.ignite.internal.processors.cache.persistence.tree.util.PageLockListener) CountDownLatch(java.util.concurrent.CountDownLatch)

Example 8 with PageLockListener

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

the class PageLockTrackerManagerTest method testDisableTracking.

/**
 */
@Test
public void testDisableTracking() {
    System.setProperty("IGNITE_PAGE_LOCK_TRACKER_TYPE", String.valueOf(-1));
    try {
        PageLockTrackerManager mgr = new PageLockTrackerManager(new ListeningTestLogger());
        PageLockListener pll = mgr.createPageLockTracker("test");
        Assert.assertNotNull(pll);
        Assert.assertSame(PageLockTrackerManager.NOOP_LSNR, pll);
    } finally {
        System.clearProperty("IGNITE_PAGE_LOCK_TRACKER_TYPE");
    }
    System.setProperty("IGNITE_PAGE_LOCK_TRACKER_TYPE", String.valueOf(HEAP_LOG));
    try {
        PageLockTrackerManager mgr = new PageLockTrackerManager(new ListeningTestLogger());
        PageLockListener pll = mgr.createPageLockTracker("test");
        Assert.assertNotNull(pll);
        Assert.assertNotSame(PageLockTrackerManager.NOOP_LSNR, pll);
    } finally {
        System.clearProperty("IGNITE_PAGE_LOCK_TRACKER_TYPE");
    }
}
Also used : ListeningTestLogger(org.apache.ignite.testframework.ListeningTestLogger) PageLockListener(org.apache.ignite.internal.processors.cache.persistence.tree.util.PageLockListener) GridCommonAbstractTest(org.apache.ignite.testframework.junits.common.GridCommonAbstractTest) Test(org.junit.Test)

Example 9 with PageLockListener

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

the class ToFileDumpProcessorTest method toFileDump.

/**
 */
@Test
public void toFileDump() throws Exception {
    Path homeDir = Paths.get(U.defaultWorkDirectory());
    System.out.println("IGNITE_HOME:" + homeDir);
    SharedPageLockTracker pageLockTracker = new SharedPageLockTracker();
    try (PageLockListener tracker = pageLockTracker.registerStructure("dummy")) {
        tracker.onBeforeReadLock(1, 2, 3);
        tracker.onReadLock(1, 2, 3, 4);
    }
    SharedPageLockTrackerDump pageLockDump = pageLockTracker.dump();
    assertNotNull(pageLockDump);
    file = Paths.get(ToFileDumpProcessor.toFileDump(pageLockDump, homeDir, "test"));
    System.out.println("Dump saved:" + file);
    try (Stream<Path> stream = Files.list(homeDir)) {
        assertTrue(stream.map(Path::toAbsolutePath).anyMatch(file::equals));
    }
    String actDumpStr = new String(Files.readAllBytes(file), StandardCharsets.UTF_8);
    assertEquals(ToStringDumpHelper.toStringDump(pageLockDump), actDumpStr);
}
Also used : Path(java.nio.file.Path) SharedPageLockTracker(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.SharedPageLockTracker) SharedPageLockTrackerDump(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.SharedPageLockTrackerDump) PageLockListener(org.apache.ignite.internal.processors.cache.persistence.tree.util.PageLockListener) Test(org.junit.Test)

Example 10 with PageLockListener

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

the class BPlusTreeSelfTest method beforeTest.

/**
 * {@inheritDoc}
 */
@Override
protected void beforeTest() throws Exception {
    stop.set(false);
    long seed = System.nanoTime();
    X.println("Test seed: " + seed + "L; // ");
    rnd = new Random(seed);
    pageMem = createPageMemory();
    reuseList = createReuseList(CACHE_ID, pageMem, 0, true);
    lockTrackerManager = new PageLockTrackerManager(log, "testTreeManager") {

        @Override
        public PageLockListener createPageLockTracker(String name) {
            return new TestPageLockListener(super.createPageLockTracker(name));
        }
    };
    lockTrackerManager.start();
}
Also used : Random(java.util.Random) GridRandom(org.apache.ignite.internal.util.GridRandom) ThreadLocalRandom(java.util.concurrent.ThreadLocalRandom) PageLockListener(org.apache.ignite.internal.processors.cache.persistence.tree.util.PageLockListener) PageLockTrackerManager(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockTrackerManager)

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