Reputation: 115
Hi I'm trying to make a cursor in mnesia from a remote node, for example: I have the node which is the mnesia database owner and runs important processes in a dedicated server machine, and another node which have a process running in other computer and have to go through all the items to make some simple operations with the data. The thing is that I can make the miscellaneous process work if runs in the same node of mnesia but not remotely. This is my code that runs locally:
make_cursor_local() ->
QD = qlc:sort(mnesia:table(customer, [{traverse, select}])),
mnesia:activity(async_dirty, fun() -> qlc:cursor(QD) end, mnesia_frag).
get_next_local(Cursor) ->
Get = fun() -> qlc:next_answers(Cursor,100) end,
mnesia:activity(async_dirty, Get, mnesia_frag).
del_cursor_local(Cursor) ->
qlc:delete_cursor(Cursor).
This is my actual code using rpc:
make_cursor() ->
Sort = rpc:call(?NamespaceNode, mnesia, table, [customer, [{traverse, select}]]),
QD = rpc:call(?NamespaceNode, qlc, sort, [Sort]),
CursorCreation = fun() -> qlc:cursor(qlc:sort(Sort)) end,
Cursor = rpc:call(?NamespaceNode, mnesia, activity, [async_dirty, CursorCreation, mnesia_frag]),
Cursor.
get_next(Cursor) ->
Get = fun() -> rpc:call(?NamespaceNode, qlc, next_answers, [Cursor, 100]) end,
Next = rpc:call(?NamespaceNode, mnesia, activity, [async_dirty, Get, mnesia_frag]),
Next.
del_cursor(Cursor) ->
rpc:call(?NamespaceNode, qlc, delete_cursor, [Cursor]).
This code is generating this error making the mnesia activity call in the make_cursor function:
{badrpc,
{'EXIT',
{undef,
[{#Fun<cleaner_app.2.116369932>,[],[]},
{mnesia_tm,non_transaction,5,
[{file,"mnesia_tm.erl"},{line,738}]},
{rpc,'-handle_call_call/6-fun-0-',5,
[{file,"rpc.erl"},{line,205}]}]}}} {badrpc,{'EXIT',{undef,[{#Fun<misc_app.2.116369932>,[],
[]},
{mnesia_tm,non_transaction,5,
[{file,"mnesia_tm.erl"},{line,738}]},
{rpc,'-handle_call_call/6-fun-0-',5,
[{file,"rpc.erl"},{line,205}]}]}}}
Upvotes: 1
Views: 215
Reputation: 115
I found that the remote node can't execute anonymous functions created in another node so the error posted can be solved this way:
make_cursor() ->
Sort = rpc:call(?NamespaceNode, mnesia, table, [customer, [{traverse, select}]]),
QD = rpc:call(?NamespaceNode, qlc, sort, [Sort]),
rpc:call(?NamespaceNode, mnesia, activity, [sync_transaction, fun qlc:cursor/1, [QD], mnesia_frag]).
I found the answer here what kind of types can be sent on an erlang message?
Now I have to solve the Cursor ownership because I cant execute it from the remote node.
This is the error:
{badrpc,
{'EXIT',
{aborted,
{not_cursor_owner,
[{qlc,next_answers,
[{qlc_cursor,{<6920.991.0>,<6920.990.0>}},100],
[{file,"qlc.erl"},{line,515}]},
{mnesia_tm,apply_fun,3,[{file,"mnesia_tm.erl"},{line,833}]},
{mnesia_tm,execute_transaction,5,
[{file,"mnesia_tm.erl"},{line,813}]},
{mnesia,wrap_trans,6,[{file,"mnesia.erl"},{line,394}]},
{rpc,'-handle_call_call/6-fun-0-',5,
[{file,"rpc.erl"},{line,205}]}]}}}}
Upvotes: 0