提交 873aa03f authored 作者: Evgenij Ryazanov's avatar Evgenij Ryazanov

Fix differences in checks for unsupported combination of lock mode with other flags

上级 f97a3dcc
...@@ -229,7 +229,7 @@ Transaction isolation is provided for all data manipulation language (DML) state ...@@ -229,7 +229,7 @@ Transaction isolation is provided for all data manipulation language (DML) state
<p> <p>
Please note that with default MVStore storage engine table level locking is not used. Please note that with default MVStore storage engine table level locking is not used.
Instead, rows are locked for update, and read committed is used in all cases Instead, rows are locked for update, and read committed is used in all cases
(changing the isolation level has no effect). except for explicitly selected read uncommitted transaction isolation level.
</p> </p>
<p> <p>
This database supports the following transaction isolation levels: This database supports the following transaction isolation levels:
...@@ -247,7 +247,9 @@ This database supports the following transaction isolation levels: ...@@ -247,7 +247,9 @@ This database supports the following transaction isolation levels:
To enable, execute the SQL statement <code>SET LOCK_MODE 1</code><br /> To enable, execute the SQL statement <code>SET LOCK_MODE 1</code><br />
or append <code>;LOCK_MODE=1</code> to the database URL: <code>jdbc:h2:~/test;LOCK_MODE=1</code> or append <code>;LOCK_MODE=1</code> to the database URL: <code>jdbc:h2:~/test;LOCK_MODE=1</code>
</li><li><b>Read Uncommitted</b><br /> </li><li><b>Read Uncommitted</b><br />
This level means that transaction isolation is disabled.<br /> This level means that transaction isolation is disabled.
This level is not supported by PageStore engine if multi-threaded mode is enabled.
<br />
To enable, execute the SQL statement <code>SET LOCK_MODE 0</code><br /> To enable, execute the SQL statement <code>SET LOCK_MODE 0</code><br />
or append <code>;LOCK_MODE=0</code> to the database URL: <code>jdbc:h2:~/test;LOCK_MODE=0</code> or append <code>;LOCK_MODE=0</code> to the database URL: <code>jdbc:h2:~/test;LOCK_MODE=0</code>
</li> </li>
......
...@@ -2265,12 +2265,12 @@ public class Database implements DataHandler { ...@@ -2265,12 +2265,12 @@ public class Database implements DataHandler {
switch (lockMode) { switch (lockMode) {
case Constants.LOCK_MODE_OFF: case Constants.LOCK_MODE_OFF:
if (multiThreaded && !isMVStore()) { if (multiThreaded && !isMVStore()) {
// currently the combination of MVCC=FALSE, LOCK_MODE=0 and MULTI_THREADED // Currently the combination of MV_STORE=FALSE, LOCK_MODE=0 and
// is not supported. also see code in // MULTI_THREADED=TRUE is not supported. Also see code in
// JdbcDatabaseMetaData#supportsTransactionIsolationLevel(int) // JdbcDatabaseMetaData#supportsTransactionIsolationLevel(int)
throw DbException.get( throw DbException.get(
ErrorCode.UNSUPPORTED_SETTING_COMBINATION, ErrorCode.UNSUPPORTED_SETTING_COMBINATION,
"MVCC=FALSE & LOCK_MODE=0 & MULTI_THREADED"); "MV_STORE=FALSE & LOCK_MODE=0 & MULTI_THREADED=TRUE");
} }
break; break;
case Constants.LOCK_MODE_READ_COMMITTED: case Constants.LOCK_MODE_READ_COMMITTED:
...@@ -2457,12 +2457,12 @@ public class Database implements DataHandler { ...@@ -2457,12 +2457,12 @@ public class Database implements DataHandler {
public void setMultiThreaded(boolean multiThreaded) { public void setMultiThreaded(boolean multiThreaded) {
if (multiThreaded && this.multiThreaded != multiThreaded) { if (multiThreaded && this.multiThreaded != multiThreaded) {
if (lockMode == 0) { if (lockMode == Constants.LOCK_MODE_OFF && !isMVStore()) {
// currently the combination of LOCK_MODE=0 and MULTI_THREADED // Currently the combination of MV_STORE=FALSE, LOCK_MODE=0 and
// is not supported // MULTI_THREADED=TRUE is not supported.
throw DbException.get( throw DbException.get(
ErrorCode.UNSUPPORTED_SETTING_COMBINATION, ErrorCode.UNSUPPORTED_SETTING_COMBINATION,
"LOCK_MODE=0 & MULTI_THREADED"); "MV_STORE=FALSE & LOCK_MODE=0 & MULTI_THREADED=TRUE");
} }
} }
this.multiThreaded = multiThreaded; this.multiThreaded = multiThreaded;
......
...@@ -2316,13 +2316,21 @@ public class JdbcDatabaseMetaData extends TraceObject implements ...@@ -2316,13 +2316,21 @@ public class JdbcDatabaseMetaData extends TraceObject implements
public boolean supportsTransactionIsolationLevel(int level) throws SQLException { public boolean supportsTransactionIsolationLevel(int level) throws SQLException {
debugCodeCall("supportsTransactionIsolationLevel"); debugCodeCall("supportsTransactionIsolationLevel");
if (level == Connection.TRANSACTION_READ_UNCOMMITTED) { if (level == Connection.TRANSACTION_READ_UNCOMMITTED) {
// currently the combination of LOCK_MODE=0 and MULTI_THREADED // Currently the combination of MV_STORE=FALSE, LOCK_MODE=0 and
// is not supported, also see code in Database#setLockMode(int) // MULTI_THREADED=TRUE is not supported. Also see code in
PreparedStatement prep = conn.prepareAutoCloseStatement( // Database#setLockMode(int)
"SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME=?"); try (PreparedStatement prep = conn.prepareStatement(
prep.setString(1, "MULTI_THREADED"); "SELECT VALUE FROM INFORMATION_SCHEMA.SETTINGS WHERE NAME=?")) {
ResultSet rs = prep.executeQuery(); // TODO skip MV_STORE check for H2 <= 1.4.197
return !rs.next() || !rs.getString(1).equals("1"); prep.setString(1, "MV_STORE");
ResultSet rs = prep.executeQuery();
if (rs.next() && Boolean.parseBoolean(rs.getString(1))) {
return true;
}
prep.setString(1, "MULTI_THREADED");
rs = prep.executeQuery();
return !rs.next() || !rs.getString(1).equals("1");
}
} }
return true; return true;
} }
......
...@@ -288,13 +288,12 @@ public class TestMultiThread extends TestDb implements Runnable { ...@@ -288,13 +288,12 @@ public class TestMultiThread extends TestDb implements Runnable {
} }
private void testLockModeWithMultiThreaded() throws Exception { private void testLockModeWithMultiThreaded() throws Exception {
// currently the combination of LOCK_MODE=0 and MULTI_THREADED
// is not supported
deleteDb("lockMode"); deleteDb("lockMode");
final String url = getURL("lockMode;MULTI_THREADED=1", true); final String url = getURL("lockMode;MULTI_THREADED=1", true);
try (Connection conn = getConnection(url)) { try (Connection conn = getConnection(url)) {
DatabaseMetaData meta = conn.getMetaData(); DatabaseMetaData meta = conn.getMetaData();
assertFalse(meta.supportsTransactionIsolationLevel( // LOCK_MODE=0 with MULTI_THREADED=TRUE is supported only by MVStore
assertEquals(config.mvStore, meta.supportsTransactionIsolationLevel(
Connection.TRANSACTION_READ_UNCOMMITTED)); Connection.TRANSACTION_READ_UNCOMMITTED));
} }
deleteDb("lockMode"); deleteDb("lockMode");
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论