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

Is there a way to do local writes and global reads (without replication) using mnesia. For example: node A writes to its local database and node B reads from the node database. Node B has no proprietary data other than schema information stored locally.

According to the documentation, {local_content, true} seems to be what I need to use, but I unsuccessfully tried to get node B to read node data.

The configuration of my schema and table looks like this:

On node A @ 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 the node B @ ip2:

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

Incorrect configuration or can it be done in any other way?

+6
erlang mnesia
source share
2 answers

I do not think you can do it the way you mentioned. Another way to do this would probably be to make an rpc call on node A and get the data this way. It makes no sense to use mnesia to read from node B, because in any case it will be just RPC.

So node B should be:

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

Hope you need it [few].

EDIT: Oh, and I forgot to mention that you don't need a circuit on both nodes for this to work. This suggests that node B does not really care about sharing any other data with node A, which it just reads; In other words, just save all the mnesia stuff on node A and just call the RPC calls from node B.

+1
source share

You may need to add node B to the extra_db_nodes configuration of the schema. You should not do this if it is a disk-based drive, but in RAM it is imperative that it does what you want.

Not sure about the specifics, I can confuse where to put things. I'm not too experienced with mnesia, but the docs say you should do this.

0
source share

All Articles