[erlang-questions] mnesia:dirty_update_counter and replicated tables

Serge Aleynikov <>
Thu Sep 21 17:41:21 CEST 2006


The answer is regretfully no.  Let's consider an example to illustrate 
this point.  You have two nodes A and B both running mnesia with a 
replicated table.

1. The content of a counter is 1.
2. Node A does a mnesia:dirty_update_counter call to increment the value 
of the counter by 2.
3. Very closely in time node B does mnesia:dirty_update_counter call to 
increment the counter by 3.

After this the value of that field could be either one of:

a) 3.
b) 4.
c) 6.

No guarantees can be made as to which value the counter would hold 
without having cross-node locking involved by using transactions.

Depending on the application you could use transactions to update data 
and dirty operations for read-only purposes.



Scott Lystig Fritchie wrote:
> There hasn't been any discussion of mnesia:dirty_update_counter here
> in quite a while.
> Looking through my archive, I didn't find a definite answer.  Is
> mnesia:dirty_update_counter safe to use when the underlying 'set'
> table is replicated?  If I use mnesia:dirty_update_counter on the same
> counter on two different Mnesia nodes, would I ever be unpleasantly
> surprised?
> The flow seems to go through the transaction manager, which bodes well
> for multi-node safety?  Umrfl, it's too late to be reading Mnesia
> code.  It will be a good learning exercise to continue my reading, but
> in the meantime ... is there a quick'ish answer from a kind soul?
> Or will a tormenting soul tell me to use tracing and the 'dbg' module
> to trace the path for myself?  :-)
> -Scott
> _______________________________________________
> erlang-questions mailing list
> http://www.erlang.org/mailman/listinfo/erlang-questions

Serge Aleynikov
R&D Telecom, MIS, IDT Corp
Tel: +1 (973) 438-3436
Fax: +1 (973) 438-1464

More information about the erlang-questions mailing list