提交 a847d39c authored 作者: christian.peter.io's avatar christian.peter.io

More bugs in the server-less multi-connection mode have been fixed:

90097 The database is read only, caches must be cleared on reconnect, etc. .
上级 c58cd967
......@@ -23,6 +23,8 @@ Change Log
</li><li>The documentation is no longer available in Japanese because the
translation was too much out of sync. Please use the Google translation instead.
</li><li>Certain queries were not sorted if subselect queries were involved
</li><li>More bugs in the server-less multi-connection mode have been fixed:
90097 The database is read only, caches must be cleared on reconnect, etc. .
</li></ul>
<h2>Version 1.2.121 (2009-10-11)</h2>
......
......@@ -188,10 +188,10 @@ return <code>X</code>. What's wrong?
<p>
This is not a bug. According the the JDBC specification, the method
<code>ResultSetMetaData.getColumnName()</code> should return the name of the column
and not the alias name. If you need the alias name, use
and not the alias name. If you need the alias name, use
<a href="http://java.sun.com/javase/6/docs/api/java/sql/ResultSetMetaData.html#getColumnLabel(int)"><code>ResultSetMetaData.getColumnLabel()</code></a>.
Other database don't work like this (they don't follow the JDBC standard).
If you need compatibility with those databases, use the <a href="features.html#compatibility">Compatibility Mode</a>,
Other database don't work like this (they don't follow the JDBC standard).
If you need compatibility with those databases, use the <a href="features.html#compatibility">Compatibility Mode</a>,
or set the system property <a href="../javadoc/org/h2/constant/SysProperties.html#h2.aliasColumnName"><code>h2.aliasColumnName</code></a>.
</p>
......
......@@ -71,6 +71,7 @@ public class CommandContainer extends Command {
prepared.checkParameters();
int updateCount = prepared.update();
prepared.trace(startTime, updateCount);
session.getDatabase().afterWriting();
return updateCount;
}
......
......@@ -42,6 +42,7 @@ public class CommandList extends Command {
public int update() throws SQLException {
int updateCount = command.executeUpdate();
executeRemaining();
session.getDatabase().afterWriting();
return updateCount;
}
......
......@@ -169,6 +169,9 @@ public class Database implements DataHandler {
private Properties reconnectLastLock;
private volatile long reconnectCheckNext;
private volatile boolean reconnectChangePending;
private volatile boolean allowedToRunCheckpoint;
private volatile boolean isCheckpointRunning;
private int cacheSize;
public Database(String name, ConnectionInfo ci, String cipher) throws SQLException {
......@@ -1801,6 +1804,21 @@ public class Database implements DataHandler {
}
}
/**
* Clears all caches.
*
* @throws SQLException
*/
public synchronized void clearCaches() throws SQLException {
if (fileData != null) {
fileData.getCache().clear();
fileIndex.getCache().clear();
}
if (pageStore != null) {
pageStore.getCache().clear();
}
}
public synchronized void setMasterUser(User user) throws SQLException {
addDatabaseObject(systemSession, user);
systemSession.commit(true);
......@@ -2365,13 +2383,23 @@ public class Database implements DataHandler {
if (fileLockMethod != FileLock.LOCK_SERIALIZED || readOnly || !reconnectChangePending || closing) {
return;
}
// To avoid race conditions, we already set it here
// (overlap with allowedToRunCheckpoint)
isCheckpointRunning = true;
if (!allowedToRunCheckpoint) {
isCheckpointRunning = false;
return;
}
long now = System.currentTimeMillis();
if (now > reconnectCheckNext + SysProperties.RECONNECT_CHECK_DELAY) {
synchronized (this) {
getTrace().debug("checkpoint");
getTrace().debug("checkpoint start");
flushIndexes(0);
checkpoint();
reconnectModified(false);
isCheckpointRunning = false;
getTrace().debug("checkpoint end");
}
}
}
......@@ -2430,12 +2458,34 @@ public class Database implements DataHandler {
*/
public boolean beforeWriting() {
if (fileLockMethod == FileLock.LOCK_SERIALIZED) {
return reconnectModified(true);
// To avoid race conditions, we already set it here (overlap with
// isCheckpointRunning)
allowedToRunCheckpoint = false;
while (isCheckpointRunning) {
try {
Thread.sleep(10+(int) Math.random() * 10);
} catch (Exception e) {
// ignore
}
}
boolean allowedToWrite = reconnectModified(true);
if (!allowedToWrite) {
// make sure the next call to isReconnectNeeded() returns yes
reconnectCheckNext = System.currentTimeMillis() - 1;
reconnectLastLock = null;
}
return allowedToWrite;
}
return true;
}
/**
* This method is called after updates are finished.
*/
public void afterWriting() {
allowedToRunCheckpoint = true;
}
/**
* Switch the database to read-only mode.
*
......
......@@ -1127,12 +1127,15 @@ public class Session extends SessionWithState {
}
}
public SessionInterface reconnect() throws SQLException {
public SessionInterface reconnect(boolean write) throws SQLException {
readSessionState();
close();
Session newSession = Engine.getInstance().getSession(connectionInfo);
newSession.sessionState = sessionState;
newSession.recreateSessionState();
database.clearCaches();
while (write && !database.beforeWriting()) {
}
return newSession;
}
......
......@@ -84,7 +84,8 @@ public interface SessionInterface {
/**
* Close the connection and open a new connection.
*
* @param write if the next operation may be writing
* @return the new connection
*/
SessionInterface reconnect() throws SQLException;
SessionInterface reconnect(boolean write) throws SQLException;
}
......@@ -653,7 +653,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
return false;
}
public SessionInterface reconnect() {
public SessionInterface reconnect(boolean write) {
return this;
}
......
......@@ -1329,7 +1329,7 @@ public class JdbcConnection extends TraceObject implements Connection {
}
if (session.isReconnectNeeded(write)) {
trace.debug("reconnect");
session = session.reconnect();
session = session.reconnect(write);
setTrace(session.getTrace());
}
}
......
......@@ -617,4 +617,4 @@ scrambling distinguish official unofficial distinguishable overwrites lastval
notranslate vince bonfanti alphabetically sysdummy sysibm activation
deactivation concatenating reproducing black railroads railroad radius moz
imageio argb bilinear rendering stroke interpolation flip diagrams draw
delim
\ No newline at end of file
delim overlap subselect
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论