ENT-1128 fix node restarts when using AzureSQLServer (#2139)

This commit is contained in:
bpaunescu 2017-11-28 10:32:30 +00:00 committed by GitHub
parent 4bd6fef0f9
commit 614779d4ec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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) {