mirror of
https://github.com/corda/corda.git
synced 2025-02-20 17:33:15 +00:00
Using Checkpoint.id when storing Checkpoints
This commit is contained in:
parent
60d555d4ed
commit
307c93858b
@ -30,9 +30,9 @@ interface CheckpointStorage {
|
||||
}
|
||||
|
||||
// This class will be serialised, so everything it points to transitively must also be serialisable (with Kryo).
|
||||
class Checkpoint(val serialisedFiber: SerializedBytes<ProtocolStateMachineImpl<*>>) {
|
||||
class Checkpoint(val serializedFiber: SerializedBytes<ProtocolStateMachineImpl<*>>) {
|
||||
|
||||
val id: SecureHash get() = serialisedFiber.hash
|
||||
val id: SecureHash get() = serializedFiber.hash
|
||||
|
||||
override fun equals(other: Any?): Boolean = other === this || other is Checkpoint && other.id == this.id
|
||||
|
||||
|
@ -7,24 +7,20 @@ import com.r3corda.core.serialization.serialize
|
||||
import com.r3corda.node.services.api.Checkpoint
|
||||
import com.r3corda.node.services.api.CheckpointStorage
|
||||
import com.r3corda.node.utilities.JDBCHashMap
|
||||
import java.util.*
|
||||
import java.util.Collections.synchronizedMap
|
||||
|
||||
/**
|
||||
* Simple checkpoint key value storage in DB using the underlying JDBCHashMap and transactional context of the call sites.
|
||||
*/
|
||||
class DBCheckpointStorage : CheckpointStorage {
|
||||
private val checkpointStorage = Collections.synchronizedMap(JDBCHashMap<SecureHash, SerializedBytes<Checkpoint>>("checkpoints", loadOnInit = false))
|
||||
private val checkpointStorage = synchronizedMap(JDBCHashMap<SecureHash, SerializedBytes<Checkpoint>>("checkpoints", loadOnInit = false))
|
||||
|
||||
override fun addCheckpoint(checkpoint: Checkpoint) {
|
||||
val serialisedCheckpoint = checkpoint.serialize()
|
||||
val id = serialisedCheckpoint.hash
|
||||
checkpointStorage.put(id, serialisedCheckpoint)
|
||||
checkpointStorage.put(checkpoint.id, checkpoint.serialize())
|
||||
}
|
||||
|
||||
override fun removeCheckpoint(checkpoint: Checkpoint) {
|
||||
val serialisedCheckpoint = checkpoint.serialize()
|
||||
val id = serialisedCheckpoint.hash
|
||||
checkpointStorage.remove(id) ?: throw IllegalArgumentException("Checkpoint not found")
|
||||
checkpointStorage.remove(checkpoint.id) ?: throw IllegalArgumentException("Checkpoint not found")
|
||||
}
|
||||
|
||||
override fun forEach(block: (Checkpoint) -> Boolean) {
|
||||
|
@ -11,6 +11,7 @@ import java.nio.file.Files
|
||||
import java.nio.file.Path
|
||||
import java.nio.file.StandardCopyOption
|
||||
import java.util.*
|
||||
import java.util.Collections.synchronizedMap
|
||||
import javax.annotation.concurrent.ThreadSafe
|
||||
|
||||
|
||||
@ -25,7 +26,7 @@ class PerFileCheckpointStorage(val storeDir: Path) : CheckpointStorage {
|
||||
private val fileExtension = ".checkpoint"
|
||||
}
|
||||
|
||||
private val checkpointFiles = Collections.synchronizedMap(IdentityHashMap<Checkpoint, Path>())
|
||||
private val checkpointFiles = synchronizedMap(IdentityHashMap<Checkpoint, Path>())
|
||||
|
||||
init {
|
||||
logger.trace { "Initialising per file checkpoint storage on $storeDir" }
|
||||
@ -39,10 +40,9 @@ class PerFileCheckpointStorage(val storeDir: Path) : CheckpointStorage {
|
||||
}
|
||||
|
||||
override fun addCheckpoint(checkpoint: Checkpoint) {
|
||||
val serialisedCheckpoint = checkpoint.serialize()
|
||||
val fileName = "${serialisedCheckpoint.hash.toString().toLowerCase()}$fileExtension"
|
||||
val fileName = "${checkpoint.id.toString().toLowerCase()}$fileExtension"
|
||||
val checkpointFile = storeDir.resolve(fileName)
|
||||
atomicWrite(checkpointFile, serialisedCheckpoint)
|
||||
atomicWrite(checkpointFile, checkpoint.serialize())
|
||||
logger.trace { "Stored $checkpoint to $checkpointFile" }
|
||||
checkpointFiles[checkpoint] = checkpointFile
|
||||
}
|
||||
|
@ -161,7 +161,7 @@ class StateMachineManager(val serviceHub: ServiceHubInternal,
|
||||
checkpointStorage.forEach {
|
||||
// If a protocol is added before start() then don't attempt to restore it
|
||||
if (!stateMachines.containsValue(it)) {
|
||||
val fiber = deserializeFiber(it.serialisedFiber)
|
||||
val fiber = deserializeFiber(it.serializedFiber)
|
||||
initFiber(fiber)
|
||||
stateMachines[fiber] = it
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user