Skip to content

Commit 1d0e5a5

Browse files
author
Andrzej Telezynski
committed
When removing MAM archive using elasitic_search retry on version conflicts
1 parent 0c2755f commit 1d0e5a5

File tree

1 file changed

+17
-3
lines changed

1 file changed

+17
-3
lines changed

src/mam/mod_mam_muc_elasticsearch_arch.erl

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -167,12 +167,26 @@ remove_archive(Acc, #{room := RoomJid}, #{host_type := HostType}) ->
167167
ok ->
168168
ok;
169169
{error, Reason} ->
170-
?LOG_ERROR(#{what => remove_muc_archive_failed,
171-
server => HostType, room_jid => RoomJid, reason => Reason}),
172-
ok
170+
maybe_retry_remove_archive(5, SearchQuery, HostType, RoomJid, Reason)
173171
end,
174172
{ok, Acc}.
175173

174+
maybe_retry_remove_archive(0, _SearchQuery, HostType, RoomJid, Reason) ->
175+
?LOG_ERROR(#{what => remove_muc_archive_failed_max_retries,
176+
server => HostType, room_jid => RoomJid, reason => Reason});
177+
maybe_retry_remove_archive(RetryTimes, SearchQuery, HostType, RoomJid, #{<<"version_conflicts">> := N} = Reason) when N > 0 ->
178+
?LOG_WARNING(#{what => remove_muc_archive_retrying, retries_left => RetryTimes,
179+
server => HostType, room_jid => RoomJid, reason => Reason}),
180+
case mongoose_elasticsearch:delete_by_query(?INDEX_NAME, ?TYPE_NAME, SearchQuery) of
181+
ok ->
182+
ok;
183+
{error, NewReason} ->
184+
maybe_retry_remove_archive(RetryTimes - 1, SearchQuery, HostType, RoomJid, NewReason)
185+
end;
186+
maybe_retry_remove_archive(_, SearchQuery, HostType, RoomJid, Reason) ->
187+
?LOG_ERROR(#{what => remove_muc_archive_failed,
188+
server => HostType, room_jid => RoomJid, reason => Reason}).
189+
176190
%%-------------------------------------------------------------------
177191
%% Helpers
178192
%%-------------------------------------------------------------------

0 commit comments

Comments
 (0)