I have a mnesia database containning different tables.
I want to be able to access the tables from different Linux terminals.
I have a function called add_record
, which takes a few parameters, say name
and id
. I want to be able to call add_record
on node1
and add record
on node2
but I want to be updating the same table from different locations.
I read a few sources and the only thing i found out was that i should use net_adm:ping
(node2). but somehow I cant access the data from the table.
i assume that you probably meant replicated
table. Suppose you have your mnesia table on node: [email protected]
with -setcookie mycookie
, whether its replicated on another node or not, if i want to access the records from another terminal, then i have to use erlang in this other terminal as well by creating a node, connecting this node to our node with the table (you ensure that they all have the same cookie), then you call a method on the remote node.
Lets say you want to use a method add_record
in module mydatabase.erl
on the node [email protected]
which is having the mnesia table, the i open a linux terminal and i enter the following:
$ erl -name [email protected] -setcookie mycookie Eshell V5.8.4 (abort with ^G) 1> N = '[email protected]'. '[email protected]' 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 a remote node, if the two nodes are connected using the same cookie. start by calling this method on the remote node:
rpc:call('[email protected]',mnesia,info,[]).It should display everything in your remote terminal. I suggest that probably, you first go through this lecture: Distributed Erlang Programming and then you will be able to see how replicated mnesia tables are managed. Go through that entire tutorial on that domain.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With