Skip to content

Commit

Permalink
add missing add_table_copy to all mnesia modules
Browse files Browse the repository at this point in the history
  • Loading branch information
Pawel Pikula committed Jun 25, 2014
1 parent 7b56efe commit d6ab1f8
Show file tree
Hide file tree
Showing 10 changed files with 43 additions and 23 deletions.
1 change: 1 addition & 0 deletions apps/ejabberd/src/ejabberd_auth_anonymous.erl
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ start(Host) ->
mnesia:create_table(anonymous, [{ram_copies, [node()]},
{type, bag},
{attributes, record_info(fields, anonymous)}]),
mnesia:add_table_copy(anonymous, node(), ram_copies),
%% The hooks are needed to add / remove users from the anonymous tables
ejabberd_hooks:add(sm_register_connection_hook, Host,
?MODULE, register_connection, 100),
Expand Down
4 changes: 3 additions & 1 deletion apps/ejabberd/src/ejabberd_auth_internal.erl
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ start(Host) ->
mnesia:create_table(reg_users_counter,
[{ram_copies, [node()]},
{attributes, record_info(fields, reg_users_counter)}]),
mnesia:add_table_copy(passwd, node(), disc_copies),
mnesia:add_table_copy(reg_users_counter, node(), ram_copies),
update_reg_users_counter_table(Host),
ok.

Expand All @@ -83,7 +85,7 @@ store_type(Server) ->
case scram:enabled(Server) of
false -> plain;
true -> scram
end.
end.

check_password(User, Server, Password) ->
LUser = jlib:nodeprep(User),
Expand Down
3 changes: 2 additions & 1 deletion apps/ejabberd/src/mod_mam_mnesia_dirty_prefs.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ start(Host, Opts) ->
mnesia:create_table(mam_prefs,
[{disc_copies, [node()]},
{attributes, record_info(fields, mam_prefs)}]),
mnesia:add_table_copy(mam_prefs, node(), disc_copies),
case gen_mod:get_module_opt(Host, ?MODULE, pm, false) of
true ->
start_pm(Host, Opts);
Expand Down Expand Up @@ -154,7 +155,7 @@ set_prefs(Result, _Host, ArcID, ArcJID, DefaultMode, AlwaysJIDs, NeverJIDs) ->

get_prefs({GlobalDefaultMode, _, _}, _Host, _ArcID, ArcJID) ->
case mnesia:dirty_read(mam_prefs, su_key(ArcJID)) of
[] ->
[] ->
{GlobalDefaultMode, [], []};
[#mam_prefs{default_mode=DefaultMode,
always_rules=ARules, never_rules=NRules}] ->
Expand Down
11 changes: 6 additions & 5 deletions apps/ejabberd/src/mod_mam_muc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,7 @@ start_host_mapping(Host, ServerHost) ->
[{ram_copies, [node()]},
{type, set},
{attributes, record_info(fields, mam_host)}]),
mnesia:add_table_copy(mam_host, node(), ram_copies),
mnesia:dirty_write(#mam_host{host = Host, server_host = ServerHost}).

stop_host_mapping(Host, ServerHost) ->
Expand Down Expand Up @@ -307,7 +308,7 @@ archive_room_packet(Packet, FromNick,
roster -> true
end,
case IsInteresting of
true ->
true ->
MessID = generate_message_id(),
Result = archive_message(Host, MessID, ArcID,
RoomJID, FromJID, SrcJID, incoming, Packet),
Expand All @@ -323,7 +324,7 @@ archive_room_packet(Packet, FromNick,
end.

%% `To' is an account or server entity hosting the archive.
%% Servers that archive messages on behalf of local users SHOULD expose archives
%% Servers that archive messages on behalf of local users SHOULD expose archives
%% to the user on their bare JID (i.e. `From.luser'),
%% while a MUC service might allow MAM queries to be sent to the room's bare JID
%% (i.e `To.luser').
Expand All @@ -334,7 +335,7 @@ archive_room_packet(Packet, FromNick,
room_process_mam_iq(From=#jid{lserver=Host}, To, IQ) ->
Action = iq_action(IQ),
case is_action_allowed(Action, From, To) of
true ->
true ->
case wait_shaper(Host, Action, From) of
ok ->
handle_mam_iq(Action, From, To, IQ);
Expand Down Expand Up @@ -436,7 +437,7 @@ handle_get_prefs(ArcJID=#jid{}, IQ=#iq{}) ->
[DefaultMode, AlwaysJIDs, NeverJIDs]),
ResultPrefsEl = result_prefs(DefaultMode, AlwaysJIDs, NeverJIDs),
IQ#iq{type = result, sub_el = [ResultPrefsEl]}.

handle_lookup_messages(
From=#jid{},
ArcJID=#jid{},
Expand Down Expand Up @@ -464,7 +465,7 @@ handle_lookup_messages(
{error, 'policy-violation'} ->
?DEBUG("Policy violation by ~p.", [jlib:jid_to_binary(From)]),
ErrorEl = ?STANZA_ERRORT(<<"">>, <<"modify">>, <<"policy-violation">>,
<<"en">>, <<"Too many results">>),
<<"en">>, <<"Too many results">>),
IQ#iq{type = error, sub_el = [ErrorEl]};
{ok, {TotalCount, Offset, MessageRows}} ->
{FirstMessID, LastMessID} =
Expand Down
6 changes: 4 additions & 2 deletions apps/ejabberd/src/mod_muc.erl
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,8 @@ init([Host, Opts]) ->
[{ram_copies, [node()]},
{attributes, record_info(fields, muc_online_room)}]),
mnesia:add_table_copy(muc_online_room, node(), ram_copies),
mnesia:add_table_copy(muc_room, node(), disc_copies),
mnesia:add_table_copy(muc_registered, node(), disc_copies),
catch ets:new(muc_online_users, [bag, named_table, public, {keypos, 2}]),
MyHost = gen_mod:get_opt_host(Host, Opts, <<"conference.@HOST@">>),
update_tables(MyHost),
Expand Down Expand Up @@ -689,11 +691,11 @@ flush() ->
children = [#xmlel{name = <<"value">>,
children = [#xmlcdata{content = Val}]}]}).

%% @doc Get a pseudo unique Room Name. The Room Name is generated as a hash of
%% @doc Get a pseudo unique Room Name. The Room Name is generated as a hash of
%% the requester JID, the local time and a random salt.
%%
%% <<"pseudo">> because we don't verify that there is not a room
%% with the returned Name already created, nor mark the generated Name
%% with the returned Name already created, nor mark the generated Name
%% as <<"already used">>. But in practice, it is unique enough. See
%% http://xmpp.org/extensions/xep-0045.html#createroom-unique
iq_get_unique(From) ->
Expand Down
1 change: 1 addition & 0 deletions apps/ejabberd/src/mod_offline_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ init(_Host, _Opts) ->
[{disc_only_copies, [node()]},
{type, bag},
{attributes, record_info(fields, offline_msg)}]),
mnesia:add_table_copy(offline_msg, node(), disc_only_copies),
ok.

pop_messages(LUser, LServer) ->
Expand Down
1 change: 1 addition & 0 deletions apps/ejabberd/src/mod_privacy_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
init(_Host, _Opts) ->
mnesia:create_table(privacy, [{disc_copies, [node()]},
{attributes, record_info(fields, privacy)}]),
mnesia:add_table_copy(privacy, node(), disc_copies),
ok.

get_default_list(LUser, LServer) ->
Expand Down
4 changes: 3 additions & 1 deletion apps/ejabberd/src/mod_private_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,8 @@ init(_Host, _Opts) ->
mnesia:create_table(private_storage,
[{disc_only_copies, [node()]},
{attributes, record_info(fields, private_storage)}]),

mnesia:add_table_copy(private_storage, node(), disc_only_copies),
ok.

multi_set_data(LUser, LServer, NS2XML) ->
Expand All @@ -57,7 +59,7 @@ multi_set_data_t(LUser, LServer, NS2XML) ->

set_data_t(LUser, LServer, NS, XML) ->
mnesia:write(#private_storage{usns = {LUser, LServer, NS}, xml = XML}).

multi_get_data(LUser, LServer, NS2Def) ->
[get_data(LUser, LServer, NS, Default) || {NS, Default} <- NS2Def].

Expand Down
4 changes: 4 additions & 0 deletions apps/ejabberd/src/mod_roster.erl
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,10 @@ start(Host, Opts) ->
update_table(),
mnesia:add_table_index(roster, us),
mnesia:add_table_index(roster_version, us),

mnesia:add_table_copy(roster, node(), disc_copies),
mnesia:add_table_copy(roster_version, node(), disc_copies),

ejabberd_hooks:add(roster_get, Host,
?MODULE, get_user_roster, 50),
ejabberd_hooks:add(roster_in_subscription, Host,
Expand Down
31 changes: 18 additions & 13 deletions apps/ejabberd/src/mod_vcard_mnesia.erl
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,8 @@ search_fields(_VHost) ->
prepare_db() ->
create_tables(),
update_tables(),
set_indexes().
set_indexes(),
add_table_copies().

create_tables() ->
mnesia:create_table(vcard, [{disc_only_copies, [node()]},
Expand All @@ -115,6 +116,10 @@ update_tables() ->
update_vcard_table(),
update_vcard_search_table().

add_table_copies() ->
mnesia:add_table_copy(vcard, node(), disc_only_copies),
mnesia:add_table_copy(vcard_search, node(), disc_copies).

set_indexes() ->
mnesia:add_table_index(vcard_search, luser),
mnesia:add_table_index(vcard_search, lfn),
Expand Down Expand Up @@ -203,18 +208,18 @@ update_vcard_search_table() ->
mnesia:write_lock_table(mod_vcard_tmp_table),
mnesia:foldl(
fun({vcard_search,
User, LUser,
FN, LFN,
Family, LFamily,
Given, LGiven,
Middle, LMiddle,
Nickname, LNickname,
BDay, LBDay,
CTRY, LCTRY,
Locality, LLocality,
EMail, LEMail,
OrgName, LOrgName,
OrgUnit, LOrgUnit
User, LUser,
FN, LFN,
Family, LFamily,
Given, LGiven,
Middle, LMiddle,
Nickname, LNickname,
BDay, LBDay,
CTRY, LCTRY,
Locality, LLocality,
EMail, LEMail,
OrgName, LOrgName,
OrgUnit, LOrgUnit
}, _) ->
mnesia:dirty_write(
mod_vcard_tmp_table,
Expand Down

0 comments on commit d6ab1f8

Please sign in to comment.