[akka-persisntence] Concurrency of persisting events

80 views
Skip to first unread message

おくみんです

unread,
Oct 4, 2015, 2:25:53 AM10/4/15
to Akka User List
Hello.

I'm implementing a plugin of akka-persistence and I have a question.

Is it possible that multiple AsyncWriteJournal#asyncWriteMessages for the same persistence id are invoked at the same time?
I think that each PersistentActor controls batching writes and so that is not possible.

If possible, should I keep writing for the same persistence id serial on AsyncWriteJournal?
Otherwise, it may cause inconsistency at the following conditions.

1. invoke asyncWriteMessages with W1 of Seq[AtomicWrite]
2. invoke asyncWriteMessages with W2 that has the same persistence id as W1 before W1 has been completed
3. W2 has been completed before W1 has done
4. a query side(recovering, PersistenceQuery) reads events without W1 and keep the highest sequence number of W2
5. W1 has been completed
6. the query side never reads W1

Patrik Nordwall

unread,
Oct 4, 2015, 3:18:59 AM10/4/15
to akka...@googlegroups.com
Hi,

On Sun, Oct 4, 2015 at 7:34 AM, おくみんです <ma...@okumin.com> wrote:
Hello.

I'm implementing a plugin of akka-persistence and I have a question.

Is it possible that multiple AsyncWriteJournal#asyncWriteMessages for the same persistence id are invoked at the same time?
I think that each PersistentActor controls batching writes and so that is not possible.

The PersistentActor may have more than one outstanding WriteMessages message (corresponding to the asyncWriteMessages call) when persistAsync is used and the max batch size is reached.

asyncWriteMessages is a method in the journal Actor, and the Actor serializes the calls to it, but I guess your concern is that if you spawn off a Future for each asyncWriteMesses call and the execution of these are not serialized.

Yes, in that case it can be a problem. You should serialize the writes for each persistentId (could also be done with consistent hashing if it is too fine grained to do it on the persistenceId level).

This is something we should clarify in the documentation.

Cheers,
Patrik
 

If possible, should I keep writing for the same persistence id serial on AsyncWriteJournal?
Otherwise, it may cause inconsistency at the following conditions.

1. invoke asyncWriteMessages with W1 of Seq[AtomicWrite]
2. invoke asyncWriteMessages with W2 that has the same persistence id as W1 before W1 has been completed
3. W2 has been completed before W1 has done
4. a query side(recovering, PersistenceQuery) reads events without W1 and keep the highest sequence number of W2
5. W1 has been completed
6. the query side never reads W1

--
>>>>>>>>>> Read the docs: http://akka.io/docs/
>>>>>>>>>> Check the FAQ: http://doc.akka.io/docs/akka/current/additional/faq.html
>>>>>>>>>> Search the archives: https://groups.google.com/group/akka-user
---
You received this message because you are subscribed to the Google Groups "Akka User List" group.
To unsubscribe from this group and stop receiving emails from it, send an email to akka-user+...@googlegroups.com.
To post to this group, send email to akka...@googlegroups.com.
Visit this group at http://groups.google.com/group/akka-user.
For more options, visit https://groups.google.com/d/optout.



--

Patrik Nordwall
Typesafe Reactive apps on the JVM
Twitter: @patriknw

Reply all
Reply to author
Forward
0 new messages