akka-persistence-sql-async icon indicating copy to clipboard operation
akka-persistence-sql-async copied to clipboard

Implementing Persistence Query

Open okumin opened this issue 10 years ago • 8 comments

https://github.com/okumin/akka-persistence-sql-async/issues/5

okumin avatar Sep 27 '15 10:09 okumin

@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?

gavares avatar Sep 28 '15 19:09 gavares

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.

okumin avatar Sep 30 '15 16:09 okumin

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.

gavares avatar Sep 30 '15 17:09 gavares

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

okumin avatar Oct 02 '15 19:10 okumin

You are right and we should serialize events by persistence id. https://groups.google.com/forum/#!topic/akka-user/hi-OlSuO_M0

okumin avatar Oct 04 '15 08:10 okumin

Created the issue for that topic. https://github.com/okumin/akka-persistence-sql-async/issues/9

okumin avatar Oct 04 '15 15:10 okumin

Is there any progress migrating this plugin to akka 2.5.x?

toggm avatar Jun 29 '17 20:06 toggm

Release akka-persistence-sql-async which depends on akka 2.5. https://github.com/okumin/akka-persistence-sql-async/releases/tag/v0.5.0

okumin avatar Nov 07 '17 17:11 okumin