class DbSequencerStore extends SequencerStore with NamedLogging with FlagCloseable with HasCloseContext

Database backed sequencer store. Supports many concurrent instances reading and writing to the same backing database.

Ordering
  1. Alphabetic
  2. By Inheritance
Inherited
  1. DbSequencerStore
  2. HasCloseContext
  3. FlagCloseable
  4. SequencerStore
  5. AutoCloseable
  6. NamedLogging
  7. AnyRef
  8. Any
  1. Hide All
  2. Show All
Visibility
  1. Public
  2. Protected

Instance Constructors

  1. new DbSequencerStore(storage: DbStorage, maxInClauseSize: PositiveNumeric[Int], timeouts: ProcessingTimeout, loggerFactory: NamedLoggerFactory)(implicit executionContext: ExecutionContext)

Type Members

  1. case class DeliverStoreEventRow[P](timestamp: CantonTimestamp, instanceIndex: Int, eventType: EventTypeDiscriminator, messageIdO: Option[MessageId] = None, senderO: Option[SequencerMemberId] = None, recipientsO: Option[NonEmpty[SortedSet[SequencerMemberId]]] = None, payloadO: Option[P] = None, signingTimestampO: Option[CantonTimestamp] = None, errorMessageO: Option[String256M] = None, traceContext: TraceContext) extends Product with Serializable
  2. sealed abstract class EventTypeDiscriminator extends AnyRef

    Single char that is persisted with the event to indicate the type of event

  3. case class ReaderState(count: Int, readers: MultiSet[String]) extends Product with Serializable
    Definition Classes
    FlagCloseable

Value Members

  1. final def !=(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  2. final def ##: Int
    Definition Classes
    AnyRef → Any
  3. final def ==(arg0: Any): Boolean
    Definition Classes
    AnyRef → Any
  4. def acknowledge(member: SequencerMemberId, timestamp: CantonTimestamp)(implicit traceContext: TraceContext): Future[Unit]

    Write an acknowledgement that member has processed earlier timestamps.

    Write an acknowledgement that member has processed earlier timestamps. Only the latest timestamp needs to be stored. Earlier timestamps can be overwritten. Acknowledgements of earlier timestamps should be ignored.

    Definition Classes
    DbSequencerStoreSequencerStore
  5. def adjustPruningTimestampForCounterCheckpoints(timestamp: CantonTimestamp, disabledMembers: Seq[SequencerMemberId])(implicit traceContext: TraceContext): Future[Option[CantonTimestamp]]

    This takes the timestamp that is considered safe to prune from and walks it back to ensure that we have retained enough events to be able to start subscriptions from the counter checkpoint immediately preceding the timestamp.

    This takes the timestamp that is considered safe to prune from and walks it back to ensure that we have retained enough events to be able to start subscriptions from the counter checkpoint immediately preceding the timestamp.

    Attributes
    protected[store]
    Definition Classes
    DbSequencerStoreSequencerStore
  6. final def asInstanceOf[T0]: T0
    Definition Classes
    Any
  7. def clone(): AnyRef
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.CloneNotSupportedException]) @native() @HotSpotIntrinsicCandidate()
  8. final def close(): Unit

    Blocks until all earlier tasks have completed and then prevents further tasks from being run.

    Blocks until all earlier tasks have completed and then prevents further tasks from being run.

    Definition Classes
    FlagCloseable → AutoCloseable
    Annotations
    @SuppressWarnings()
  9. implicit val closeContext: CloseContext
    Definition Classes
    HasCloseContext
  10. def closingTimeout: FiniteDuration
    Attributes
    protected
    Definition Classes
    FlagCloseable
  11. def countRecords(implicit traceContext: TraceContext): Future[SequencerStoreRecordCounts]

    Count records currently stored by the sequencer.

    Count records currently stored by the sequencer. Used for pruning tests.

    Attributes
    protected[store]
    Definition Classes
    DbSequencerStoreSequencerStore
    Annotations
    @VisibleForTesting()
  12. def deleteEventsPastWatermark(instanceIndex: Int)(implicit traceContext: TraceContext): Future[Unit]

    Delete all events that are ahead of the watermark of this sequencer.

    Delete all events that are ahead of the watermark of this sequencer. These events will not have been read and should be removed before returning the sequencer online. Should not be called alongside updating the watermark for this sequencer and only while the sequencer is offline.

    Definition Classes
    DbSequencerStoreSequencerStore
  13. def disableMember(member: SequencerMemberId)(implicit traceContext: TraceContext): Future[Unit]

    Prevents member from sending and reading from the sequencer, and allows unread data for this member to be pruned.

    Prevents member from sending and reading from the sequencer, and allows unread data for this member to be pruned. It however won't stop any sends addressed to this member.

    Definition Classes
    DbSequencerStoreSequencerStore
  14. final def eq(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  15. def equals(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef → Any
  16. implicit val executionContext: ExecutionContext
    Attributes
    protected
    Definition Classes
    DbSequencerStoreSequencerStore
  17. def fetchClosestCheckpointBefore(memberId: SequencerMemberId, counter: SequencerCounter)(implicit traceContext: TraceContext): Future[Option[CounterCheckpoint]]

    Fetch a checkpoint with a counter value less than the provided counter.

    Fetch a checkpoint with a counter value less than the provided counter.

    Definition Classes
    DbSequencerStoreSequencerStore
  18. def fetchLowerBound()(implicit traceContext: TraceContext): Future[Option[CantonTimestamp]]

    Fetch the lower bound of events that can be read.

    Fetch the lower bound of events that can be read. Returns None if all events can be read.

    Definition Classes
    DbSequencerStoreSequencerStore
  19. def fetchOnlineInstances(implicit traceContext: TraceContext): Future[SortedSet[Int]]

    Fetch the indexes of all sequencers that are currently online

    Fetch the indexes of all sequencers that are currently online

    Definition Classes
    DbSequencerStoreSequencerStore
  20. def fetchWatermark(instanceIndex: Int)(implicit traceContext: TraceContext): Future[Option[Watermark]]

    Read the watermark for this sequencer and its online/offline status.

    Read the watermark for this sequencer and its online/offline status. Currently only used for testing.

    Definition Classes
    DbSequencerStoreSequencerStore
  21. final def getClass(): Class[_ <: AnyRef]
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  22. def goOffline(instanceIndex: Int)(implicit traceContext: TraceContext): Future[Unit]

    Flag that we're going offline (likely due to a shutdown)

    Flag that we're going offline (likely due to a shutdown)

    Definition Classes
    DbSequencerStoreSequencerStore
  23. def goOnline(instanceIndex: Int, now: CantonTimestamp)(implicit traceContext: TraceContext): Future[CantonTimestamp]

    Mark the sequencer as online and return a timestamp for when this sequencer can start safely producing events.

    Mark the sequencer as online and return a timestamp for when this sequencer can start safely producing events.

    now

    Now according to this sequencer's clock which will be used if it is ahead of the lowest available timestamp from other sequencers.

    Definition Classes
    DbSequencerStoreSequencerStore
  24. def hashCode(): Int
    Definition Classes
    AnyRef → Any
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  25. def internalPerformUnlessClosingF[A](name: String)(f: => Future[A])(implicit ec: ExecutionContext, traceContext: TraceContext): UnlessShutdown[Future[A]]
    Attributes
    protected
    Definition Classes
    FlagCloseable
  26. def isClosing: Boolean

    Check whether we're closing.

    Check whether we're closing. Susceptible to race conditions; unless you're using using this as a flag to the retry lib or you really know what you're doing, prefer performUnlessClosing and friends.

    Definition Classes
    FlagCloseable
  27. def isEnabled(member: SequencerMemberId)(implicit traceContext: TraceContext): EitherT[Future, MemberDisabledError.type, Unit]

    Check whether the member is enabled.

    Check whether the member is enabled. Currently used when receiving a request for reading.

    Definition Classes
    DbSequencerStoreSequencerStore
  28. final def isInstanceOf[T0]: Boolean
    Definition Classes
    Any
  29. def keepTrackOfOpenFutures: Boolean

    track running futures on shutdown

    track running futures on shutdown

    set to true to get detailed information about all futures that did not complete during shutdown. if set to false, we don't do anything.

    Attributes
    protected
    Definition Classes
    FlagCloseable
  30. def latestAcknowledgements()(implicit traceContext: TraceContext): Future[Map[SequencerMemberId, CantonTimestamp]]

    Return the latest acknowledgements for all members

    Return the latest acknowledgements for all members

    Definition Classes
    DbSequencerStoreSequencerStore
  31. def logger: TracedLogger
    Attributes
    protected
    Definition Classes
    NamedLogging
  32. val loggerFactory: NamedLoggerFactory
    Attributes
    protected
    Definition Classes
    DbSequencerStoreNamedLogging
  33. implicit def loggingContext(implicit traceContext: TraceContext): ErrorLoggingContext
    Attributes
    protected
    Definition Classes
    NamedLogging
  34. final def lookupMember(member: Member)(implicit traceContext: TraceContext): Future[Option[RegisteredMember]]

    Lookup an existing member id for the given member.

    Lookup an existing member id for the given member. Will return a cached value if available. Return scala.None if no id exists.

    Definition Classes
    SequencerStore
  35. def lookupMemberInternal(member: Member)(implicit traceContext: TraceContext): Future[Option[RegisteredMember]]

    Lookup member directly without caching.

    Lookup member directly without caching.

    Attributes
    protected
    Definition Classes
    DbSequencerStoreSequencerStore
  36. def markLaggingSequencersOffline(cutoffTime: CantonTimestamp)(implicit traceContext: TraceContext): Future[Unit]

    Flag any sequencers that have a last updated watermark on or before the given cutoffTime as offline.

    Flag any sequencers that have a last updated watermark on or before the given cutoffTime as offline.

    Definition Classes
    DbSequencerStoreSequencerStore
  37. def maxSleepMillis: Long
    Attributes
    protected
    Definition Classes
    FlagCloseable
  38. final def ne(arg0: AnyRef): Boolean
    Definition Classes
    AnyRef
  39. def noTracingLogger: Logger
    Attributes
    protected
    Definition Classes
    NamedLogging
  40. final def notify(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  41. final def notifyAll(): Unit
    Definition Classes
    AnyRef
    Annotations
    @native() @HotSpotIntrinsicCandidate()
  42. def onClosed(): Unit
    Attributes
    protected
    Definition Classes
    FlagCloseable
  43. def performUnlessClosing[A](name: String)(f: => A)(implicit traceContext: TraceContext): UnlessShutdown[A]

    Performs the task given by f unless a shutdown has been initiated.

    Performs the task given by f unless a shutdown has been initiated. The shutdown will only begin after f completes, but other tasks may execute concurrently with f, if started using this function, or one of the other variants (performUnlessClosingF and performUnlessClosingEitherT). The tasks are assumed to take less than closingTimeout to complete.

    DO NOT CALL this.close as part of f, because it will result in a deadlock.

    f

    The task to perform

    returns

    scala.None$ if a shutdown has been initiated. Otherwise the result of the task.

    Definition Classes
    FlagCloseable
  44. def performUnlessClosingEitherT[E, R](name: String, onClosing: => E)(etf: => EitherT[Future, E, R])(implicit ec: ExecutionContext, traceContext: TraceContext): EitherT[Future, E, R]

    Performs the EitherT[Future] given by etf unless a shutdown has been initiated, in which case the provided error is returned instead.

    Performs the EitherT[Future] given by etf unless a shutdown has been initiated, in which case the provided error is returned instead. Both etf and the error are lazy; etf is only evaluated if there is no shutdown, the error only if we're shutting down. The shutdown will only begin after etf completes, but other tasks may execute concurrently with etf, if started using this function, or one of the other variants (performUnlessClosing and performUnlessClosingF). The tasks are assumed to take less than closingTimeout to complete.

    DO NOT CALL this.close as part of etf, because it will result in a deadlock.

    etf

    The task to perform

    Definition Classes
    FlagCloseable
  45. def performUnlessClosingEitherTF[E, R](name: String, onClosing: => E)(etf: => EitherT[Future, E, Future[R]])(implicit ec: ExecutionContext, traceContext: TraceContext): EitherT[Future, E, Future[R]]
    Definition Classes
    FlagCloseable
  46. def performUnlessClosingF[A](name: String)(f: => Future[A])(implicit ec: ExecutionContext, traceContext: TraceContext): FutureUnlessShutdown[A]

    Performs the Future given by f unless a shutdown has been initiated.

    Performs the Future given by f unless a shutdown has been initiated. The future is lazy and not evaluated during shutdown. The shutdown will only begin after f completes, but other tasks may execute concurrently with f, if started using this function, or one of the other variants (performUnlessClosing and performUnlessClosingEitherT). The tasks are assumed to take less than closingTimeout to complete.

    DO NOT CALL this.close as part of f, because it will result in a deadlock.

    f

    The task to perform

    returns

    The future completes with com.digitalasset.canton.lifecycle.UnlessShutdown.AbortedDueToShutdown if a shutdown has been initiated. Otherwise the result of the task wrapped in com.digitalasset.canton.lifecycle.UnlessShutdown.Outcome.

    Definition Classes
    FlagCloseable
  47. def prune(requestedTimestamp: CantonTimestamp, status: SequencerPruningStatus, payloadToEventMargin: NonNegativeFiniteDuration)(implicit traceContext: TraceContext): EitherT[Future, PruningError, String]

    Prune as much data as safely possible from before the given timestamp.

    Prune as much data as safely possible from before the given timestamp. Return a human readable report on what has been removed.

    requestedTimestamp

    the timestamp that we would like to prune from (see docs on using the pruning status and disabling members for picking this value)

    status

    the pruning status that should be used for determining a safe to prune time for validation

    payloadToEventMargin

    the maximum time margin between payloads and events. once we have a safe to prune timestamp we simply prune all payloads at safeTimestamp - margin to ensure no payloads are removed where events will remain. typically sourced from SequencerWriterConfig.payloadToEventMargin.

    Definition Classes
    SequencerStore
  48. def pruneCheckpoints(timestamp: CantonTimestamp)(implicit traceContext: TraceContext): Future[Int]

    Prune counter checkpoints for the given member before the given timestamp.

    Prune counter checkpoints for the given member before the given timestamp.

    returns

    A lower bound on the number of checkpoints removed.

    Attributes
    protected[store]
    Definition Classes
    DbSequencerStoreSequencerStore
  49. def pruneEvents(timestamp: CantonTimestamp)(implicit traceContext: TraceContext): Future[Int]

    Prune events before the given timestamp

    Prune events before the given timestamp

    returns

    a best efforts count of how many events were removed. this value can be less than the number of events actually removed if technical issues prevent a full count from being returned (e.g. with a database we may retry a delete after a connectivity issue and find that all events were successfully removed and have 0 rows removed returned).

    Attributes
    protected[store]
    Definition Classes
    DbSequencerStoreSequencerStore
  50. def prunePayloads(timestamp: CantonTimestamp)(implicit traceContext: TraceContext): Future[Int]

    Prune payloads before the given timestamp

    Prune payloads before the given timestamp

    returns

    a best efforts count of how many events were removed. this value can be less than the number of payloads actually removed if technical issues prevent a full count from being returned.

    Attributes
    protected[store]
    Definition Classes
    DbSequencerStoreSequencerStore
  51. def readEvents(memberId: SequencerMemberId, fromTimestampO: Option[CantonTimestamp], limit: Int)(implicit traceContext: TraceContext): Future[Seq[Sequenced[Payload]]]

    Read all events of which a member is a recipient from the provided timestamp but no greater than the earliest watermark.

    Read all events of which a member is a recipient from the provided timestamp but no greater than the earliest watermark.

    Definition Classes
    DbSequencerStoreSequencerStore
  52. def registerMember(member: Member, timestamp: CantonTimestamp)(implicit traceContext: TraceContext): Future[SequencerMemberId]

    Register the provided member.

    Register the provided member. Should be idempotent if member is already registered and return the existing id.

    Definition Classes
    DbSequencerStoreSequencerStore
  53. def runOnShutdown[T](task: RunOnShutdown)(implicit traceContext: TraceContext): Unit

    Register a task that will run onClose after all "performUnlessShutdown" tasks have finished

    Register a task that will run onClose after all "performUnlessShutdown" tasks have finished

    Definition Classes
    FlagCloseable
  54. def runStateChanged(waitingState: Boolean = false): Unit
    Attributes
    protected
    Definition Classes
    FlagCloseable
    Annotations
    @VisibleForTesting()
  55. def saveCounterCheckpoint(memberId: SequencerMemberId, counter: SequencerCounter, ts: CantonTimestamp)(implicit traceContext: TraceContext): EitherT[Future, SaveCounterCheckpointError, Unit]

    Save a checkpoint that as of a certain timestamp the member has this counter value.

    Save a checkpoint that as of a certain timestamp the member has this counter value. Any future subscriptions can then use this as a starting point for serving their event stream rather than starting from 0.

    Definition Classes
    DbSequencerStoreSequencerStore
  56. def saveEvents(instanceIndex: Int, events: NonEmpty[Seq[Sequenced[PayloadId]]])(implicit traceContext: TraceContext): Future[Unit]

    Save a series of events to the store.

    Save a series of events to the store. Callers should determine batch size. No batching is done within the store. Callers MUST ensure that event-ids are unique as no errors will be returned if a duplicate is present (for the sequencer writer see sequencer.PartitionedTimestampGenerator for use with their instance index).

    Definition Classes
    DbSequencerStoreSequencerStore
  57. def saveLowerBound(ts: CantonTimestamp)(implicit traceContext: TraceContext): EitherT[Future, SaveLowerBoundError, Unit]

    Save an updated lower bound of events that can be read.

    Save an updated lower bound of events that can be read. Must be equal or greater than any prior set lower bound.

    Definition Classes
    DbSequencerStoreSequencerStore
    Exceptions thrown

    java.lang.IllegalArgumentException if timestamp is lower than existing lower bound

  58. def savePayloads(payloads: NonEmpty[Seq[Payload]], instanceDiscriminator: UUID)(implicit traceContext: TraceContext): EitherT[Future, SavePayloadsError, Unit]

    Save the provided payloads to the store.

    Save the provided payloads to the store.

    For DB implementations we suspect that this will be a hot spot for performance primarily due to size of the payload content values being inserted. To help with this we use storage.queryAndUpdateUnsafe to do these inserts using the full connection pool of the node instead of the single connection that is protected with an exclusive lock in the HA sequencer setup.

    The downside of this optimization is that if a HA writer was to lose its lock, writes for payloads will continue regardless for a period until it shuts down. During this time another writer with the same instance index could come online. As we generate the payload id using a value generated for a partition based on the instance index this could worse case mean that two sequencer writers attempt to insert different payloads with the same id. If we use a simple idempotency method of just ignoring conflicts this could result in the active sequencer writing an event with a different payload resulting in a horrid corruption problem. This will admittedly be difficult to hit, but possible all the same.

    The approach we use here is to generate an ephemeral instance discriminator for each writer instance.

    • We insert the payloads using a simple insert (intentionally not ignoring conflicts unlike our other idempotent inserts). If this was successful we end here.
    • If this insert hits a payload with the same id the query will blow up with a unique constraint violation exception. Now there's a couple of reasons this may have happened:
      1. Another instance is running and has inserted a conflicting payload (bad!) 2. There was some connection issue when running this query and our storage layer didn't see a successful result so it retried our query unaware that it did actually succeed so now we conflicting with our own insert. (a bit of a shame but not really a problem).
    • We now query filtered on the payload ids we're attempting to insert to select out which payloads exist and their respective discriminators. For any payloads that exist we check that the discriminators indicate that we inserted this payload, if not a SavePayloadsError.ConflictingPayloadId error will be returned.
    • Finally we filter to payloads that haven't yet been successfully inserted and go back to the first step attempting to reinsert just this subset.
    payloads

    the payloads to save

    instanceDiscriminator

    a unique ephemeral value to ensure that no other sequencer instances are writing conflicting payloads without having to check the payload body

    Definition Classes
    DbSequencerStoreSequencerStore
  59. def saveWatermark(instanceIndex: Int, ts: CantonTimestamp)(implicit traceContext: TraceContext): EitherT[Future, SaveWatermarkError, Unit]

    Write the watermark that we promise not to write anything earlier than.

    Write the watermark that we promise not to write anything earlier than. Does not indicate that there is an event written by this sequencer for this timestamp as there may be no activity at the sequencer, but updating the timestamp allows the sequencer to indicate that it's still alive. Return an error if we find our sequencer is offline.

    Definition Classes
    DbSequencerStoreSequencerStore
  60. def status(now: CantonTimestamp)(implicit traceContext: TraceContext): Future[SequencerPruningStatus]

    Build a status object representing the current state of the sequencer.

    Build a status object representing the current state of the sequencer.

    Definition Classes
    DbSequencerStoreSequencerStore
  61. final def synchronized[T0](arg0: => T0): T0
    Definition Classes
    AnyRef
  62. val timeouts: ProcessingTimeout
    Attributes
    protected
    Definition Classes
    DbSequencerStoreFlagCloseable
  63. def toString(): String
    Definition Classes
    AnyRef → Any
  64. def validateCommitMode(configuredCommitMode: CommitMode)(implicit traceContext: TraceContext): EitherT[Future, String, Unit]

    Validate that the commit mode of a session is inline with the configured expected commit mode.

    Validate that the commit mode of a session is inline with the configured expected commit mode. Return a human readable message about the mismatch in commit modes if not.

    Definition Classes
    DbSequencerStoreSequencerStore
  65. final def wait(arg0: Long, arg1: Int): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  66. final def wait(arg0: Long): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException]) @native()
  67. final def wait(): Unit
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.InterruptedException])
  68. object DeliverStoreEventRow extends Serializable
  69. object EventTypeDiscriminator
  70. object ReaderState extends Serializable
    Definition Classes
    FlagCloseable

Deprecated Value Members

  1. def finalize(): Unit
    Attributes
    protected[lang]
    Definition Classes
    AnyRef
    Annotations
    @throws(classOf[java.lang.Throwable]) @Deprecated
    Deprecated

Inherited from HasCloseContext

Inherited from FlagCloseable

Inherited from SequencerStore

Inherited from AutoCloseable

Inherited from NamedLogging

Inherited from AnyRef

Inherited from Any

Ungrouped