提交 62babe31 authored 作者: christian.peter.io's avatar christian.peter.io

More bugs in the server-less multi-connection mode have been fixed: Wrong…

More bugs in the server-less multi-connection mode have been fixed: Wrong Database instance after session reconnect
上级 04ff535e
......@@ -566,12 +566,6 @@ public class SysProperties {
*/
public static final int RECONNECT_CHECK_DELAY = getIntSetting("h2.reconnectCheckDelay", 200);
/**
* System property <code>h2.reconnectClearCache</code> (default: false).<br />
* Clear the database cache after re-connecting.
*/
public static final boolean RECONNECT_CLEAR_CACHE = getBooleanSetting("h2.reconnectClearCache", false);
/**
* System property <code>h2.redoBufferSize</code> (default: 262144).<br />
* Size of the redo buffer (used at startup when recovering).
......
......@@ -1804,23 +1804,6 @@ public class Database implements DataHandler {
}
}
/**
* Clears all caches.
*
* @throws SQLException
*/
public synchronized void clearCaches() throws SQLException {
if (SysProperties.RECONNECT_CLEAR_CACHE) {
if (fileData != null) {
fileData.getCache().clear();
fileIndex.getCache().clear();
}
if (pageStore != null) {
pageStore.getCache().clear();
}
}
}
public synchronized void setMasterUser(User user) throws SQLException {
addDatabaseObject(systemSession, user);
systemSession.commit(true);
......
......@@ -111,6 +111,8 @@ public class Engine {
String lockMethodName = ci.getProperty("FILE_LOCK", null);
int fileLockMethod = FileLock.getFileLockMethod(lockMethodName);
if (fileLockMethod == FileLock.LOCK_SERIALIZED) {
// In serialized mode, database instance sharing is not possible
ci.setProperty("OPEN_NEW", "TRUE");
try {
backup = (ConnectionInfo) ci.clone();
} catch (CloneNotSupportedException e) {
......
......@@ -1133,7 +1133,6 @@ public class Session extends SessionWithState {
Session newSession = Engine.getInstance().getSession(connectionInfo);
newSession.sessionState = sessionState;
newSession.recreateSessionState();
database.clearCaches();
if (write) {
while (!database.beforeWriting()) {
// wait until we are allowed to write
......
......@@ -33,8 +33,12 @@ public class TestFileLockSerialized extends TestBase {
}
public void test() throws Exception {
println("testCache()");
testCache();
println("testWrongDatabaseInstanceOnReconnect");
testWrongDatabaseInstanceOnReconnect();
println("testCache(false)");
testCache(false);
println("testCache(true)");
testCache(true);
println("testBigDatabase(false)");
testBigDatabase(false);
println("testBigDatabase(true)");
......@@ -368,27 +372,48 @@ public class TestFileLockSerialized extends TestBase {
*
* @throws Exception
*/
private void testCache() throws Exception {
private void testCache(boolean reconnectClearCache) throws Exception {
deleteDb("fileLockSerialized");
String urlShared = "jdbc:h2:" + baseDir + "/fileLockSerialized;FILE_LOCK=SERIALIZED";
String urlForNew = urlShared + ";OPEN_NEW=TRUE";
Connection connShared1 = DriverManager.getConnection(urlShared);
Statement statement1 = connShared1.createStatement();
Connection connShared2 = DriverManager.getConnection(urlShared);
Connection connNew = DriverManager.getConnection(urlForNew);
connShared1.createStatement().execute("create table test(id int)");
connShared1.createStatement().execute("insert into test values(1)");
ResultSet rs = connShared1.createStatement().executeQuery("select id from test");
Statement statement2 = connShared2.createStatement();
statement1.execute("create table test1(id int)");
statement1.execute("insert into test1 values(1)");
ResultSet rs = statement1.executeQuery("select id from test1");
rs.close();
rs = statement2.executeQuery("select id from test1");
rs.close();
connNew.createStatement().execute("update test set id=2");
statement1.execute("update test1 set id=2");
Thread.sleep(500);
rs = connShared1.createStatement().executeQuery("select id from test");
rs = statement2.executeQuery("select id from test1");
assertTrue(rs.next());
assertEquals(2, rs.getInt(1));
rs.close();
connShared1.close();
connShared2.close();
deleteDb("fileLockSerialized");
}
private void testWrongDatabaseInstanceOnReconnect() throws Exception {
deleteDb("fileLockSerialized");
String urlShared = "jdbc:h2:" + baseDir + "/fileLockSerialized;FILE_LOCK=SERIALIZED";
String urlForNew = urlShared + ";OPEN_NEW=TRUE";
Connection connShared1 = DriverManager.getConnection(urlShared);
Statement statement1 = connShared1.createStatement();
Connection connShared2 = DriverManager.getConnection(urlShared);
Connection connNew = DriverManager.getConnection(urlForNew);
statement1.execute("create table test1(id int)");
connShared1.close();
connShared2.close();
connNew.close();
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论