[erlang-questions] Shouldn't Mnesia be fully initialized after mnesia:start()?

Andreas Hillqvist andreas.hillqvist@REDACTED
Thu Jan 24 08:17:29 CET 2008


I belive you are looking for: mnesia:wait_for_tables/2

Try:
 test_no_wait() ->
  mnesia:start(),
  ok = mnesia:wait_for_tables([registered_symbol], 1000),
  Fun = fun() ->
          Q = qlc:q([E || E <- mnesia:table(registered_symbol)]),
          qlc:e(Q)
       end,
  mnesia:transaction(Fun).


Regards
Andreas Hillqvist

2008/1/24, Artur Matos <arturmatos78@REDACTED>:
> Hi to all,
>
> I have started studying Mnesia recently, and as a test I've wrote the
> following simple program:
>
> -module(mnesiatest).
> -compile([export_all]).
>
>  -include_lib("stdlib/include/qlc.hrl").
>
> -record(registered_symbol, {symbol, date}).
>
> test_no_wait() ->
>  mnesia:start(),
>  Fun = fun() ->
>          Q = qlc:q([E || E <-
> mnesia:table(registered_symbol)]),
>          qlc:e(Q)
>       end,
>  mnesia:transaction(Fun).
>
> So test_no_wait() basically starts Mnesia and does a query of
> all the records registered in the registered_symbol table. Now if I run this
> program,
> I get the following error (using Erlang R12B on Mac OS X 10.4, PPC):
>
>
> 10> mnesiatest:test_no_wait().
> {aborted,{no_exists,registered_symbol}}
>
> Although the record registered_symbol is defined in the source code. But if
> I
> change test_no_wait() to include a slight delay between mnesia:start() and
> the
> querying:
>
> test_wait() ->
>  mnesia:start(),        %% Blocks for 10 seconds
>  receive
>         after 10000 ->
>     true
>         end,
>  Fun = fun() ->
>          Q = qlc:q([E || E <-
> mnesia:table(registered_symbol)]),
>          qlc:e(Q)
>       end,
>  mnesia:transaction(Fun).
>
> and run this version:
>
> 11> mnesia:stop().
>
> =INFO REPORT==== 20-Jan-2008::17:27:16 ===
>     application: mnesia
>     exited: stopped
>     type: temporary
> stopped
> 12> mnesiatest:test_wait().
> {atomic,[{registered_symbol,"IBM",{2008,1,20}}]}
> 13>
>
> then my query works, but I find this behavior a bit strange. It looks like
> some Mnesia initialization is still going on after my call to
> mnesia:start(), but shouldn't mnesia:start() block until Mnesia is fully
> initialized? or shouldn't at least mnesia:transaction(Fun) do this? Or is
> there any command that I should be calling that blocks until everything
> is initialized?
>
> In case it helps, this is the call I am using to define my database:
>
> init() ->
>        mnesia:create_table(registered_symbol,
> [{disc_copies, [node()]}, {attributes, record_info(fields,
> registered_symbol)}]).
> Thanks for the help,
>
> Artur.
>
>
>
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>



More information about the erlang-questions mailing list