mirror of
https://github.com/corda/corda.git
synced 2025-06-17 22:58:19 +00:00
All uses of CheckpointStorage.getAllCheckpoints() close the stream after use (#5230)
This commit is contained in:
@ -36,22 +36,24 @@ object CheckpointVerifier {
|
|||||||
|
|
||||||
val cordappsByHash = currentCordapps.associateBy { it.jarHash }
|
val cordappsByHash = currentCordapps.associateBy { it.jarHash }
|
||||||
|
|
||||||
checkpointStorage.getAllCheckpoints().forEach { (_, serializedCheckpoint) ->
|
checkpointStorage.getAllCheckpoints().use {
|
||||||
val checkpoint = try {
|
it.forEach { (_, serializedCheckpoint) ->
|
||||||
serializedCheckpoint.checkpointDeserialize(context = checkpointSerializationContext)
|
val checkpoint = try {
|
||||||
} catch (e: ClassNotFoundException) {
|
serializedCheckpoint.checkpointDeserialize(context = checkpointSerializationContext)
|
||||||
val message = e.message
|
} catch (e: ClassNotFoundException) {
|
||||||
if (message != null) {
|
val message = e.message
|
||||||
throw CheckpointIncompatibleException.CordappNotInstalledException(message)
|
if (message != null) {
|
||||||
} else {
|
throw CheckpointIncompatibleException.CordappNotInstalledException(message)
|
||||||
|
} else {
|
||||||
|
throw CheckpointIncompatibleException.CannotBeDeserialisedException(e)
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
throw CheckpointIncompatibleException.CannotBeDeserialisedException(e)
|
throw CheckpointIncompatibleException.CannotBeDeserialisedException(e)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
|
||||||
throw CheckpointIncompatibleException.CannotBeDeserialisedException(e)
|
|
||||||
}
|
|
||||||
|
|
||||||
// For each Subflow, compare the checkpointed version to the current version.
|
// For each Subflow, compare the checkpointed version to the current version.
|
||||||
checkpoint.subFlowStack.forEach { checkFlowCompatible(it, cordappsByHash, platformVersion) }
|
checkpoint.subFlowStack.forEach { checkFlowCompatible(it, cordappsByHash, platformVersion) }
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -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,19 +316,21 @@ class SingleThreadedStateMachineManager(
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun restoreFlowsFromCheckpoints(): List<Flow> {
|
private fun restoreFlowsFromCheckpoints(): List<Flow> {
|
||||||
return checkpointStorage.getAllCheckpoints().map { (id, serializedCheckpoint) ->
|
return checkpointStorage.getAllCheckpoints().use {
|
||||||
// If a flow is added before start() then don't attempt to restore it
|
it.mapNotNull { (id, serializedCheckpoint) ->
|
||||||
mutex.locked { if (flows.containsKey(id)) return@map null }
|
// If a flow is added before start() then don't attempt to restore it
|
||||||
val checkpoint = deserializeCheckpoint(serializedCheckpoint) ?: return@map null
|
mutex.locked { if (id in flows) return@mapNotNull null }
|
||||||
logger.debug { "Restored $checkpoint" }
|
val checkpoint = deserializeCheckpoint(serializedCheckpoint) ?: return@mapNotNull null
|
||||||
createFlowFromCheckpoint(
|
logger.debug { "Restored $checkpoint" }
|
||||||
id = id,
|
createFlowFromCheckpoint(
|
||||||
checkpoint = checkpoint,
|
id = id,
|
||||||
initialDeduplicationHandler = null,
|
checkpoint = checkpoint,
|
||||||
isAnyCheckpointPersisted = true,
|
initialDeduplicationHandler = null,
|
||||||
isStartIdempotent = false
|
isAnyCheckpointPersisted = true,
|
||||||
)
|
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 {
|
||||||
|
Reference in New Issue
Block a user