Reputation: 586
I am writing a distributed mnesia application and use a schema. When a new node joins the cluster, it is added to the mnesia schema by a rpc call (from the masternode which started the schema) which runs the following functions:
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].
When a node crashes or disconnects, the master node receives a nodedown
event and the node should be removed from the cluster. How can I achieve this?
EDIT: I ended up with following solution: TabList is a list of all tables in my schema which my node is using.
mnesia:del_table_copy(TabList, Node)
Upvotes: 3
Views: 1209
Reputation: 8340
This should do what you want. According to the documentations:
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.
Upvotes: 1