diff --git a/src/auth/ejabberd_auth_anonymous.erl b/src/auth/ejabberd_auth_anonymous.erl index 85424abd527..a6f8f6104d4 100644 --- a/src/auth/ejabberd_auth_anonymous.erl +++ b/src/auth/ejabberd_auth_anonymous.erl @@ -67,10 +67,9 @@ -spec start(mongooseim:host_type()) -> ok. start(HostType) -> %% TODO: Check cluster mode - mnesia:create_table(anonymous, [{ram_copies, [node()]}, - {type, bag}, - {attributes, record_info(fields, anonymous)}]), - mnesia:add_table_copy(anonymous, node(), ram_copies), + mongoose_mnesia:create_table(anonymous, + [{ram_copies, [node()]}, {type, bag}, + {attributes, record_info(fields, anonymous)}]), %% The hooks are needed to add / remove users from the anonymous tables gen_hook:add_handlers(hooks(HostType)), ok. diff --git a/src/auth/ejabberd_auth_internal.erl b/src/auth/ejabberd_auth_internal.erl index e808386462d..dbf7aa0abf1 100644 --- a/src/auth/ejabberd_auth_internal.erl +++ b/src/auth/ejabberd_auth_internal.erl @@ -79,16 +79,13 @@ -spec start(HostType :: mongooseim:host_type()) -> ok. start(HostType) -> - mnesia:create_table(passwd, [{disc_copies, [node()]}, - {attributes, record_info(fields, passwd)}, - {storage_properties, - [{ets, [{read_concurrency, true}]}]} - ]), - 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), + mongoose_mnesia:create_table(passwd, + [{disc_copies, [node()]}, + {attributes, record_info(fields, passwd)}, + {storage_properties, [{ets, [{read_concurrency, true}]}]}]), + mongoose_mnesia:create_table(reg_users_counter, + [{ram_copies, [node()]}, + {attributes, record_info(fields, reg_users_counter)}]), update_reg_users_counter_table(HostType), ok. diff --git a/src/component/mongoose_component_mnesia.erl b/src/component/mongoose_component_mnesia.erl index 7911570248a..56a1256a417 100644 --- a/src/component/mongoose_component_mnesia.erl +++ b/src/component/mongoose_component_mnesia.erl @@ -14,10 +14,11 @@ init(_) -> update_tables(), %% add distributed service_component routes - mnesia:create_table(external_component, - [{attributes, record_info(fields, external_component)}, - {type, bag}, {ram_copies, [node()]}]), - mnesia:add_table_copy(external_component, node(), ram_copies). + mongoose_mnesia:create_table(external_component, + [{type, bag}, + {ram_copies, [node()]}, + {attributes, + record_info(fields, external_component)}]). update_tables() -> %% delete old schema diff --git a/src/ejabberd_sm_mnesia.erl b/src/ejabberd_sm_mnesia.erl index 72c8288139d..6debecfe128 100644 --- a/src/ejabberd_sm_mnesia.erl +++ b/src/ejabberd_sm_mnesia.erl @@ -26,12 +26,11 @@ -spec init(map()) -> any(). init(_Opts) -> - mnesia:create_table(session, - [{ram_copies, [node()]}, - {attributes, record_info(fields, session)}]), + mongoose_mnesia:create_table(session, + [{ram_copies, [node()]}, + {attributes, record_info(fields, session)}]), mnesia:add_table_index(session, usr), - mnesia:add_table_index(session, us), - mnesia:add_table_copy(session, node(), ram_copies). + mnesia:add_table_index(session, us). -spec get_sessions() -> [ejabberd_sm:session()]. get_sessions() -> diff --git a/src/event_pusher/mod_event_pusher_push_mnesia.erl b/src/event_pusher/mod_event_pusher_push_mnesia.erl index ce7632b9db3..951f5f65846 100644 --- a/src/event_pusher/mod_event_pusher_push_mnesia.erl +++ b/src/event_pusher/mod_event_pusher_push_mnesia.erl @@ -43,11 +43,9 @@ -spec init(mongooseim:host_type(), gen_mod:module_opts()) -> ok. init(_HostType, _Opts) -> - mnesia:create_table(push_subscription, - [{disc_copies, [node()]}, - {type, bag}, - {attributes, record_info(fields, push_subscription)}]), - mnesia:add_table_copy(push_subscription, node(), disc_copies), + mongoose_mnesia:create_table(push_subscription, + [{disc_copies, [node()]}, {type, bag}, + {attributes, record_info(fields, push_subscription)}]), ok. -spec enable(mongooseim:host_type(), UserJID :: jid:jid(), PubsubJID :: jid:jid(), diff --git a/src/jingle_sip/mod_jingle_sip_mnesia.erl b/src/jingle_sip/mod_jingle_sip_mnesia.erl index bd3a96e9d14..8ef756476c7 100644 --- a/src/jingle_sip/mod_jingle_sip_mnesia.erl +++ b/src/jingle_sip/mod_jingle_sip_mnesia.erl @@ -17,9 +17,9 @@ -spec init(mongooseim:host_type(), gen_mod:module_opts()) -> ok. init(_Host, _Opts) -> - mnesia:create_table(jingle_sip_session, - [{ram_copies, [node()]}, - {attributes, record_info(fields, jingle_sip_session)}]), + mongoose_mnesia:create_table(jingle_sip_session, + [{ram_copies, [node()]}, + {attributes, record_info(fields, jingle_sip_session)}]), ok. -spec read_session(call_id()) -> [session()]. diff --git a/src/mam/mod_mam_mnesia_prefs.erl b/src/mam/mod_mam_mnesia_prefs.erl index 218422eca89..20938eaed2f 100644 --- a/src/mam/mod_mam_mnesia_prefs.erl +++ b/src/mam/mod_mam_mnesia_prefs.erl @@ -41,10 +41,9 @@ -spec start(mongooseim:host_type(), gen_mod:module_opts()) -> ok. start(HostType, Opts) -> - mnesia:create_table(mam_prefs, - [{disc_copies, [node()]}, - {attributes, record_info(fields, mam_prefs)}]), - mnesia:add_table_copy(mam_prefs, node(), disc_copies), + mongoose_mnesia:create_table(mam_prefs, + [{disc_copies, [node()]}, + {attributes, record_info(fields, mam_prefs)}]), gen_hook:add_handlers(hooks(HostType, Opts)). -spec stop(mongooseim:host_type()) -> ok. diff --git a/src/mod_bosh_mnesia.erl b/src/mod_bosh_mnesia.erl index fcb4a395512..4be96baaf20 100644 --- a/src/mod_bosh_mnesia.erl +++ b/src/mod_bosh_mnesia.erl @@ -14,10 +14,9 @@ -spec start() -> any(). start() -> - mnesia:create_table(bosh_session, - [{ram_copies, [node()]}, - {attributes, record_info(fields, bosh_session)}]), - mnesia:add_table_copy(bosh_session, node(), ram_copies). + mongoose_mnesia:create_table(bosh_session, + [{ram_copies, [node()]}, + {attributes, record_info(fields, bosh_session)}]). %% The choice of the operation context here (transaction vs dirty, %% see man on mnesia:activity/4 for description of contexts) and the deletion diff --git a/src/mod_caps.erl b/src/mod_caps.erl index 7b461719092..b37d720c253 100644 --- a/src/mod_caps.erl +++ b/src/mod_caps.erl @@ -378,13 +378,10 @@ init_db(mnesia) -> _ -> mnesia:delete_table(caps_features) end, - mnesia:create_table(caps_features, - [{disc_only_copies, [node()]}, - {local_content, true}, - {attributes, - record_info(fields, caps_features)}]), - mnesia:add_table_copy(caps_features, node(), - disc_only_copies). + mongoose_mnesia:create_table(caps_features, + [{disc_only_copies, [node()]}, + {local_content, true}, + {attributes, record_info(fields, caps_features)}]). -spec init(list()) -> {ok, state()}. init([HostType, #{cache_size := MaxSize, cache_life_time := LifeTime}]) -> diff --git a/src/mod_keystore_mnesia.erl b/src/mod_keystore_mnesia.erl index 4adcc61d967..28b433feca5 100644 --- a/src/mod_keystore_mnesia.erl +++ b/src/mod_keystore_mnesia.erl @@ -11,11 +11,9 @@ -spec init(mongooseim:host_type(), gen_mod:module_opts()) -> ok. init(_HostType, _Opts) -> - mnesia:create_table(key, - [{ram_copies, [node()]}, - {type, set}, - {attributes, record_info(fields, key)}]), - mnesia:add_table_copy(key, node(), ram_copies), + mongoose_mnesia:create_table(key, + [{ram_copies, [node()]}, {type, set}, + {attributes, record_info(fields, key)}]), ok. -spec init_ram_key(ProposedKey) -> Result when diff --git a/src/mod_last_mnesia.erl b/src/mod_last_mnesia.erl index ce18cb59553..27555a67bab 100644 --- a/src/mod_last_mnesia.erl +++ b/src/mod_last_mnesia.erl @@ -29,10 +29,9 @@ -spec init(host_type(), gen_mod:module_opts()) -> ok. init(_HostType, _Opts) -> - mnesia:create_table(last_activity, - [{disc_copies, [node()]}, - {attributes, - record_info(fields, last_activity)}]), + mongoose_mnesia:create_table(last_activity, + [{disc_copies, [node()]}, + {attributes, record_info(fields, last_activity)}]), ok. -spec get_last(host_type(), jid:luser(), jid:lserver()) -> diff --git a/src/mod_muc_mnesia.erl b/src/mod_muc_mnesia.erl index 5fb4c134389..19186a43546 100644 --- a/src/mod_muc_mnesia.erl +++ b/src/mod_muc_mnesia.erl @@ -47,14 +47,12 @@ }). init(_HostType, _Opts) -> - mnesia:create_table(muc_room, - [{disc_copies, [node()]}, - {attributes, record_info(fields, muc_room)}]), - mnesia:create_table(muc_registered, - [{disc_copies, [node()]}, - {attributes, record_info(fields, muc_registered)}]), - mnesia:add_table_copy(muc_room, node(), disc_copies), - mnesia:add_table_copy(muc_registered, node(), disc_copies), + mongoose_mnesia:create_table(muc_room, + [{disc_copies, [node()]}, + {attributes, record_info(fields, muc_room)}]), + mongoose_mnesia:create_table(muc_registered, + [{disc_copies, [node()]}, + {attributes, record_info(fields, muc_registered)}]), mnesia:add_table_index(muc_registered, nick), ok. diff --git a/src/mod_private_mnesia.erl b/src/mod_private_mnesia.erl index fbc4728b420..a50fc5cbc51 100644 --- a/src/mod_private_mnesia.erl +++ b/src/mod_private_mnesia.erl @@ -43,10 +43,9 @@ -record(private_storage, {usns, xml}). init(_HostType, _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), + mongoose_mnesia:create_table(private_storage, + [{disc_only_copies, [node()]}, + {attributes, record_info(fields, private_storage)}]), ok. multi_set_data(_HostType, LUser, LServer, NS2XML) -> diff --git a/src/mod_register.erl b/src/mod_register.erl index e1f5451d913..9e2c054bf18 100644 --- a/src/mod_register.erl +++ b/src/mod_register.erl @@ -51,11 +51,10 @@ start(HostType, #{iqdisc := IQDisc}) -> [gen_iq_handler:add_iq_handler_for_domain(HostType, ?NS_REGISTER, Component, Fn, #{}, IQDisc) || {Component, Fn} <- iq_handlers()], - mnesia:create_table(mod_register_ip, - [{ram_copies, [node()]}, - {local_content, true}, - {attributes, [key, value]}]), - mnesia:add_table_copy(mod_register_ip, node(), ram_copies), + mongoose_mnesia:create_table(mod_register_ip, + [{ram_copies, [node()]}, + {local_content, true}, + {attributes, [key, value]}]), ok. -spec stop(mongooseim:host_type()) -> ok. diff --git a/src/mod_roster_mnesia.erl b/src/mod_roster_mnesia.erl index 8e68e4b51cf..5c188f85a2b 100644 --- a/src/mod_roster_mnesia.erl +++ b/src/mod_roster_mnesia.erl @@ -30,12 +30,12 @@ -spec init(mongooseim:host_type(), gen_mod:module_opts()) -> ok. init(_HostType, _Opts) -> - mnesia:create_table(roster, - [{disc_copies, [node()]}, - {attributes, record_info(fields, roster)}]), - mnesia:create_table(roster_version, - [{disc_copies, [node()]}, - {attributes, record_info(fields, roster_version)}]), + mongoose_mnesia:create_table(roster, + [{disc_copies, [node()]}, + {attributes, record_info(fields, roster)}]), + mongoose_mnesia:create_table(roster_version, + [{disc_copies, [node()]}, + {attributes, record_info(fields, roster_version)}]), mnesia:add_table_index(roster, us), mnesia:add_table_index(roster_version, us), ok. diff --git a/src/mongoose_cluster_id.erl b/src/mongoose_cluster_id.erl index 56d628535a6..1420314e6fe 100644 --- a/src/mongoose_cluster_id.erl +++ b/src/mongoose_cluster_id.erl @@ -94,13 +94,12 @@ init_cache() -> init_cache(which_volatile_backend_available()). init_cache(mnesia) -> - mnesia:create_table(mongoose_cluster_id, + mongoose_mnesia:create_table(mongoose_cluster_id, [{type, set}, {record_name, mongoose_cluster_id}, {attributes, record_info(fields, mongoose_cluster_id)}, {ram_copies, [node()]} - ]), - mnesia:add_table_copy(mongoose_cluster_id, node(), ram_copies); + ]); init_cache(cets) -> cets:start(cets_cluster_id, #{}), cets_discovery:add_table(mongoose_cets_discovery, cets_cluster_id), diff --git a/src/mongoose_mnesia.erl b/src/mongoose_mnesia.erl new file mode 100644 index 00000000000..44647072260 --- /dev/null +++ b/src/mongoose_mnesia.erl @@ -0,0 +1,46 @@ +-module(mongoose_mnesia). +-export([create_table/2]). + +-include("mongoose.hrl"). + +%% @doc A wrapper around `mnesia:create_table/2': +%% - Automatically adds table copies. +%% - Checks that mnesia is running or fail with an error. +%% - Checks result of create_table +-spec create_table(atom(), list()) -> + {atomic, ok} | {aborted, {already_exists, atom()}}. +create_table(Table, Opts) -> + case mnesia:system_info(is_running) of + no -> + report_mnesia_table_error(Table, Opts, mnesia_not_running); + yes -> + Res = mnesia:create_table(Table, Opts), + check_create_table_result(Table, Opts, Res), + Res + end. + +check_create_table_result(_Table, _Opts, {atomic, ok}) -> + ok; +check_create_table_result(Table, Opts, {aborted, {already_exists, Table}}) -> + [maybe_add_copies(Table, Opts, Type) || Type <- table_types()], + ok; +check_create_table_result(Table, Opts, Res) -> + report_mnesia_table_error(Table, Opts, Res). + +table_types() -> + [disc_copies, disc_only_copies, ram_copies]. + +report_mnesia_table_error(Table, Opts, Res) -> + ?LOG_CRITICAL(#{what => mnesia_create_table_failed, + table => Table, create_opts => Opts, reason => Res, + schema_nodes => catch mnesia:table_info(schema, disc_copies)}), + error({mnesia_create_table_failed, Table, Res}). + +maybe_add_copies(Table, Opts, Type) -> + case proplists:get_value(Type, Opts) of + [_|_] -> + mnesia:add_table_copy(Table, node(), Type), + ok; + _ -> + ok + end. diff --git a/src/mongoose_node_num_mnesia.erl b/src/mongoose_node_num_mnesia.erl index 4a3f209f53a..07f18159774 100644 --- a/src/mongoose_node_num_mnesia.erl +++ b/src/mongoose_node_num_mnesia.erl @@ -6,11 +6,10 @@ num :: mongoose_node_num:node_num() }). init() -> - mnesia:create_table(node_num, + mongoose_mnesia:create_table(node_num, [{ram_copies, [node()]}, {type, set}, {attributes, record_info(fields, node_num)}]), mnesia:add_table_index(node_num, num), - mnesia:add_table_copy(node_num, node(), ram_copies), register_node(node()), [#node_num{num = Num}] = mnesia:dirty_read(node_num, node()), mongoose_node_num:set_node_num(Num), diff --git a/src/muc/mongoose_muc_online_mnesia.erl b/src/muc/mongoose_muc_online_mnesia.erl index db6a467f52f..a6f010de310 100644 --- a/src/muc/mongoose_muc_online_mnesia.erl +++ b/src/muc/mongoose_muc_online_mnesia.erl @@ -14,10 +14,9 @@ -spec start(mongooseim:host_type(), gen_mod:module_opts()) -> ok. start(_HostType, _Opts) -> - mnesia:create_table(muc_online_room, - [{ram_copies, [node()]}, - {attributes, record_info(fields, muc_online_room)}]), - mnesia:add_table_copy(muc_online_room, node(), ram_copies), + mongoose_mnesia:create_table(muc_online_room, + [{ram_copies, [node()]}, + {attributes, record_info(fields, muc_online_room)}]), ok. -spec stop(mongooseim:host_type()) -> ok. diff --git a/src/muc_light/mod_muc_light_db_mnesia.erl b/src/muc_light/mod_muc_light_db_mnesia.erl index 5c4f72ad465..3d06e0a7df1 100644 --- a/src/muc_light/mod_muc_light_db_mnesia.erl +++ b/src/muc_light/mod_muc_light_db_mnesia.erl @@ -248,32 +248,17 @@ force_clear() -> -spec init_tables() -> ok. init_tables() -> - create_table(muc_light_room, - [{disc_copies, [node()]}, - {attributes, record_info(fields, muc_light_room)}]), - create_table(muc_light_user_room, - [{disc_copies, [node()]}, - {attributes, record_info(fields, muc_light_user_room)}, - {type, bag}]), - create_table(muc_light_blocking, - [{disc_copies, [node()]}, - {attributes, record_info(fields, muc_light_blocking)}, - {type, bag}]), + mongoose_mnesia:create_table(muc_light_room, + [{disc_copies, [node()]}, + {attributes, record_info(fields, muc_light_room)}]), + mongoose_mnesia:create_table(muc_light_user_room, + [{disc_copies, [node()]}, {type, bag}, + {attributes, record_info(fields, muc_light_user_room)}]), + mongoose_mnesia:create_table(muc_light_blocking, + [{disc_copies, [node()]}, {type, bag}, + {attributes, record_info(fields, muc_light_blocking)}]), ok. --spec create_table(Name :: atom(), TabDef :: list()) -> ok. -create_table(Name, TabDef) -> - case mnesia:create_table(Name, TabDef) of - {atomic, ok} -> ok; - {aborted, exists} -> ok; - {aborted, {already_exists, _}} -> ok - end, - case mnesia:add_table_copy(Name, node(), disc_copies) of - {atomic, ok} -> ok; - {aborted, exists} -> ok; - {aborted, {already_exists, _, _}} -> ok - end. - %% ------------------------ General room management ------------------------ %% Expects config to have unique fields! diff --git a/src/offline/mod_offline_mnesia.erl b/src/offline/mod_offline_mnesia.erl index ed6b6e4d433..5ecdd24fa62 100644 --- a/src/offline/mod_offline_mnesia.erl +++ b/src/offline/mod_offline_mnesia.erl @@ -42,11 +42,9 @@ -spec init(mongooseim:host_type(), gen_mod:module_opts()) -> ok. init(_HostType, _Opts) -> - mnesia:create_table(offline_msg, - [{disc_only_copies, [node()]}, - {type, bag}, - {attributes, record_info(fields, offline_msg)}]), - mnesia:add_table_copy(offline_msg, node(), disc_only_copies), + mongoose_mnesia:create_table(offline_msg, + [{disc_only_copies, [node()]}, {type, bag}, + {attributes, record_info(fields, offline_msg)}]), upgrade_table(), ok. diff --git a/src/privacy/mod_privacy_mnesia.erl b/src/privacy/mod_privacy_mnesia.erl index d215314ff9b..ef5bd92ce57 100644 --- a/src/privacy/mod_privacy_mnesia.erl +++ b/src/privacy/mod_privacy_mnesia.erl @@ -46,9 +46,9 @@ -include("mod_privacy.hrl"). init(_HostType, _Opts) -> - mnesia:create_table(privacy, [{disc_copies, [node()]}, - {attributes, record_info(fields, privacy)}]), - mnesia:add_table_copy(privacy, node(), disc_copies), + mongoose_mnesia:create_table(privacy, + [{disc_copies, [node()]}, + {attributes, record_info(fields, privacy)}]), ok. get_default_list(_HostType, LUser, LServer) -> diff --git a/src/pubsub/mod_pubsub_cache_mnesia.erl b/src/pubsub/mod_pubsub_cache_mnesia.erl index fff003623e9..9a1f43f03c3 100644 --- a/src/pubsub/mod_pubsub_cache_mnesia.erl +++ b/src/pubsub/mod_pubsub_cache_mnesia.erl @@ -63,17 +63,9 @@ delete_last_item(_ServerHost, Nidx) -> %% ------------------------ Helpers ---------------------------- --spec create_table() -> ok | {error, Reason :: term()}. +-spec create_table() -> ok. create_table() -> - QueryResult = mnesia:create_table( - pubsub_last_item, - [ - {ram_copies, [node()]}, - {attributes, record_info(fields, pubsub_last_item)} - ]), - mnesia:add_table_copy(pubsub_last_item, node(), ram_copies), - process_query_result(QueryResult). - -process_query_result({atomic, ok}) -> ok; -process_query_result({aborted, {already_exists, pubsub_last_item}}) -> ok; -process_query_result({aborted, Reason}) -> {error, Reason}. + mongoose_mnesia:create_table(pubsub_last_item, + [{ram_copies, [node()]}, + {attributes, record_info(fields, pubsub_last_item)}]), + ok. diff --git a/src/pubsub/mod_pubsub_db_mnesia.erl b/src/pubsub/mod_pubsub_db_mnesia.erl index b9cac767e4c..b0f8b28c7ac 100644 --- a/src/pubsub/mod_pubsub_db_mnesia.erl +++ b/src/pubsub/mod_pubsub_db_mnesia.erl @@ -90,29 +90,22 @@ %% ------------------------ Backend start/stop ------------------------ init(_HostType, _Opts) -> - mnesia:create_table(pubsub_state, - [{disc_copies, [node()]}, - {type, ordered_set}, - {attributes, record_info(fields, pubsub_state)}]), - mnesia:add_table_copy(pubsub_state, node(), disc_copies), - mnesia:create_table(pubsub_item, - [{disc_only_copies, [node()]}, - {attributes, record_info(fields, pubsub_item)}]), - mnesia:add_table_copy(pubsub_item, node(), disc_only_copies), - mnesia:create_table(pubsub_node, - [{disc_copies, [node()]}, - {attributes, record_info(fields, pubsub_node)}]), + mongoose_mnesia:create_table(pubsub_state, + [{disc_copies, [node()]}, {type, ordered_set}, + {attributes, record_info(fields, pubsub_state)}]), + mongoose_mnesia:create_table(pubsub_item, + [{disc_only_copies, [node()]}, + {attributes, record_info(fields, pubsub_item)}]), + mongoose_mnesia:create_table(pubsub_node, + [{disc_copies, [node()]}, + {attributes, record_info(fields, pubsub_node)}]), mnesia:add_table_index(pubsub_node, id), - mnesia:create_table(pubsub_subscription, - [{disc_copies, [node()]}, - {attributes, record_info(fields, pubsub_subscription)}, - {type, set}]), - mnesia:add_table_copy(pubsub_subscription, node(), disc_copies), - CreateSubnodeTableResult = mnesia:create_table(pubsub_subnode, - [{disc_copies, [node()]}, - {attributes, record_info(fields, pubsub_subnode)}, - {type, bag}]), - mnesia:add_table_copy(pubsub_subnode, node(), disc_copies), + mongoose_mnesia:create_table(pubsub_subscription, + [{disc_copies, [node()]}, {type, set}, + {attributes, record_info(fields, pubsub_subscription)}]), + CreateSubnodeTableResult = mongoose_mnesia:create_table(pubsub_subnode, + [{disc_copies, [node()]}, {type, bag}, + {attributes, record_info(fields, pubsub_subnode)}]), maybe_fill_subnode_table(CreateSubnodeTableResult), pubsub_index:init(), ok. diff --git a/src/pubsub/mod_pubsub_db_rdbms.erl b/src/pubsub/mod_pubsub_db_rdbms.erl index 57e5d2422e8..83a02a0c68b 100644 --- a/src/pubsub/mod_pubsub_db_rdbms.erl +++ b/src/pubsub/mod_pubsub_db_rdbms.erl @@ -80,8 +80,7 @@ %% ------------------------ Backend start/stop ------------------------ -init(HostType, Opts) -> - mod_pubsub_db_mnesia:init(HostType, Opts), +init(_HostType, _Opts) -> % -------------------- State building ---------------------------- mongoose_rdbms:prepare(pubsub_get_item_rows_id, pubsub_items, [nidx], <<"SELECT nidx, created_luser, created_lserver, itemid " @@ -251,7 +250,7 @@ init(HostType, Opts) -> -spec stop() -> ok. stop() -> - mod_pubsub_db_mnesia:stop(). + ok. %% ------------------------ Queries execution -------------------- prepare_select_nodes_by_owner() -> diff --git a/src/pubsub/pubsub_index.erl b/src/pubsub/pubsub_index.erl index b24c577ea4e..f78f5099199 100644 --- a/src/pubsub/pubsub_index.erl +++ b/src/pubsub/pubsub_index.erl @@ -35,9 +35,9 @@ -export([init/0, new/1]). init() -> - mnesia:create_table(pubsub_index, - [{disc_copies, [node()]}, - {attributes, record_info(fields, pubsub_index)}]). + mongoose_mnesia:create_table(pubsub_index, + [{disc_copies, [node()]}, + {attributes, record_info(fields, pubsub_index)}]). new(Index) -> %% Create a new short lived transaction to reduce lock contention diff --git a/src/s2s/mongoose_s2s_mnesia.erl b/src/s2s/mongoose_s2s_mnesia.erl index e09ec15acc0..4dcda40ac51 100644 --- a/src/s2s/mongoose_s2s_mnesia.erl +++ b/src/s2s/mongoose_s2s_mnesia.erl @@ -32,8 +32,7 @@ init(_) -> init_pids() -> Opts = [{ram_copies, [node()]}, {type, bag}, {attributes, record_info(fields, s2s)}], - mnesia:create_table(s2s, Opts), - mnesia:add_table_copy(s2s, node(), ram_copies). + mongoose_mnesia:create_table(s2s, Opts). -spec get_s2s_out_pids(ejabberd_s2s:fromto()) -> ejabberd_s2s:s2s_pids(). get_s2s_out_pids(FromTo) -> @@ -98,8 +97,7 @@ s2s_to_pids(List) -> %% Secrets init_secrets() -> Opts = [{ram_copies, [node()]}, {attributes, record_info(fields, s2s_shared)}], - mnesia:create_table(s2s_shared, Opts), - mnesia:add_table_copy(s2s_shared, node(), ram_copies). + mongoose_mnesia:create_table(s2s_shared, Opts). -spec register_secret(HostType :: mongooseim:host_type(), Secret :: ejabberd_s2s:base16_secret()) -> ok. diff --git a/src/stream_management/mod_stream_management_mnesia.erl b/src/stream_management/mod_stream_management_mnesia.erl index c455fd01a67..d4790182923 100644 --- a/src/stream_management/mod_stream_management_mnesia.erl +++ b/src/stream_management/mod_stream_management_mnesia.erl @@ -27,10 +27,10 @@ sid :: ejabberd_sm:sid() }). init(HostType, #{stale_h := StaleOpts}) -> - mnesia:create_table(sm_session, [{ram_copies, [node()]}, - {attributes, record_info(fields, sm_session)}]), + mongoose_mnesia:create_table(sm_session, + [{ram_copies, [node()]}, + {attributes, record_info(fields, sm_session)}]), mnesia:add_table_index(sm_session, sid), - mnesia:add_table_copy(sm_session, node(), ram_copies), maybe_init_stale_h(HostType, StaleOpts), ok. @@ -39,10 +39,9 @@ stop(HostType) -> maybe_init_stale_h(HostType, StaleOpts = #{enabled := true}) -> ?LOG_INFO(#{what => stream_mgmt_stale_h_start}), - mnesia:create_table(stream_mgmt_stale_h, - [{ram_copies, [node()]}, - {attributes, record_info(fields, stream_mgmt_stale_h)}]), - mnesia:add_table_copy(stream_mgmt_stale_h, node(), ram_copies), + mongoose_mnesia:create_table(stream_mgmt_stale_h, + [{ram_copies, [node()]}, + {attributes, record_info(fields, stream_mgmt_stale_h)}]), start_cleaner(HostType, StaleOpts); maybe_init_stale_h(_, _) -> ok. diff --git a/src/vcard/mod_vcard_mnesia.erl b/src/vcard/mod_vcard_mnesia.erl index 1c40c49da40..909eca23751 100644 --- a/src/vcard/mod_vcard_mnesia.erl +++ b/src/vcard/mod_vcard_mnesia.erl @@ -100,11 +100,12 @@ prepare_db() -> add_table_copies(). create_tables() -> - mnesia:create_table(vcard, [{disc_only_copies, [node()]}, - {attributes, record_info(fields, vcard)}]), - mnesia:create_table(vcard_search, - [{disc_copies, [node()]}, - {attributes, record_info(fields, vcard_search)}]). + mongoose_mnesia:create_table(vcard, + [{disc_only_copies, [node()]}, + {attributes, record_info(fields, vcard)}]), + mongoose_mnesia:create_table(vcard_search, + [{disc_copies, [node()]}, + {attributes, record_info(fields, vcard_search)}]). add_table_copies() -> mnesia:add_table_copy(vcard, node(), disc_only_copies),