Q: Adding nodes to an Mnesia db - the best way?

Bruce Fitzsimons Bruce@REDACTED
Fri Jul 13 10:34:14 CEST 2001


Hi,

I have been playing with adding and deleting nodes on an Mnesia db. Every
single time I manage to stuff it up in some way and have Mnesia dump on me.

All I want to be able to do is to extend the schema onto a remote db, and
then add the tables to the remote db.

There appears to be some omissions from the current docs about the schema -
the R7B-3 code explicitly limits mnesia:add_table_copy to ram_copies for the
schema table. I'm not sure why. Any explanation would be welcome, I am
presuming that there is some dependency issue that caused this design.

Anyway, the code:

rpc:call(Node, mnesia, stop, []),
mnesia:add_table_copy(schema, Node, ram_copies),
io:format("Created Schema (ram copy)"),
    rpc:call(Node, mnesia, start, []),
%% Wait for Mnesia to start up
receive
     _ ->
         true
after 3000 ->
     ok
end,
io:format("Changing schema to disc_copies~n~n"),
mnesia:change_table_copy_type(schema, Node, disc_copies),
io:format("schema changed - adding tables~n"),
mnesia:add_table_copy(worker, Node, disc_copies).

I have a local node with everything and a remote node with nothing. There is
another node, but that was turned off.

I have many weird errors with this code (eg "table schema does not exist"
from the change_table_copy_type), but the final situation I got myself into
was the local node believing that the remote node was sharing the schema,
but the remote node thought that it just had a ram_copies schema of its own.
Very weird. I could not delete the table copy because the remote node
"wasn't active", and I couldn't get the remote node to realise its place in
the world and get the schema copy. A third node that was previously sharing
the schema crashed when I started it because the schemas could not be
merged.

I ended up removing all copies of the database and starting afresh
(create_schema(all_three_nodes)). Its not too big a deal at this stage, but
it would be nice to know the definitive way of doing this - I am envisaging
building a nice screen or two that will let me add/delete nodes at will.

Any hints or suggestions about the correct way to add and remove new nodes
would be appreciated.

Cheers,
Bruce





More information about the erlang-questions mailing list