Transaction creation performance (#303) (#320)

* Default autoCommit to false, remove setting of autocommit and only set isolationLevel if it's changed.

* Set default transaction isolation from database config
This commit is contained in:
Christian Sailer 2018-01-09 17:17:10 +00:00 committed by GitHub
parent 0c646ff662
commit 40edc286f5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 13 additions and 3 deletions

View File

@ -35,7 +35,8 @@ enum class TransactionIsolationLevel {
/**
* The JDBC constant value of the same name but prefixed with TRANSACTION_ defined in [java.sql.Connection].
*/
val jdbcValue: Int = java.sql.Connection::class.java.getField("TRANSACTION_$name").get(null) as Int
val jdbcString = "TRANSACTION_$name"
val jdbcValue: Int = java.sql.Connection::class.java.getField(jdbcString).get(null) as Int
}
class CordaPersistence(

View File

@ -20,8 +20,10 @@ class DatabaseTransaction(
cordaPersistence.dataSource.connection
.apply {
_connectionCreated = true
autoCommit = false
transactionIsolation = isolation
// only set the transaction isolation level if it's actually changed - setting isn't free.
if (transactionIsolation != isolation) {
transactionIsolation = isolation
}
}
}

View File

@ -135,6 +135,13 @@ data class NodeConfigurationImpl(
require(security == null || rpcUsers.isEmpty()) {
"Cannot specify both 'rpcUsers' and 'security' in configuration"
}
// ensure our datasource configuration is sane
require(dataSourceProperties.get("autoCommit") != true) { "Datbase auto commit cannot be enabled, Corda requires transactional behaviour" }
dataSourceProperties.set("autoCommit", false)
if (dataSourceProperties.get("transactionIsolation") == null) {
dataSourceProperties["transactionIsolation"] = database.transactionIsolationLevel.jdbcString
}
}
}