CORDA-1790 - Roll back flow transaction on exception (#3597) (#3616)

* CORDA-1790 Roll back flow transaction on exception

* CORDA-1790 Roll back flow transaction on exception

* CORDA-1790 Roll back flow transaction on exception
This commit is contained in:
Katelyn Baker 2018-07-16 17:44:34 +01:00 committed by GitHub
parent ac6cbeca0c
commit 729d1b29a6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 21 additions and 4 deletions

View File

@ -147,6 +147,19 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
}
}
internal fun rollbackTransaction() {
val transaction = contextTransaction
try {
logger.trace { "Rolling back transaction $transaction on ${Strand.currentStrand()}." }
transaction.rollback()
} catch (e: SQLException) {
logger.error("Transaction rollback failed: ${e.message}", e)
System.exit(1)
} finally {
transaction.close()
}
}
@Suspendable
override fun initiateFlow(otherParty: Party, sessionFlow: FlowLogic<*>): FlowSession {
val sessionKey = Pair(sessionFlow, otherParty)

View File

@ -452,10 +452,14 @@ class StateMachineManagerImpl(
}
endAllFiberSessions(fiber, result, propagated)
} finally {
fiber.commitTransaction()
if (result.isSuccess) {
fiber.commitTransaction()
totalFinishedFlows.inc()
unfinishedFibers.countDown()
} else {
fiber.rollbackTransaction()
}
decrementLiveFibers()
totalFinishedFlows.inc()
unfinishedFibers.countDown()
}
}
mutex.locked {

View File

@ -375,7 +375,7 @@ class FlowFrameworkTests {
.withMessage("Nothing useful")
.withStackTraceContaining(ReceiveFlow::class.java.name) // Make sure the stack trace is that of the receiving flow
bobNode.database.transaction {
assertThat(bobNode.checkpointStorage.checkpoints()).isEmpty()
assertThat(bobNode.checkpointStorage.checkpoints()).isNotEmpty()
}
assertThat(receivingFiber.isTerminated).isTrue()