Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implementing Persistence Query #8

Open
okumin opened this issue Sep 27, 2015 · 8 comments
Open

Implementing Persistence Query #8

okumin opened this issue Sep 27, 2015 · 8 comments

Comments

@okumin
Copy link
Owner

okumin commented Sep 27, 2015

#5

@gavares
Copy link

gavares commented Sep 28, 2015

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

@okumin
Copy link
Owner Author

okumin commented Sep 30, 2015

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.

@gavares
Copy link

gavares commented Sep 30, 2015

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.

@okumin
Copy link
Owner Author

okumin commented Oct 2, 2015

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
Copy link
Owner Author

okumin commented Oct 4, 2015

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

@okumin
Copy link
Owner Author

okumin commented Oct 4, 2015

Created the issue for that topic.
#9

@toggm
Copy link

toggm commented Jun 29, 2017

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

@okumin
Copy link
Owner Author

okumin commented Nov 7, 2017

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants