我正在编写一个分布式 mnesia 应用程序并使用模式。 当新节点加入集群时,它会通过 rpc 调用(来自启动该架构的主节点)添加到 mnesia 架构中,该调用运行以下功能:
start_Mnesia(MasterNode) ->
mnesia:start(),
mnesia:change_config(extra_db_nodes, [MasterNode]),
Tabs=mnesia:system_info(tables) -- [schema],
[mnesia:add_table_copy(Tab, node(), ram_copies) || Tab <- Tabs].
当节点崩溃或断开连接时,主节点会收到 nodedown
事件,并且应从集群中删除该节点。我怎样才能实现这个目标?
编辑: 我最终得到以下解决方案: TabList 是我的节点正在使用的架构中所有表的列表。
mnesia:del_table_copy(TabList, Node)
最佳答案
This should do what you want 。根据文档:
del_table_copy(Tab, Node) -> {aborted, R} | {atomic, ok}
Deletes the replica of table Tab at node Node. When the last replica is deleted with this function, the table disappears entirely.
This function can also be used to delete a replica of the table named schema. The Mnesia node is then removed. Notice that Mnesia must be stopped on the node first.
关于Erlang:如何从 Mnesia 集群中删除节点,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37394049/