Bug in mnesia:dirty_update_counter

Anders Nygren <>
Tue Mar 8 16:33:04 CET 2005


There seems to be a bug in mnesia:dirty_update_counter. 
The first time dirty_update_counter(Tab,Key,Incr) is called with a specific Key
the counter is set to 0.
The offending code seems to be mnesia_tm:do_update_op(....)


do_update_op(Tid, Storage, {{Tab, K}, {RecName, Incr}, update_counter}) ->
    {NewObj, OldObjs} = 
        case catch mnesia_lib:db_update_counter(Storage, Tab, K, Incr) of
            NewVal when integer(NewVal), NewVal >= 0 ->
                {{RecName, K, NewVal}, [{RecName, K, NewVal - Incr}]};
            _ ->
                Zero = {RecName, K, 0},    
                mnesia_lib:db_put(Storage, Tab, Zero),
                {Zero, []}
        end,
    commit_update(?catch_val({Tab, commit_work}), Tid, Tab, 
		  K, NewObj, OldObjs),
    element(3, NewObj);

It always stores 0 when there is no record with the specified Key.

/Anders Nygren



More information about the erlang-questions mailing list