@@ -219,6 +219,7 @@ update_config(Conf, State) ->
219219 competing
220220 end ,
221221 Cfg = State #? STATE .cfg ,
222+ DefConsumerTimeout = maps :get (consumer_timeout , Conf , 1800 ),
222223
223224 LastActive = maps :get (created , Conf , undefined ),
224225 State #? STATE {cfg = Cfg # cfg {dead_letter_handler = DLH ,
@@ -228,7 +229,8 @@ update_config(Conf, State) ->
228229 consumer_strategy = ConsumerStrategy ,
229230 delivery_limit = DeliveryLimit ,
230231 expires = Expires ,
231- msg_ttl = MsgTTL },
232+ msg_ttl = MsgTTL ,
233+ default_consumer_timeout_s = DefConsumerTimeout },
232234 last_active = LastActive }.
233235
234236% msg_ids are scoped per consumer
@@ -677,7 +679,7 @@ live_indexes(#?STATE{cfg = #cfg{},
677679 DlxIndexes , Returns ),
678680 maps :fold (fun (_Cid , # consumer {checked_out = Ch }, Acc0 ) ->
679681 maps :fold (
680- fun (_MsgId , Msg , Acc ) ->
682+ fun (_MsgId , ? C_MSG ( Msg ) , Acc ) ->
681683 [get_msg_idx (Msg ) | Acc ]
682684 end , Acc0 , Ch )
683685 end , RtnIndexes , Consumers ).
@@ -704,8 +706,11 @@ snapshot_installed(_Meta, #?MODULE{cfg = #cfg{},
704706 Acc ) ->
705707 case node (Pid ) == node () of
706708 true ->
707- Iter = maps :iterator (Checked , reversed ),
708- Acc #{{Tag , Pid } => maps :to_list (Iter )};
709+ Iter = maps :iterator (Checked , ordered ),
710+ Msgs = maps :fold (fun (K , ? C_MSG (M ), Ac0 ) ->
711+ [{K , M } | Ac0 ]
712+ end , [], Iter ),
713+ Acc #{{Tag , Pid } => Msgs };
709714 false ->
710715 Acc
711716 end
@@ -715,8 +720,14 @@ snapshot_installed(_Meta, #?MODULE{cfg = #cfg{},
715720convert_v7_to_v8 (#{system_time := Ts } = _Meta , StateV7 ) ->
716721 % % the structure is intact for now
717722 Cons0 = element (#? STATE .consumers , StateV7 ),
718- Cons = maps :map (fun (_CKey , # consumer {status = suspected_down } = C ) ->
719- C # consumer {status = {suspected_down , up }};
723+ % % TODO: use default for now
724+ Timeout = Ts + 1_800_000 ,
725+ Cons = maps :map (fun (_CKey , # consumer {status = suspected_down ,
726+ checked_out = Ch0 } = C ) ->
727+ Ch = maps :map (fun (_ , M ) -> ? C_MSG (Timeout , M ) end ,
728+ Ch0 ),
729+ C # consumer {status = {suspected_down , up },
730+ checked_out = Ch };
720731 (_CKey , C ) ->
721732 C
722733 end , Cons0 ),
@@ -732,6 +743,7 @@ convert_v7_to_v8(#{system_time := Ts} = _Meta, StateV7) ->
732743 StateV8 #? STATE {discarded_bytes = 0 ,
733744 messages = Pq ,
734745 consumers = Cons ,
746+ next_consumer_timeout = Timeout ,
735747 last_command_time = Ts }.
736748
737749purge_node (Meta , Node , State , Effects ) ->
@@ -939,7 +951,7 @@ get_checked_out(CKey, From, To, #?STATE{consumers = Consumers}) ->
939951 case find_consumer (CKey , Consumers ) of
940952 {_CKey , # consumer {checked_out = Checked }} ->
941953 [begin
942- Msg = maps :get (K , Checked ),
954+ ? C_MSG ( Msg ) = maps :get (K , Checked ),
943955 I = get_msg_idx (Msg ),
944956 H = get_msg_header (Msg ),
945957 {K , {I , H }}
@@ -974,9 +986,10 @@ which_module(8) -> ?MODULE.
974986 gc = # aux_gc {} :: # aux_gc {},
975987 tick_pid :: undefined | pid (),
976988 cache = #{} :: map (),
977- last_checkpoint :: tuple () | # snapshot {},
978- bytes_in = 0 :: non_neg_integer (),
979- bytes_out = 0 :: non_neg_integer ()}).
989+ last_checkpoint :: tuple () | # snapshot {}
990+ % bytes_in = 0 :: non_neg_integer(),
991+ % bytes_out = 0 :: non_neg_integer()
992+ }).
980993
981994init_aux (Name ) when is_atom (Name ) ->
982995 % % TODO: catch specific exception throw if table already exists
@@ -1001,9 +1014,10 @@ handle_aux(RaftState, Tag, Cmd, AuxV3, RaAux)
10011014 gc = element (5 , AuxV3 ),
10021015 tick_pid = element (6 , AuxV3 ),
10031016 cache = element (7 , AuxV3 ),
1004- last_checkpoint = element (8 , AuxV3 ),
1005- bytes_in = element (9 , AuxV3 ),
1006- bytes_out = 0 },
1017+ last_checkpoint = element (8 , AuxV3 )
1018+ % bytes_in = element(9, AuxV3),
1019+ % bytes_out = 0
1020+ },
10071021 handle_aux (RaftState , Tag , Cmd , AuxV4 , RaAux );
10081022handle_aux (leader , cast , eval ,
10091023 #? AUX {last_decorators_state = LastDec ,
@@ -1048,14 +1062,14 @@ handle_aux(_RaftState, cast, eval,
10481062 {Check , Effects } = do_snapshot (EffMacVer , Ts , Check0 , RaAux ,
10491063 DiscardedBytes , false ),
10501064 {no_reply , Aux0 #? AUX {last_checkpoint = Check }, RaAux , Effects };
1051- handle_aux (_RaftState , cast , {bytes_in , {MetaSize , BodySize }},
1052- #? AUX {bytes_in = Bytes } = Aux0 ,
1053- RaAux ) ->
1054- {no_reply , Aux0 #? AUX {bytes_in = Bytes + MetaSize + BodySize }, RaAux , []};
1055- handle_aux (_RaftState , cast , {bytes_out , BodySize },
1056- #? AUX {bytes_out = Bytes } = Aux0 ,
1057- RaAux ) ->
1058- {no_reply , Aux0 #? AUX {bytes_out = Bytes + BodySize }, RaAux , []};
1065+ % handle_aux(_RaftState, cast, {bytes_in, {MetaSize, BodySize}},
1066+ % #?AUX{bytes_in = Bytes} = Aux0,
1067+ % RaAux) ->
1068+ % {no_reply, Aux0#?AUX{bytes_in = Bytes + MetaSize + BodySize}, RaAux, []};
1069+ % handle_aux(_RaftState, cast, {bytes_out, BodySize},
1070+ % #?AUX{bytes_out = Bytes} = Aux0,
1071+ % RaAux) ->
1072+ % {no_reply, Aux0#?AUX{bytes_out = Bytes + BodySize}, RaAux, []};
10591073handle_aux (_RaftState , cast , {# return {msg_ids = MsgIds ,
10601074 consumer_key = Key } = Ret , Corr , Pid },
10611075 Aux0 , RaAux0 ) ->
@@ -1066,7 +1080,7 @@ handle_aux(_RaftState, cast, {#return{msg_ids = MsgIds,
10661080 {ConsumerKey , # consumer {checked_out = Checked }} ->
10671081 {RaAux , ToReturn } =
10681082 maps :fold (
1069- fun (MsgId , Msg , {RA0 , Acc }) ->
1083+ fun (MsgId , ? C_MSG ( Msg ) , {RA0 , Acc }) ->
10701084 Idx = get_msg_idx (Msg ),
10711085 Header = get_msg_header (Msg ),
10721086 % % it is possible this is not found if the consumer
@@ -1113,7 +1127,7 @@ handle_aux(_, _, {get_checked_out, ConsumerKey, MsgIds}, Aux0, RaAux0) ->
11131127 #{ConsumerKey := # consumer {checked_out = Checked }} ->
11141128 {RaState , IdMsgs } =
11151129 maps :fold (
1116- fun (MsgId , Msg , {S0 , Acc }) ->
1130+ fun (MsgId , ? C_MSG ( Msg ) , {S0 , Acc }) ->
11171131 Idx = get_msg_idx (Msg ),
11181132 Header = get_msg_header (Msg ),
11191133 % % it is possible this is not found if the consumer
@@ -1201,6 +1215,11 @@ handle_aux(leader, _, {dlx, setup}, Aux, RaAux) ->
12011215 {no_reply , Aux , RaAux };
12021216handle_aux (_ , _ , {dlx , teardown , Pid }, Aux , RaAux ) ->
12031217 terminate_dlx_worker (Pid ),
1218+ {no_reply , Aux , RaAux };
1219+ handle_aux (_ , _ , Unhandled , Aux , RaAux ) ->
1220+ #? STATE {cfg = # cfg {resource = QR }} = ra_aux :machine_state (RaAux ),
1221+ ? LOG_DEBUG (" ~ts : rabbit_fifo: unhandled aux command ~P " ,
1222+ [rabbit_misc :rs (QR ), Unhandled , 10 ]),
12041223 {no_reply , Aux , RaAux }.
12051224
12061225
@@ -1782,8 +1801,8 @@ return(Meta, ConsumerKey,
17821801 lists :foldl (
17831802 fun (MsgId , Acc = {S0 , E0 }) ->
17841803 case Checked of
1785- #{MsgId := Msg } ->
1786- return_one (Meta , MsgId , Msg , IncrDelCount , Anns ,
1804+ #{MsgId := CMsg } ->
1805+ return_one (Meta , MsgId , CMsg , IncrDelCount , Anns ,
17871806 S0 , E0 , ConsumerKey );
17881807 #{} ->
17891808 Acc
@@ -1806,7 +1825,7 @@ complete(Meta, ConsumerKey, [MsgId],
18061825 messages_total = Tot } = State0 ,
18071826 Effects ) ->
18081827 case maps :take (MsgId , Checked0 ) of
1809- {Msg , Checked } ->
1828+ {? C_MSG ( Msg ) , Checked } ->
18101829 Hdr = get_msg_header (Msg ),
18111830 SettledSize = get_header (size , Hdr ),
18121831 Con = Con0 # consumer {checked_out = Checked ,
@@ -1828,7 +1847,7 @@ complete(Meta, ConsumerKey, MsgIds,
18281847 = lists :foldl (
18291848 fun (MsgId , {S0 , Ch0 }) ->
18301849 case maps :take (MsgId , Ch0 ) of
1831- {Msg , Ch } ->
1850+ {? C_MSG ( Msg ) , Ch } ->
18321851 Hdr = get_msg_header (Msg ),
18331852 S = get_header (size , Hdr ) + S0 ,
18341853 {S , Ch };
@@ -1964,7 +1983,7 @@ annotate_msg(Header, Msg0) ->
19641983 Msg0
19651984 end .
19661985
1967- return_one (Meta , MsgId , Msg0 , DeliveryFailed , Anns ,
1986+ return_one (Meta , MsgId , ? C_MSG ( Msg0 ) , DeliveryFailed , Anns ,
19681987 #? STATE {returns = Returns ,
19691988 consumers = Consumers ,
19701989 dlx = DlxState0 ,
@@ -2005,8 +2024,8 @@ return_one(Meta, MsgId, Msg0, DeliveryFailed, Anns,
20052024return_all (Meta , #? STATE {consumers = Cons } = State0 , Effects0 , ConsumerKey ,
20062025 # consumer {checked_out = Checked } = Con , DeliveryFailed ) ->
20072026 State = State0 #? STATE {consumers = Cons #{ConsumerKey => Con }},
2008- maps :fold (fun (MsgId , Msg , {S , E }) ->
2009- return_one (Meta , MsgId , Msg , DeliveryFailed , #{},
2027+ maps :fold (fun (MsgId , CMsg , {S , E }) ->
2028+ return_one (Meta , MsgId , CMsg , DeliveryFailed , #{},
20102029 S , E , ConsumerKey )
20112030 end , {State , Effects0 }, maps :iterator (Checked , ordered )).
20122031
@@ -2248,7 +2267,10 @@ checkout_one(#{system_time := Ts} = Meta, ExpiredMsg0, InitState0, Effects0) ->
22482267 credit = Credit ,
22492268 delivery_count = DelCnt0 ,
22502269 cfg = Cfg } = Con0 ->
2251- Checked = maps :put (Next , Msg , Checked0 ),
2270+ Timeout = (Ts div 1000 ) + State0 #? STATE .cfg # cfg .default_consumer_timeout_s ,
2271+ Checked = maps :put (Next ,
2272+ ? C_MSG (Timeout * 1000 , Msg ),
2273+ Checked0 ),
22522274 DelCnt = case credit_api_v2 (Cfg ) of
22532275 true -> add (DelCnt0 , 1 );
22542276 false -> DelCnt0 + 1
@@ -2950,7 +2972,7 @@ smallest_raft_index(#?STATE{messages = Messages,
29502972 min (get_msg_idx (Msg ), Acc )
29512973 end , Min0 , Returns ),
29522974 Min2 = maps :fold (fun (_Cid , # consumer {checked_out = Ch }, Acc0 ) ->
2953- maps :fold (fun (_MsgId , Msg , Acc ) ->
2975+ maps :fold (fun (_MsgId , ? C_MSG ( Msg ) , Acc ) ->
29542976 min (get_msg_idx (Msg ), Acc )
29552977 end , Acc0 , Ch )
29562978 end , Min1 , Consumers ),
@@ -3185,7 +3207,7 @@ discard(Meta, MsgIds, ConsumerKey,
31853207 case maps :get (Id , Checked , undefined ) of
31863208 undefined ->
31873209 false ;
3188- Msg0 ->
3210+ ? C_MSG ( Msg0 ) ->
31893211 {true , incr_msg_headers (Msg0 , DelFailed , Anns )}
31903212 end
31913213 end , MsgIds ),
0 commit comments