提交 8372db51 authored 作者: Thomas Mueller's avatar Thomas Mueller

server-less multi-connection mode: if a process terminated while writing, other…

server-less multi-connection mode: if a process terminated while writing, other open connections were blocked.
上级 cf22c641
...@@ -310,10 +310,18 @@ public class Database implements DataHandler { ...@@ -310,10 +310,18 @@ public class Database implements DataHandler {
} }
private void reconnectModified(boolean pending) { private void reconnectModified(boolean pending) {
if (readOnly || pending == reconnectChangePending || lock == null) { if (readOnly || lock == null) {
return; return;
} }
try { try {
if (pending == reconnectChangePending) {
long now = System.currentTimeMillis();
if (now > reconnectCheckNext) {
lock.save();
reconnectCheckNext = now + SysProperties.RECONNECT_CHECK_DELAY;
}
return;
}
if (pending) { if (pending) {
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));
...@@ -324,6 +332,7 @@ public class Database implements DataHandler { ...@@ -324,6 +332,7 @@ public class Database implements DataHandler {
lock.save(); lock.save();
reconnectLastLock = lock.load(); reconnectLastLock = lock.load();
reconnectChangePending = pending; reconnectChangePending = pending;
reconnectCheckNext = System.currentTimeMillis() + SysProperties.RECONNECT_CHECK_DELAY;
} catch (Exception e) { } catch (Exception e) {
getTrace().error("pending:"+ pending, e); getTrace().error("pending:"+ pending, e);
} }
...@@ -511,6 +520,7 @@ public class Database implements DataHandler { ...@@ -511,6 +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.getSQLException(ErrorCode.FEATURE_NOT_SUPPORTED); throw Message.getSQLException(ErrorCode.FEATURE_NOT_SUPPORTED);
} }
} }
...@@ -523,6 +533,7 @@ public class Database implements DataHandler { ...@@ -523,6 +533,7 @@ public class Database implements DataHandler {
} }
// wait until pending changes are written // wait until pending changes are written
isReconnectNeeded(); isReconnectNeeded();
beforeWriting();
if (SysProperties.PAGE_STORE) { if (SysProperties.PAGE_STORE) {
starting = true; starting = true;
getPageStore(); getPageStore();
...@@ -625,6 +636,7 @@ public class Database implements DataHandler { ...@@ -625,6 +636,7 @@ public class Database implements DataHandler {
} }
systemSession.commit(true); systemSession.commit(true);
traceSystem.getTrace(Trace.DATABASE).info("opened " + databaseName); traceSystem.getTrace(Trace.DATABASE).info("opened " + databaseName);
afterWriting();
} }
public Schema getMainSchema() { public Schema getMainSchema() {
...@@ -2183,6 +2195,12 @@ public class Database implements DataHandler { ...@@ -2183,6 +2195,12 @@ public class Database implements DataHandler {
if (prop.getProperty("changePending", null) == null) { if (prop.getProperty("changePending", null) == null) {
break; break;
} }
if (System.currentTimeMillis() > now + SysProperties.RECONNECT_CHECK_DELAY * 4) {
// the writing process didn't update the file -
// it may have terminated
lock.setProperty("changePending", null);
lock.save();
}
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 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论