I'm currently attempting to implement snapshotting to an event sourced application using Akka Persistence. The strategy that I'm attempting to take here is:
schemaVersion
property on my state object. The purpose of the schemaVersion
is to allow me to evolve/migrate my state if I change the way I'm replying my events.state.schemaVersion
is less than my current schema version, discard that snapshot and replay events from the beginningHowever, I'm finding that I'm not able to discard snapshots during recovery. If there is a snapshot in the snapshot store, earlier events will not be offered to me.
I'm having a hard time reading up on how this should be handled. What's the proper approach here?
There is one thing I don't get, what is the state object? And from where it's getting the schemaVersion
? Isn't the state exactly the state of your actor that is reconstructed from the snapshot / events?
In any case, you can't delete and/or skip a snapshot once it's offered. Instead, you can do the following:
drop-snapshot
(defaults to false
)on preStart
override def preStart(): Unit = { super.preStart() if (dropSnapshot) deleteSnapshots(SnapshotSelectionCriteria.Latest) }
override recovery
method
override def recovery = { if (dropSnapshot) { Recovery(fromSnapshot = SnapshotSelectionCriteria.None) } else { Recovery(fromSnapshot = SnapshotSelectionCriteria.Latest) } }