diff --git a/rebar.config b/rebar.config index 9c26c7f8e6..05645c3d77 100644 --- a/rebar.config +++ b/rebar.config @@ -26,7 +26,6 @@ mod_keystore_backend, mod_mam_cassandra_arch_params, mod_mam_cassandra_prefs_params, mod_mam_muc_cassandra_arch_params, - mod_pubsub_cache_backend, mod_pubsub_db_backend, mod_revproxy_dynamic, mod_roster_backend, mod_routing_machine, mod_shared_roster, mongoose_rdbms_type, diff --git a/src/pubsub/mod_pubsub.erl b/src/pubsub/mod_pubsub.erl index 56c5e0b2db..d243d55107 100644 --- a/src/pubsub/mod_pubsub.erl +++ b/src/pubsub/mod_pubsub.erl @@ -111,7 +111,6 @@ -export([config_metrics/1]). -define(MOD_PUBSUB_DB_BACKEND, mod_pubsub_db_backend). --define(MOD_PUBSUB_CACHE_BACKEND, mod_pubsub_cache_backend). -ignore_xref([ {?MOD_PUBSUB_DB_BACKEND, transaction, 2}, {?MOD_PUBSUB_DB_BACKEND, get_user_nodes, 2}, @@ -120,10 +119,6 @@ {?MOD_PUBSUB_DB_BACKEND, start, 0}, {?MOD_PUBSUB_DB_BACKEND, set_subscription_opts, 4}, {?MOD_PUBSUB_DB_BACKEND, stop, 0}, - {?MOD_PUBSUB_CACHE_BACKEND, get_last_item, 2}, - {?MOD_PUBSUB_CACHE_BACKEND, upsert_last_item, 5}, - {?MOD_PUBSUB_CACHE_BACKEND, start, 1}, - {?MOD_PUBSUB_CACHE_BACKEND, delete_last_item, 2}, affiliation_to_string/1, caps_recognised/4, config/3, create_node/7, default_host/0, delete_item/4, delete_node/3, disco_local_features/1, disco_sm_features/1, disco_sm_identity/1, disco_sm_items/1, extended_error/3, get_cached_item/2, @@ -4140,14 +4135,10 @@ maybe_start_cache_module(ServerHost, Opts) -> case proplists:get_value(last_item_cache, Opts, false) of false -> ok; - Backend -> - start_cache_module(ServerHost, Backend) + _Backend -> + mod_pubsub_cache_backend:start(ServerHost, Opts) end. -start_cache_module(ServerHost, Backend) -> - gen_mod:start_backend_module(mod_pubsub_cache, [{backend, Backend}], - [upsert_last_item, delete_last_item, get_last_item]), - mod_pubsub_cache_backend:start(ServerHost). is_last_item_cache_enabled(Host) -> case cache_backend(Host) of diff --git a/src/pubsub/mod_pubsub_cache.erl b/src/pubsub/mod_pubsub_cache.erl deleted file mode 100644 index 2d0234bb96..0000000000 --- a/src/pubsub/mod_pubsub_cache.erl +++ /dev/null @@ -1,27 +0,0 @@ --module(mod_pubsub_cache). - --ignore_xref([behaviour_info/1]). - -%%==================================================================== -%% Behaviour callbacks -%%==================================================================== - -%% ------------------------ Backend start/stop ------------------------ - --callback start(jid:lserver()) -> ok. - --callback stop() -> ok. - --callback upsert_last_item(ServerHost :: binary(), - Nidx :: mod_pubsub:nodeIdx(), - ItemID :: mod_pubsub:itemId(), - Publisher:: jid:jid(), - Payload :: mod_pubsub:payload()) -> ok | {error, Reason :: term()}. - --callback delete_last_item(ServerHost :: binary(), - Nidx :: mod_pubsub:nodeIdx()) -> ok | {error, Reason :: term()}. - --callback get_last_item(ServerHost :: binary(), - Nidx :: mod_pubsub:nodeIdx()) -> - {ok, LastItem :: mod_pubsub:pubsubLastItem()} | {error, Reason :: term()}. - diff --git a/src/pubsub/mod_pubsub_cache_backend.erl b/src/pubsub/mod_pubsub_cache_backend.erl new file mode 100644 index 0000000000..ceec3e9804 --- /dev/null +++ b/src/pubsub/mod_pubsub_cache_backend.erl @@ -0,0 +1,67 @@ +-module(mod_pubsub_cache_backend). + +-export([start/2, + stop/1, + upsert_last_item/5, + delete_last_item/2, + get_last_item/2]). + +-ignore_xref([stop/1]). + +-define(MAIN_MODULE, mod_pubsub_cache). + +%%==================================================================== +%% Behaviour callbacks +%%==================================================================== + +%% ------------------------ Backend start/stop ------------------------ + +-callback start(jid:lserver()) -> ok. + +-callback stop() -> ok. + +-callback upsert_last_item(ServerHost :: binary(), + Nidx :: mod_pubsub:nodeIdx(), + ItemID :: mod_pubsub:itemId(), + Publisher :: jid:jid(), + Payload :: mod_pubsub:payload()) -> ok | {error, Reason :: term()}. + +-callback delete_last_item(ServerHost :: binary(), + Nidx :: mod_pubsub:nodeIdx()) -> ok | {error, Reason :: term()}. + +-callback get_last_item(ServerHost :: binary(), + Nidx :: mod_pubsub:nodeIdx()) -> + {ok, LastItem :: mod_pubsub:pubsubLastItem()} | {error, Reason :: term()}. + +-spec start(jid:lserver(), gen_mod:module_opts()) -> ok. +start(ServerHost, Opts) -> + TrackedFuns = [upsert_last_item, delete_last_item, get_last_item], + mongoose_backend:init_per_host_type(ServerHost, ?MAIN_MODULE, TrackedFuns, Opts), + Args = [ServerHost], + mongoose_backend:call(ServerHost, ?MAIN_MODULE, ?FUNCTION_NAME, Args). + +-spec stop(jid:lserver()) -> ok. +stop(ServerHost) -> + mongoose_backend:call(ServerHost, ?MAIN_MODULE, ?FUNCTION_NAME, []). + +-spec upsert_last_item(ServerHost :: binary(), + Nidx :: mod_pubsub:nodeIdx(), + ItemID :: mod_pubsub:itemId(), + Publisher :: jid:jid(), + Payload :: mod_pubsub:payload()) -> ok | {error, Reason :: term()}. +upsert_last_item(ServerHost, Nidx, ItemID, Publisher, Payload) -> + Args = [ServerHost, Nidx, ItemID, Publisher, Payload], + mongoose_backend:call_tracked(ServerHost, ?MAIN_MODULE, ?FUNCTION_NAME, Args). + +-spec delete_last_item(ServerHost :: binary(), + Nidx :: mod_pubsub:nodeIdx()) -> ok | {error, Reason :: term()}. +delete_last_item(ServerHost, Nidx) -> + Args = [ServerHost, Nidx], + mongoose_backend:call_tracked(ServerHost, ?MAIN_MODULE, ?FUNCTION_NAME, Args). + +-spec get_last_item(ServerHost :: binary(), + Nidx :: mod_pubsub:nodeIdx()) -> + {ok, LastItem :: mod_pubsub:pubsubLastItem()} | {error, Reason :: term()}. +get_last_item(ServerHost, Nidx) -> + Args = [ServerHost, Nidx], + mongoose_backend:call_tracked(ServerHost, ?MAIN_MODULE, ?FUNCTION_NAME, Args). diff --git a/src/pubsub/mod_pubsub_cache_mnesia.erl b/src/pubsub/mod_pubsub_cache_mnesia.erl index 7291401b88..fff003623e 100644 --- a/src/pubsub/mod_pubsub_cache_mnesia.erl +++ b/src/pubsub/mod_pubsub_cache_mnesia.erl @@ -1,6 +1,6 @@ -module(mod_pubsub_cache_mnesia). --behaviour(mod_pubsub_cache). +-behaviour(mod_pubsub_cache_backend). -include("pubsub.hrl"). -include("jlib.hrl"). diff --git a/src/pubsub/mod_pubsub_cache_rdbms.erl b/src/pubsub/mod_pubsub_cache_rdbms.erl index 1a0ca5caf0..1ed6d4db60 100644 --- a/src/pubsub/mod_pubsub_cache_rdbms.erl +++ b/src/pubsub/mod_pubsub_cache_rdbms.erl @@ -1,6 +1,6 @@ -module(mod_pubsub_cache_rdbms). --behaviour(mod_pubsub_cache). +-behaviour(mod_pubsub_cache_backend). -include("pubsub.hrl"). -include("jlib.hrl").