[erlang-questions] non-atomic nature of mnesia:dirty_update_counter
Ulf Wiger
ulf.wiger@REDACTED
Sun Mar 6 08:19:22 CET 2011
On 6 Mar 2011, at 06:54, Ken Ellis wrote:
> After running test_counter:run(5000,1) on each node simultaneously,
> and comparing the files, i get 2893 duplicates out of 5000. Although
> the counter has been incremented by 10000. I can't repro running on a
> single node with a large number of processes, so it seems atomic in
> that case.
It is exactly the single-node case that is atomic. The documentation should
spell this out.
The User Guide does say that you lose mnesia's atomicity and isolation properties if you use dirty operations, which does seem to contradict what is said about dirty_update_counter(), but what the Reference Manual (*and* User Guide) should say is that dirty_update_counter() is atomic only in a very limited context.
The User Guide does say something else that is, strictly speaking, wrong:
"It is not possible to have transaction protected updates of counter records."
It is of course possible - they are only records after all. You can do an update counter inside a transaction through a combination of read() and write().
BR,
Ulf W
Ulf Wiger, CTO, Erlang Solutions, Ltd.
http://erlang-solutions.com
More information about the erlang-questions
mailing list