Implementing Persistence Query
https://github.com/okumin/akka-persistence-sql-async/issues/5
@okumin I'm concerned that asyncWriteMessages can't safely be written using asynchronous database writes.
Since AsyncWriteJournal is an actor, writing a message M1 to the database asynchronously can result in a subsequent write of message M2 being processed and persisted before the write of M1 has completed. While I don't think this will actually cause any errors to be thrown by the database, it does mean that reads from the database could return streams with missing data.
The LevelDb implementation avoids this by performing all state modifications and writes in a synchronous block of code that is simply wrapped with Future.fromTry { ... } which allows the synchronous code to conform to the async interface.
This obviously isn't perfect as it results in blocking the AsyncWriteJournal actor's thread but it does guarantee that there are no race conditions in side-effecting code.
Thoughts?
I have thought that any pair of asyncWriteMessages for the same persistence_id is not invoked at once and then the current implementation is safe since all the AtomicWrite is inserted in one transaction.
I can't find any documentation that seems to indicate that asyncWriteMessages will not be invoked concurrently for the same persistence_id and it's not obvious to me how that would be happening in AsyncWriteJournal.scala
Let me know if I've overlooked something.
It seems that PersistentActor writes one or batched events seqentially, but I would like to have more time to get the evidence.
https://github.com/akka/akka/blob/master/akka-persistence/src/main/scala/akka/persistence/Eventsourced.scala
You are right and we should serialize events by persistence id. https://groups.google.com/forum/#!topic/akka-user/hi-OlSuO_M0
Created the issue for that topic. https://github.com/okumin/akka-persistence-sql-async/issues/9
Is there any progress migrating this plugin to akka 2.5.x?
Release akka-persistence-sql-async which depends on akka 2.5. https://github.com/okumin/akka-persistence-sql-async/releases/tag/v0.5.0