提交 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 ...@@ -23,6 +23,8 @@ Change Log
</li><li>The documentation is no longer available in Japanese because the </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. 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>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> </li></ul>
<h2>Version 1.2.121 (2009-10-11)</h2> <h2>Version 1.2.121 (2009-10-11)</h2>
......
...@@ -71,6 +71,7 @@ public class CommandContainer extends Command { ...@@ -71,6 +71,7 @@ public class CommandContainer extends Command {
prepared.checkParameters(); prepared.checkParameters();
int updateCount = prepared.update(); int updateCount = prepared.update();
prepared.trace(startTime, updateCount); prepared.trace(startTime, updateCount);
session.getDatabase().afterWriting();
return updateCount; return updateCount;
} }
......
...@@ -42,6 +42,7 @@ public class CommandList extends Command { ...@@ -42,6 +42,7 @@ public class CommandList extends Command {
public int update() throws SQLException { public int update() throws SQLException {
int updateCount = command.executeUpdate(); int updateCount = command.executeUpdate();
executeRemaining(); executeRemaining();
session.getDatabase().afterWriting();
return updateCount; return updateCount;
} }
......
...@@ -169,6 +169,9 @@ public class Database implements DataHandler { ...@@ -169,6 +169,9 @@ public class Database implements DataHandler {
private Properties reconnectLastLock; private Properties reconnectLastLock;
private volatile long reconnectCheckNext; private volatile long reconnectCheckNext;
private volatile boolean reconnectChangePending; private volatile boolean reconnectChangePending;
private volatile boolean allowedToRunCheckpoint;
private volatile boolean isCheckpointRunning;
private int cacheSize; private int cacheSize;
public Database(String name, ConnectionInfo ci, String cipher) throws SQLException { public Database(String name, ConnectionInfo ci, String cipher) throws SQLException {
...@@ -1801,6 +1804,21 @@ public class Database implements DataHandler { ...@@ -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 { public synchronized void setMasterUser(User user) throws SQLException {
addDatabaseObject(systemSession, user); addDatabaseObject(systemSession, user);
systemSession.commit(true); systemSession.commit(true);
...@@ -2365,13 +2383,23 @@ public class Database implements DataHandler { ...@@ -2365,13 +2383,23 @@ public class Database implements DataHandler {
if (fileLockMethod != FileLock.LOCK_SERIALIZED || readOnly || !reconnectChangePending || closing) { if (fileLockMethod != FileLock.LOCK_SERIALIZED || readOnly || !reconnectChangePending || closing) {
return; return;
} }
// To avoid race conditions, we already set it here
// (overlap with allowedToRunCheckpoint)
isCheckpointRunning = true;
if (!allowedToRunCheckpoint) {
isCheckpointRunning = false;
return;
}
long now = System.currentTimeMillis(); long now = System.currentTimeMillis();
if (now > reconnectCheckNext + SysProperties.RECONNECT_CHECK_DELAY) { if (now > reconnectCheckNext + SysProperties.RECONNECT_CHECK_DELAY) {
synchronized (this) { synchronized (this) {
getTrace().debug("checkpoint"); getTrace().debug("checkpoint start");
flushIndexes(0); flushIndexes(0);
checkpoint(); checkpoint();
reconnectModified(false); reconnectModified(false);
isCheckpointRunning = false;
getTrace().debug("checkpoint end");
} }
} }
} }
...@@ -2430,12 +2458,34 @@ public class Database implements DataHandler { ...@@ -2430,12 +2458,34 @@ public class Database implements DataHandler {
*/ */
public boolean beforeWriting() { public boolean beforeWriting() {
if (fileLockMethod == FileLock.LOCK_SERIALIZED) { if (fileLockMethod == FileLock.LOCK_SERIALIZED) {
// To avoid race conditions, we already set it here (overlap with
return reconnectModified(true); // 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; return true;
} }
/**
* This method is called after updates are finished.
*/
public void afterWriting() {
allowedToRunCheckpoint = true;
}
/** /**
* Switch the database to read-only mode. * Switch the database to read-only mode.
* *
......
...@@ -1127,12 +1127,15 @@ public class Session extends SessionWithState { ...@@ -1127,12 +1127,15 @@ public class Session extends SessionWithState {
} }
} }
public SessionInterface reconnect() throws SQLException { public SessionInterface reconnect(boolean write) throws SQLException {
readSessionState(); readSessionState();
close(); close();
Session newSession = Engine.getInstance().getSession(connectionInfo); Session newSession = Engine.getInstance().getSession(connectionInfo);
newSession.sessionState = sessionState; newSession.sessionState = sessionState;
newSession.recreateSessionState(); newSession.recreateSessionState();
database.clearCaches();
while (write && !database.beforeWriting()) {
}
return newSession; return newSession;
} }
......
...@@ -84,7 +84,8 @@ public interface SessionInterface { ...@@ -84,7 +84,8 @@ public interface SessionInterface {
/** /**
* Close the connection and open a new connection. * Close the connection and open a new connection.
* *
* @param write if the next operation may be writing
* @return the new connection * @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 ...@@ -653,7 +653,7 @@ public class SessionRemote extends SessionWithState implements SessionFactory, D
return false; return false;
} }
public SessionInterface reconnect() { public SessionInterface reconnect(boolean write) {
return this; return this;
} }
......
...@@ -1329,7 +1329,7 @@ public class JdbcConnection extends TraceObject implements Connection { ...@@ -1329,7 +1329,7 @@ public class JdbcConnection extends TraceObject implements Connection {
} }
if (session.isReconnectNeeded(write)) { if (session.isReconnectNeeded(write)) {
trace.debug("reconnect"); trace.debug("reconnect");
session = session.reconnect(); session = session.reconnect(write);
setTrace(session.getTrace()); setTrace(session.getTrace());
} }
} }
......
...@@ -617,4 +617,4 @@ scrambling distinguish official unofficial distinguishable overwrites lastval ...@@ -617,4 +617,4 @@ scrambling distinguish official unofficial distinguishable overwrites lastval
notranslate vince bonfanti alphabetically sysdummy sysibm activation notranslate vince bonfanti alphabetically sysdummy sysibm activation
deactivation concatenating reproducing black railroads railroad radius moz deactivation concatenating reproducing black railroads railroad radius moz
imageio argb bilinear rendering stroke interpolation flip diagrams draw imageio argb bilinear rendering stroke interpolation flip diagrams draw
delim delim overlap subselect
\ No newline at end of file
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论