25
25
-type publisher_id () :: byte ().
26
26
-type publisher_reference () :: binary ().
27
27
-type subscription_id () :: byte ().
28
+ -type internal_id () :: integer ().
28
29
29
30
-record (publisher ,
30
31
{publisher_id :: publisher_id (),
31
32
stream :: stream (),
32
33
reference :: undefined | publisher_reference (),
33
34
leader :: pid (),
34
- message_counters :: atomics :atomics_ref ()}).
35
+ message_counters :: atomics :atomics_ref (),
36
+ % % use to distinguish a stale publisher from a live publisher with the same ID
37
+ % % used only for publishers without a reference (dedup off)
38
+ internal_id :: internal_id ()}).
35
39
-record (consumer_configuration ,
36
40
{socket :: rabbit_net :socket (), % % ranch_transport:socket(),
37
41
member_pid :: pid (),
95
99
outstanding_requests :: #{integer () => # request {}},
96
100
deliver_version :: rabbit_stream_core :command_version (),
97
101
request_timeout :: pos_integer (),
98
- outstanding_requests_timer :: undefined | erlang :reference ()}).
102
+ outstanding_requests_timer :: undefined | erlang :reference (),
103
+ % % internal sequence used for publishers
104
+ internal_sequence = 0 :: integer ()}).
99
105
-record (configuration ,
100
106
{initial_credits :: integer (),
101
107
credits_required_for_unblocking :: integer (),
@@ -1042,16 +1048,17 @@ open(cast,
1042
1048
config = Configuration } =
1043
1049
StatemData ) ->
1044
1050
ByPublisher =
1045
- lists :foldr (fun ({PublisherId , PublishingId }, Acc ) ->
1046
- case maps : is_key ( PublisherId , Publishers ) of
1047
- true ->
1051
+ lists :foldr (fun ({PublisherId , InternalId , PublishingId }, Acc ) ->
1052
+ case Publishers of
1053
+ #{ PublisherId : = # publisher { internal_id = InternalId }} ->
1048
1054
case maps :get (PublisherId , Acc , undefined ) of
1049
1055
undefined ->
1050
1056
Acc #{PublisherId => [PublishingId ]};
1051
1057
Ids ->
1052
1058
Acc #{PublisherId => [PublishingId | Ids ]}
1053
1059
end ;
1054
- false -> Acc
1060
+ _ ->
1061
+ Acc
1055
1062
end
1056
1063
end ,
1057
1064
#{}, CorrelationList ),
@@ -1680,7 +1687,8 @@ handle_frame_post_auth(Transport,
1680
1687
{Connection0 , State };
1681
1688
{ClusterLeader ,
1682
1689
# stream_connection {publishers = Publishers0 ,
1683
- publisher_to_ids = RefIds0 } =
1690
+ publisher_to_ids = RefIds0 ,
1691
+ internal_sequence = InternalSequence } =
1684
1692
Connection1 } ->
1685
1693
{PublisherReference , RefIds1 } =
1686
1694
case WriterRef of
@@ -1698,7 +1706,8 @@ handle_frame_post_auth(Transport,
1698
1706
leader = ClusterLeader ,
1699
1707
message_counters =
1700
1708
atomics :new (3 ,
1701
- [{signed , false }])},
1709
+ [{signed , false }]),
1710
+ internal_id = InternalSequence },
1702
1711
response (Transport ,
1703
1712
Connection0 ,
1704
1713
declare_publisher ,
@@ -1709,12 +1718,10 @@ handle_frame_post_auth(Transport,
1709
1718
Connection1 ),
1710
1719
PublisherId ,
1711
1720
PublisherReference ),
1712
- {Connection1 # stream_connection {publishers =
1713
- Publishers0 #{PublisherId
1714
- =>
1715
- Publisher },
1716
- publisher_to_ids =
1717
- RefIds1 },
1721
+ {Connection1 # stream_connection {
1722
+ publishers = Publishers0 #{PublisherId => Publisher },
1723
+ publisher_to_ids = RefIds1 ,
1724
+ internal_sequence = InternalSequence + 1 },
1718
1725
State }
1719
1726
end ;
1720
1727
{_ , _ } ->
@@ -1752,6 +1759,7 @@ handle_frame_post_auth(Transport,
1752
1759
#{PublisherId := Publisher } ->
1753
1760
# publisher {stream = Stream ,
1754
1761
reference = Reference ,
1762
+ internal_id = InternalId ,
1755
1763
leader = Leader ,
1756
1764
message_counters = Counters } =
1757
1765
Publisher ,
@@ -1769,6 +1777,7 @@ handle_frame_post_auth(Transport,
1769
1777
rabbit_stream_utils :write_messages (Leader ,
1770
1778
Reference ,
1771
1779
PublisherId ,
1780
+ InternalId ,
1772
1781
Messages ),
1773
1782
sub_credits (Credits , MessageCount ),
1774
1783
{Connection , State };
0 commit comments