提交 c4a5040b authored 作者: Thomas Mueller's avatar Thomas Mueller

SET EXCLUSIVE now supports 0 (disable), 1 (enable), and 2 (enable and close all other connections).

上级 6f600224
...@@ -153,7 +153,19 @@ public class Set extends Prepared { ...@@ -153,7 +153,19 @@ public class Set extends Prepared {
case SetTypes.EXCLUSIVE: { case SetTypes.EXCLUSIVE: {
session.getUser().checkAdmin(); session.getUser().checkAdmin();
int value = getIntValue(); int value = getIntValue();
database.setExclusiveSession(value == 1 ? session : null); switch (value) {
case 0:
database.setExclusiveSession(null, false);
break;
case 1:
database.setExclusiveSession(session, false);
break;
case 2:
database.setExclusiveSession(session, true);
break;
default:
throw DbException.getInvalidValueException("" + value, "EXCLUSIVE");
}
break; break;
} }
case SetTypes.IGNORECASE: case SetTypes.IGNORECASE:
......
...@@ -979,6 +979,23 @@ public class Database implements DataHandler { ...@@ -979,6 +979,23 @@ public class Database implements DataHandler {
} }
} }
private synchronized void closeAllSessionsException(Session except) {
Session[] all = new Session[userSessions.size()];
userSessions.toArray(all);
for (Session s : all) {
if (s != except) {
try {
// must roll back, otherwise the session is removed and
// the transaction log that contains its uncommitted operations as well
s.rollback();
s.close();
} catch (DbException e) {
traceSystem.getTrace(Trace.SESSION).error("disconnecting #" + s.getId(), e);
}
}
}
}
/** /**
* Close the database. * Close the database.
* *
...@@ -1007,18 +1024,7 @@ public class Database implements DataHandler { ...@@ -1007,18 +1024,7 @@ public class Database implements DataHandler {
return; return;
} }
traceSystem.getTrace(Trace.DATABASE).info("closing " + databaseName + " from shutdown hook"); traceSystem.getTrace(Trace.DATABASE).info("closing " + databaseName + " from shutdown hook");
Session[] all = new Session[userSessions.size()]; closeAllSessionsException(null);
userSessions.toArray(all);
for (Session s : all) {
try {
// must roll back, otherwise the session is removed and
// the transaction log that contains its uncommitted operations as well
s.rollback();
s.close();
} catch (DbException e) {
traceSystem.getTrace(Trace.SESSION).error("disconnecting #" + s.getId(), e);
}
}
} }
traceSystem.getTrace(Trace.DATABASE).info("closing " + databaseName); traceSystem.getTrace(Trace.DATABASE).info("closing " + databaseName);
if (eventListener != null) { if (eventListener != null) {
...@@ -1968,8 +1974,11 @@ public class Database implements DataHandler { ...@@ -1968,8 +1974,11 @@ public class Database implements DataHandler {
return exclusiveSession; return exclusiveSession;
} }
public void setExclusiveSession(Session session) { public void setExclusiveSession(Session session, boolean closeOthers) {
this.exclusiveSession = session; this.exclusiveSession = session;
if (closeOthers) {
closeAllSessionsException(session);
}
} }
public SmallLRUCache<String, String[]> getLobFileListCache() { public SmallLRUCache<String, String[]> getLobFileListCache() {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论