[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.

Still...

Eshell V5.10.2  (abort with ^G)
1> mnesia:start().
ok
2> dbg:tracer(), dbg:tp(ets,new,[]), dbg:p(all,[c]).
{ok,[{matched,nonode@REDACTED,40}]}
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},
 public,named_table,set,
 {write_concurrency,true},
 {read_concurrency,true}])
{atomic,ok}
4> mnesia:delete_table(t).
(<0.44.0>) call ets:new(mnesia_trans_store,[bag,public])
{atomic,ok}
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}])
{atomic,ok}

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)).
{cstruct,t,set,
         [nonode@REDACTED],
         [],[],0,read_write,false,[],[],false,t,
         [key,val],
         [],[],
         [{ets,[{read_concurrency,true}]},
          {ets,[{write_concurrency,true}]}],
         {{1377,772088,582589},nonode@REDACTED},
         {{2,0},[]}}

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}),
    if
        ...;
        (Storage == ram_copies) or (Storage == disc_copies) ->
            EtsOpts = proplists:get_value(ets, StorageProps, []),
            Args = [{keypos, 2}, public, named_table, Cs#cstruct.type | EtsOpts],
    end.

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.

BR,
Ulf W

Ulf Wiger, Co-founder & Developer Advocate, Feuerlabs Inc.
http://feuerlabs.com






More information about the erlang-questions mailing list