Mnesia - Replicate ram_copy table to disc_only_copy table from another node

820 views Asked by At

What I want to do is this:

Create a table ram_copies in node A which resides in a computer with lot of Ram and CPU power

mnesia:create_table(person, [{ram_copies, [node()]},
                        {frag_properties, [{node_pool, [node()]}, {n_fragments, 10}, {n_ram_copies, 1}]},
                        {attributes, record_info(fields, person)},
                        {storage_properties, [{ets, [compressed, {write_concurrency,true}, {read_concurrency,true}]}]}])

And node A starts working this ram_copy table.

At some unspecified time (which may be 1 second or 1 hour) after the node "A" have created the table, create node B on a computer with lots of hard drive, but less RAM and CPU power , to replicate (structure and data) RAM table in the "a" node but disc_only_copies.

The idea is to run critical processes using all the power at node A, and run trivial processes on another node and keep the data synchronized.

Is this possible?

Greetings.

1

There are 1 answers

0
Hamidreza Soleimani On BEST ANSWER

Yes, it is possible.

Let's say we have two nodes; node_1 which has lots of Disc and node_2 which has lots of RAM, and we have a foo table which must be disc_only_copies in node_1 and ram_copies in node_2. The steps are as follows:

Node 1:

$ erl -sname node_1
(node_1@host)1> mnesia:create_schema([node()]). 
(node_1@host)2> mnesia:start(). 
(node_1@host)3> mnesia:add_table_copy(schema, node_2@host, ram_copies).

Node 2:

$ erl -sname node_2
(node_2@host)1> mnesia:start().
(node_2@host)2> mnesia:change_config(extra_db_nodes, [node_1@host]).

That's it. Now we can create foo table in node_1:

Node 1:

(node_1@host)4> mnesia:create_table(foo, [
                    {disc_only_copies, [node_1@host]}, 
                    {ram_copies, [node_2@host]}]).

Finally we can check if it is created on both nodes with mnesia:info/0:

Node 1:

running db nodes   = [node_2@host,node_1@host]
stopped db nodes   = [] 
master node tables = []
remote             = []
ram_copies         = []
disc_copies        = [schema]
disc_only_copies   = [foo]
[{node_1@host,disc_copies},{node_2@host,ram_copies}] = [schema]
[{node_1@host,disc_only_copies},{node_2@host,ram_copies}] = [foo]

Node 2:

running db nodes   = [node_1@host,node_2@host]
stopped db nodes   = [] 
master node tables = []
remote             = []
ram_copies         = [foo,schema]
disc_copies        = []
disc_only_copies   = []
[{node_1@host,disc_copies},{node_2@host,ram_copies}] = [schema]
[{node_1@host,disc_only_copies},{node_2@host,ram_copies}] = [foo]