提交 08d945e0 authored 作者: Thomas Mueller's avatar Thomas Mueller

Server-less multi-connection mode: two processes writing, corrupt after closing.

上级 62974d5f
...@@ -244,7 +244,7 @@ public class Database implements DataHandler { ...@@ -244,7 +244,7 @@ public class Database implements DataHandler {
} }
traceSystem.close(); traceSystem.close();
} }
closeOpenFilesAndUnlock(); closeOpenFilesAndUnlock(false);
throw Message.convert(e); throw Message.convert(e);
} }
} }
...@@ -371,7 +371,7 @@ public class Database implements DataHandler { ...@@ -371,7 +371,7 @@ public class Database implements DataHandler {
if (log != null) { if (log != null) {
try { try {
stopWriter(); stopWriter();
log.close(); log.close(false);
} catch (SQLException e) { } catch (SQLException e) {
// ignore // ignore
} }
...@@ -520,8 +520,7 @@ public class Database implements DataHandler { ...@@ -520,8 +520,7 @@ public class Database implements DataHandler {
.info("opening " + databaseName + " (build " + Constants.BUILD_ID + ")"); .info("opening " + databaseName + " (build " + Constants.BUILD_ID + ")");
if (autoServerMode) { if (autoServerMode) {
if (readOnly || fileLockMethod == FileLock.LOCK_NO) { if (readOnly || fileLockMethod == FileLock.LOCK_NO) {
int todoImproveErrorMessage; throw Message.getUnsupportedException("autoServerMode && (readOnly || fileLockMethod == NO)");
throw Message.getSQLException(ErrorCode.FEATURE_NOT_SUPPORTED);
} }
} }
if (!readOnly && fileLockMethod != FileLock.LOCK_NO) { if (!readOnly && fileLockMethod != FileLock.LOCK_NO) {
...@@ -1059,6 +1058,17 @@ public class Database implements DataHandler { ...@@ -1059,6 +1058,17 @@ public class Database implements DataHandler {
if (closing) { if (closing) {
return; return;
} }
if (isReconnectNeeded()) {
// another connection wrote - don't write anything
try {
closeOpenFilesAndUnlock(false);
} catch (SQLException e) {
// ignore
}
traceSystem.close();
Engine.getInstance().close(databaseName);
return;
}
closing = true; closing = true;
stopServer(); stopServer();
if (userSessions.size() > 0) { if (userSessions.size() > 0) {
...@@ -1131,7 +1141,7 @@ public class Database implements DataHandler { ...@@ -1131,7 +1141,7 @@ public class Database implements DataHandler {
} }
tempFileDeleter.deleteAll(); tempFileDeleter.deleteAll();
try { try {
closeOpenFilesAndUnlock(); closeOpenFilesAndUnlock(true);
} catch (SQLException e) { } catch (SQLException e) {
traceSystem.getTrace(Trace.DATABASE).error("close", e); traceSystem.getTrace(Trace.DATABASE).error("close", e);
} }
...@@ -1172,18 +1182,20 @@ public class Database implements DataHandler { ...@@ -1172,18 +1182,20 @@ public class Database implements DataHandler {
} }
} }
private synchronized void closeOpenFilesAndUnlock() throws SQLException { private synchronized void closeOpenFilesAndUnlock(boolean checkpoint) throws SQLException {
if (log != null) { if (log != null) {
stopWriter(); stopWriter();
try { try {
log.close(); log.close(checkpoint);
} 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) {
pageStore.checkpoint(); if (checkpoint) {
pageStore.checkpoint();
}
} }
closeFiles(); closeFiles();
if (persistent && lock == null && fileLockMethod != FileLock.LOCK_NO) { if (persistent && lock == null && fileLockMethod != FileLock.LOCK_NO) {
...@@ -1200,7 +1212,11 @@ public class Database implements DataHandler { ...@@ -1200,7 +1212,11 @@ public class Database implements DataHandler {
systemSession = null; systemSession = null;
} }
if (lock != null) { if (lock != null) {
lock.unlock(); if (fileLockMethod != FileLock.LOCK_SERIALIZED) {
// must not delete the .lock file if we wrote something,
// otherwise other connections can not detect that
lock.unlock();
}
lock = null; lock = null;
} }
} }
...@@ -2200,6 +2216,7 @@ public class Database implements DataHandler { ...@@ -2200,6 +2216,7 @@ public class Database implements DataHandler {
// it may have terminated // it may have terminated
lock.setProperty("changePending", null); lock.setProperty("changePending", null);
lock.save(); lock.save();
break;
} }
getTrace().debug("delay (change pending)"); getTrace().debug("delay (change pending)");
Thread.sleep(SysProperties.RECONNECT_CHECK_DELAY); Thread.sleep(SysProperties.RECONNECT_CHECK_DELAY);
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论