mirror of
https://github.com/corda/corda.git
synced 2025-04-13 22:23:31 +00:00
ENT-2355 Insert transactions without checking for duplicates (#1350)
* ENT-2355 Make transactions storage optimistic if in a flow and the flow has never restored from a checkpoint. (cherry picked from commit 9a2e9b0) * ENT-2355 Insert transactions with optimism. * Added some comments.
This commit is contained in:
parent
866e2a2a13
commit
759419fcc1
@ -101,8 +101,16 @@ class DBTransactionStorage(cacheSizeBytes: Long, private val database: CordaPers
|
||||
|
||||
override fun addTransaction(transaction: SignedTransaction): Boolean = database.transaction {
|
||||
txStorage.concurrent {
|
||||
addWithDuplicatesAllowed(transaction.id, transaction.toTxCacheValue()).apply {
|
||||
updatesPublisher.bufferUntilDatabaseCommit().onNext(transaction)
|
||||
// Be optimistic if we are a flow and never restarted (i.e. cannot have been to the flow hospital due to primary key collision).
|
||||
val optimistic = FlowStateMachineImpl.currentStateMachine()?.isNotRestarted ?: false
|
||||
if (optimistic) {
|
||||
set(transaction.id, transaction.toTxCacheValue()).apply {
|
||||
updatesPublisher.bufferUntilDatabaseCommit().onNext(transaction)
|
||||
}
|
||||
} else {
|
||||
addWithDuplicatesAllowed(transaction.id, transaction.toTxCacheValue()).apply {
|
||||
updatesPublisher.bufferUntilDatabaseCommit().onNext(transaction)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -87,6 +87,9 @@ class FlowStateMachineImpl<R>(override val id: StateMachineRunId,
|
||||
internal var transientValues: TransientReference<TransientValues>? = null
|
||||
internal var transientState: TransientReference<StateMachineState>? = null
|
||||
|
||||
// Utilise the behaviour of `ourSenderUUID` to indicate whether we have restarted ever. Can be used to make certain code paths optimistic.
|
||||
internal val isNotRestarted: Boolean get() = (ourSenderUUID != null)
|
||||
|
||||
/**
|
||||
* What sender identifier to put on messages sent by this flow. This will either be the identifier for the current
|
||||
* state machine manager / messaging client, or null to indicate this flow is restored from a checkpoint and
|
||||
|
Loading…
x
Reference in New Issue
Block a user