diff --git a/osmosis-apidb/src/main/java/org/openstreetmap/osmosis/apidb/common/DatabaseContext2.java b/osmosis-apidb/src/main/java/org/openstreetmap/osmosis/apidb/common/DatabaseContext2.java index 65b676e5e..4f5bbd33b 100644 --- a/osmosis-apidb/src/main/java/org/openstreetmap/osmosis/apidb/common/DatabaseContext2.java +++ b/osmosis-apidb/src/main/java/org/openstreetmap/osmosis/apidb/common/DatabaseContext2.java @@ -16,6 +16,7 @@ import org.springframework.jdbc.datasource.DataSourceTransactionManager; import org.springframework.jdbc.datasource.DataSourceUtils; import org.springframework.transaction.PlatformTransactionManager; +import org.springframework.transaction.TransactionDefinition; import org.springframework.transaction.support.TransactionCallback; import org.springframework.transaction.support.TransactionTemplate; @@ -47,6 +48,12 @@ public DatabaseContext2(DatabaseLoginCredentials loginCredentials) { dataSource = DataSourceFactory.createDataSource(loginCredentials); txnManager = new DataSourceTransactionManager(dataSource); txnTemplate = new TransactionTemplate(txnManager); + // Use REPEATABLE READ so that all sequential reads within one osmosis dump + // (way_nodes read, then nodes geometry read, then relations read) share a + // single MVCC snapshot. Without this, READ COMMITTED lets a concurrent + // cgimap edit delete nodes between the two reads, producing ways with + // missing node references ("Way with less than two nodes" in osmium). + txnTemplate.setIsolationLevel(TransactionDefinition.ISOLATION_REPEATABLE_READ); jdbcTemplate = new JdbcTemplate(dataSource); this.dbType = loginCredentials.getDbType();