mirror of
https://github.com/corda/corda.git
synced 2025-06-11 03:41:41 +00:00
All uses of CheckpointStorage.getAllCheckpoints() close the stream after use (#5230)
This commit is contained in:
parent
f01f8a129e
commit
843c3a0190
@ -36,7 +36,8 @@ object CheckpointVerifier {
|
|||||||
|
|
||||||
val cordappsByHash = currentCordapps.associateBy { it.jarHash }
|
val cordappsByHash = currentCordapps.associateBy { it.jarHash }
|
||||||
|
|
||||||
checkpointStorage.getAllCheckpoints().forEach { (_, serializedCheckpoint) ->
|
checkpointStorage.getAllCheckpoints().use {
|
||||||
|
it.forEach { (_, serializedCheckpoint) ->
|
||||||
val checkpoint = try {
|
val checkpoint = try {
|
||||||
serializedCheckpoint.checkpointDeserialize(context = checkpointSerializationContext)
|
serializedCheckpoint.checkpointDeserialize(context = checkpointSerializationContext)
|
||||||
} catch (e: ClassNotFoundException) {
|
} catch (e: ClassNotFoundException) {
|
||||||
@ -54,6 +55,7 @@ object CheckpointVerifier {
|
|||||||
checkpoint.subFlowStack.forEach { checkFlowCompatible(it, cordappsByHash, platformVersion) }
|
checkpoint.subFlowStack.forEach { checkFlowCompatible(it, cordappsByHash, platformVersion) }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// Throws exception when the flow is incompatible
|
// Throws exception when the flow is incompatible
|
||||||
private fun checkFlowCompatible(subFlow: SubFlow, currentCordappsByHash: Map<SecureHash.SHA256, Cordapp>, platformVersion: Int) {
|
private fun checkFlowCompatible(subFlow: SubFlow, currentCordappsByHash: Map<SecureHash.SHA256, Cordapp>, platformVersion: Int) {
|
||||||
|
@ -13,10 +13,7 @@ import net.corda.core.flows.FlowInfo
|
|||||||
import net.corda.core.flows.FlowLogic
|
import net.corda.core.flows.FlowLogic
|
||||||
import net.corda.core.flows.StateMachineRunId
|
import net.corda.core.flows.StateMachineRunId
|
||||||
import net.corda.core.identity.Party
|
import net.corda.core.identity.Party
|
||||||
import net.corda.core.internal.FlowStateMachine
|
import net.corda.core.internal.*
|
||||||
import net.corda.core.internal.ThreadBox
|
|
||||||
import net.corda.core.internal.bufferUntilSubscribed
|
|
||||||
import net.corda.core.internal.castIfPossible
|
|
||||||
import net.corda.core.internal.concurrent.OpenFuture
|
import net.corda.core.internal.concurrent.OpenFuture
|
||||||
import net.corda.core.internal.concurrent.map
|
import net.corda.core.internal.concurrent.map
|
||||||
import net.corda.core.internal.concurrent.openFuture
|
import net.corda.core.internal.concurrent.openFuture
|
||||||
@ -37,11 +34,7 @@ import net.corda.node.services.api.ServiceHubInternal
|
|||||||
import net.corda.node.services.config.shouldCheckCheckpoints
|
import net.corda.node.services.config.shouldCheckCheckpoints
|
||||||
import net.corda.node.services.messaging.DeduplicationHandler
|
import net.corda.node.services.messaging.DeduplicationHandler
|
||||||
import net.corda.node.services.statemachine.FlowStateMachineImpl.Companion.createSubFlowVersion
|
import net.corda.node.services.statemachine.FlowStateMachineImpl.Companion.createSubFlowVersion
|
||||||
import net.corda.node.services.statemachine.interceptors.DumpHistoryOnErrorInterceptor
|
import net.corda.node.services.statemachine.interceptors.*
|
||||||
import net.corda.node.services.statemachine.interceptors.FiberDeserializationChecker
|
|
||||||
import net.corda.node.services.statemachine.interceptors.FiberDeserializationCheckingInterceptor
|
|
||||||
import net.corda.node.services.statemachine.interceptors.HospitalisingInterceptor
|
|
||||||
import net.corda.node.services.statemachine.interceptors.PrintingInterceptor
|
|
||||||
import net.corda.node.services.statemachine.transitions.StateMachine
|
import net.corda.node.services.statemachine.transitions.StateMachine
|
||||||
import net.corda.node.utilities.AffinityExecutor
|
import net.corda.node.utilities.AffinityExecutor
|
||||||
import net.corda.node.utilities.errorAndTerminate
|
import net.corda.node.utilities.errorAndTerminate
|
||||||
@ -57,12 +50,13 @@ import rx.subjects.PublishSubject
|
|||||||
import java.lang.Integer.min
|
import java.lang.Integer.min
|
||||||
import java.security.SecureRandom
|
import java.security.SecureRandom
|
||||||
import java.util.HashSet
|
import java.util.HashSet
|
||||||
import java.util.concurrent.ConcurrentHashMap
|
import java.util.concurrent.*
|
||||||
import java.util.concurrent.ExecutorService
|
|
||||||
import java.util.concurrent.Executors
|
|
||||||
import java.util.concurrent.ScheduledFuture
|
|
||||||
import java.util.concurrent.TimeUnit
|
|
||||||
import javax.annotation.concurrent.ThreadSafe
|
import javax.annotation.concurrent.ThreadSafe
|
||||||
|
import kotlin.collections.ArrayList
|
||||||
|
import kotlin.collections.HashMap
|
||||||
|
import kotlin.collections.component1
|
||||||
|
import kotlin.collections.component2
|
||||||
|
import kotlin.collections.set
|
||||||
import kotlin.streams.toList
|
import kotlin.streams.toList
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -322,10 +316,11 @@ class SingleThreadedStateMachineManager(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun restoreFlowsFromCheckpoints(): List<Flow> {
|
private fun restoreFlowsFromCheckpoints(): List<Flow> {
|
||||||
return checkpointStorage.getAllCheckpoints().map { (id, serializedCheckpoint) ->
|
return checkpointStorage.getAllCheckpoints().use {
|
||||||
|
it.mapNotNull { (id, serializedCheckpoint) ->
|
||||||
// If a flow is added before start() then don't attempt to restore it
|
// If a flow is added before start() then don't attempt to restore it
|
||||||
mutex.locked { if (flows.containsKey(id)) return@map null }
|
mutex.locked { if (id in flows) return@mapNotNull null }
|
||||||
val checkpoint = deserializeCheckpoint(serializedCheckpoint) ?: return@map null
|
val checkpoint = deserializeCheckpoint(serializedCheckpoint) ?: return@mapNotNull null
|
||||||
logger.debug { "Restored $checkpoint" }
|
logger.debug { "Restored $checkpoint" }
|
||||||
createFlowFromCheckpoint(
|
createFlowFromCheckpoint(
|
||||||
id = id,
|
id = id,
|
||||||
@ -334,7 +329,8 @@ class SingleThreadedStateMachineManager(
|
|||||||
isAnyCheckpointPersisted = true,
|
isAnyCheckpointPersisted = true,
|
||||||
isStartIdempotent = false
|
isStartIdempotent = false
|
||||||
)
|
)
|
||||||
}.toList().filterNotNull()
|
}.toList()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun resumeRestoredFlows(flows: List<Flow>) {
|
private fun resumeRestoredFlows(flows: List<Flow>) {
|
||||||
|
@ -31,8 +31,9 @@ import org.junit.Test
|
|||||||
import kotlin.streams.toList
|
import kotlin.streams.toList
|
||||||
|
|
||||||
internal fun CheckpointStorage.checkpoints(): List<SerializedBytes<Checkpoint>> {
|
internal fun CheckpointStorage.checkpoints(): List<SerializedBytes<Checkpoint>> {
|
||||||
val checkpoints = getAllCheckpoints().toList()
|
return getAllCheckpoints().use {
|
||||||
return checkpoints.map { it.second }
|
it.map { it.second }.toList()
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class DBCheckpointStorageTests {
|
class DBCheckpointStorageTests {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user