mirror of
https://github.com/corda/corda.git
synced 2025-02-22 18:12:53 +00:00
Remove mutex and stop catching deadlock / SQLExceptions. (#3242)
SQL Exceptions thrown with Cash Selection are now retried via Flow Hospital
This commit is contained in:
parent
78c759e2e6
commit
accb9eb5b3
@ -16,11 +16,8 @@ import net.corda.finance.contracts.asset.Cash
|
|||||||
import java.sql.Connection
|
import java.sql.Connection
|
||||||
import java.sql.DatabaseMetaData
|
import java.sql.DatabaseMetaData
|
||||||
import java.sql.ResultSet
|
import java.sql.ResultSet
|
||||||
import java.sql.SQLException
|
|
||||||
import java.util.*
|
import java.util.*
|
||||||
import java.util.concurrent.atomic.AtomicReference
|
import java.util.concurrent.atomic.AtomicReference
|
||||||
import java.util.concurrent.locks.ReentrantLock
|
|
||||||
import kotlin.concurrent.withLock
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Pluggable interface to allow for different cash selection provider implementations
|
* Pluggable interface to allow for different cash selection provider implementations
|
||||||
@ -54,7 +51,6 @@ abstract class AbstractCashSelection {
|
|||||||
private val MAX_RETRIES = 8
|
private val MAX_RETRIES = 8
|
||||||
private val RETRY_SLEEP = 100
|
private val RETRY_SLEEP = 100
|
||||||
private val RETRY_CAP = 2000
|
private val RETRY_CAP = 2000
|
||||||
private val spendLock: ReentrantLock = ReentrantLock()
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Upon dynamically loading configured Cash Selection algorithms declared in META-INF/services
|
* Upon dynamically loading configured Cash Selection algorithms declared in META-INF/services
|
||||||
@ -126,7 +122,6 @@ abstract class AbstractCashSelection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun attemptSpend(services: ServiceHub, amount: Amount<Currency>, lockId: UUID, notary: Party?, onlyFromIssuerParties: Set<AbstractParty>, withIssuerRefs: Set<OpaqueBytes>, stateAndRefs: MutableList<StateAndRef<Cash.State>>): Boolean {
|
private fun attemptSpend(services: ServiceHub, amount: Amount<Currency>, lockId: UUID, notary: Party?, onlyFromIssuerParties: Set<AbstractParty>, withIssuerRefs: Set<OpaqueBytes>, stateAndRefs: MutableList<StateAndRef<Cash.State>>): Boolean {
|
||||||
spendLock.withLock {
|
|
||||||
val connection = services.jdbcSession()
|
val connection = services.jdbcSession()
|
||||||
try {
|
try {
|
||||||
// we select spendable states irrespective of lock but prioritised by unlocked ones (Eg. null)
|
// we select spendable states irrespective of lock but prioritised by unlocked ones (Eg. null)
|
||||||
@ -166,15 +161,10 @@ abstract class AbstractCashSelection {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// retry as more states may become available
|
// retry as more states may become available
|
||||||
} catch (e: SQLException) {
|
|
||||||
log.error("""Failed retrieving unconsumed states for: amount [$amount], onlyFromIssuerParties [$onlyFromIssuerParties], notary [$notary], lockId [$lockId]
|
|
||||||
$e.
|
|
||||||
""")
|
|
||||||
} catch (e: StatesNotAvailableException) { // Should never happen with single threaded state machine
|
} catch (e: StatesNotAvailableException) { // Should never happen with single threaded state machine
|
||||||
log.warn(e.message)
|
log.warn(e.message)
|
||||||
// retry only if there are locked states that may become available again (or consumed with change)
|
// retry only if there are locked states that may become available again (or consumed with change)
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
}
|
}
|
Loading…
x
Reference in New Issue
Block a user