-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Low-level snapshot API #8
Comments
In case you would find it useful, here is the gist of the api I'm using to control snapshot creation : /** Control how the a snapshot is stored, relatively to existing snapshots:
* - Epoch: The snapshot is deemed to the earliest snapshot,
* any existing snapshots with a smaller sequence number are discarded.
* - Cache: persist the snapshot, keeping all other existing snapshots.
*/
sealed trait SnapshotStoreMode
object SnapshotStoreMode {
case object Epoch extends SnapshotStoreMode
case object Cache extends SnapshotStoreMode
} Then the EventSource graph stage would be parametrized with a /** Control when and how snapshots are persisted. Ie, given:
* - the number of events stored since the last snapshot.
* - the duration since the last snapshot.
* - the event being persisted, up to which the snapshot would be created.
* decide if a snapshot should be created and how (Some[SnapshotStoreMode]) or not (None).
*
* Implementation details: In the case where multiple events are persisted
* after a single request, this strategy is applied for each events, but if multiple
* [SnapshotStoreMode.Epoch] are yielded, only the last one is actually acted-on.
* Also any [SnapshotStoreMode.Cache] directives appearing before a
* [SnapshotStoreMode.Epoch] is ignored.
*/
type SnapshotStrategy[-E] = (Long, Duration, E) => Option[SnapshotStoreMode]
|
Thanks for sharing your ideas. The main purpose of the low-level snapshot API is to provide a foundation for implementing what you proposed (among other possible solution). I'd like to avoid to parameterize the |
The ability to explicitly create (tagged) snapshots would enable support for versioned state. |
@2Beaucoup the low level API will provide sources that associate (i.e. tag) emitted snapshots with offsets (= version numbers). Do you see any issues? |
Nope. :) Are these snapshots created just at static intervals or will it be possible to trigger them by a prop on e.g. |
Here's the idea. Given a import com.github.krasserm.ases.Durable
import com.github.krasserm.ases.EventSourcing.EventHandler
trait Snapshot[S] {
def state: S
def sequenceNr: Long // state "version"
}
def eventSource[E](fromSequenceNr: Long): Source[Durable[E], _]
def eventHandler[E, S]: EventHandler[E, S] a snapshot source can be created with: def snapshotSource[E, S](snapshot: Snapshot[S]): Source[Snapshot[S], _] =
eventSource[E](snapshot.sequenceNr + 1L)
.scan(snapshot)((s, d) => Snapshot(eventHandler(s.state, d.event), d.sequenceNr)) It emits a new snapshot with every new event from On the command side, an |
Looks pretty flexible. Thanks for the heads-up @krasserm! |
@krasserm why not make |
@t3hnar it will be. The above only explains the concept i.e. no need to cover implementation details. |
EventSourcing
stage with state snapshotThe text was updated successfully, but these errors were encountered: