提交 26a94693 authored 作者: noelgrandin's avatar noelgrandin

Issue 506: RFE: Include Thread.getName() in case of a deadlock

上级 dc3c9717
......@@ -106,6 +106,7 @@ public class Session extends SessionWithState {
private int queryTimeout;
private boolean commitOrRollbackDisabled;
private Table waitForLock;
private Thread waitForLockThread;
private int modificationId;
private int objectId;
private final int queryCacheSize;
......@@ -1292,14 +1293,19 @@ public class Session extends SessionWithState {
return queryTimeout;
}
public void setWaitForLock(Table table) {
this.waitForLock = table;
public void setWaitForLock(Table waitForLock, Thread waitForLockThread) {
this.waitForLock = waitForLock;
this.waitForLockThread = waitForLockThread;
}
public Table getWaitForLock() {
return waitForLock;
}
public Thread getWaitForLockThread() {
return waitForLockThread;
}
public int getModificationId() {
return modificationId;
}
......
......@@ -11,7 +11,6 @@ import java.util.Collections;
import java.util.Comparator;
import java.util.HashSet;
import java.util.Set;
import org.h2.api.DatabaseEventListener;
import org.h2.command.ddl.Analyze;
import org.h2.command.ddl.CreateTableData;
......@@ -127,7 +126,7 @@ public class MVTable extends TableBase {
try {
doLock(session, lockMode, exclusive);
} finally {
session.setWaitForLock(null);
session.setWaitForLock(null, null);
}
}
}
......@@ -175,7 +174,7 @@ public class MVTable extends TableBase {
return;
}
}
session.setWaitForLock(this);
session.setWaitForLock(this, Thread.currentThread());
if (checkDeadlock) {
ArrayList<Session> sessions = checkDeadlock(session, null, null);
if (sessions != null) {
......@@ -219,11 +218,16 @@ public class MVTable extends TableBase {
}
private static String getDeadlockDetails(ArrayList<Session> sessions) {
// We add the thread details here to make it easier for customers to match up
// these error messages with their own logs.
StringBuilder buff = new StringBuilder();
for (Session s : sessions) {
Table lock = s.getWaitForLock();
Thread thread = s.getWaitForLockThread();
buff.append("\nSession ").
append(s.toString()).
append(" on thread ").
append(thread.getName()).
append(" is waiting to lock ").
append(lock.toString()).
append(" while locking ");
......
......@@ -451,7 +451,7 @@ public class RegularTable extends TableBase {
try {
doLock(session, lockMode, exclusive);
} finally {
session.setWaitForLock(null);
session.setWaitForLock(null, null);
}
}
}
......@@ -499,7 +499,7 @@ public class RegularTable extends TableBase {
return;
}
}
session.setWaitForLock(this);
session.setWaitForLock(this, Thread.currentThread());
if (checkDeadlock) {
ArrayList<Session> sessions = checkDeadlock(session, null, null);
if (sessions != null) {
......@@ -543,11 +543,16 @@ public class RegularTable extends TableBase {
}
private static String getDeadlockDetails(ArrayList<Session> sessions) {
// We add the thread details here to make it easier for customers to match up
// these error messages with their own logs.
StringBuilder buff = new StringBuilder();
for (Session s : sessions) {
Table lock = s.getWaitForLock();
Thread thread = s.getWaitForLockThread();
buff.append("\nSession ").
append(s.toString()).
append(" on thread ").
append(thread.getName()).
append(" is waiting to lock ").
append(lock.toString()).
append(" while locking ");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论