Search in sources :

Example 1 with SharedPageLockTracker

use of org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.SharedPageLockTracker 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 2 with SharedPageLockTracker

use of org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.SharedPageLockTracker 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)

Aggregations

SharedPageLockTracker (org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.SharedPageLockTracker)2 SharedPageLockTrackerDump (org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.SharedPageLockTrackerDump)2 PageLockListener (org.apache.ignite.internal.processors.cache.persistence.tree.util.PageLockListener)2 Test (org.junit.Test)2 Path (java.nio.file.Path)1 PageLockDump (org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockDump)1 ThreadPageLockState (org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.ThreadPageLockState)1 GridCommonAbstractTest (org.apache.ignite.testframework.junits.common.GridCommonAbstractTest)1