Access to mnesia distributed database from different sites

I have a mnesia database containing different tables.

I want to have access to tables from different Linux terminals.

I have a function called add_record that takes several parameters like name and id . I want to be able to call add_record on node1 and add record on node2 , but I want to update the same table from different places.

I read several sources, and the only thing I found out is that I should use net_adm:ping (node2). but somehow I can't access the data from the table.

+4
source share
1 answer

I assume that you probably meant the replicated table. Suppose you have a mnesia table on node: nodea@127.0.0.1 with -setcookie mycookie , whether it replicates to another node or not, if I want to access records from another terminal, then I have to use erlang in this other Also By creating a node, connecting this node to our node using a table (you will make sure that they all have the same cookie), you call the method on the remote node.

Suppose you want to use the add_record method in the mydatabase.erl module on node nodea@127.0.0.1 , which has the mnesia table, I open the linux terminal and I enter the following:

  $ erl -name remote@127.0.0.1 -setcookie mycookie
 Eshell V5.8.4 (abort with ^ G)
 1> N = ' nodea@127.0.0.1 '.
 ' nodea@127.0.0.1 '
 2> net_adm: ping (N).
 pong
 3> rpc: call (N, mydatabase, add_record, [RECORD]).
 {atomic, ok}
 4> 

with this module ( rpc ), you can call any method on the remote node if two nodes are connected using the same cookie. start by calling this method on the remote node device:

  rpc: call (' nodea@127.0.0.1 ', mnesia, info, []).
It should display everything on your remote terminal. I guess you might read this lecture first: Erlang Distributed Programming , and then you can see how mnesia replication tables are managed. Go through this entire tutorial in this domain.
+4
source

Source: https://habr.com/ru/post/1398152/


All Articles