从不同节点访问分布式mnesia数据库 [英] Access distributed mnesia database from different nodes

查看:368
本文介绍了从不同节点访问分布式mnesia数据库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含不同表格的mnesia数据库。

I have a mnesia database containning different tables.

我想能够从不同的Linux终端访问表格。

I want to be able to access the tables from different Linux terminals.

我有一个名为 add_record 的函数,它需要一些参数,例如 name id 。我想能够在节点1 上添加记录调用 add_record c> node2 ,但我想从不同的位置更新相同的表。

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.

我唯一发现的是,我应该使用 net_adm :ping (node2)。但我无法从表中访问数据。

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.

推荐答案

我认为你可能意味着 / code>表。假设你在节点上有你的mnesia表: nodea@127.0.0.1 with -setcookie mycookie ,它是否复制在另一个节点上,如果我想从另一个终端访问记录,那么我必须使用erlang在这个其他终端,以及通过创建一个节点,将这个节点连接到我们的节点与表(你确保它们都有相同的cookie),然后在远程节点上调用一个方法。

假设您要在节点上使用 mydatabase.erl 模块中的 add_record code> nodea@127.0.0.1
这是有mnesia表,我打开一个linux终端,我输入以下:

i assume that you probably meant replicated table. Suppose you have your mnesia table on node: nodea@127.0.0.1 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 nodea@127.0.0.1 which is having the mnesia table, the i open a 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> 

使用此模块( rpc ),节点,如果两个节点使用相同的cookie连接。通过在远程节点上调用此方法开始:

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('nodea@127.0.0.1',mnesia,info,[]).


它应该显示远程终端中的所有内容。我建议您可能先通过本讲座:分布式Erlang编程然后您将能够看到如何管理复制的mnesia表。浏览该域上的整个教程。

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.

这篇关于从不同节点访问分布式mnesia数据库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆