From 3c44f24aadaaecca676c1bd65f9597724a3f96da Mon Sep 17 00:00:00 2001 From: Alexey Shchepin Date: Tue, 13 Feb 2007 17:23:36 +0000 Subject: [PATCH] * src/mod_muc/mod_muc.erl: Clean online room table on cluster node restart SVN Revision: 724 --- ChangeLog | 5 +++++ src/mod_muc/mod_muc.erl | 17 +++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/ChangeLog b/ChangeLog index 044ffa6c4..251d799d7 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,8 @@ +2007-02-13 Alexey Shchepin + + * src/mod_muc/mod_muc.erl: Clean online room table on cluster node + restart + 2007-02-13 Mickael Remond * src/ejabberd_auth_ldap.erl: Added ldap_local_filter option. This diff --git a/src/mod_muc/mod_muc.erl b/src/mod_muc/mod_muc.erl index 9a8eadbac..d531ad2be 100644 --- a/src/mod_muc/mod_muc.erl +++ b/src/mod_muc/mod_muc.erl @@ -149,6 +149,7 @@ init([Host, Opts]) -> MyHost = gen_mod:get_opt(host, Opts, "conference." ++ Host), update_tables(MyHost), mnesia:add_table_index(muc_registered, nick), + mnesia:subscribe(system), Access = gen_mod:get_opt(access, Opts, all), AccessCreate = gen_mod:get_opt(access_create, Opts, all), AccessAdmin = gen_mod:get_opt(access_admin, Opts, none), @@ -207,6 +208,9 @@ handle_info({room_destroyed, RoomHost, Pid}, State) -> end, mnesia:transaction(F), {noreply, State}; +handle_info({mnesia_system_event, {mnesia_down, Node}}, State) -> + clean_table_from_bad_node(Node), + {noreply, State}; handle_info(_Info, State) -> {noreply, State}. @@ -616,6 +620,19 @@ get_vh_rooms(Host) -> ['$_']}]). +clean_table_from_bad_node(Node) -> + F = fun() -> + Es = mnesia:select( + muc_online_room, + [{#muc_online_room{pid = '$1', _ = '_'}, + [{'==', {node, '$1'}, Node}], + ['$_']}]), + lists:foreach(fun(E) -> + mnesia:delete_object(E) + end, Es) + end, + mnesia:transaction(F). + update_tables(Host) -> update_muc_room_table(Host),