Abhijith
Abhijith

Reputation: 939

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

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?

Upvotes: 6

Views: 775

Answers (2)

Mazen Harake
Mazen Harake

Reputation: 1726

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.

Upvotes: 1

Tor Valamo
Tor Valamo

Reputation: 33749

You may need to add node B to the schema's extra_db_nodes config thingy. You shouldn't have to do that if it's a disc based db, but in RAM it's mandatory to make it do what you want.

Not sure about the specifics, i may be confusing where to put stuff. I'm not too experienced with mnesia, but the docs indicate that you should do this.

Upvotes: 0

Related Questions