Creating mnesia disk_copies of existing ram table
Asked Answered
R

1

3

I have a complete mnesia ram_copies-only database but I am experiencing problems adding a disk_copy table to a node. At the moment I do:

  1. Create all my ram_copy tables/nodes

  2. Start mnesia on the disk_copy-to-be node.

  3. Create a new schema (I didnt create a schema for the ram_copy tables) using mnesia:create_schema([Node])
  4. Copy the table I wish to be a disk_copy, using mnesia:add_table_copy(table, Node, disk_copy)
  5. I then wait for the tables to be created

Everything seems to go according to plan (no run-time errors), but when I go to the pwd(). directory and check, there is no file reflecting the table I just created. Also when I call mnesia:info() on the node, there are no disk_copy tables, only a ram_copy schema.

Rodrickrodrigez answered 15/11, 2012 at 13:38 Comment(0)
K
4

Can you check that the field "running db nodes" lists both nodes that you have started ? It could be that you did not add the second node to the mnesia cluster.

So if your second node was called BNode, then on the first node you would run these commands in this order:

1) mnesia:change_config(extra_db_nodes, [BNode]).  
2) mnesia:add_table_copy(table, BNode, disc_copies).

Second: I think you should be creating the schema (step 3) before you start up mnesia on the disk_copy-to-be node (step 2).

This is what I did to create the schema you require:
Lets assume you have 2 nodes NodeA and NodeB.
Make sure that there is no Mnesia dir already existing before you start this.

%% From NodeA, setup the A node
erl -sname a -setcookie cookie
mnesia:start().
mnesia:create_table(mytable, [{attributes, [field1, field2]}]).

%% From NodeB, setup the B node
erl -sname b -setcookie cookie
net_adm:ping(NodeA).
mnesia:create_schema([node()]).
mnesia:start().

%% From NodeA, Add the NodeB to the mnesia cluster
[BNode | _] = nodes().
mnesia:change_config(extra_db_nodes, [BNode]).

%% From NodeA, add NodeB as a disc copy
mnesia:add_table_copy(mytable, BNode, disc_copies).
Kailakaile answered 15/11, 2012 at 14:19 Comment(4)
Ok done that (I created a schema at the beginning, using create_schema([node()]), which is my original starting node). I now have all the ram tables in the "remote" part of mnesia:info() (when called from BNode), but nothing under "disc_copies". "Schema" is the only table under "ram_copies". "disc_only_copies" also blank.Rodrickrodrigez
You should only need to do create_schema([node()]) on the node where you want to have disk copies. Also, if the tables are listed as 'remote' then BNode does not have the tables yet. I suspect that add_table_copy did not work. I will add to the answer the steps I used to get this to workKailakaile
I will reply properly in a good few hours, just getting on a planeRodrickrodrigez
@mezamorphic, so you are saying that my solution works but your script does not work. I think you need to do some debugging. Can you simply the script a bit. After the call to create_schema in NodeB, I have the Mnesia dir created on disk. After the next call to mnesia:start, the schema.DAT file is created. No need to create extra tables.Kailakaile

© 2022 - 2024 — McMap. All rights reserved.