如何删除多余的节点

发布于 2024-07-19 00:55:11 字数 372 浏览 3 评论 0原文

我有一组 erlang 节点,它们通过 Mnesia 的“extra_db_nodes”复制数据...我需要升级硬件和软件,所以当我从一个节点移动到另一个节点时,我必须分离一些节点。

如何删除一个节点并仍然保留插入的数据?

[更新]删除节点与添加节点一样重要。 随着时间的推移,随着集群的增长,它也必须收缩。 如果不是,那么 Mnesia 将忙于尝试向不存在的节点发送数据,从而填满队列并保持网络繁忙。

[最终更新]在仔细阅读 erlang/mnesia 源代码后,我确定不可能完全解除节点关联。 虽然 del_table_copy 删除了表之间的链接,但它是不完整的。 我想结束这个问题,但没有一个密切的描述是足够的。

I have a group of erlang nodes that are replicating their data through Mnesia's "extra_db_nodes"... I need to upgrade hardware and software so I have to detach some nodes as I make my way from node to node.

How does one remove a node and still preserve the data that was inserted?

[update] removing nodes is as important as adding them. Over time as your cluster grows it must also contract. If not then Mnesia is going to be busy trying to send data to nonexistent nodes filling up queues and keeping the network busy.

[final update] after pouring through the erlang/mnesia source code I was able to determine that it is not possible to completely disassociate nodes. While del_table_copy removes the linkage between tables it is incomplete. I would close this question but none of the close descriptions are adequate.

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

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

发布评论

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

评论(4

Saygoodbye 2024-07-26 00:55:11

我希望我很久以前就发现了这个: http: //weblambdazero.blogspot.com/2008/08/erlang-tips-and-tricks-mnesia.html

基本上,具有正常运行的集群....

  • 登录到要删除的集群

  • 停止mnesia

    mnesia:stop()。 
      
  • 登录到集群上的不同节点

  • 删除架构

    mnesia:del_table_copy(schema, [电子邮件受保护] )。 
      

I wish I had found this a long time ago: http://weblambdazero.blogspot.com/2008/08/erlang-tips-and-tricks-mnesia.html

basically, with a properly functioning cluster....

  • login to the cluster to be removed

  • stop mnesia

    mnesia:stop().
    
  • login to a different node on the cluster

  • delete the schema

    mnesia:del_table_copy(schema, [email protected]).
    
三生一梦 2024-07-26 00:55:11

我参加聚会非常晚,但在寻找同一问题的解决方案时在文档中发现了以下信息:

“函数调用
mnesia:del_table_copy(架构,
mynode@host) 删除节点
来自 Mnesia 系统的“mynode@host”。
如果 mnesia 正在运行,则调用失败
'mynode@主机'。 其他记忆节点
永远不会尝试连接到该节点
再次。 注意,如果有光盘
节点上的常驻模式
'mynode@host',整个 mnesia
目录应该被删除。 这个可以
使用 mnesia:delete_schema/1 完成。
如果记忆再次启动
节点“mynode@host”和目录
尚未清除,mnesia的
行为是未定义的。”
(http://www.erlang.org/doc/apps/mnesia /Mnesia_chap5.html#id74278)

我认为以下内容可能会满足您的要求:

AllTables = mnesia:system_info(tables),
DataTables = lists:filter(fun(Table) -> Table =/= schema end,
                          AllTables),

RemoveTableCopy = fun(Table,Node) ->
  Nodes = mnesia:table_info(Table,ram_copies) ++
          mnesia:table_info(Table,disc_copies) ++
          mnesia:table_info(Table,disc_only_copies),
  case lists:member(Node,Nodes) of
    true -> mnesia:del_table_copy(Table,Node);
    false -> ok
  end
end,

[RemoveTableCopy(Tbl,'gone@gone_host') || Tbl <- DataTables].

rpc:call('gone@gone_host',mnesia,stop,[]),
rpc:call('gone@gone_host',mnesia,delete_schema,[SchemaDir]),
RemoveTablecopy(schema,'gone@gone_host').

不过,我还没有测试它,因为我的场景略有不同。

I'm extremely late to the party, but came across this info in the doc when looking for a solution to the same problem:

"The function call
mnesia:del_table_copy(schema,
mynode@host) deletes the node
'mynode@host' from the Mnesia system.
The call fails if mnesia is running on
'mynode@host'. The other mnesia nodes
will never try to connect to that node
again. Note, if there is a disc
resident schema on the node
'mynode@host', the entire mnesia
directory should be deleted. This can
be done with mnesia:delete_schema/1.
If mnesia is started again on the the
node 'mynode@host' and the directory
has not been cleared, mnesia's
behaviour is undefined."
(http://www.erlang.org/doc/apps/mnesia/Mnesia_chap5.html#id74278)

I think the following might do what you desire:

AllTables = mnesia:system_info(tables),
DataTables = lists:filter(fun(Table) -> Table =/= schema end,
                          AllTables),

RemoveTableCopy = fun(Table,Node) ->
  Nodes = mnesia:table_info(Table,ram_copies) ++
          mnesia:table_info(Table,disc_copies) ++
          mnesia:table_info(Table,disc_only_copies),
  case lists:member(Node,Nodes) of
    true -> mnesia:del_table_copy(Table,Node);
    false -> ok
  end
end,

[RemoveTableCopy(Tbl,'gone@gone_host') || Tbl <- DataTables].

rpc:call('gone@gone_host',mnesia,stop,[]),
rpc:call('gone@gone_host',mnesia,delete_schema,[SchemaDir]),
RemoveTablecopy(schema,'gone@gone_host').

Though, I haven't tested it since my scenario is slightly different.

少女净妖师 2024-07-26 00:55:11

我当然使用了这种方法来执行此操作(支持 mnesia:del_table_copy/2 使用)。 请参阅下面的removeNode/1:

-module(tool_bootstrap).

-export([bootstrapNewNode/1, closedownNode/0,
     finalBootstrap/0, removeNode/1]).

-include_lib("records.hrl").

-include_lib("stdlib/include/qlc.hrl").

bootstrapNewNode(Node) ->
    %% Make the given node part of the family and start the cloud on it
    mnesia:change_config(extra_db_nodes, [Node]),
    %% Now make the other node set things up
    rpc:call(Node, tool_bootstrap, finalBootstrap, []).

removeNode(Node) ->
    rpc:call(Node, tool_bootstrap, closedownNode, []),
    mnesia:del_table_copy(schema, Node).

finalBootstrap() ->
    %% Code removed to actually copy over my tables etc...
    application:start(cloud).

closedownNode() ->
    application:stop(cloud), mnesia:stop().

I've certainly used this method to perform this (supporting the mnesia:del_table_copy/2 use). See removeNode/1 below:

-module(tool_bootstrap).

-export([bootstrapNewNode/1, closedownNode/0,
     finalBootstrap/0, removeNode/1]).

-include_lib("records.hrl").

-include_lib("stdlib/include/qlc.hrl").

bootstrapNewNode(Node) ->
    %% Make the given node part of the family and start the cloud on it
    mnesia:change_config(extra_db_nodes, [Node]),
    %% Now make the other node set things up
    rpc:call(Node, tool_bootstrap, finalBootstrap, []).

removeNode(Node) ->
    rpc:call(Node, tool_bootstrap, closedownNode, []),
    mnesia:del_table_copy(schema, Node).

finalBootstrap() ->
    %% Code removed to actually copy over my tables etc...
    application:start(cloud).

closedownNode() ->
    application:stop(cloud), mnesia:stop().
∞梦里开花 2024-07-26 00:55:11

如果您已在要删除的节点以外的节点上复制了表(添加的表副本),那么就已经没问题了 - 只需删除该节点即可。

如果您想稍微整洁一点,可以通过 mnesia:del_table_copy/2 从要首先删除的节点中删除表副本。

一般来说,mnesia 会优雅地处理节点丢失并检测节点重新加入(重新启动的节点从继续运行的节点获取新的表副本,未重新启动的节点被检测为网络分区事件)。 Mnesia 不会为已关闭的节点消耗 CPU 或网络流量。 我认为,尽管我没有在源中确认,mnesia 不会重新连接到自动关闭的节点 - 关闭的节点预计会重新启动(mnesia)并重新连接。

mnesia:add_table_copy/3mnesia:move_table_copy/3mnesia:del_table_copy/2 是您应该查看实时模式管理的函数。

extra_db_nodes 参数仅应在初始化新数据库节点时使用 - 一旦新节点拥有架构副本,就不需要 extra_db_nodes 参数。

If you have replicated the table (added table copies) on nodes other than the one you're removing, then you're already fine - just remove the node.

If you wanted to be slightly tidier you'd delete the table copies from the node you're about to remove first via mnesia:del_table_copy/2.

Generally, mnesia gracefully handles node loss and detects node rejoin (rebooted nodes obtain new table copies from nodes that kept running, nodes that didn't reboot are detected as a network partition event). Mnesia does not consume CPU or network traffic for nodes that have gone down. I think, though I haven't confirmed it in the source, mnesia won't reconnect to nodes that have gone down automatically - the node that goes down is expected to reboot (mnesia) and reconnect.

mnesia:add_table_copy/3, mnesia:move_table_copy/3 and mnesia:del_table_copy/2 are the functions you should look at for live schema management.

The extra_db_nodes parameter should only be used when initialising a new DB node - once a new node has a copy of the schema it doesn't need the extra_db_nodes parameter.

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