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]. * 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( class CordaPersistence(

View File

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

View File

@ -135,6 +135,13 @@ data class NodeConfigurationImpl(
require(security == null || rpcUsers.isEmpty()) { require(security == null || rpcUsers.isEmpty()) {
"Cannot specify both 'rpcUsers' and 'security' in configuration" "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
}
} }
} }