diff --git a/big_tests/tests/mongoose_helper.erl b/big_tests/tests/mongoose_helper.erl index 0fcc14e3ba..33191e1a5e 100644 --- a/big_tests/tests/mongoose_helper.erl +++ b/big_tests/tests/mongoose_helper.erl @@ -6,7 +6,7 @@ -export([is_rdbms_enabled/1, mnesia_or_rdbms_backend/0, - get_backend_name/1]). + get_backend_name/2]). -export([auth_modules/0]). @@ -141,13 +141,30 @@ new_mongoose_acc(Location, Server) -> clear_caps_cache(CapsNode) -> ok = rpc(mim(), mod_caps, delete_caps, [CapsNode]). -get_backend(Module) -> - case rpc(mim(), Module, backend, []) of - {badrpc, _Reason} -> false; - Backend -> Backend - end. +get_backend(HostType, Module) -> + try rpc(mim(), mongoose_backend, get_backend_module, [HostType, Module]) + catch + error:{badrpc, _Reason} -> + % TODO: get rid of this after dynamically compiled modules are gone + get_backend_old(Module) + end. + +get_backend_name(HostType, Module) -> + try rpc(mim(), mongoose_backend, get_backend_name, [HostType, Module]) + catch + error:{badrpc, _Reason} -> + % TODO: get rid of this after dynamically compiled modules are gone + % used by offline_SUITE + get_backend_name_old(Module) + end. + +get_backend_old(Module) -> + case rpc(mim(), Module, backend, []) of + {badrpc, _Reason} -> false; + Backend -> Backend + end. -get_backend_name(Module) -> +get_backend_name_old(Module) -> case rpc(mim(), Module, backend_name, []) of {badrpc, _Reason} -> false; Backend -> Backend @@ -158,9 +175,12 @@ generic_count(mod_offline_backend, {LUser, LServer}) -> rpc(mim(), mod_offline_backend, count_offline_messages, [HostType, LUser, LServer, 100]). generic_count(Module) -> - case get_backend(Module) of + lists:sum([generic_count_per_host_type(HT, Module) || HT <- domain_helper:host_types()]). + +generic_count_per_host_type(HostType, Module) -> + case get_backend(HostType, Module) of false -> %% module disabled - false; + 0; B when is_atom(B) -> generic_count_backend(B) end. diff --git a/big_tests/tests/offline_SUITE.erl b/big_tests/tests/offline_SUITE.erl index fe7bd59695..1f5734aa0b 100644 --- a/big_tests/tests/offline_SUITE.erl +++ b/big_tests/tests/offline_SUITE.erl @@ -74,7 +74,7 @@ init_per_group(chatmarkers, C) -> init_per_group(_, C) -> C. with_groupchat_modules() -> - OfflineBackend = mongoose_helper:get_backend_name(mod_offline_backend), + OfflineBackend = mongoose_helper:get_backend_name(host_type(), mod_offline_backend), MucLightBackend = mongoose_helper:mnesia_or_rdbms_backend(), MucPattern = distributed_helper:subhost_pattern(muc_light_helper:muc_host_pattern()), [{mod_offline, [{store_groupchat_messages, true}, diff --git a/src/mongoose_backend.erl b/src/mongoose_backend.erl index 853b7808ea..85044acc2f 100644 --- a/src/mongoose_backend.erl +++ b/src/mongoose_backend.erl @@ -3,12 +3,16 @@ %% API -export([init_per_host_type/4, call/4, - call_tracked/4]). + call_tracked/4, + get_backend_name/2]). + +%% remove after mongoose_rdbms is refactored not to use dynamically compiled backend +-ignore_xref([get_backend_name/2]). %% Legacy call from backend_module -export([ensure_backend_metrics/2]). -%% For debugging +%% For debugging and tests -export([get_backend_module/2]). -ignore_xref([get_backend_module/2]). @@ -24,7 +28,7 @@ init_per_host_type(HostType, MainModule, TrackedFuns, Opts) -> ensure_backend_metrics(MainModule, TrackedFuns), Backend = gen_mod:get_opt(backend, Opts, mnesia), BackendModule = backend_module(MainModule, Backend), - persist_backend_name(HostType, MainModule, BackendModule), + persist_backend_name(HostType, MainModule, Backend, BackendModule), ok. backend_module(Module, Backend) -> @@ -39,6 +43,9 @@ time_metric(MainModule, FunName) -> backend_key(HostType, MainModule) -> {backend_module, HostType, MainModule}. +backend_name_key(HostType, MainModule) -> + {backend_name, HostType, MainModule}. + -spec ensure_backend_metrics(MainModule :: main_module(), FunNames :: [function_name()]) -> ok. ensure_backend_metrics(MainModule, FunNames) -> @@ -50,17 +57,25 @@ ensure_backend_metrics(MainModule, FunNames) -> end, lists:foreach(EnsureFun, FunNames). -persist_backend_name(HostType, MainModule, Backend) -> - Key = backend_key(HostType, MainModule), - persistent_term:put(Key, Backend). +persist_backend_name(HostType, MainModule, Backend, BackendModule) -> + ModuleKey = backend_key(HostType, MainModule), + persistent_term:put(ModuleKey, BackendModule), + NameKey = backend_name_key(HostType, MainModule), + persistent_term:put(NameKey, Backend). -%% Get a backend name, stored in init_per_host_type +%% @doc Get a backend module, stored in init_per_host_type. -spec get_backend_module(HostType :: mongooseim:host_type(), MainModule :: main_module()) -> BackendModule :: backend_module(). get_backend_module(HostType, MainModule) -> - Key = backend_key(HostType, MainModule), - %% Would crash, if the key is missing + ModuleKey = backend_key(HostType, MainModule), + persistent_term:get(ModuleKey). + +%% @doc Get a backend name, like `pgsql', stored in init_per_host_type. +-spec get_backend_name(HostType :: mongooseim:host_type(), + MainModule :: main_module()) -> BackendName :: atom(). +get_backend_name(HostType, MainModule) -> + Key = backend_name_key(HostType, MainModule), persistent_term:get(Key). -spec call(HostType :: mongooseim:host_type(),