[erlang-questions] select error when using fragmented tables
Dan Gudmundsson
dgud@REDACTED
Wed Mar 7 17:20:23 CET 2007
Thanks
I will take a look at it.
/Dan
Primanathan Reddy [ MTN - Innovation Centre ] wrote:
> 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,Type),
>
> 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,Type),
>
> frag_sel_cont(Res, NameNodes, {Pat,LockKind,Limit})
>
> end.
>
>
More information about the erlang-questions
mailing list