mirror of
https://github.com/corda/corda.git
synced 2025-06-13 20:58:19 +00:00
ENT-2923 - remove db access code from the verification thread pool (#4504)
* ENT-2923 - remove db access code from the verification thread pool * Remove worker pool for tx verification and disable db access. * Address code review comments
This commit is contained in:
@ -64,6 +64,22 @@ private val _contextDatabase = InheritableThreadLocal<CordaPersistence>()
|
||||
var contextDatabase: CordaPersistence
|
||||
get() = _contextDatabase.get() ?: error("Was expecting to find CordaPersistence set on current thread: ${Strand.currentStrand()}")
|
||||
set(database) = _contextDatabase.set(database)
|
||||
|
||||
private val _prohibitDatabaseAccess = ThreadLocal.withInitial { false }
|
||||
|
||||
/**
|
||||
* The logic in the [block] will be prevented from opening a database transaction.
|
||||
*/
|
||||
fun <T> withoutDatabaseAccess(block: () -> T): T {
|
||||
val oldValue = _prohibitDatabaseAccess.get()
|
||||
_prohibitDatabaseAccess.set(true)
|
||||
try {
|
||||
return block()
|
||||
} finally {
|
||||
_prohibitDatabaseAccess.set(oldValue)
|
||||
}
|
||||
}
|
||||
|
||||
val contextDatabaseOrNull: CordaPersistence? get() = _contextDatabase.get()
|
||||
|
||||
class CordaPersistence(
|
||||
@ -115,6 +131,9 @@ class CordaPersistence(
|
||||
private val liveTransactions = ConcurrentHashMap<UUID, DatabaseTransaction>()
|
||||
|
||||
fun newTransaction(isolation: TransactionIsolationLevel = defaultIsolationLevel): DatabaseTransaction {
|
||||
if(_prohibitDatabaseAccess.get()){
|
||||
throw IllegalAccessException("Database access is not allowed in the current context.")
|
||||
}
|
||||
val outerTransaction = contextTransactionOrNull
|
||||
return DatabaseTransaction(isolation.jdbcValue, contextTransactionOrNull, this).also {
|
||||
contextTransactionOrNull = it
|
||||
|
Reference in New Issue
Block a user