mirror of
https://github.com/corda/corda.git
synced 2025-04-07 11:27:01 +00:00
ENT-1128 fix node restarts when using AzureSQLServer (#2139)
This commit is contained in:
parent
4bd6fef0f9
commit
614779d4ec
@ -172,13 +172,13 @@ open class PersistentNetworkMapCache(private val database: CordaPersistence) : S
|
||||
if (previousNode == null) {
|
||||
logger.info("No previous node found")
|
||||
database.transaction {
|
||||
updateInfoDB(node)
|
||||
updateInfoDB(node, session)
|
||||
changePublisher.onNext(MapChange.Added(node))
|
||||
}
|
||||
} else if (previousNode != node) {
|
||||
logger.info("Previous node was found as: $previousNode")
|
||||
database.transaction {
|
||||
updateInfoDB(node)
|
||||
updateInfoDB(node, session)
|
||||
changePublisher.onNext(MapChange.Modified(node, previousNode))
|
||||
}
|
||||
} else {
|
||||
@ -233,25 +233,14 @@ open class PersistentNetworkMapCache(private val database: CordaPersistence) : S
|
||||
}
|
||||
}
|
||||
|
||||
private fun updateInfoDB(nodeInfo: NodeInfo) {
|
||||
// TODO Temporary workaround to force isolated transaction (otherwise it causes race conditions when processing
|
||||
// network map registration on network map node)
|
||||
database.dataSource.connection.use {
|
||||
val session = database.entityManagerFactory.withOptions().connection(it.apply {
|
||||
transactionIsolation = 1
|
||||
}).openSession()
|
||||
session.use {
|
||||
val tx = session.beginTransaction()
|
||||
// TODO For now the main legal identity is left in NodeInfo, this should be set comparision/come up with index for NodeInfo?
|
||||
val info = findByIdentityKey(session, nodeInfo.legalIdentitiesAndCerts.first().owningKey)
|
||||
val nodeInfoEntry = generateMappedObject(nodeInfo)
|
||||
if (info.isNotEmpty()) {
|
||||
nodeInfoEntry.id = info[0].id
|
||||
}
|
||||
session.merge(nodeInfoEntry)
|
||||
tx.commit()
|
||||
}
|
||||
private fun updateInfoDB(nodeInfo: NodeInfo, session: Session) {
|
||||
// TODO For now the main legal identity is left in NodeInfo, this should be set comparision/come up with index for NodeInfo?
|
||||
val info = findByIdentityKey(session, nodeInfo.legalIdentitiesAndCerts.first().owningKey)
|
||||
val nodeInfoEntry = generateMappedObject(nodeInfo)
|
||||
if (info.isNotEmpty()) {
|
||||
nodeInfoEntry.id = info.first().id
|
||||
}
|
||||
session.merge(nodeInfoEntry)
|
||||
}
|
||||
|
||||
private fun removeInfoDB(session: Session, nodeInfo: NodeInfo) {
|
||||
|
Loading…
x
Reference in New Issue
Block a user