How to manually delete snapshots?

I am looking for a way to lookup the local snapshot store actor in order to delete snapshots, because in Akka typed I have no API anymore to clean-up ALL events when a persistent actor is not needed anymore. See How to remove/clean-up state of EventSourcedBehavior when task done?

My current approach is to lookup the persistent actor and send a DeleteSnapshots message to it. This is fine. But the code looks really hacky and I am wondering if there is a better way to lookup the actor. My code looks like this:

ActorPath path = _context.getSelf().path().root().child("system").child("akka.persistence.snapshot-store.local");
ActorSelection actorSelection = _context.classicActorContext().actorSelection(path);
actorSelection.tell(new SnapshotProtocol.DeleteSnapshots(persistenceId().id(), SnapshotSelectionCriteria.latest()),

Any suggestion?

Yes, if you want to look up an actor by path you have to fall back to classic APIs.

I think another, better, option would be using persistence plugin specific APIs to interact with the underlying database.

Note that since SnapshotProtocol.DeleteSnapshots, and the snapshot actor are internal APIs we do not promise source and binary compatibility, this means your code could potentially break with a patch release upgrade of Akka. This specific protocol however is shared with all the plugin implementations so incompatible change is less likely to happen.

Hi @johanandren, thanks for the reply. I will leave it in this case.

If I would have found any kind of documentation about the API of the local filesystem snapshot plug-in (which writes to a distributed filesystem in our case), I would have used this. Before AKKA typed I had an API to delete all snapshots (see How to remove/clean-up state of EventSourcedBehavior when task done?), now I don’t see any public API anymore how to do this. That’s why I am using the internal API.

Actually, if you are anyway touching internals, you could perhaps use Persistence.snapshotStoreFor to avoid that lookup.

I think we moved towards more declarative API and less imperative because we saw many users ending up shooting themselves in the foot, but if you think we should open up some API to imperatively do that, please open up an issue over in the issue tracker and we can discuss it there.