[erlang-bugs] mnesia:dirty_update_counter/3 doesn't work on ordered sets

Ulf Wiger ulf@REDACTED
Sun Nov 13 11:57:31 CET 2011


The function mnesia:dirty_update_counter/3 checks the type of the 
table, and only wants to work for Type==set.

However, ordered_set tables also have 'set' semantics, and are 
perfectly capable of supporting update_counter/3.

Eshell V5.8.4  (abort with ^G)
(foo@REDACTED)1> mnesia:start().
ok
(foo@REDACTED)2> mnesia:create_table(t,[{type,ordered_set}]).
{atomic,ok}
(foo@REDACTED)3> mnesia:dirty_update_counter(t,a,1).
** exception exit: {aborted,{combine_error,t,update_counter}}
     in function  mnesia:abort/1


(foo@REDACTED)4> mnesia:create_table(u,[{type,set}]).        
{atomic,ok}
(foo@REDACTED)5> mnesia:dirty_update_counter(u,a,1). 
1


The reason for this is the following code in mnesia.erl:

do_dirty_update_counter(SyncMode, Tab, Key, Incr)
  when is_atom(Tab), Tab /= schema, is_integer(Incr) ->
    case ?catch_val({Tab, record_validation}) of
        {RecName, 3, set} ->
            Oid = {Tab, Key},
            mnesia_tm:dirty(SyncMode, {Oid, {RecName, Incr}, update_counter});
        _ ->
            abort({combine_error, Tab, update_counter})
    end;

If it were to be changed to 


do_dirty_update_counter(SyncMode, Tab, Key, Incr)
  when is_atom(Tab), Tab /= schema, is_integer(Incr) ->
    case ?catch_val({Tab, record_validation}) of
        {RecName, 3, Type} when Type==set; Type==ordered_set ->
            ...
    end;

…it would work as expected, IMHO. :)

No patch - apologies, but I'm knee-deep in other stuff atm.

BR,
Ulf W





More information about the erlang-bugs mailing list