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