[erlang-questions] Re-using Mnesia disk files for a different node

Evgeny M donpedrothird@REDACTED
Thu Sep 26 23:46:48 CEST 2013


You do can convert live database, but there are some limitation, and you 
could lose some of your data. You will lose all data which is not yet 
transferred from log file. If you don't want to risk losing data, you may 
open DECISION_TAB.LOG and LATEST.LOG with disc_log module and convert them 
as well. They contain many different types of records though.

This method is for disk-only-copy tables only. I think there could be 
problems with disk-copy tables, as ets dumps contain node information too. 
But maybe not.

So
You need to stop mnesia, and open file schema.DAT with dets:open_file(). It 
contains records of type {schema, SchemaName, ParamsList}.

ParamsList is a proplist. Node name (node_name()) contains in 
{ram_copies,[node_name()]}, {disc_copies, [node_name()]}, 
 {disc_only_copies, [node_name()]}, {version, {Version, {node_name(), 
TimeStamp}}} and {cookie, {TimeStamp, node_name()}}. {cookie, ..} and 
{version, ..} could contain an empty list as value as well.
You need to iterate records in this table, change nodename() from old to 
current node name (or just change any to current node name if you have 
single-node database) and insert them back.
Then close the dets file, delete two files - DECISION_TAB.LOG 
and LATEST.LOG, and start mnesia again.

This could be done in auto mode on each restart, if you're brave one. Just 
stop mnesia, open scheme.DAT, check if all record have current node, and if 
some have different node name do the conversion.


понедельник, 23 сентября 2013 г., 10:58:34 UTC+4 пользователь Yash Ganthe 
написал:
>
>  Hi,
>
>  
>
> On a node named node1@REDACTED I created an Mnesia schema using:
>
> mnesia:create_schema([node()]).
>
> and created a table using:
>
> mnesia:create_table(tab1, [{disc_copies, [node()]}, {attributes, 
> record_info(fields, tab1)}]).
>
>  
>
> The mnesia directory was set to "mnesia_node1". The directory was created 
> and the DB files were created inside it.
>
>  
>
> Once the node was stopped, the DB files still exist in the directory. I 
> hoped to re-use the DB as the mnesia DB for another node, node2.
>
>  
>
> So I started the other node using:
>
> erl -name node2 -mnesia dir "mnesia_node1".
>
>  
>
> On node2 when I start mnesia and do a tv:start(), I see the tab1 listed in 
> the schema. However, it shows no records. I was expecting Mnesia to use the 
> directory as the location of all DB files.
>
>  
>
> Is there something I have missed?
>
>  
>
> Thanks,
>
> Yash
>  
> DISCLAIMER ========== This e-mail may contain privileged and confidential 
> information which is the property of Persistent Systems Ltd. It is intended 
> only for the use of the individual or entity to which it is addressed. If 
> you are not the intended recipient, you are not authorized to read, retain, 
> copy, print, distribute or use this message. If you have received this 
> communication in error, please notify the sender and delete all copies of 
> this message. Persistent Systems Ltd. does not accept any liability for 
> virus infected mails. 
>  
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20130926/012c7277/attachment.htm>


More information about the erlang-questions mailing list