@@ -376,46 +376,49 @@ record_death(Reason, SourceQueue,
376
376
count = 1 ,
377
377
anns = DeathAnns },
378
378
Anns = case Anns0 of
379
- #{deaths := Deaths = # deaths {records = Rs0 }} ->
380
- Rs = case is_list (Rs0 ) of
381
- true ->
382
- % % records are ordered by recency
383
- case lists :keytake (Key , 1 , Rs0 ) of
384
- {value , {Key , D0 }, Rs1 } ->
385
- D = update_death (D0 , Timestamp ),
386
- [{Key , D } | Rs1 ];
387
- false ->
388
- [{Key , NewDeath } | Rs0 ]
389
- end ;
390
- false ->
391
- maps :update_with (
392
- Key ,
393
- fun (Death ) -> update_death (Death , Timestamp ) end ,
394
- NewDeath ,
395
- Rs0 )
396
- end ,
379
+ #{deaths := Deaths0 } ->
380
+ Deaths = case Deaths0 of
381
+ # deaths {records = Rs0 } ->
382
+ Rs = maps :update_with (
383
+ Key ,
384
+ fun (Death ) ->
385
+ update_death (Death , Timestamp )
386
+ end ,
387
+ NewDeath ,
388
+ Rs0 ),
389
+ Deaths0 # deaths {last = Key ,
390
+ records = Rs };
391
+ _ ->
392
+ % % Deaths are ordered by recency
393
+ case lists :keytake (Key , 1 , Deaths0 ) of
394
+ {value , {Key , D0 }, Deaths1 } ->
395
+ D = update_death (D0 , Timestamp ),
396
+ [{Key , D } | Deaths1 ];
397
+ false ->
398
+ [{Key , NewDeath } | Deaths0 ]
399
+ end
400
+ end ,
397
401
Anns0 #{<<" x-last-death-reason" >> := atom_to_binary (Reason ),
398
402
<<" x-last-death-queue" >> := SourceQueue ,
399
403
<<" x-last-death-exchange" >> := Exchange ,
400
- deaths := Deaths # deaths {last = Key ,
401
- records = Rs }};
404
+ deaths := Deaths };
402
405
_ ->
403
- Rs = case Env of
404
- #{? FF_MC_DEATHS_V2 := false } ->
405
- #{Key => NewDeath };
406
- _ ->
407
- [{Key , NewDeath }]
408
- end ,
406
+ Deaths = case Env of
407
+ #{? FF_MC_DEATHS_V2 := false } ->
408
+ # deaths {last = Key ,
409
+ first = Key ,
410
+ records = #{Key => NewDeath }};
411
+ _ ->
412
+ [{Key , NewDeath }]
413
+ end ,
409
414
ReasonBin = atom_to_binary (Reason ),
410
415
Anns0 #{<<" x-first-death-reason" >> => ReasonBin ,
411
416
<<" x-first-death-queue" >> => SourceQueue ,
412
417
<<" x-first-death-exchange" >> => Exchange ,
413
418
<<" x-last-death-reason" >> => ReasonBin ,
414
419
<<" x-last-death-queue" >> => SourceQueue ,
415
420
<<" x-last-death-exchange" >> => Exchange ,
416
- deaths => # deaths {last = Key ,
417
- first = Key ,
418
- records = Rs }}
421
+ deaths => Deaths }
419
422
end ,
420
423
State #? MODULE {annotations = Anns };
421
424
record_death (Reason , SourceQueue , BasicMsg , Env ) ->
@@ -428,11 +431,9 @@ update_death(#death{count = Count,
428
431
429
432
-spec is_death_cycle (rabbit_misc :resource_name (), state ()) -> boolean ().
430
433
is_death_cycle (TargetQueue , #? MODULE {annotations = #{deaths := # deaths {records = Rs }}}) ->
431
- if is_list (Rs ) ->
432
- is_cycle_v2 (TargetQueue , Rs );
433
- is_map (Rs ) ->
434
- is_cycle_v1 (TargetQueue , maps :keys (Rs ))
435
- end ;
434
+ is_cycle_v1 (TargetQueue , maps :keys (Rs ));
435
+ is_death_cycle (TargetQueue , #? MODULE {annotations = #{deaths := Deaths }}) ->
436
+ is_cycle_v2 (TargetQueue , Deaths );
436
437
is_death_cycle (_TargetQueue , #? MODULE {}) ->
437
438
false ;
438
439
is_death_cycle (TargetQueue , BasicMsg ) ->
@@ -441,13 +442,11 @@ is_death_cycle(TargetQueue, BasicMsg) ->
441
442
% % Returns death queue names ordered by recency.
442
443
-spec death_queue_names (state ()) -> [rabbit_misc :resource_name ()].
443
444
death_queue_names (#? MODULE {annotations = #{deaths := # deaths {records = Rs }}}) ->
444
- if is_list (Rs ) ->
445
- lists :map (fun ({{Queue , _Reason }, _Death }) ->
446
- Queue
447
- end , Rs );
448
- is_map (Rs ) ->
449
- proplists :get_keys (maps :keys (Rs ))
450
- end ;
445
+ proplists :get_keys (maps :keys (Rs ));
446
+ death_queue_names (#? MODULE {annotations = #{deaths := Deaths }}) ->
447
+ lists :map (fun ({{Queue , _Reason }, _Death }) ->
448
+ Queue
449
+ end , Deaths );
451
450
death_queue_names (#? MODULE {}) ->
452
451
[];
453
452
death_queue_names (BasicMsg ) ->
0 commit comments