forked from digital-asset/daml
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ledger-on-memory: Split the Writer from the Reader. (digital-asset#8732)
There's no real reason to connect the two. CHANGELOG_BEGIN CHANGELOG_END
- Loading branch information
1 parent
d7d9543
commit b413d7e
Showing
3 changed files
with
66 additions
and
67 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
ledger/ledger-on-memory/src/main/scala/com/daml/ledger/on/memory/InMemoryLedgerWriter.scala
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// Copyright (c) 2021 Digital Asset (Switzerland) GmbH and/or its affiliates. All rights reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
|
||
package com.daml.ledger.on.memory | ||
|
||
import com.daml.api.util.TimeProvider | ||
import com.daml.caching.Cache | ||
import com.daml.dec.DirectExecutionContext | ||
import com.daml.ledger.api.health.{HealthStatus, Healthy} | ||
import com.daml.ledger.participant.state.kvutils.DamlKvutils.{DamlStateKey, DamlStateValue} | ||
import com.daml.ledger.participant.state.kvutils.Raw | ||
import com.daml.ledger.participant.state.kvutils.api.{CommitMetadata, LedgerWriter} | ||
import com.daml.ledger.participant.state.v1.{ParticipantId, SubmissionResult} | ||
import com.daml.ledger.validator.ValidateAndCommit | ||
import com.daml.platform.akkastreams.dispatcher.Dispatcher | ||
|
||
import scala.concurrent.Future | ||
import scala.util.Success | ||
|
||
final class InMemoryLedgerWriter private[memory] ( | ||
override val participantId: ParticipantId, | ||
dispatcher: Dispatcher[Index], | ||
state: InMemoryState, | ||
validateAndCommit: ValidateAndCommit, | ||
) extends LedgerWriter { | ||
override def commit( | ||
correlationId: String, | ||
envelope: Raw.Value, | ||
metadata: CommitMetadata, | ||
): Future[SubmissionResult] = | ||
validateAndCommit(correlationId, envelope, participantId) | ||
.andThen { case Success(SubmissionResult.Acknowledged) => | ||
dispatcher.signalNewHead(state.newHeadSinceLastWrite()) | ||
}(DirectExecutionContext) | ||
|
||
override def currentHealth(): HealthStatus = Healthy | ||
} | ||
|
||
object InMemoryLedgerWriter { | ||
|
||
private[memory] val DefaultTimeProvider: TimeProvider = TimeProvider.UTC | ||
|
||
private[memory] type StateValueCache = Cache[DamlStateKey, DamlStateValue] | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters