[erlang-questions] QLC Cursor confusion

Dan Gudmundsson dgud@REDACTED
Wed Feb 22 15:58:18 CET 2012


Yes, after the transaction is done, all locks are released and
temporary data is cleaned up.

/Dan

On Wed, Feb 22, 2012 at 3:50 PM, Artem Teslenko <ates@REDACTED> wrote:
> Hello,
>
> Try to use ets:table instead of mnesia:table
>
> On Wed, 22 Feb 2012, Ignas Vyšniauskas wrote:
>
>> Hi Erlangers,
>>
>> I'm somewhat confused with the correct usage of QLC Cursors. I'd like to
>> return the cursor (or a equivalently a reference to it), so that the
>> receiver could perform consecutive calls to qlc:next_answers(CursorRef,
>> N). But as far as I understand, this is not quite possible. Here is me
>> failing to make friends with QLC (sorry for the mangled formatting):
>>
>> 40> Q = qlc:q([P || P <- mnesia:table('number.info'),
>> P#'number.info'.owner_id == <<"13">>]).
>> {qlc_handle,{qlc_lc,#Fun<erl_eval.20.21881191>,
>>                     {qlc_opt,false,false,-1,any,[],any,524288,allowed}}}
>> 41> qlc:cursor(Q).
>>
>> ** exception exit: {aborted,no_transaction}
>>      in function  mnesia:abort/1
>>      in call from mnesia:pre_qlc/2
>>      in call from qlc:call/4
>>      in call from qlc:table_handle/3
>>      in call from qlc:setup_le/3
>>      in call from qlc:setup_quals/6
>>      in call from qlc:setup_quals/4
>>      in call from qlc:setup_le/3
>>
>> Okayy, let's try it in a transaction:
>>
>> 42> {atomic, QR} = mnesia:transaction(fun() -> qlc:cursor(Q) end).
>>
>> {atomic,{qlc_cursor,{<0.436.0>,<0.434.0>}}}
>>
>> Cool, it works, but...
>>
>> 43> qlc:next_answers(QR, 1).
>> ** exception error: {qlc_cursor_pid_no_longer_exists,<0.436.0>}
>>      in function  qlc:next_loop/3
>>
>> Hm, but...
>>
>> 44> mnesia:transaction(fun() -> qlc:next_answers(QR, 1) end).
>> {aborted,{not_cursor_owner,[{qlc,next_answers,
>>                                  [{qlc_cursor,{<0.436.0>,<0.434.0>}},1]},
>>                             {mnesia_tm,apply_fun,3},
>>                             {mnesia_tm,execute_transaction,5},
>>                             {erl_eval,do_apply,5},
>>                             {shell,exprs,7},
>>                             {shell,eval_exprs,7},
>>                             {shell,eval_loop,3}]}}
>>
>> I'm confused. Does that mean the cursor lives in some process owned by
>> mnesia and I can only access it from within a single transaction? What
>> am I doing wrong here?
>>
>> Thanks,
>> Ignas
>> _______________________________________________
>> erlang-questions mailing list
>> erlang-questions@REDACTED
>> http://erlang.org/mailman/listinfo/erlang-questions
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list