提交 c6584ac2 authored 作者: Noel Grandin's avatar Noel Grandin

revert some unnecessary synchronization

revert parts of  21da5178 "Issue #255: ConcurrentModificationException
with multiple threads in embedded mode and temporary LOBs"

There is no need to lock all sessions this aggressively, it's just the
system session we have to be careful with.
上级 53439d35
......@@ -76,52 +76,50 @@ public class Engine implements SessionFactory {
DATABASES.put(name, database);
}
}
synchronized (database) {
if (opened) {
// start the thread when already synchronizing on the database
// otherwise a deadlock can occur when the writer thread
// opens a new database (as in recovery testing)
database.opened();
}
if (database.isClosing()) {
return null;
}
if (user == null) {
if (database.validateFilePasswordHash(cipher, ci.getFilePasswordHash())) {
user = database.findUser(ci.getUserName());
if (user != null) {
if (!user.validateUserPasswordHash(ci.getUserPasswordHash())) {
user = null;
}
if (opened) {
// start the thread when already synchronizing on the database
// otherwise a deadlock can occur when the writer thread
// opens a new database (as in recovery testing)
database.opened();
}
if (database.isClosing()) {
return null;
}
if (user == null) {
if (database.validateFilePasswordHash(cipher, ci.getFilePasswordHash())) {
user = database.findUser(ci.getUserName());
if (user != null) {
if (!user.validateUserPasswordHash(ci.getUserPasswordHash())) {
user = null;
}
}
if (opened && (user == null || !user.isAdmin())) {
// reset - because the user is not an admin, and has no
// right to listen to exceptions
database.setEventListener(null);
}
}
if (user == null) {
DbException er = DbException.get(ErrorCode.WRONG_USER_OR_PASSWORD);
database.getTrace(Trace.DATABASE).error(er, "wrong user or password; user: \"" +
ci.getUserName() + "\"");
database.removeSession(null);
throw er;
if (opened && (user == null || !user.isAdmin())) {
// reset - because the user is not an admin, and has no
// right to listen to exceptions
database.setEventListener(null);
}
checkClustering(ci, database);
Session session = database.createSession(user);
if (ci.getProperty("JMX", false)) {
try {
Utils.callStaticMethod(
"org.h2.jmx.DatabaseInfo.registerMBean", ci, database);
} catch (Exception e) {
database.removeSession(session);
throw DbException.get(ErrorCode.FEATURE_NOT_SUPPORTED_1, e, "JMX");
}
jmx = true;
}
if (user == null) {
DbException er = DbException.get(ErrorCode.WRONG_USER_OR_PASSWORD);
database.getTrace(Trace.DATABASE).error(er, "wrong user or password; user: \"" +
ci.getUserName() + "\"");
database.removeSession(null);
throw er;
}
checkClustering(ci, database);
Session session = database.createSession(user);
if (ci.getProperty("JMX", false)) {
try {
Utils.callStaticMethod(
"org.h2.jmx.DatabaseInfo.registerMBean", ci, database);
} catch (Exception e) {
database.removeSession(session);
throw DbException.get(ErrorCode.FEATURE_NOT_SUPPORTED_1, e, "JMX");
}
return session;
jmx = true;
}
return session;
}
/**
......
......@@ -650,7 +650,8 @@ public class Session extends SessionWithState {
private void removeTemporaryLobs(boolean onTimeout) {
if (SysProperties.CHECK2) {
if (!Thread.holdsLock(this) && !Thread.holdsLock(getDatabase())) {
if (this == getDatabase().getLobSession()
&& !Thread.holdsLock(this) && !Thread.holdsLock(getDatabase())) {
throw DbException.throwInternalError();
}
}
......
......@@ -581,9 +581,7 @@ public class SessionRemote extends SessionWithState implements DataHandler {
}
traceSystem.close();
if (embedded != null) {
synchronized (embedded) {
embedded.close();
}
embedded.close();
embedded = null;
}
if (closeError != null) {
......
......@@ -181,9 +181,7 @@ public class TcpServerThread implements Runnable {
server.traceError(e);
}
try {
synchronized (session) {
session.close();
}
session.close();
server.removeConnection(threadId);
} catch (RuntimeException e) {
if (closeError == null) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论