[erlang-questions] mnesia and storage_properties

Ulf Wiger ulf@REDACTED
Thu Aug 29 12:35:30 CEST 2013

Playing around with mnesia storage properties, I decided to check what happens if e.g. duplicate {ets,Ps} entries are given for the same table.

First, I note that mnesia allows it.
Second, I note that ets doesn't allow me to check concurrency "tweaks" via ets:info/2 - bummer.


Eshell V5.10.2  (abort with ^G)
1> mnesia:start().
2> dbg:tracer(), dbg:tp(ets,new,[]), dbg:p(all,[c]).
3> mnesia:create_table(t,[{storage_properties,[{ets,[{write_concurrency,true},{read_concurrency,true}]}]}]).
(<0.44.0>) call ets:new(mnesia_trans_store,[bag,public])
(<0.40.0>) call ets:new(t,[{keypos,2},
4> mnesia:delete_table(t).
(<0.44.0>) call ets:new(mnesia_trans_store,[bag,public])
5> mnesia:create_table(t,[{storage_properties,[{ets,[{write_concurrency,true}]},{ets,[{read_concurrency,true}]}]}]).
(<0.44.0>) call ets:new(mnesia_trans_store,[bag,public])
(<0.40.0>) call ets:new(t,[{keypos,2},public,named_table,set,{read_concurrency,true}])

So, in the second case, when the two ets properties are given as separate {ets, Ps} entries, mnesia accepts the definition, but ignores the *first* entry.

6> rp(mnesia:table_info(t,cstruct)).

The problem (unless it is that mnesia_schema doesn't merge the properties, or disallow multiple entries in the first place) seems to be in mnesia_loader:

create_table(Tab, TabSize, Storage, Cs) ->
    StorageProps = val({Tab, storage_properties}),
        (Storage == ram_copies) or (Storage == disc_copies) ->
            EtsOpts = proplists:get_value(ets, StorageProps, []),
            Args = [{keypos, 2}, public, named_table, Cs#cstruct.type | EtsOpts],

Note that mnesia_schema seems to have reversed the list before storing it in the cstruct. In fact, what it does is call lists:sort/1 on the list.

Ulf W

Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.

More information about the erlang-questions mailing list