提交 36098d30 authored 作者: Thomas Mueller's avatar Thomas Mueller

Server-less multi-connection mode: more bugs are fixed.

上级 4be10d34
...@@ -334,6 +334,9 @@ public class Database implements DataHandler { ...@@ -334,6 +334,9 @@ public class Database implements DataHandler {
} }
Properties old = lock.load(); Properties old = lock.load();
if (pending) { if (pending) {
if (old.getProperty("changePending") != null) {
return false;
}
getTrace().debug("wait before writing"); getTrace().debug("wait before writing");
Thread.sleep((int) (SysProperties.RECONNECT_CHECK_DELAY * 1.1)); Thread.sleep((int) (SysProperties.RECONNECT_CHECK_DELAY * 1.1));
Properties now = lock.load(); Properties now = lock.load();
...@@ -358,6 +361,8 @@ public class Database implements DataHandler { ...@@ -358,6 +361,8 @@ public class Database implements DataHandler {
// somebody else was faster // somebody else was faster
return false; return false;
} }
} else {
Thread.sleep(1);
} }
reconnectLastLock = old; reconnectLastLock = old;
reconnectChangePending = pending; reconnectChangePending = pending;
...@@ -567,9 +572,8 @@ public class Database implements DataHandler { ...@@ -567,9 +572,8 @@ public class Database implements DataHandler {
startServer(lock.getUniqueId()); startServer(lock.getUniqueId());
} }
} }
// wait until pending changes are written while (isReconnectNeeded() && !beforeWriting()) {
isReconnectNeeded(); // wait until others stopped writing and
while (!beforeWriting()) {
// until we can write (file are not open - no need to re-connect) // until we can write (file are not open - no need to re-connect)
} }
if (exists) { if (exists) {
...@@ -1213,18 +1217,23 @@ public class Database implements DataHandler { ...@@ -1213,18 +1217,23 @@ public class Database implements DataHandler {
} }
} }
private synchronized void closeOpenFilesAndUnlock(boolean checkpoint) throws SQLException { /**
* Close all open files and unlock the database.
*
* @param flush whether writing is allowed
*/
private synchronized void closeOpenFilesAndUnlock(boolean flush) throws SQLException {
if (log != null) { if (log != null) {
stopWriter(); stopWriter();
try { try {
log.close(checkpoint); log.close(flush);
} catch (Throwable e) { } catch (Throwable e) {
traceSystem.getTrace(Trace.DATABASE).error("close", e); traceSystem.getTrace(Trace.DATABASE).error("close", e);
} }
log = null; log = null;
} }
if (pageStore != null) { if (pageStore != null) {
if (checkpoint) { if (flush) {
try { try {
pageStore.checkpoint(); pageStore.checkpoint();
} catch (Throwable e) { } catch (Throwable e) {
...@@ -2249,7 +2258,7 @@ public class Database implements DataHandler { ...@@ -2249,7 +2258,7 @@ public class Database implements DataHandler {
* Check if the contents of the database was changed and therefore it is * Check if the contents of the database was changed and therefore it is
* required to re-connect. This method waits until pending changes are * required to re-connect. This method waits until pending changes are
* completed. If a pending change takes too long (more than 2 seconds), the * completed. If a pending change takes too long (more than 2 seconds), the
* pending change is broken. * pending change is broken (removed from the properties file).
* *
* @return true if reconnecting is required * @return true if reconnecting is required
*/ */
...@@ -2319,6 +2328,10 @@ public class Database implements DataHandler { ...@@ -2319,6 +2328,10 @@ public class Database implements DataHandler {
} }
} }
public boolean isFileLockSerialized() {
return fileLockMethod == FileLock.LOCK_SERIALIZED;
}
/** /**
* Flush the indexes that were last changed prior to some time. * Flush the indexes that were last changed prior to some time.
* *
...@@ -2369,6 +2382,7 @@ public class Database implements DataHandler { ...@@ -2369,6 +2382,7 @@ public class Database implements DataHandler {
*/ */
public boolean beforeWriting() { public boolean beforeWriting() {
if (fileLockMethod == FileLock.LOCK_SERIALIZED) { if (fileLockMethod == FileLock.LOCK_SERIALIZED) {
return reconnectModified(true); return reconnectModified(true);
} }
return true; return true;
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论