From a3e51353a3cff557e8d30ed9c51af327dcc676ec Mon Sep 17 00:00:00 2001 From: Andrzej Telezynski Date: Mon, 15 Dec 2025 15:35:52 +0100 Subject: [PATCH 1/3] When removing MAM archive using elasitic_search retry on version conflicts --- src/mam/mod_mam_muc_elasticsearch_arch.erl | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/mam/mod_mam_muc_elasticsearch_arch.erl b/src/mam/mod_mam_muc_elasticsearch_arch.erl index 6d3165863dd..aebd34244b2 100644 --- a/src/mam/mod_mam_muc_elasticsearch_arch.erl +++ b/src/mam/mod_mam_muc_elasticsearch_arch.erl @@ -167,12 +167,26 @@ remove_archive(Acc, #{room := RoomJid}, #{host_type := HostType}) -> ok -> ok; {error, Reason} -> - ?LOG_ERROR(#{what => remove_muc_archive_failed, - server => HostType, room_jid => RoomJid, reason => Reason}), - ok + maybe_retry_remove_archive(5, SearchQuery, HostType, RoomJid, Reason) end, {ok, Acc}. +maybe_retry_remove_archive(0, _SearchQuery, HostType, RoomJid, Reason) -> + ?LOG_ERROR(#{what => remove_muc_archive_failed_max_retries, + server => HostType, room_jid => RoomJid, reason => Reason}); +maybe_retry_remove_archive(RetryTimes, SearchQuery, HostType, RoomJid, #{<<"version_conflicts">> := N} = Reason) when N > 0 -> + ?LOG_WARNING(#{what => remove_muc_archive_retrying, retries_left => RetryTimes, + server => HostType, room_jid => RoomJid, reason => Reason}), + case mongoose_elasticsearch:delete_by_query(?INDEX_NAME, ?TYPE_NAME, SearchQuery) of + ok -> + ok; + {error, NewReason} -> + maybe_retry_remove_archive(RetryTimes - 1, SearchQuery, HostType, RoomJid, NewReason) + end; +maybe_retry_remove_archive(_, _SearchQuery, HostType, RoomJid, Reason) -> + ?LOG_ERROR(#{what => remove_muc_archive_failed, + server => HostType, room_jid => RoomJid, reason => Reason}). + %%------------------------------------------------------------------- %% Helpers %%------------------------------------------------------------------- From 39b31eebbbabe75b87d3e13ceb2885f89324a3a4 Mon Sep 17 00:00:00 2001 From: Andrzej Telezynski Date: Thu, 18 Dec 2025 19:04:12 +0100 Subject: [PATCH 2/3] Correct error description in transaction_with_delayed_retry --- src/rdbms/mongoose_rdbms.erl | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/rdbms/mongoose_rdbms.erl b/src/rdbms/mongoose_rdbms.erl index df90ef127f3..31f50f800ed 100644 --- a/src/rdbms/mongoose_rdbms.erl +++ b/src/rdbms/mongoose_rdbms.erl @@ -372,7 +372,7 @@ do_transaction_with_delayed_retry(HostType, F, Retries, Delay, Info) -> timer:sleep(Delay), do_transaction_with_delayed_retry(HostType, F, Retries - 1, Delay, Info); _ -> - Err = Info#{what => mam_transaction_failed, + Err = Info#{what => rdbms_transaction_failed, text => <<"Transaction failed. Do not restart">>, reason => Result}, ?LOG_ERROR(Err), From 56d1dd57a0b14f8080bdead308ee73193e96a7d7 Mon Sep 17 00:00:00 2001 From: Andrzej Telezynski Date: Thu, 18 Dec 2025 21:16:17 +0100 Subject: [PATCH 3/3] Retry when deleting pubsub subscriptions --- src/pubsub/mod_pubsub_db_rdbms.erl | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/pubsub/mod_pubsub_db_rdbms.erl b/src/pubsub/mod_pubsub_db_rdbms.erl index 1fcf315f164..efe934e00b4 100644 --- a/src/pubsub/mod_pubsub_db_rdbms.erl +++ b/src/pubsub/mod_pubsub_db_rdbms.erl @@ -384,7 +384,9 @@ execute_delete_all_subscriptions(Nidx, LU, LS, LR) -> -spec execute_delete_all_subscriptions_id(Nidx :: mod_pubsub:nodeIdx()) -> mongoose_rdbms:query_result(). execute_delete_all_subscriptions_id(Nidx) -> - mongoose_rdbms:execute_successfully(global, pubsub_delete_all_subscriptions_id, [Nidx]). + mongoose_rdbms:transaction_with_delayed_retry(global, fun() -> + mongoose_rdbms:execute(global, pubsub_delete_all_subscriptions_id, [Nidx]) + end, #{retries => 5, delay => 100}). -spec execute_delete_user_subscriptions(LS :: jid:lserver(), LU :: jid:luser()) -> mongoose_rdbms:query_result().