how do I remove an extra node

后端 未结 4 1590
你的背包
你的背包 2021-02-04 13:25

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

4条回答
  •  佛祖请我去吃肉
    2021-02-04 14:02

    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.

提交回复
热议问题