Search in sources :

Example 1 with SharedPageLockTrackerDump

use of org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.SharedPageLockTrackerDump in project ignite by apache.

the class ToStringDumpProcessor method processDump.

/**
 * @param snapshot Process lock thread dump snapshot.
 */
void processDump(SharedPageLockTrackerDump snapshot) {
    sb.append("Page locks dump:").append(U.nl()).append(U.nl());
    List<ThreadPageLockState> threadPageLockStates = new ArrayList<>(snapshot.threadPageLockStates);
    // Sort thread dump by thread names.
    threadPageLockStates.sort(Comparator.comparing(state -> state.threadName));
    for (ThreadPageLockState ths : threadPageLockStates) {
        PageLockDump pageLockDump0;
        if (ths.invalidContext == null)
            pageLockDump0 = ths.pageLockDump;
        else {
            sb.append(ths.invalidContext.msg).append(U.nl());
            pageLockDump0 = ths.invalidContext.dump;
        }
        processDump(pageLockDump0, ths);
        sb.append(U.nl());
    }
}
Also used : ThreadPageLockState(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.ThreadPageLockState) IgniteUtils.hexInt(org.apache.ignite.internal.util.IgniteUtils.hexInt) PageIdUtils.pageIndex(org.apache.ignite.internal.pagemem.PageIdUtils.pageIndex) WRITE_LOCK(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockTracker.WRITE_LOCK) LogEntry(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.log.LogEntry) U(org.apache.ignite.internal.util.typedef.internal.U) IgniteUtils.hexLong(org.apache.ignite.internal.util.IgniteUtils.hexLong) PageLockLogSnapshot(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.log.PageLockLogSnapshot) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SharedPageLockTrackerDump(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.SharedPageLockTrackerDump) SB(org.apache.ignite.internal.util.typedef.internal.SB) Map(java.util.Map) ThreadPageLockState(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.ThreadPageLockState) PageLockTracker.pageIdToString(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockTracker.pageIdToString) PageLockStackSnapshot(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.stack.PageLockStackSnapshot) WRITE_UNLOCK(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockTracker.WRITE_UNLOCK) IntFunction(java.util.function.IntFunction) PageIdUtils.partId(org.apache.ignite.internal.pagemem.PageIdUtils.partId) Instant(java.time.Instant) READ_UNLOCK(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockTracker.READ_UNLOCK) DATE_FMT(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.dumpprocessors.ToStringDumpHelper.DATE_FMT) List(java.util.List) LOCK_OP_MASK(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockTracker.LOCK_OP_MASK) PageLockDump(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockDump) BEFORE_READ_LOCK(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockTracker.BEFORE_READ_LOCK) BEFORE_WRITE_LOCK(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockTracker.BEFORE_WRITE_LOCK) READ_LOCK(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockTracker.READ_LOCK) PageIdUtils.flag(org.apache.ignite.internal.pagemem.PageIdUtils.flag) Comparator(java.util.Comparator) PageMetaInfoStore(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageMetaInfoStore) PageLockDump(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockDump) ArrayList(java.util.ArrayList)

Example 2 with SharedPageLockTrackerDump

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

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

SharedPageLockTrackerDump (org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.SharedPageLockTrackerDump)3 PageLockDump (org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockDump)2 SharedPageLockTracker (org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.SharedPageLockTracker)2 ThreadPageLockState (org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.ThreadPageLockState)2 PageLockListener (org.apache.ignite.internal.processors.cache.persistence.tree.util.PageLockListener)2 Test (org.junit.Test)2 Path (java.nio.file.Path)1 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)1 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 IntFunction (java.util.function.IntFunction)1 PageIdUtils.flag (org.apache.ignite.internal.pagemem.PageIdUtils.flag)1 PageIdUtils.pageIndex (org.apache.ignite.internal.pagemem.PageIdUtils.pageIndex)1 PageIdUtils.partId (org.apache.ignite.internal.pagemem.PageIdUtils.partId)1 BEFORE_READ_LOCK (org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockTracker.BEFORE_READ_LOCK)1 BEFORE_WRITE_LOCK (org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockTracker.BEFORE_WRITE_LOCK)1 LOCK_OP_MASK (org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockTracker.LOCK_OP_MASK)1