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

* 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:
Tudor Malene 2018-07-16 11:07:28 +01:00 committed by Katelyn Baker
parent a8cd1eea2b
commit a90a5bb75a
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()