DurableStateStore

peloton.persistence.DurableStateStore
See theDurableStateStore companion object
abstract class DurableStateStore

The persistence layer typeclass for a given state class A that provides methods to store and retrieve instances of type A from and to a specific storage backend.

Attributes

Companion
object
Graph
Supertypes
class Object
trait Matchable
class Any
Known subtypes

Members list

Value members

Abstract methods

def clear(): IO[Unit]

Clears/resets the internal data structures used by the storage backend if not already created.

Clears/resets the internal data structures used by the storage backend if not already created.

Attributes

Returns

an IO[Unit]

def create(): IO[Unit]

Create and initialize the internal data structures used by the storage backend if not already created.

Create and initialize the internal data structures used by the storage backend if not already created.

Note: It is guaranteed that this operation will not truncate/clear the underlying storage, but just create it in case it does not already exist. If you need to clear the storage, use method clear instead.

Attributes

Returns

an IO[Unit]

def drop(): IO[Unit]

Drops the internal data structures used by the storage backend.

Drops the internal data structures used by the storage backend.

Attributes

Returns

an IO[Unit]

def readEncodedState(persistenceId: PersistenceId): IO[Option[EncodedState]]

Reads the current encoded (serialized) state for a given persistenceId from the storage backend.

Reads the current encoded (serialized) state for a given persistenceId from the storage backend.

Value parameters

persistenceId

The PersistenceId of the encoded state instance to read

Attributes

Returns

Some if the entry exists in the storage backend, else None

def writeEncodedState(persistenceId: PersistenceId, encodedState: EncodedState): IO[Unit]

Writes (creates or replaces) an encoded (serialized) state for a given persistenceId into the storage backend.

Writes (creates or replaces) an encoded (serialized) state for a given persistenceId into the storage backend.

The method will fail if the revision of new encoded state is not exactly the successor of the revision of the current encoded state, i.e., newRevision == currentRevision + 1. This ensures that there is no collision with persistence IDs that have accidentally been used multiple times.

Implementation note: The revision check could have easily been put into the generic write method. This would have eliminated the need to do the logic in each implementation of writeEncodedState, but it would also have eliminated the possibility to do the logic more efficient. This is why the decision was made to do it here for each implementation.

Value parameters

encodedState

The state instance of type EncodedState

persistenceId

The PersistenceId of the encoded state instance to write

Attributes

Returns

IO[Unit]

Concrete methods

def read[A](persistenceId: PersistenceId)(using payloadCodec: PayloadCodec[A]): IO[Option[DurableState[A]]]

Reads the current revision of the DurableState for type A from storage backend.

Reads the current revision of the DurableState for type A from storage backend.

Value parameters

payloadCodec

a given PayloadCodec to convert instances of type A to a byte array and vice versa

persistenceId

The PersistenceId of the durable state instance to read

Attributes

Returns

Some if the entry exists in the storage backend, else None

def write[A](persistenceId: PersistenceId, state: DurableState[A])(using payloadCodec: PayloadCodec[A]): IO[Unit]

Writes a new revision of the DurableState for type A from storage backend.

Writes a new revision of the DurableState for type A from storage backend.

The method will fail if the revision of new encoded state is not exactly the successor of the revision of the current encoded state, i.e., newRevision == currentRevision + 1. This ensures that there is no collision with persistence IDs that have accidentally been used multiple times.

Value parameters

payloadCodec

a given PayloadCodec to convert instances of type A to a byte array and vice versa

persistenceId

The PersistenceId of the durable state instance to write

state

The DurableState of type A

Attributes

Returns

An IO[Unit]