Skip to content

Commit

Permalink
pom.xml: Infamous downgrade of H2 to 1.4.197
Browse files Browse the repository at this point in the history
This seems to work similarly to previously long used 1.4.193.
1.4.198 is too disruptive and many new bugs appear not only in tests.
  • Loading branch information
virgo47 committed Sep 11, 2020
1 parent 7900ead commit e537d52
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 9 deletions.
7 changes: 4 additions & 3 deletions pom.xml
Expand Up @@ -182,12 +182,13 @@
<!--
Default Spring Boot 2.3.3 uses H2 1.4.200 but that one has NPE bug:
https://github.com/h2database/h2database/issues/1808
Sometimes occurs on heavy concurrent test, e.g. on TestDummyParallelism.
Sometimes occurs on heavy concurrent test, e.g. on TestDummyParallelism, but also during app run.
This bug was introduced in 1.4.198, which was major version that also changed queries in OrgClosureManager.
If h2<=1.4.197 is used, the OrgClosureManager must be changed to previous version.
Between 1.4.197 and 198 changes of OrgClosureManager and around MVCC must be made (see commit history).
With 1.4.200 TestObjectLifecycleApprovalGlobal fails consistently.
197 seems to be last version that works OK with midPoint before very disruptive changes.
-->
<h2.version>1.4.199</h2.version>
<h2.version>1.4.197</h2.version>
<!-- Spring Boot parent declares most fresh versions for JDBC drivers for all our servers -->
<wicket.version>8.6.0</wicket.version>
<groovy.version>2.5.12</groovy.version>
Expand Down
Expand Up @@ -567,6 +567,8 @@ private String readFile(String filename) throws IOException {

private String getDefaultEmbeddedJdbcUrl() {
return getDefaultEmbeddedJdbcUrlPrefix()
// TODO: Was used for 1.4.193, but do we really need it?
// + ";MVCC=FALSE" // Turn off MVCC, revert to table locking.
// Disable database closing on exit. By default, a database is closed when the last connection is closed.
+ ";DB_CLOSE_ON_EXIT=FALSE"
// Both read locks and write locks are kept until the transaction commits.
Expand Down
Expand Up @@ -222,8 +222,8 @@ private String[] createArguments(SqlRepositoryConfiguration config) {
args.add(Integer.toString(config.getPort()));
}
// Allows auto-creation of remote database, which is a security hole and was forbidden
// from 1.4.138, see https://h2database.com/html/tutorial.html#creating_new_databases
args.add("-ifNotExists");
// from 1.4.198, see https://h2database.com/html/tutorial.html#creating_new_databases
// args.add("-ifNotExists"); // we're using <198 version now

return args.toArray(new String[0]);
}
Expand Down
Expand Up @@ -593,7 +593,13 @@ private void addIndependentEdgesInternal(List<Edge> edges, Context context, Sess

long startUpdate = System.currentTimeMillis();
String updateInClosureQueryText;
if (isH2() || isPostgreSQL()) {
// Can/must be unified with PG after H2 > 1.4.200 if no other issues emerge.
if (isH2()) {
updateInClosureQueryText = "update " + CLOSURE_TABLE_NAME + " " +
"set val = val + (select val from " + deltaTempTableName + " td " +
"where td.descendant_oid=" + CLOSURE_TABLE_NAME + ".descendant_oid and td.ancestor_oid=" + CLOSURE_TABLE_NAME + ".ancestor_oid) " +
"where (descendant_oid, ancestor_oid) in (select (descendant_oid, ancestor_oid) from " + deltaTempTableName + ")";
} else if (isPostgreSQL()) {
updateInClosureQueryText = "update " + CLOSURE_TABLE_NAME + " " +
"set val = val + (select val from " + deltaTempTableName + " td " +
"where td.descendant_oid=" + CLOSURE_TABLE_NAME + ".descendant_oid and td.ancestor_oid=" + CLOSURE_TABLE_NAME + ".ancestor_oid) " +
Expand All @@ -616,7 +622,10 @@ private void addIndependentEdgesInternal(List<Edge> edges, Context context, Sess
"insert into " + CLOSURE_TABLE_NAME + " (descendant_oid, ancestor_oid, val) " +
"select descendant_oid, ancestor_oid, val from " + deltaTempTableName + " delta ";
if (countUpdate > 0) {
if (isH2() || isPostgreSQL()) {
// Can/must be unified with PG after H2 > 1.4.200 if no other issues emerge.
if (isH2()) {
addQuery += " where (descendant_oid, ancestor_oid) not in (select (descendant_oid, ancestor_oid) from " + CLOSURE_TABLE_NAME + ")";
} else if (isPostgreSQL()) {
addQuery += " where not exists (select 1 from " + CLOSURE_TABLE_NAME + " cl where cl.descendant_oid=delta.descendant_oid and cl.ancestor_oid=delta.ancestor_oid)";
} else {
throw new UnsupportedOperationException("Org. closure manager - unsupported database operation");
Expand Down Expand Up @@ -799,7 +808,19 @@ private void removeIndependentEdgesInternal(List<Edge> edges, Context context, S
int count;

String deleteFromClosureQueryText, updateInClosureQueryText;
if (isH2() || isPostgreSQL() || isOracle()) {
// Can/must be unified with PG after H2 > 1.4.200 if no other issues emerge.
if (isH2()) {
// delete with join is not supported by H2
// and the "postgresql/oracle version" does not work for some reasons
deleteFromClosureQueryText = "delete from " + CLOSURE_TABLE_NAME + " cl " +
"where exists (" +
"select 0 from " + deltaTempTableName + " delta " +
"where cl.descendant_oid = delta.descendant_oid and cl.ancestor_oid = delta.ancestor_oid and cl.val = delta.val)";
updateInClosureQueryText = "update " + CLOSURE_TABLE_NAME + " " +
"set val = val - (select val from " + deltaTempTableName + " td " +
"where td.descendant_oid=" + CLOSURE_TABLE_NAME + ".descendant_oid and td.ancestor_oid=" + CLOSURE_TABLE_NAME + ".ancestor_oid) " +
"where (descendant_oid, ancestor_oid) in (select (descendant_oid, ancestor_oid) from " + deltaTempTableName + ")";
} else if (isPostgreSQL() || isOracle()) {
deleteFromClosureQueryText = "delete from " + CLOSURE_TABLE_NAME + " " +
"where (descendant_oid, ancestor_oid, val) in " +
"(select descendant_oid, ancestor_oid, val from " + deltaTempTableName + ")";
Expand Down
Expand Up @@ -447,7 +447,7 @@ void setJdbcJobStoreInformation(MidpointConfiguration masterConfig, SqlRepositor
if (explicitJdbcUrl == null) {
if (sqlConfig != null) {
if (sqlConfig.isEmbedded()) {
jdbcUrl = defaultJdbcUrlPrefix + "-quartz;DB_CLOSE_ON_EXIT=FALSE";
jdbcUrl = defaultJdbcUrlPrefix + "-quartz;MVCC=TRUE;DB_CLOSE_ON_EXIT=FALSE";
} else {
jdbcUrl = sqlConfig.getJdbcUrl();
}
Expand Down

0 comments on commit e537d52

Please sign in to comment.