Erlang:如何从 Mnesia 集群中删除节点

Erlang: How to remove node from Mnesia cluster

我正在编写分布式 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.