@@ -253,7 +253,7 @@ apply(#command_unregister_consumer{vhost = VirtualHost,
253
253
of
254
254
{value , Consumer } ->
255
255
G1 = remove_from_group (Consumer , Group0 ),
256
- handle_consumer_removal (G1 , Consumer );
256
+ handle_consumer_removal (G1 , Consumer , Stream , ConsumerName );
257
257
false ->
258
258
{Group0 , []}
259
259
end ,
@@ -269,19 +269,24 @@ apply(#command_activate_consumer{vhost = VirtualHost,
269
269
stream = Stream ,
270
270
consumer_name = ConsumerName },
271
271
#? MODULE {groups = StreamGroups0 } = State0 ) ->
272
+ rabbit_log :debug (" Activating consumer on ~tp , group ~p " ,
273
+ [Stream , ConsumerName ]),
272
274
{G , Eff } =
273
275
case lookup_group (VirtualHost , Stream , ConsumerName , StreamGroups0 ) of
274
276
undefined ->
275
- rabbit_log :warning (" trying to activate consumer in group ~p , but "
277
+ rabbit_log :warning (" Trying to activate consumer in group ~tp , but "
276
278
" the group does not longer exist" ,
277
279
[{VirtualHost , Stream , ConsumerName }]),
278
280
{undefined , []};
279
281
Group ->
280
282
# consumer {pid = Pid , subscription_id = SubId } =
281
283
evaluate_active_consumer (Group ),
284
+ rabbit_log :debug (" New active consumer on ~tp , group ~tp " ++
285
+ " is ~tp from ~tp " ,
286
+ [Stream , ConsumerName , SubId , Pid ]),
282
287
Group1 =
283
288
update_consumer_state_in_group (Group , Pid , SubId , true ),
284
- {Group1 , [notify_consumer_effect (Pid , SubId , true )]}
289
+ {Group1 , [notify_consumer_effect (Pid , SubId , Stream , ConsumerName , true )]}
285
290
end ,
286
291
StreamGroups1 =
287
292
update_groups (VirtualHost , Stream , ConsumerName , G , StreamGroups0 ),
@@ -521,7 +526,8 @@ do_register_consumer(VirtualHost,
521
526
Effects =
522
527
case Active of
523
528
true ->
524
- [notify_consumer_effect (ConnectionPid , SubscriptionId , Active )];
529
+ [notify_consumer_effect (ConnectionPid , SubscriptionId ,
530
+ Stream , ConsumerName , Active )];
525
531
_ ->
526
532
[]
527
533
end ,
@@ -549,7 +555,8 @@ do_register_consumer(VirtualHost,
549
555
active = true },
550
556
G1 = add_to_group (Consumer0 , Group0 ),
551
557
{G1 ,
552
- [notify_consumer_effect (ConnectionPid , SubscriptionId , true )]};
558
+ [notify_consumer_effect (ConnectionPid , SubscriptionId ,
559
+ Stream , ConsumerName , true )]};
553
560
_G ->
554
561
% % whatever the current state is, the newcomer will be passive
555
562
Consumer0 =
@@ -568,18 +575,28 @@ do_register_consumer(VirtualHost,
568
575
% % the current active stays the same
569
576
{G1 , []};
570
577
_ ->
578
+ rabbit_log :debug (" SAC consumer registration: " ++
579
+ " active consumer change on stream ~tp , group ~tp . " ++
580
+ " Notifying ~tp from ~tp it is no longer active." ,
581
+ [Stream , ConsumerName , ActSubId , ActPid ]),
571
582
% % there's a change, telling the active it's not longer active
572
583
{update_consumer_state_in_group (G1 ,
573
584
ActPid ,
574
585
ActSubId ,
575
586
false ),
576
587
[notify_consumer_effect (ActPid ,
577
588
ActSubId ,
589
+ Stream ,
590
+ ConsumerName ,
578
591
false ,
579
592
true )]}
580
593
end ;
581
594
false ->
582
- % % no active consumer in the (non-empty) group, we are waiting for the reply of a former active
595
+ rabbit_log :debug (" SAC consumer registration: no active consumer on stream ~tp , group ~tp . " ++
596
+ " Likely waiting for a response from former active consumer." ,
597
+ [Stream , ConsumerName ]),
598
+ % % no active consumer in the (non-empty) group,
599
+ % % we are waiting for the reply of a former active
583
600
{G1 , []}
584
601
end
585
602
end ,
@@ -593,27 +610,27 @@ do_register_consumer(VirtualHost,
593
610
lookup_consumer (ConnectionPid , SubscriptionId , Group1 ),
594
611
{State #? MODULE {groups = StreamGroups1 }, {ok , Active }, Effects }.
595
612
596
- handle_consumer_removal (# group {consumers = []} = G , _ ) ->
613
+ handle_consumer_removal (# group {consumers = []} = G , _ , _ , _ ) ->
597
614
{G , []};
598
615
handle_consumer_removal (# group {partition_index = - 1 } = Group0 ,
599
- Consumer ) ->
616
+ Consumer , Stream , ConsumerName ) ->
600
617
case Consumer of
601
618
# consumer {active = true } ->
602
619
% % this is the active consumer we remove, computing the new one
603
620
Group1 = compute_active_consumer (Group0 ),
604
621
case lookup_active_consumer (Group1 ) of
605
622
{value , # consumer {pid = Pid , subscription_id = SubId }} ->
606
623
% % creating the side effect to notify the new active consumer
607
- {Group1 , [notify_consumer_effect (Pid , SubId , true )]};
624
+ {Group1 , [notify_consumer_effect (Pid , SubId , Stream , ConsumerName , true )]};
608
625
_ ->
609
626
% % no active consumer found in the group, nothing to do
610
627
{Group1 , []}
611
628
end ;
612
629
# consumer {active = false } ->
613
- % % not the active consumer, nothing to do."),
630
+ % % not the active consumer, nothing to do.
614
631
{Group0 , []}
615
632
end ;
616
- handle_consumer_removal (Group0 , Consumer ) ->
633
+ handle_consumer_removal (Group0 , Consumer , Stream , ConsumerName ) ->
617
634
case lookup_active_consumer (Group0 ) of
618
635
{value ,
619
636
# consumer {pid = ActPid , subscription_id = ActSubId } =
@@ -623,40 +640,81 @@ handle_consumer_removal(Group0, Consumer) ->
623
640
% % the current active stays the same
624
641
{Group0 , []};
625
642
_ ->
643
+ rabbit_log :debug (" SAC consumer removal: " ++
644
+ " active consumer change on stream ~tp , group ~tp . " ++
645
+ " Notifying ~tp from ~tp it is no longer active." ,
646
+ [Stream , ConsumerName , ActSubId , ActPid ]),
647
+
626
648
% % there's a change, telling the active it's not longer active
627
649
{update_consumer_state_in_group (Group0 ,
628
650
ActPid ,
629
651
ActSubId ,
630
652
false ),
631
- [notify_consumer_effect (ActPid , ActSubId , false , true )]}
653
+ [notify_consumer_effect (ActPid , ActSubId ,
654
+ Stream , ConsumerName , false , true )]}
632
655
end ;
633
656
false ->
634
657
case Consumer # consumer .active of
635
658
true ->
636
659
% % the active one is going away, picking a new one
637
660
# consumer {pid = P , subscription_id = SID } =
638
661
evaluate_active_consumer (Group0 ),
662
+ rabbit_log :debug (" SAC consumer removal: " ++
663
+ " active consumer change on stream ~tp , group ~tp . " ++
664
+ " Notifying ~tp from ~tp it is the new active consumer." ,
665
+ [Stream , ConsumerName , SID , P ]),
639
666
{update_consumer_state_in_group (Group0 , P , SID , true ),
640
- [notify_consumer_effect (P , SID , true )]};
667
+ [notify_consumer_effect (P , SID ,
668
+ Stream , ConsumerName , true )]};
641
669
false ->
642
- % % no active consumer in the (non-empty) group, we are waiting for the reply of a former active
670
+ rabbit_log :debug (" SAC consumer removal: no active consumer on stream ~tp , group ~tp . " ++
671
+ " Likely waiting for a response from former active consumer." ,
672
+ [Stream , ConsumerName ]),
673
+ % % no active consumer in the (non-empty) group,
674
+ % % we are waiting for the reply of a former active
643
675
{Group0 , []}
644
676
end
645
677
end .
646
678
647
- notify_consumer_effect (Pid , SubId , Active ) ->
648
- notify_consumer_effect (Pid , SubId , Active , false ).
679
+ message_type () ->
680
+ case has_unblock_group_support () of
681
+ true ->
682
+ map ;
683
+ false ->
684
+ tuple
685
+ end .
686
+
687
+ notify_consumer_effect (Pid , SubId , Stream , Name , Active ) ->
688
+ notify_consumer_effect (Pid , SubId , Stream , Name , Active , false ).
649
689
650
- notify_consumer_effect (Pid , SubId , Active , false = _SteppingDown ) ->
690
+ notify_consumer_effect (Pid , SubId , Stream , Name , Active , SteppingDown ) ->
691
+ notify_consumer_effect (Pid , SubId , Stream , Name , Active , SteppingDown , message_type ()).
692
+
693
+ notify_consumer_effect (Pid , SubId , _Stream , _Name , Active , false = _SteppingDown , tuple ) ->
651
694
mod_call_effect (Pid ,
652
695
{sac ,
653
- {{subscription_id , SubId }, {active , Active },
696
+ {{subscription_id , SubId },
697
+ {active , Active },
654
698
{extra , []}}});
655
- notify_consumer_effect (Pid , SubId , Active , true = _SteppingDown ) ->
699
+ notify_consumer_effect (Pid , SubId , _Stream , _Name , Active , true = _SteppingDown , tuple ) ->
656
700
mod_call_effect (Pid ,
657
701
{sac ,
658
- {{subscription_id , SubId }, {active , Active },
659
- {extra , [{stepping_down , true }]}}}).
702
+ {{subscription_id , SubId },
703
+ {active , Active },
704
+ {extra , [{stepping_down , true }]}}});
705
+ notify_consumer_effect (Pid , SubId , Stream , Name , Active , false = _SteppingDown , map ) ->
706
+ mod_call_effect (Pid ,
707
+ {sac , #{subscription_id => SubId ,
708
+ stream => Stream ,
709
+ consumer_name => Name ,
710
+ active => Active }});
711
+ notify_consumer_effect (Pid , SubId , Stream , Name , Active , true = _SteppingDown , map ) ->
712
+ mod_call_effect (Pid ,
713
+ {sac , #{subscription_id => SubId ,
714
+ stream => Stream ,
715
+ consumer_name => Name ,
716
+ active => Active ,
717
+ stepping_down => true }}).
660
718
661
719
maybe_create_group (VirtualHost ,
662
720
Stream ,
@@ -768,3 +826,6 @@ send_message(ConnectionPid, Msg) ->
768
826
769
827
is_ff_enabled () ->
770
828
rabbit_feature_flags :is_enabled (stream_single_active_consumer ).
829
+
830
+ has_unblock_group_support () ->
831
+ rabbit_feature_flags :is_enabled (stream_sac_coordinator_unblock_group ).
0 commit comments