Always remove any soft locks associated with a completed flow. (#561)

Fix issue whereby soft locks associated with a flow were not being released because they were not initially registered properly.
This commit is contained in:
josecoll 2017-04-21 13:38:03 +01:00 committed by GitHub
parent 6f9b70520c
commit 2b1a71955c
3 changed files with 8 additions and 5 deletions

View File

@ -98,6 +98,10 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
// This state IS serialised, as we need it to know what the fiber is waiting for.
internal val openSessions = HashMap<Pair<FlowLogic<*>, Party>, FlowSession>()
internal var waitingForResponse: WaitingRequest? = null
internal var hasSoftLockedStates: Boolean = false
set(value) {
if (value) field = value else throw IllegalArgumentException("Can only set to true")
}
init {
logic.stateMachine = this

View File

@ -19,6 +19,7 @@ import net.corda.core.crypto.Party
import net.corda.core.crypto.SecureHash
import net.corda.core.crypto.containsAny
import net.corda.core.crypto.toBase58String
import net.corda.core.flows.FlowStateMachine
import net.corda.core.node.ServiceHub
import net.corda.core.node.services.StatesNotAvailableException
import net.corda.core.node.services.Vault
@ -263,6 +264,7 @@ class NodeVaultService(private val services: ServiceHub, dataSourceProperties: P
.and(stateRefCompositeColumn.`in`(stateRefArgs)).get().value()
if (updatedRows > 0 && updatedRows == stateRefs.size) {
log.trace("Reserving soft lock states for $lockId: $stateRefs")
FlowStateMachineImpl.currentStateMachine()?.hasSoftLockedStates = true
} else {
// revert partial soft locks
val revertUpdatedRows = update(VaultStatesEntity::class)

View File

@ -6,6 +6,7 @@ import net.corda.core.flows.StateMachineRunId
import net.corda.core.node.services.VaultService
import net.corda.core.utilities.loggerFor
import net.corda.core.utilities.trace
import net.corda.node.services.statemachine.FlowStateMachineImpl
import net.corda.node.services.statemachine.StateMachineManager
import net.corda.node.utilities.AddOrRemove
import java.util.*
@ -16,15 +17,12 @@ class VaultSoftLockManager(val vault: VaultService, smm: StateMachineManager) {
val log = loggerFor<VaultSoftLockManager>()
}
private val trackingFlowIds: MutableSet<UUID> = Collections.synchronizedSet(HashSet())
init {
smm.changes.subscribe { (logic, addOrRemove, id) ->
if (addOrRemove == AddOrRemove.REMOVE && id.uuid in trackingFlowIds) {
if (addOrRemove == AddOrRemove.REMOVE && (FlowStateMachineImpl.currentStateMachine())?.hasSoftLockedStates == true) {
log.trace { "$addOrRemove Flow name ${logic.javaClass} with id $id" }
unregisterSoftLocks(id, logic)
}
trackingFlowIds.remove(id.uuid)
}
// Discussion
@ -43,7 +41,6 @@ class VaultSoftLockManager(val vault: VaultService, smm: StateMachineManager) {
update.flowId?.let {
if (update.produced.isNotEmpty()) {
registerSoftLocks(update.flowId as UUID, update.produced.map { it.ref })
trackingFlowIds.add(update.flowId as UUID)
}
}
}