Add CachingDamlLedgerStateReaderWithFingerprints factory method (#6769)

CHANGELOG_BEGIN
CHANGELOG_END
This commit is contained in:
fabiotudone-da 2020-07-17 16:07:54 +02:00 committed by GitHub
parent 2904a5d236
commit ebf312873c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 30 additions and 6 deletions

View File

@ -6,6 +6,7 @@ package com.daml.ledger.validator.caching
import com.daml.caching.Cache
import com.daml.ledger.participant.state.kvutils.DamlKvutils.{DamlStateKey, DamlStateValue}
import com.daml.ledger.validator.LedgerStateOperations.Key
import com.daml.ledger.validator.caching.CachingDamlLedgerStateReader.StateCache
import com.daml.ledger.validator.{
DamlLedgerStateReader,
LedgerStateReader,
@ -29,7 +30,7 @@ trait QueryableReadSet {
* package state values (which are too expensive to deserialize from bytes every time).
*/
class CachingDamlLedgerStateReader(
val cache: Cache[DamlStateKey, DamlStateValue],
val cache: StateCache,
shouldCache: DamlStateKey => Boolean,
keySerializationStrategy: StateKeySerializationStrategy,
delegate: DamlLedgerStateReader)(implicit executionContext: ExecutionContext)
@ -69,16 +70,18 @@ class CachingDamlLedgerStateReader(
}
object CachingDamlLedgerStateReader {
type StateCache = Cache[DamlStateKey, DamlStateValue]
private[validator] def apply(
cache: Cache[DamlStateKey, DamlStateValue],
cache: StateCache,
cachingPolicy: CacheUpdatePolicy,
ledgerStateOperations: LedgerStateReader,
keySerializationStrategy: StateKeySerializationStrategy)(
implicit executionContext: ExecutionContext): CachingDamlLedgerStateReader = {
implicit executionContext: ExecutionContext): CachingDamlLedgerStateReader =
new CachingDamlLedgerStateReader(
cache,
cachingPolicy.shouldCacheOnRead,
keySerializationStrategy,
new RawToDamlLedgerStateReaderAdapter(ledgerStateOperations, keySerializationStrategy))
}
}

View File

@ -7,7 +7,12 @@ import com.daml.caching.{Cache, Weight}
import com.daml.ledger.participant.state.kvutils.DamlKvutils.{DamlStateKey, DamlStateValue}
import com.daml.ledger.participant.state.kvutils.{DamlKvutils, Fingerprint}
import com.daml.ledger.validator.StateKeySerializationStrategy
import com.daml.ledger.validator.preexecution.DamlLedgerStateReaderWithFingerprints
import com.daml.ledger.validator.caching.CachingDamlLedgerStateReaderWithFingerprints.StateCacheWithFingerprints
import com.daml.ledger.validator.preexecution.{
DamlLedgerStateReaderWithFingerprints,
LedgerStateReaderWithFingerprints,
RawToDamlLedgerStateReaderWithFingerprintsAdapter
}
import com.google.protobuf.MessageLite
import scala.concurrent.{ExecutionContext, Future}
@ -17,7 +22,7 @@ import scala.concurrent.{ExecutionContext, Future}
* Caches only positive lookups, i.e., in case the values for a requested key are available on the ledger.
*/
class CachingDamlLedgerStateReaderWithFingerprints(
val cache: Cache[DamlStateKey, (DamlStateValue, Fingerprint)],
val cache: StateCacheWithFingerprints,
shouldCache: DamlStateKey => Boolean,
keySerializationStrategy: StateKeySerializationStrategy,
delegate: DamlLedgerStateReaderWithFingerprints)(implicit executionContext: ExecutionContext)
@ -60,4 +65,20 @@ object CachingDamlLedgerStateReaderWithFingerprints {
value._1.getSerializedSize.toLong + value._2.size()
}
type StateCacheWithFingerprints = Cache[DamlStateKey, (DamlStateValue, Fingerprint)]
def apply(
cache: StateCacheWithFingerprints,
cachingPolicy: CacheUpdatePolicy,
ledgerStateReaderWithFingerprints: LedgerStateReaderWithFingerprints,
keySerializationStrategy: StateKeySerializationStrategy)(
implicit executionContext: ExecutionContext): CachingDamlLedgerStateReaderWithFingerprints =
new CachingDamlLedgerStateReaderWithFingerprints(
cache,
cachingPolicy.shouldCacheOnRead,
keySerializationStrategy,
new RawToDamlLedgerStateReaderWithFingerprintsAdapter(
ledgerStateReaderWithFingerprints,
keySerializationStrategy)
)
}