提交 5f5b2e7d authored 作者: Thomas Mueller's avatar Thomas Mueller

Serialized access mode (server-less multi-connection mode): sequences did not work as expected.

上级 e5c1e4df
...@@ -18,7 +18,9 @@ Change Log ...@@ -18,7 +18,9 @@ Change Log
<h1>Change Log</h1> <h1>Change Log</h1>
<h2>Next Version (unreleased)</h2> <h2>Next Version (unreleased)</h2>
<ul><li>Page store: new databases can not be opened with older versions. <ul><li>Serialized access mode (server-less multi-connection mode): sequences did not work as expected
(there were gaps in generated values when using multiple connections).
</li><li>Page store: new databases can not be opened with older versions.
</li><li>Page store: adding data to new database is now faster. </li><li>Page store: adding data to new database is now faster.
</li><li>File system: getting the file name from a path is now faster. This should </li><li>File system: getting the file name from a path is now faster. This should
speed up BLOB and CLOB access. speed up BLOB and CLOB access.
......
...@@ -2412,6 +2412,7 @@ public class Database implements DataHandler { ...@@ -2412,6 +2412,7 @@ public class Database implements DataHandler {
synchronized (this) { synchronized (this) {
getTrace().debug("checkpoint start"); getTrace().debug("checkpoint start");
flushIndexes(0); flushIndexes(0);
flushSequences();
checkpoint(); checkpoint();
reconnectModified(false); reconnectModified(false);
getTrace().debug("checkpoint end"); getTrace().debug("checkpoint end");
...@@ -2455,6 +2456,13 @@ public class Database implements DataHandler { ...@@ -2455,6 +2456,13 @@ public class Database implements DataHandler {
} }
} }
private void flushSequences() throws SQLException {
for (SchemaObject obj : getAllSchemaObjects(DbObject.SEQUENCE)) {
Sequence sequence = (Sequence) obj;
sequence.flushWithoutMargin();
}
}
/** /**
* Flush all changes and open a new log file. * Flush all changes and open a new log file.
*/ */
...@@ -2463,7 +2471,6 @@ public class Database implements DataHandler { ...@@ -2463,7 +2471,6 @@ public class Database implements DataHandler {
if (pageStore != null) { if (pageStore != null) {
pageStore.checkpoint(); pageStore.checkpoint();
} }
LogSystem log = getLog();
if (log != null) { if (log != null) {
log.checkpoint(); log.checkpoint();
} }
......
...@@ -99,6 +99,16 @@ public class Sequence extends SchemaObjectBase { ...@@ -99,6 +99,16 @@ public class Sequence extends SchemaObjectBase {
return v; return v;
} }
/**
* Flush the current value to disk.
*/
public void flushWithoutMargin() throws SQLException {
if (valueWithMargin != value) {
valueWithMargin = value;
flush(null);
}
}
/** /**
* Flush the current value, including the margin, to disk. * Flush the current value, including the margin, to disk.
* *
...@@ -133,8 +143,7 @@ public class Sequence extends SchemaObjectBase { ...@@ -133,8 +143,7 @@ public class Sequence extends SchemaObjectBase {
* Flush the current value to disk and close this object. * Flush the current value to disk and close this object.
*/ */
public void close() throws SQLException { public void close() throws SQLException {
valueWithMargin = value; flushWithoutMargin();
flush(null);
} }
public int getType() { public int getType() {
......
...@@ -299,6 +299,9 @@ java org.h2.test.TestAll timer ...@@ -299,6 +299,9 @@ java org.h2.test.TestAll timer
/* /*
power failure test: larger binaries and additional indexes
(with many columns).
increment storage read version increment storage read version
update copyright to 2010 update copyright to 2010
......
...@@ -36,6 +36,8 @@ public class TestFileLockSerialized extends TestBase { ...@@ -36,6 +36,8 @@ public class TestFileLockSerialized extends TestBase {
} }
public void test() throws Exception { public void test() throws Exception {
println("testSequenceFlush");
testSequenceFlush();
println("testLeftLogFiles"); println("testLeftLogFiles");
testLeftLogFiles(); testLeftLogFiles();
println("testWrongDatabaseInstanceOnReconnect"); println("testWrongDatabaseInstanceOnReconnect");
...@@ -66,6 +68,25 @@ public class TestFileLockSerialized extends TestBase { ...@@ -66,6 +68,25 @@ public class TestFileLockSerialized extends TestBase {
testConcurrentReadWrite(); testConcurrentReadWrite();
} }
private void testSequenceFlush() throws Exception {
deleteDb("fileLockSerialized");
String url = "jdbc:h2:" + baseDir + "/fileLockSerialized;FILE_LOCK=SERIALIZED;OPEN_NEW=TRUE";
ResultSet rs;
Connection conn1 = DriverManager.getConnection(url);
Statement stat1 = conn1.createStatement();
stat1.execute("create sequence seq");
rs = stat1.executeQuery("call seq.nextval");
rs.next();
assertEquals(1, rs.getInt(1));
Connection conn2 = DriverManager.getConnection(url);
Statement stat2 = conn2.createStatement();
rs = stat2.executeQuery("call seq.nextval");
rs.next();
assertEquals(2, rs.getInt(1));
conn1.close();
conn2.close();
}
private void testThreeMostlyReaders(final boolean write) throws Exception { private void testThreeMostlyReaders(final boolean write) throws Exception {
boolean longRun = false; boolean longRun = false;
deleteDb("fileLockSerialized"); deleteDb("fileLockSerialized");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论