4

Cleaning old snapshots in the snapshot store is easy: After each successful snapshot, the actor receives a saveSnapshotSuccess with the meta-data indicating its sequence number, this information can be used to construct a snapshot SnapshotSelectionCriteria and then be fed to deleteSnapshots.

There is however no equivalent to saveSnapshotSuccess for persisting messages. As such, it is not possible to know what the sequence number of the "last-ish" message is in the journal. One could potentially keep a local cache of the persisted messages count and snapshot it, to use for calling deleteMessages but that is too tedious.

Is there a way of using persistence-query to receive the last persisted message for an actor to get an indication of what the sequence number is and then maybe call deleteMessages with say val seqNr = sequenceNumberObtainedFromReadJournal - 100, (assuming that we snapshot the state of the actor, say after every 50 messages)?

P.S. The choice of sequence number for passing to deleteMessages is of course a bit more complicated than mentioned above: even if there is a way of getting the sequence number of the last message for an actor from the journal, one has to worry about the possibility of say the last three snapshots having failed, so it's not as easy as just using 100 and 50) so the implementation would be a bit more involved, but at least we are not contaminating the snapshot type with the persistence sequence count.

Maths noob
  • 1,684
  • 20
  • 42

1 Answers1

3

You can simply call lastSequenceNr from your persistent actor.

ghostdogpr
  • 631
  • 5
  • 9