user2645074
user2645074

Reputation: 107

Making sequences of events atomic in acid-state

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?

Upvotes: 2

Views: 176

Answers (1)

Lemmih
Lemmih

Reputation: 56

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.

Upvotes: 3

Related Questions