24
1
mirror of https://github.com/processone/ejabberd.git synced 2024-06-14 22:00:16 +02:00

Fix race between join_cluster and ejabberd_mnesia (#2079)

This commit is contained in:
Christophe Romain 2017-12-21 14:07:29 +01:00
parent 32ad7d3761
commit a3083b5d71

View File

@ -60,16 +60,15 @@ join(Node) ->
application:stop(mnesia), application:stop(mnesia),
mnesia:delete_schema([node()]), mnesia:delete_schema([node()]),
application:start(mnesia), application:start(mnesia),
mnesia:change_config(extra_db_nodes, [Node]), case mnesia:change_config(extra_db_nodes, [Node]) of
mnesia:change_table_copy_type(schema, node(), disc_copies), {ok, _} ->
spawn(fun() -> replicate_database(Node),
lists:foreach(fun(Table) -> wait_for_sync(infinity),
Type = ejabberd_cluster:call( application:stop(mnesia),
Node, mnesia, table_info, [Table, storage_type]),
mnesia:add_table_copy(Table, node(), Type)
end, mnesia:system_info(tables)--[schema])
end),
application:start(ejabberd); application:start(ejabberd);
{error, Reason} ->
{error, Reason}
end;
_ -> _ ->
{error, {no_ping, Node}} {error, {no_ping, Node}}
end. end.
@ -94,8 +93,8 @@ leave([], Node) ->
leave([Master|_], Node) -> leave([Master|_], Node) ->
application:stop(ejabberd), application:stop(ejabberd),
application:stop(mnesia), application:stop(mnesia),
ejabberd_cluster:call(Master, mnesia, del_table_copy, [schema, Node]),
spawn(fun() -> spawn(fun() ->
rpc:call(Master, mnesia, del_table_copy, [schema, Node]),
mnesia:delete_schema([node()]), mnesia:delete_schema([node()]),
erlang:halt(0) erlang:halt(0)
end), end),
@ -130,6 +129,15 @@ subscribe(_) ->
%%%=================================================================== %%%===================================================================
%%% Internal functions %%% Internal functions
%%%=================================================================== %%%===================================================================
replicate_database(Node) ->
mnesia:change_table_copy_type(schema, node(), disc_copies),
lists:foreach(
fun(Table) ->
Type = ejabberd_cluster:call(Node, mnesia, table_info, [Table, storage_type]),
mnesia:add_table_copy(Table, node(), Type)
end, mnesia:system_info(tables)--[schema]).
-spec match_node_id(integer()) -> node(). -spec match_node_id(integer()) -> node().
match_node_id(I) -> match_node_id(I) ->
match_node_id(I, get_nodes()). match_node_id(I, get_nodes()).