mirror of
https://github.com/corda/corda.git
synced 2024-12-21 05:53:23 +00:00
CORDA-4101: Remove attachmentPresence cache (#6845)
* CORDA-4101: Remove the attachmentCache and just rely on attachmentContentCache * CORDA-4101: Remove the attachmentCacheBound variable.
This commit is contained in:
parent
af87d1d50d
commit
284fd48918
@ -60,7 +60,6 @@ interface NodeConfiguration : ConfigurationWithOptionsContainer {
|
|||||||
val noLocalShell: Boolean get() = false
|
val noLocalShell: Boolean get() = false
|
||||||
val transactionCacheSizeBytes: Long get() = defaultTransactionCacheSize
|
val transactionCacheSizeBytes: Long get() = defaultTransactionCacheSize
|
||||||
val attachmentContentCacheSizeBytes: Long get() = defaultAttachmentContentCacheSize
|
val attachmentContentCacheSizeBytes: Long get() = defaultAttachmentContentCacheSize
|
||||||
val attachmentCacheBound: Long get() = defaultAttachmentCacheBound
|
|
||||||
// do not change this value without syncing it with ScheduledFlowsDrainingModeTest
|
// do not change this value without syncing it with ScheduledFlowsDrainingModeTest
|
||||||
val drainingModePollPeriod: Duration get() = Duration.ofSeconds(5)
|
val drainingModePollPeriod: Duration get() = Duration.ofSeconds(5)
|
||||||
val extraNetworkMapKeys: List<UUID>
|
val extraNetworkMapKeys: List<UUID>
|
||||||
@ -110,7 +109,6 @@ interface NodeConfiguration : ConfigurationWithOptionsContainer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
internal val defaultAttachmentContentCacheSize: Long = 10.MB
|
internal val defaultAttachmentContentCacheSize: Long = 10.MB
|
||||||
internal const val defaultAttachmentCacheBound = 1024L
|
|
||||||
|
|
||||||
const val cordappDirectoriesKey = "cordappDirectories"
|
const val cordappDirectoriesKey = "cordappDirectories"
|
||||||
|
|
||||||
|
@ -65,7 +65,6 @@ data class NodeConfigurationImpl(
|
|||||||
override val database: DatabaseConfig = Defaults.database(devMode),
|
override val database: DatabaseConfig = Defaults.database(devMode),
|
||||||
private val transactionCacheSizeMegaBytes: Int? = Defaults.transactionCacheSizeMegaBytes,
|
private val transactionCacheSizeMegaBytes: Int? = Defaults.transactionCacheSizeMegaBytes,
|
||||||
private val attachmentContentCacheSizeMegaBytes: Int? = Defaults.attachmentContentCacheSizeMegaBytes,
|
private val attachmentContentCacheSizeMegaBytes: Int? = Defaults.attachmentContentCacheSizeMegaBytes,
|
||||||
override val attachmentCacheBound: Long = Defaults.attachmentCacheBound,
|
|
||||||
override val extraNetworkMapKeys: List<UUID> = Defaults.extraNetworkMapKeys,
|
override val extraNetworkMapKeys: List<UUID> = Defaults.extraNetworkMapKeys,
|
||||||
// do not use or remove (breaks DemoBench together with rejection of unknown configuration keys during parsing)
|
// do not use or remove (breaks DemoBench together with rejection of unknown configuration keys during parsing)
|
||||||
private val h2port: Int? = Defaults.h2port,
|
private val h2port: Int? = Defaults.h2port,
|
||||||
@ -112,7 +111,6 @@ data class NodeConfigurationImpl(
|
|||||||
const val localShellUnsafe: Boolean = false
|
const val localShellUnsafe: Boolean = false
|
||||||
val transactionCacheSizeMegaBytes: Int? = null
|
val transactionCacheSizeMegaBytes: Int? = null
|
||||||
val attachmentContentCacheSizeMegaBytes: Int? = null
|
val attachmentContentCacheSizeMegaBytes: Int? = null
|
||||||
const val attachmentCacheBound: Long = NodeConfiguration.defaultAttachmentCacheBound
|
|
||||||
val extraNetworkMapKeys: List<UUID> = emptyList()
|
val extraNetworkMapKeys: List<UUID> = emptyList()
|
||||||
val h2port: Int? = null
|
val h2port: Int? = null
|
||||||
val h2Settings: NodeH2Settings? = null
|
val h2Settings: NodeH2Settings? = null
|
||||||
|
@ -40,7 +40,6 @@ internal object V1NodeConfigurationSpec : Configuration.Specification<NodeConfig
|
|||||||
private val localShellUnsafe by boolean().optional().withDefaultValue(Defaults.localShellUnsafe)
|
private val localShellUnsafe by boolean().optional().withDefaultValue(Defaults.localShellUnsafe)
|
||||||
private val database by nested(DatabaseConfigSpec).optional()
|
private val database by nested(DatabaseConfigSpec).optional()
|
||||||
private val noLocalShell by boolean().optional().withDefaultValue(Defaults.noLocalShell)
|
private val noLocalShell by boolean().optional().withDefaultValue(Defaults.noLocalShell)
|
||||||
private val attachmentCacheBound by long().optional().withDefaultValue(Defaults.attachmentCacheBound)
|
|
||||||
private val extraNetworkMapKeys by string().mapValid(::toUUID).list().optional().withDefaultValue(Defaults.extraNetworkMapKeys)
|
private val extraNetworkMapKeys by string().mapValid(::toUUID).list().optional().withDefaultValue(Defaults.extraNetworkMapKeys)
|
||||||
private val tlsCertCrlDistPoint by string().mapValid(::toURL).optional()
|
private val tlsCertCrlDistPoint by string().mapValid(::toURL).optional()
|
||||||
private val tlsCertCrlIssuer by string().mapValid(::toPrincipal).optional()
|
private val tlsCertCrlIssuer by string().mapValid(::toPrincipal).optional()
|
||||||
@ -118,7 +117,6 @@ internal object V1NodeConfigurationSpec : Configuration.Specification<NodeConfig
|
|||||||
localShellUnsafe = config[localShellUnsafe],
|
localShellUnsafe = config[localShellUnsafe],
|
||||||
database = database,
|
database = database,
|
||||||
noLocalShell = config[noLocalShell],
|
noLocalShell = config[noLocalShell],
|
||||||
attachmentCacheBound = config[attachmentCacheBound],
|
|
||||||
extraNetworkMapKeys = config[extraNetworkMapKeys],
|
extraNetworkMapKeys = config[extraNetworkMapKeys],
|
||||||
tlsCertCrlDistPoint = config[tlsCertCrlDistPoint],
|
tlsCertCrlDistPoint = config[tlsCertCrlDistPoint],
|
||||||
tlsCertCrlIssuer = config[tlsCertCrlIssuer],
|
tlsCertCrlIssuer = config[tlsCertCrlIssuer],
|
||||||
|
@ -26,7 +26,6 @@ import net.corda.core.serialization.*
|
|||||||
import net.corda.core.utilities.contextLogger
|
import net.corda.core.utilities.contextLogger
|
||||||
import net.corda.node.services.vault.HibernateAttachmentQueryCriteriaParser
|
import net.corda.node.services.vault.HibernateAttachmentQueryCriteriaParser
|
||||||
import net.corda.node.utilities.InfrequentlyMutatedCache
|
import net.corda.node.utilities.InfrequentlyMutatedCache
|
||||||
import net.corda.node.utilities.NonInvalidatingCache
|
|
||||||
import net.corda.node.utilities.NonInvalidatingWeightBasedCache
|
import net.corda.node.utilities.NonInvalidatingWeightBasedCache
|
||||||
import net.corda.nodeapi.exceptions.DuplicateAttachmentException
|
import net.corda.nodeapi.exceptions.DuplicateAttachmentException
|
||||||
import net.corda.nodeapi.internal.persistence.CordaPersistence
|
import net.corda.nodeapi.internal.persistence.CordaPersistence
|
||||||
@ -259,18 +258,6 @@ class NodeAttachmentService @JvmOverloads constructor(
|
|||||||
Token(id, checkOnLoad, uploader, signerKeys)
|
Token(id, checkOnLoad, uploader, signerKeys)
|
||||||
}
|
}
|
||||||
|
|
||||||
// slightly complex 2 level approach to attachment caching:
|
|
||||||
// On the first level we cache attachment contents loaded from the DB by their key. This is a weight based
|
|
||||||
// cache (we don't want to waste too much memory on this) and could be evicted quite aggressively. If we fail
|
|
||||||
// to load an attachment from the db, the loader will insert a non present optional - we invalidate this
|
|
||||||
// immediately as we definitely want to retry whether the attachment was just delayed.
|
|
||||||
// On the second level, we cache Attachment implementations that use the first cache to load their content
|
|
||||||
// when required. As these are fairly small, we can cache quite a lot of them, this will make checking
|
|
||||||
// repeatedly whether an attachment exists fairly cheap. Here as well, we evict non-existent entries immediately
|
|
||||||
// to force a recheck if required.
|
|
||||||
// If repeatedly looking for non-existing attachments becomes a performance issue, this is either indicating a
|
|
||||||
// a problem somewhere else or this needs to be revisited.
|
|
||||||
|
|
||||||
private val attachmentContentCache = NonInvalidatingWeightBasedCache(
|
private val attachmentContentCache = NonInvalidatingWeightBasedCache(
|
||||||
cacheFactory = cacheFactory,
|
cacheFactory = cacheFactory,
|
||||||
name = "NodeAttachmentService_attachmentContent",
|
name = "NodeAttachmentService_attachmentContent",
|
||||||
@ -309,27 +296,13 @@ class NodeAttachmentService @JvmOverloads constructor(
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private val attachmentCache = NonInvalidatingCache<SecureHash, Optional<Attachment>>(
|
override fun openAttachment(id: SecureHash): Attachment? {
|
||||||
cacheFactory = cacheFactory,
|
val content = attachmentContentCache.get(id)!!
|
||||||
name = "NodeAttachmentService_attachmentPresence",
|
|
||||||
loadFunction = { key -> Optional.ofNullable(createAttachment(key)) })
|
|
||||||
|
|
||||||
private fun createAttachment(key: SecureHash): Attachment? {
|
|
||||||
val content = attachmentContentCache.get(key)!!
|
|
||||||
if (content.isPresent) {
|
if (content.isPresent) {
|
||||||
return content.get().first
|
return content.get().first
|
||||||
}
|
}
|
||||||
// If no attachment has been found, we don't want to cache that - it might arrive later.
|
// If no attachment has been found, we don't want to cache that - it might arrive later.
|
||||||
attachmentContentCache.invalidate(key)
|
attachmentContentCache.invalidate(id)
|
||||||
return null
|
|
||||||
}
|
|
||||||
|
|
||||||
override fun openAttachment(id: SecureHash): Attachment? {
|
|
||||||
val attachment = attachmentCache.get(id)!!
|
|
||||||
if (attachment.isPresent) {
|
|
||||||
return attachment.get()
|
|
||||||
}
|
|
||||||
attachmentCache.invalidate(id)
|
|
||||||
return null
|
return null
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -426,7 +399,6 @@ class NodeAttachmentService @JvmOverloads constructor(
|
|||||||
loadAttachmentContent(id)?.let { attachmentAndContent ->
|
loadAttachmentContent(id)?.let { attachmentAndContent ->
|
||||||
// TODO: this is racey. ENT-2870
|
// TODO: this is racey. ENT-2870
|
||||||
attachmentContentCache.put(id, Optional.of(attachmentAndContent))
|
attachmentContentCache.put(id, Optional.of(attachmentAndContent))
|
||||||
attachmentCache.put(id, Optional.of(attachmentAndContent.first))
|
|
||||||
}
|
}
|
||||||
return@withContractsInJar id
|
return@withContractsInJar id
|
||||||
}
|
}
|
||||||
|
@ -43,7 +43,6 @@ open class DefaultNamedCacheFactory protected constructor(private val metricRegi
|
|||||||
name == "HibernateConfiguration_sessionFactories" -> caffeine.maximumSize(database.mappedSchemaCacheSize)
|
name == "HibernateConfiguration_sessionFactories" -> caffeine.maximumSize(database.mappedSchemaCacheSize)
|
||||||
name == "DBTransactionStorage_transactions" -> caffeine.maximumWeight(transactionCacheSizeBytes)
|
name == "DBTransactionStorage_transactions" -> caffeine.maximumWeight(transactionCacheSizeBytes)
|
||||||
name == "NodeAttachmentService_attachmentContent" -> caffeine.maximumWeight(attachmentContentCacheSizeBytes)
|
name == "NodeAttachmentService_attachmentContent" -> caffeine.maximumWeight(attachmentContentCacheSizeBytes)
|
||||||
name == "NodeAttachmentService_attachmentPresence" -> caffeine.maximumSize(attachmentCacheBound)
|
|
||||||
name == "NodeAttachmentService_contractAttachmentVersions" -> caffeine.maximumSize(defaultCacheSize)
|
name == "NodeAttachmentService_contractAttachmentVersions" -> caffeine.maximumSize(defaultCacheSize)
|
||||||
name == "PersistentIdentityService_keyToPartyAndCert" -> caffeine.maximumSize(defaultCacheSize)
|
name == "PersistentIdentityService_keyToPartyAndCert" -> caffeine.maximumSize(defaultCacheSize)
|
||||||
name == "PersistentIdentityService_nameToParty" -> caffeine.maximumSize(defaultCacheSize)
|
name == "PersistentIdentityService_nameToParty" -> caffeine.maximumSize(defaultCacheSize)
|
||||||
|
Loading…
Reference in New Issue
Block a user