I am strugging with grouping sequences of events into one atomic transaction.
Consider a Map
stored in acid-state, and imagine you want to implement Data.Map.alter
. The function that takes a maybe-value and returns one cannot be stored in the change log, so it is not possible to define an acidic event Alter
. However, if I write a function that calls query st Lookup ...
to lookup the old value and then update st Insert ...
to write the new one (or delete the old), there is a race condition and I might destroy information from updates that have happened in between.
In https://github.com/acid-state/acid-state/pull/48, I have used an extra MVar
to do manual locking, but there must be a better solution.
Any ideas?
Author of acid-state here.
The solution is to not use higher order functions like 'alter'. The benefits of acid-state (ACID guarantees, running code remotely, etc) comes at the cost of only using serialisable data. This restriction is unlikely to ever be lifted.
Usually this is a not a big problem; Just specialise your code. If this doesn't cut it, maybe you want to keep your state in an MVar.
Cheers, David.