Minor persistent uniqueness provider tweak

This commit is contained in:
Andrius Dagys 2016-09-13 10:24:55 +01:00
parent 789bb2bb9d
commit 422a766c1a
2 changed files with 7 additions and 4 deletions

View File

@ -333,12 +333,11 @@ abstract class AbstractNode(val dir: Path, val configuration: NodeConfiguration,
}
open protected fun makeNotaryService(type: ServiceType): NotaryService {
val uniquenessProvider = makeUniquenessProvider()
val timestampChecker = TimestampChecker(platformClock, 30.seconds)
return when (type) {
SimpleNotaryService.Type -> SimpleNotaryService(smm, net, timestampChecker, uniquenessProvider, services.networkMapCache)
ValidatingNotaryService.Type -> ValidatingNotaryService(smm, net, timestampChecker, uniquenessProvider, services.networkMapCache)
SimpleNotaryService.Type -> SimpleNotaryService(smm, net, timestampChecker, uniquenessProvider!!, services.networkMapCache)
ValidatingNotaryService.Type -> ValidatingNotaryService(smm, net, timestampChecker, uniquenessProvider!!, services.networkMapCache)
else -> {
throw IllegalArgumentException("Notary type ${type.id} is not handled by makeNotaryService.")
}

View File

@ -7,16 +7,18 @@ import com.r3corda.core.crypto.SecureHash
import com.r3corda.core.node.services.UniquenessException
import com.r3corda.core.node.services.UniquenessProvider
import com.r3corda.core.serialization.SingletonSerializeAsToken
import com.r3corda.core.utilities.loggerFor
import com.r3corda.node.utilities.JDBCHashMap
import com.r3corda.node.utilities.databaseTransaction
import java.util.*
import javax.annotation.concurrent.ThreadSafe
/** A a RDBMS backed Uniqueness provider */
/** A RDBMS backed Uniqueness provider */
@ThreadSafe
class PersistentUniquenessProvider() : UniquenessProvider, SingletonSerializeAsToken() {
companion object {
private val TABLE_NAME = "notary_commit_log"
private val log = loggerFor<PersistentUniquenessProvider>()
}
/**
@ -37,11 +39,13 @@ class PersistentUniquenessProvider() : UniquenessProvider, SingletonSerializeAsT
if (consumingTx != null) conflictingStates[inputState] = consumingTx
}
if (conflictingStates.isNotEmpty()) {
log.debug("Failure, input states already committed: ${conflictingStates.keys.toString()}")
UniquenessProvider.Conflict(conflictingStates)
} else {
states.forEachIndexed { i, stateRef ->
put(stateRef, UniquenessProvider.ConsumingTx(txId, i, callerIdentity))
}
log.debug("Successfully committed all input states: $states")
null
}
}