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:
Tudor Malene
2019-01-08 14:37:26 +00:00
committed by GitHub
parent ce250cfafd
commit d33cb16c5e
4 changed files with 435 additions and 407 deletions

View File

@ -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