Erlang Mnesia nested transaction aborted
i have the following code:
J = fun()->mnesia:clear_table(names) end.
mnesia:activity(transaction, J, [], mnesia_frag).
and i get this error:
** exception exit: {aborted,{aborted,nested_transaction}}
i could just run
mnesia:clear_table(names)
but since table name is fragmented over several nodes i thought i hav开发者_运维百科e to use mnesia_frag module.
what am i doing wrong ? and how would it be correct? Thank you.
you are correct that mnesia:clear_table(names) will not clear the entire fragmented table.
mnesia:clear_table/1 already runs inside a transaction, so you can not use it with the mnesia:activity transaction AccessContext.
instead try:
mnesia:activity(sync_dirty, fun mnesia:clear_table/1, [names], mnesia_frag).
if you look at the source code in mnesia_frag.erl, you'll see that it's just calling mnesia:clear_table/1 on each individual table. Assuming 4 frags, the above is basically equivalent to:
[mnesia:clear_table(T) || T <- [names, names_frag2, names_frag3, names_frag4]].
the table names coming from:
mnesia_frag:frag_names(names).
精彩评论