We have recently had som issues where the persist action node fails. The error message we receive is the following:
**Caused by :: Write conflict during plan execution and yielding is disabled. :: Please retry your operation or multi-document transaction.
**
I believe this occurs when we are trying to modify the same object from two different instances of a service. **
**
I can’t find any information about this in the Appfarm documentation. Does anybody have any insight into what a good way of handling this is?
This is a MongoDB error message that occurs when trying to write to the same object simultaneously. This can happen if several users try to edit the same object or if services run in the background on the same object
Thank you, and yes the error message is from MongoDB. If we were working with traditional development we could solve this by making a que system for writing to the database.
As far as I know that is not possible in appfarm. Are there any good general solutions for this problem that is possible to implement in appfarm?
We have added a while loop that continues to retry write until success if error message is this one. You can set a sleep at each iteration to spread load. Of course you should always try to batch persist and limit single DB operations
Thanks! That is one way to handle it, which I suspect will work well in most cases. We did implement something similar but with a limit of 10 retries to avoid retrying forever. This worked well for a while, however, when the workload increased write conflicts increased to the point where 10 retries was insufficient.
We could of course increase the number of retries, but that seems like a solution with limited scalability. We do also have some time pressure for the service to finish.
I have an open support ticket in regards to this issue aswell. I received an instruction on how one could create a queue in Appfarm. I will share it here in case it is usefull for someone who runs in to this problem in the future. This is my interpretation of how to make a queue system in Appfarm not an exact quote:
Problem: Action A and action B both need to persist an updated version of the same object. Action A and action B can run at the same time.
Queue solution:
Action A creates a new object oA with the information that is required to update the original object.
Action B creates a new object oB with the information that is required to update the original object.
Action C is triggered on a schedule, reads object A and B, updates the original object, and deletes oA and oB.