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());
}
}
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());
}
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);
}
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());
}
Aggregations