Mnesia:以{local_content,true}模式读取远程节点数据

发布于 2024-08-23 23:13:27 字数 832 浏览 8 评论 0原文

有没有办法使用 mnesia 进行本地写入和全局读取(没有复制)。例如:节点 A 写入其本地 DB,节点 B 从节点 A 的 DB 读取。 除了本地存储的模式信息之外,节点 B 没有自己的任何数据。

根据文档, {local_content, true} 似乎是我需要使用的,但我一直未能成功尝试让节点 B 读取节点 A 的数据。

我的架构和表配置如下所示:

在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

在nodeB@ip2上:

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

配置是否错误或者可以通过其他方式完成吗?

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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

も星光 2024-08-30 23:13:27

我认为你不能按照你提到的方式做到这一点。另一种方法可能是对节点 A 进行 rpc 调用并以这种方式获取数据。使用 mnesia 从节点 B 进行读取是没有意义的,因为无论如何它本质上只是执行 RPC。

所以节点 B 应该是:

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

希望这是你[某种程度上]需要的。

编辑:
哦,我忘了提一下,您不需要两个节点上的架构才能正常工作。这是假设节点 B 并不真正关心与节点 A 共享任何其他数据,它只是读取这些数据;换句话说,只需将所有 mnesia 内容保留在节点 A 上,并从节点 B 进行 RPC 调用即可。

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.

水晶透心 2024-08-30 23:13:27

您可能需要将节点 B 添加到架构的 extra_db_nodes 配置中。如果它是基于光盘的数据库,则不必这样做,但在 RAM 中,必须使其执行您想要的操作。

不确定具体细节,我可能会混淆把东西放在哪里。我对记忆症不太有经验,但文档表明你应该这样做。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文