From ac86a6cad73cbcee0e94e65f245c5b89fffb220b Mon Sep 17 00:00:00 2001 From: kjnilsson Date: Tue, 25 Feb 2020 14:40:09 +0000 Subject: Fix QQ crash recovery bug When using dead letter handlers the state machine would crash when a prefix_msg was being dead-lettered on recovery. This handles this case and also fixes an issue where the incorrect initial release cursor interval would have been set when overriding the release cursor default. [#171463230] --- src/rabbit_fifo.erl | 13 +++++++++---- src/rabbit_fifo.hrl | 6 +++--- 2 files changed, 12 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/rabbit_fifo.erl b/src/rabbit_fifo.erl index 0917836b6a..251b370caa 100644 --- a/src/rabbit_fifo.erl +++ b/src/rabbit_fifo.erl @@ -146,7 +146,9 @@ update_config(Conf, State) -> SHICur = case State#?MODULE.cfg of #cfg{release_cursor_interval = {_, C}} -> C; - #cfg{release_cursor_interval = C} -> + #cfg{release_cursor_interval = undefined} -> + SHI; + #cfg{release_cursor_interval = C} -> C end, @@ -1086,8 +1088,9 @@ snd(T) -> return(Meta, ConsumerId, Returned, Effects0, #?MODULE{service_queue = SQ0} = State0) -> {State1, Effects1} = maps:fold( - fun(MsgId, {Tag, _} = Msg, {S0, E0}) when Tag == '$prefix_msg'; - Tag == '$empty_msg'-> + fun(MsgId, {Tag, _} = Msg, {S0, E0}) + when Tag == '$prefix_msg'; + Tag == '$empty_msg'-> return_one(MsgId, 0, Msg, S0, E0, ConsumerId); (MsgId, {MsgNum, Msg}, {S0, E0}) -> return_one(MsgId, MsgNum, Msg, S0, E0, @@ -1158,7 +1161,9 @@ dead_letter_effects(Reason, Discarded, #?MODULE{cfg = #cfg{dead_letter_handler = {Mod, Fun, Args}}}, Effects) -> DeadLetters = maps:fold(fun(_, {_, {_, {_Header, Msg}}}, Acc) -> - [{Reason, Msg} | Acc] + [{Reason, Msg} | Acc]; + (_, _, Acc) -> + Acc end, [], Discarded), [{mod_call, Mod, Fun, Args ++ [DeadLetters]} | Effects]. diff --git a/src/rabbit_fifo.hrl b/src/rabbit_fifo.hrl index 16e665f9df..2fae8c10ca 100644 --- a/src/rabbit_fifo.hrl +++ b/src/rabbit_fifo.hrl @@ -104,9 +104,9 @@ -record(cfg, {name :: atom(), resource :: rabbit_types:r('queue'), - release_cursor_interval = - {?RELEASE_CURSOR_EVERY, ?RELEASE_CURSOR_EVERY} :: - non_neg_integer() | {non_neg_integer(), non_neg_integer()}, + release_cursor_interval :: + undefined | non_neg_integer() | + {non_neg_integer(), non_neg_integer()}, dead_letter_handler :: option(applied_mfa()), become_leader_handler :: option(applied_mfa()), max_length :: option(non_neg_integer()), -- cgit v1.2.1