Search in sources :

Example 1 with ThreadPageLockState

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

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

the class ToStringDumpProcessor method processDump.

/**
 * @param snapshot Process lock log snapshot.
 */
private void processDump(PageLockLogSnapshot snapshot, ThreadPageLockState threadState) {
    Map<Long, LockState> holdetLocks = new LinkedHashMap<>();
    SB logLocksStr = new SB();
    List<LogEntry> locklog = snapshot.locklog;
    int nextOp = snapshot.nextOp;
    long nextOpPageId = snapshot.nextOpPageId;
    int nextOpStructureId = snapshot.nextOpStructureId;
    for (LogEntry entry : locklog) {
        int op = entry.operation;
        long pageId = entry.pageId;
        int locksHolded = entry.holdedLocks;
        if (op == READ_LOCK || op == WRITE_LOCK || op == BEFORE_READ_LOCK || op == BEFORE_WRITE_LOCK) {
            LockState state = holdetLocks.get(pageId);
            if (state == null)
                holdetLocks.put(pageId, state = new LockState());
            if (op == READ_LOCK)
                state.readlock++;
            if (op == WRITE_LOCK)
                state.writelock++;
            logLocksStr.a("L=" + locksHolded + " -> " + buildPageInfo(entry) + U.nl());
        }
        if (op == READ_UNLOCK || op == WRITE_UNLOCK) {
            LockState state = holdetLocks.get(pageId);
            if (op == READ_UNLOCK)
                state.readlock--;
            if (op == WRITE_UNLOCK)
                state.writelock--;
            if (state.readlock == 0 && state.writelock == 0)
                holdetLocks.remove(pageId);
            logLocksStr.a("L=" + locksHolded + " <- " + buildPageInfo(entry) + U.nl());
        }
    }
    if (nextOpPageId != 0) {
        logLocksStr.a("-> " + operationToString(nextOp) + " nextOpPageId=" + nextOpPageId + ", nextOpStructureId=" + structureIdMapFunc.apply(nextOpStructureId) + " [pageIdHex=" + hexLong(nextOpPageId) + ", partId=" + partId(nextOpPageId) + ", pageIdx=" + pageIndex(nextOpPageId) + ", flags=" + hexInt(flag(nextOpPageId)) + "]" + U.nl());
    }
    if (threadState != null) {
        if (holdetLocks.isEmpty() && logLocksStr.length() == 0)
            return;
        appendThreadInfo(sb, threadState);
    }
    sb.append(lockedPagesInfo(holdetLocks)).append(U.nl());
    sb.append("Locked pages log: ").append(snapshot.name).append(" time=(").append(snapshot.time).append(", ").append(DATE_FMT.format(Instant.ofEpochMilli(snapshot.time))).append(")").append(U.nl());
    sb.append(logLocksStr).append(U.nl());
}
Also used : IgniteUtils.hexLong(org.apache.ignite.internal.util.IgniteUtils.hexLong) ThreadPageLockState(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.ThreadPageLockState) LogEntry(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.log.LogEntry) LinkedHashMap(java.util.LinkedHashMap) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Example 3 with ThreadPageLockState

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

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

the class ToStringDumpProcessor method processDump.

/**
 * @param snapshot Process lock stack snapshot.
 */
private void processDump(PageLockStackSnapshot snapshot, ThreadPageLockState threadState) {
    int headIdx = snapshot.headIdx;
    PageMetaInfoStore pageIdLocksStack = snapshot.pageIdLocksStack;
    long nextOpPageId = snapshot.nextOpPageId;
    Map<Long, LockState> holdedLocks = new LinkedHashMap<>();
    SB stackStr = new SB();
    if (nextOpPageId != 0)
        stackStr.a("\t-> " + operationToString(snapshot.nextOp) + " structureId=" + structureIdMapFunc.apply(snapshot.nextOpStructureId) + " " + pageIdToString(nextOpPageId) + U.nl());
    for (int itemIdx = headIdx - 1; itemIdx >= 0; itemIdx--) {
        long pageId = pageIdLocksStack.getPageId(itemIdx);
        if (pageId == 0 && itemIdx == 0)
            break;
        int op;
        if (pageId == 0) {
            stackStr.a("\t -\n");
            continue;
        } else {
            op = pageIdLocksStack.getOperation(itemIdx) & LOCK_OP_MASK;
            int structureId = pageIdLocksStack.getStructureId(itemIdx);
            stackStr.a("\t" + operationToString(op) + " structureId=" + structureIdMapFunc.apply(structureId) + " " + pageIdToString(pageId) + U.nl());
        }
        if (op == READ_LOCK || op == WRITE_LOCK || op == BEFORE_READ_LOCK) {
            LockState state = holdedLocks.get(pageId);
            if (state == null)
                holdedLocks.put(pageId, state = new LockState());
            if (op == READ_LOCK)
                state.readlock++;
            if (op == WRITE_LOCK)
                state.writelock++;
        }
    }
    if (threadState != null) {
        if (holdedLocks.isEmpty())
            return;
        appendThreadInfo(sb, threadState);
    }
    sb.append(lockedPagesInfo(holdedLocks)).append(U.nl());
    sb.append("Locked pages stack: ").append(snapshot.name).append(" time=(").append(snapshot.time).append(", ").append(DATE_FMT.format(Instant.ofEpochMilli(snapshot.time))).append(")").append(U.nl());
    sb.append(stackStr).append(U.nl());
}
Also used : PageMetaInfoStore(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageMetaInfoStore) IgniteUtils.hexLong(org.apache.ignite.internal.util.IgniteUtils.hexLong) ThreadPageLockState(org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.ThreadPageLockState) LinkedHashMap(java.util.LinkedHashMap) SB(org.apache.ignite.internal.util.typedef.internal.SB)

Aggregations

ThreadPageLockState (org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.ThreadPageLockState)4 LinkedHashMap (java.util.LinkedHashMap)3 IgniteUtils.hexLong (org.apache.ignite.internal.util.IgniteUtils.hexLong)3 SB (org.apache.ignite.internal.util.typedef.internal.SB)3 PageLockDump (org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageLockDump)2 PageMetaInfoStore (org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.PageMetaInfoStore)2 SharedPageLockTrackerDump (org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.SharedPageLockTrackerDump)2 LogEntry (org.apache.ignite.internal.processors.cache.persistence.diagnostic.pagelocktracker.log.LogEntry)2 Instant (java.time.Instant)1 ArrayList (java.util.ArrayList)1 Comparator (java.util.Comparator)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