Skip to content

Commit

Permalink
Bring a bit of symmetry between both async mam workers
Browse files Browse the repository at this point in the history
  • Loading branch information
NelsonVides committed Nov 28, 2021
1 parent ec9d240 commit 928eb74
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 2 additions & 2 deletions src/mam/mod_mam_rdbms_async_pool_writer.erl
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ do_run_flush(MessageCount, State = #state{host_type = HostType, max_batch_size =
Error -> Error
end
end,
[mod_mam_rdbms_arch:retract_message(HostType, Params) || Params <- Acc],
case InsertResult of
{updated, _Count} -> ok;
{error, Reason} ->
Expand All @@ -249,7 +248,8 @@ do_run_flush(MessageCount, State = #state{host_type = HostType, max_batch_size =
message_count => MessageCount, reason => Reason}),
ok
end,
mongoose_metrics:update(HostType, modMamFlushed, MessageCount),
[mod_mam_rdbms_arch:retract_message(HostType, Params) || Params <- Acc],
mongoose_hooks:mam_flush_messages(HostType, MessageCount),
erlang:garbage_collect(),
State#state{acc=[], flush_interval_tref=undefined}.

Expand Down
5 changes: 5 additions & 0 deletions src/metrics/mongoose_metrics_mam_hooks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
mam_remove_archive/4,
mam_lookup_messages/3,
mam_archive_message/3,
mam_flush_messages/3,
mam_muc_get_prefs/4,
mam_muc_set_prefs/7,
mam_muc_remove_archive/4,
Expand Down Expand Up @@ -106,6 +107,10 @@ mam_archive_message(Result, Host, _Params) ->
mongoose_metrics:update(Host, modMamArchived, 1),
Result.

mam_flush_messages(Acc, Host, MessageCount) ->
mongoose_metrics:update(Host, modMamFlushed, MessageCount),
Acc.

%% ----------------------------------------------------------------------------
%% mod_mam_muc

Expand Down
11 changes: 10 additions & 1 deletion src/mongoose_hooks.erl
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@
mam_get_prefs/4,
mam_remove_archive/3,
mam_lookup_messages/2,
mam_archive_message/2]).
mam_archive_message/2,
mam_flush_messages/2]).

-export([mam_muc_archive_id/2,
mam_muc_archive_size/3,
Expand Down Expand Up @@ -1008,6 +1009,14 @@ mam_lookup_messages(HookServer, Params) ->
mam_archive_message(HookServer, Params) ->
run_hook_for_host_type(mam_archive_message, HookServer, ok, [HookServer, Params]).

%%% @doc The `mam_flush_messages' hook is run after the async bulk write
%%% happens for messages despite the result of the write.
-spec mam_flush_messages(HookServer :: jid:lserver(),
MessageCount :: integer()) -> ok.
mam_flush_messages(HookServer, MessageCount) ->
run_hook_for_host_type(mam_flush_messages, HookServer, ok,
[HookServer, MessageCount]).


%% MAM MUC related hooks

Expand Down

0 comments on commit 928eb74

Please sign in to comment.