提交 670b4e10 authored 作者: Noel Grandin's avatar Noel Grandin

add some debugging for meta locking

上级 14d4d8ee
......@@ -899,6 +899,9 @@ public class Database implements DataHandler {
}
}
private static final ThreadLocal<Session> metaLockDebugging = new ThreadLocal<Session>();
private static final ThreadLocal<Throwable> metaLockDebuggingStack = new ThreadLocal<Throwable>();
/**
* Lock the metadata table for updates.
*
......@@ -913,6 +916,19 @@ public class Database implements DataHandler {
if (meta == null) {
return true;
}
if (SysProperties.CHECK2) {
final Session prev = metaLockDebugging.get();
if (prev == null) {
metaLockDebugging.set(session);
metaLockDebuggingStack.set(new Throwable());
} else if (prev != session) {
metaLockDebuggingStack.get().printStackTrace();
throw new IllegalStateException("meta currently locked by "
+ prev
+ " and trying to be locked by different session, "
+ session + " on same thread");
}
}
boolean wasLocked = meta.lock(session, true, true);
return wasLocked;
}
......@@ -923,10 +939,20 @@ public class Database implements DataHandler {
* @param session the session
*/
public void unlockMeta(Session session) {
unlockMetaDebug(session);
meta.unlock(session);
session.unlock(meta);
}
public void unlockMetaDebug(Session session) {
if (SysProperties.CHECK2) {
if (metaLockDebugging.get() == session) {
metaLockDebugging.set(null);
metaLockDebuggingStack.set(null);
}
}
}
/**
* Remove the given object from the meta data.
*
......@@ -956,6 +982,7 @@ public class Database implements DataHandler {
checkMetaFree(session, id);
}
} else if (!wasLocked) {
unlockMetaDebug(session);
// must not keep the lock if it was not locked
// otherwise updating sequences may cause a deadlock
meta.unlock(session);
......
......@@ -856,6 +856,9 @@ public class Session extends SessionWithState {
removeTemporaryLobs(false);
cleanTempTables(true);
// sometimes Table#removeChildrenAndResources
// will take the meta lock
database.unlockMeta(this);
undoLog.clear();
database.removeSession(this);
} finally {
......@@ -965,6 +968,7 @@ public class Session extends SessionWithState {
}
locks.clear();
}
database.unlockMetaDebug(this);
savepoints = null;
sessionStateChanged = true;
}
......@@ -991,11 +995,6 @@ public class Session extends SessionWithState {
table.truncate(this);
}
}
// sometimes Table#removeChildrenAndResources
// will take the meta lock
if (closeSession) {
database.unlockMeta(this);
}
}
}
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论