Creating mnesia disk_copies of existing ram table

梦想的初衷 提交于 2019-12-21 22:02:48

问题


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.


回答1:


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).


来源:https://stackoverflow.com/questions/13398632/creating-mnesia-disk-copies-of-existing-ram-table

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!