提交 7e9cf632 authored 作者: Noel Grandin's avatar Noel Grandin

vmlens: fix race condition in Database.exclusiveSession field

上级 5508d260
......@@ -16,6 +16,7 @@ import java.util.Set;
import java.util.StringTokenizer;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicReference;
import org.h2.api.DatabaseEventListener;
import org.h2.api.ErrorCode;
import org.h2.api.JavaObjectSerializer;
......@@ -115,7 +116,7 @@ public class Database implements DataHandler {
private final Set<Session> userSessions =
Collections.synchronizedSet(new HashSet<Session>());
private Session exclusiveSession;
private final AtomicReference<Session> exclusiveSession = new AtomicReference<Session>();
private final BitField objectIds = new BitField();
private final Object lobSyncObject = new Object();
......@@ -1148,7 +1149,7 @@ public class Database implements DataHandler {
if (closing) {
return null;
}
if (exclusiveSession != null) {
if (exclusiveSession.get() != null) {
throw DbException.get(ErrorCode.DATABASE_IS_IN_EXCLUSIVE_MODE);
}
Session session = new Session(this, user, ++nextSessionId);
......@@ -1168,9 +1169,7 @@ public class Database implements DataHandler {
*/
public synchronized void removeSession(Session session) {
if (session != null) {
if (exclusiveSession == session) {
exclusiveSession = null;
}
exclusiveSession.compareAndSet(session, null);
userSessions.remove(session);
if (session != systemSession && session != lobSession) {
trace.info("disconnecting session #{0}", session.getId());
......@@ -1984,7 +1983,7 @@ public class Database implements DataHandler {
mvStore.getStore().setRetentionTime(value);
}
}
public void setAllowBuiltinAliasOverride(boolean b) {
allowBuiltinAliasOverride = b;
}
......@@ -1992,7 +1991,7 @@ public class Database implements DataHandler {
public boolean isAllowBuiltinAliasOverride() {
return allowBuiltinAliasOverride;
}
/**
* Check if flush-on-each-commit is enabled.
*
......@@ -2409,7 +2408,7 @@ public class Database implements DataHandler {
}
public Session getExclusiveSession() {
return exclusiveSession;
return exclusiveSession.get();
}
/**
......@@ -2419,10 +2418,10 @@ public class Database implements DataHandler {
* @param closeOthers whether other sessions are closed
*/
public void setExclusiveSession(Session session, boolean closeOthers) {
this.exclusiveSession = session;
if (closeOthers) {
closeAllSessionsException(session);
}
this.exclusiveSession.set(session);
if (closeOthers) {
closeAllSessionsException(session);
}
}
@Override
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论