Erlang/OTP Forums

Author Message

<  Advanced Erlang/OTP  ~  Strange Happenings with Mnesia

ptmoy
Posted: Thu Feb 09, 2012 4:01 am Reply with quote
User Joined: 24 Dec 2009 Posts: 10 Location: New Jersey, U.S.A.
Apologies for the lengthy lead-in. The 3 sample modules (a.erl, b.erl,
and d.erl) will highlight my observations. My questions are at the end of the post.

-module (a).
-export ([start/0]).
start()->
mnesia:create_schema ([node()]),
mnesia:start().


-module (b).
-export ([start/0]).
-record (dummy, {d1,d2}).
start()->
net_adm:ping (n1@T110),
mnesia:start(),
mnesia:change_config(extra_db_nodes, nodes()),
mnesia:add_table_copy(schema, node(), ram_copies),
mnesia:create_table (dummy,[{ram_copies, [node()]}, {attributes,
record_info (fields, dummy)}]).


-module (d).
-export ([start/0]).
-record (dummy, {d1,d2}).
start()->
net_adm:ping (n1@T110),
mnesia:start(),
mnesia:change_config(extra_db_nodes, nodes()),
mnesia:add_table_copy(schema, node(), ram_copies),
Result1 = mnesia:delete_table (dummy),
io:format ("Return val from mnesia:delete_table~p~n", [Result1]),
Result2 = mnesia:create_table (dummy, [{ram_copies, [node()]},
{attributes, record_info (fields, dummy)}]),
io:format ("Return val from mnesia:create_table~p~n", [Result2]).


I ran a.beam on a node named n1@T110, which created a schema. Then I
ran b.beam on a node named n2@T110, which created a ram copy of the
schema, and a table named dummy on n2@T110. Nothing strange so far. I
exited n2@T110 with q(), then started n3@T110 and ran d.beam. I got
this:


pm@T110:~/t1$ erl -sname n3
Erlang R15B (erts-5.9) [source] [64-bit] [smp:4:4] [async-threads:0]
[hipe] [kernel-poll:false]

Eshell V5.9 (abort with ^G)
(n3@T110)1> d:start().
Return val from mnesia:delete_table{aborted,{no_exists,dummy}}
Return val from mnesia:create_table{aborted,{already_exists,dummy}}
ok
(n3@T110)2>


Going back to n1@T110 and doing an mnesia:table_info (dummy, all)
resulted in this:

(n1@T110)2> mnesia:table_info (dummy, all).
[{access_mode,read_write},
{active_replicas,[]},
{all_nodes,[n2@T110]},
{arity,3},
{attributes,[d1,d2]},
{checkpoints,[]},
{commit_work,[]},
{cookie,{{1328,757112,486107},n2@T110}},
{cstruct,{cstruct,dummy,set,
[n2@T110],
[],[],0,read_write,false,[],[],false,dummy,
[d1,d2],
[],[],[],{...},...}},
{disc_copies,[]},
{disc_only_copies,[]},
{frag_properties,[]},
{index,[]},
{load_by_force,false},
{load_node,unknown},
{load_order,0},
{load_reason,unknown},
{local_content,false},
{majority,false},
{master_nodes,[]},
{memory,0},(n1@T110)3>
{ram_copies,[n2@T110]},
{record_name,dummy},
{record_validation,{dummy,3,set}},
{type,set},
{size,0},
{snmp,[]},
{storage_properties,...},
{...}|...]
(n1@T110)6> nodes().
[n3@T110]
(n1@T110)7>



Here are my questions:
1) From n3@T110, d.erl wasn't able to delete the "dummy" table because
mnesia doesn't think it exists. But I can't create a table name "dummy"
because Mnesia thinks it already exists. What am I doing wrong here?

2) Even though n2@T110 is already dead. mnesia:table_info still shows
n2@T110 having a ram copy of "dummy." Why is this?


Thanks in advance for your help.

Regards,
Patrick Moy
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum