Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mnesia: reading remote node data in {local_content, true} mode

Tags:

erlang

mnesia

Is there a way to do local writes and and global reads ( without replication ) using mnesia. Eg: node A writes to its local DB and node B reads from node A's DB. Node B does not have any data of its own, apart from the schema information stored locally.

According to the documentation, {local_content, true} seems like what I need to use, but I have been unsuccessful trying to get node B to read node A's data.

My schema and table configuration look like this:

On nodeA@ip1:

    net_adm:ping('nodeB@ip2').
    rd(user, {name, nick}).
    mnesia:create_schema([node()|nodes()]).
    mnesia:start().
    mnesia:create_table(user, [ {local_content, true}, 
                                {disc_copies, [node()]}, 
                                {attributes,record_info(fields, user) }]).

%% insert data and list rows on nodeA 
%% WORKS

On nodeB@ip2:

    mnesia:start().
    %% code to list rows from user table on nodeA 
    %% throws an ERROR saying table does not exist.

Is the configuration wrong or can this be done in any other way?

like image 522
Abhijith Avatar asked Mar 04 '10 10:03

Abhijith


1 Answers

I don't think you can do it the way you mention. Another way of doing it would probably be to make an rpc call to node A and get the data that way. There is no point in using mnesia to do the read from node B because it will essentially just do an RPC anyway.

So node B should be:

rpc:call(nodeA@ip1, mnesia, read, ....).

Hope this is what you [somewhat] needs.

EDIT: Oh and I forgot to mention that you don't need the schema on both nodes for this to work. This is assuming that Node B doesn't really care about sharing any other data with Node A it just reads it; In other words just keep all the mnesia stuff on Node A and just do RPC calls from Node B.

like image 111
Mazen Harake Avatar answered Nov 07 '22 15:11

Mazen Harake