[erlang-questions] select error when using fragmented tables
Primanathan Reddy [ MTN - Innovation Centre ]
Reddy_P@REDACTED
Wed Mar 7 16:43:05 CET 2007
Hello
I'm using mnesia:select/4 in an activity with the mnesia_frag access
module.
Erlang R11B
I get the following error:
** exited: {{badmatch,[{tab_frag2,node@REDACTED,disc_copies}]},
[{mnesia_frag,init_select,6},
{mnesia_tm,non_transaction,5},
{erl_eval,do_apply,5},
{shell,exprs,6},
{shell,eval_loop,3}]} **
% --------------------
% Original Code
% ---------------------
init_select(Tid,Opaque,Tab,Pat,Limit,LockKind) ->
case ?catch_val({Tab, frag_hash}) of
{'EXIT', _} ->
mnesia:select(Tid, Opaque, Tab, Pat, Limit,LockKind);
FH ->
FragNumbers = verify_numbers(FH,Pat),
Fun = fun(Num) ->
Name = n_to_frag_name(Tab, Num),
Node = val({Name, where_to_read}),
Storage =
mnesia_lib:storage_type_at_node(Node, Name),
mnesia:lock(Tid, Opaque, {table,
Name}, LockKind),
{Name, Node, Storage}
end,
[{Tab,Node,Type}|NameNodes] = lists:map(Fun,
FragNumbers),
InitFun = fun(FixedSpec) ->
mnesia:dirty_sel_init(Node,Tab,FixedSpec,Limit,Type) end,
Res =
mnesia:fun_select(Tid,Opaque,Tab,Pat,LockKind,Tab,InitFun,Limit,Node,Typ
e),
frag_sel_cont(Res, NameNodes, {Pat,LockKind,Limit})
end.
After investigating I found that mnesia_frag:init_select/6 is trying to
match the result from lists:map( Fun, FragNumbers ) to
[{Tab,Node,Type}|NameNodes], where Tab is the name of fragmented table.
This will work in all the cases where key is not specified as a part of
match specification. However, if the key was specified, instead of Tab,
the name of the fragment where key resides is returned instead, which
causes the code above to crash. The patch for it is provided below, so
I'd like to ask ERLANG/OTP team to include it, or provide equivalent fix
for it.
% ---------
% Patch
% ---------
init_select(Tid,Opaque,Tab,Pat,Limit,LockKind) ->
case ?catch_val({Tab, frag_hash}) of
{'EXIT', _} ->
mnesia:select(Tid, Opaque, Tab, Pat, Limit,LockKind);
FH ->
FragNumbers = verify_numbers(FH,Pat),
Fun = fun(Num) ->
Name = n_to_frag_name(Tab, Num),
Node = val({Name, where_to_read}),
Storage =
mnesia_lib:storage_type_at_node(Node, Name),
mnesia:lock(Tid, Opaque, {table,
Name}, LockKind),
{Name, Node, Storage}
end,
[{PTab,Node,Type}|NameNodes] = lists:map(Fun,
FragNumbers),
InitFun = fun(FixedSpec) ->
mnesia:dirty_sel_init(Node,PTab,FixedSpec,Limit,Type) end,
Res =
mnesia:fun_select(Tid,Opaque,PTab,Pat,LockKind,Tab,InitFun,Limit,Node,Ty
pe),
frag_sel_cont(Res, NameNodes, {Pat,LockKind,Limit})
end.
Regards
Primanathan Reddy
Pharos Consulting (Pty) Ltd.
+27832129774
NOTE: This e-mail message is subject to the MTN Group disclaimer see http://www.mtn.co.za/default.aspx?pid=34411
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070307/9a8917f2/attachment.htm>
More information about the erlang-questions
mailing list