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

Artur Matos <>
Thu Jan 24 07:46:11 CET 2008


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.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20080124/ad3fb8ea/attachment.html>


More information about the erlang-questions mailing list