14
14
-dialyzer (no_improper_lists ).
15
15
16
16
-include (" rabbit_fifo.hrl" ).
17
- -include_lib (" rabbit_common/include/rabbit.hrl" ).
18
17
19
18
-define (STATE , ? MODULE ).
20
19
@@ -739,8 +738,9 @@ apply(_Meta, Cmd, State) ->
739
738
{State , ok , []}.
740
739
741
740
convert_v3_to_v4 (#{system_time := Ts },
742
- # rabbit_fifo {messages = Messages0 ,
743
- consumers = Consumers0 } = StateV3 ) ->
741
+ StateV3 ) ->
742
+ Messages0 = rabbit_fifo_v3 :get_field (messages , StateV3 ),
743
+ Consumers0 = rabbit_fifo_v3 :get_field (consumers , StateV3 ),
744
744
Messages = rabbit_fifo_q :from_lqueue (Messages0 ),
745
745
Consumers = maps :map (
746
746
fun (_CKey , # consumer {checked_out = Ch0 } = C ) ->
@@ -750,8 +750,23 @@ convert_v3_to_v4(#{system_time := Ts},
750
750
end , Ch0 ),
751
751
C # consumer {checked_out = Ch }
752
752
end , Consumers0 ),
753
- StateV3 #? MODULE {messages = Messages ,
754
- consumers = Consumers }.
753
+ #? MODULE {cfg = rabbit_fifo_v3 :get_field (cfg , StateV3 ),
754
+ messages = Messages ,
755
+ messages_total = rabbit_fifo_v3 :get_field (messages_total , StateV3 ),
756
+ returns = rabbit_fifo_v3 :get_field (returns , StateV3 ),
757
+ enqueue_count = rabbit_fifo_v3 :get_field (enqueue_count , StateV3 ),
758
+ enqueuers = rabbit_fifo_v3 :get_field (enqueuers , StateV3 ),
759
+ ra_indexes = rabbit_fifo_v3 :get_field (ra_indexes , StateV3 ),
760
+ release_cursors = rabbit_fifo_v3 :get_field (release_cursors , StateV3 ),
761
+ consumers = Consumers ,
762
+ % consumers that require further service are queued here
763
+ service_queue = rabbit_fifo_v3 :get_field (service_queue , StateV3 ),
764
+ dlx = rabbit_fifo_v3 :get_field (dlx , StateV3 ),
765
+ msg_bytes_enqueue = rabbit_fifo_v3 :get_field (msg_bytes_enqueue , StateV3 ),
766
+ msg_bytes_checkout = rabbit_fifo_v3 :get_field (msg_bytes_checkout , StateV3 ),
767
+ waiting_consumers = rabbit_fifo_v3 :get_field (waiting_consumers , StateV3 ),
768
+ last_active = rabbit_fifo_v3 :get_field (last_active , StateV3 ),
769
+ msg_cache = rabbit_fifo_v3 :get_field (msg_cache , StateV3 )}.
755
770
756
771
purge_node (Meta , Node , State , Effects ) ->
757
772
lists :foldl (fun (Pid , {S0 , E0 }) ->
@@ -1605,19 +1620,6 @@ drop_head(#?STATE{ra_indexes = Indexes0} = State0, Effects) ->
1605
1620
{State0 , Effects }
1606
1621
end .
1607
1622
1608
- maybe_set_msg_ttl (# basic_message {content = # content {properties = none }},
1609
- RaCmdTs , Header ,
1610
- #? STATE {cfg = # cfg {msg_ttl = PerQueueMsgTTL }}) ->
1611
- update_expiry_header (RaCmdTs , PerQueueMsgTTL , Header );
1612
- maybe_set_msg_ttl (# basic_message {content = # content {properties = Props }},
1613
- RaCmdTs , Header ,
1614
- #? STATE {cfg = # cfg {msg_ttl = PerQueueMsgTTL }}) ->
1615
- % % rabbit_quorum_queue will leave the properties decoded if and only if
1616
- % % per message message TTL is set.
1617
- % % We already check in the channel that expiration must be valid.
1618
- {ok , PerMsgMsgTTL } = rabbit_basic :parse_expiration (Props ),
1619
- TTL = min (PerMsgMsgTTL , PerQueueMsgTTL ),
1620
- update_expiry_header (RaCmdTs , TTL , Header );
1621
1623
maybe_set_msg_ttl (Msg , RaCmdTs , Header ,
1622
1624
#? STATE {cfg = # cfg {msg_ttl = MsgTTL }}) ->
1623
1625
case mc :is (Msg ) of
@@ -1832,10 +1834,10 @@ update_smallest_raft_index(IncomingRaftIdx, Reply,
1832
1834
#? STATE {cfg = Cfg ,
1833
1835
release_cursors = Cursors0 } = State0 ,
1834
1836
Effects ) ->
1835
- Total = messages_total (State0 ),
1837
+ % Total = messages_total(State0),
1836
1838
% % TODO: optimise
1837
1839
case smallest_raft_index (State0 ) of
1838
- undefined when Total == 0 ->
1840
+ undefined ->
1839
1841
% there are no messages on queue anymore and no pending enqueues
1840
1842
% we can forward release_cursor all the way until
1841
1843
% the last received command, hooray
@@ -1846,8 +1848,8 @@ update_smallest_raft_index(IncomingRaftIdx, Reply,
1846
1848
release_cursors = lqueue :new (),
1847
1849
enqueue_count = 0 },
1848
1850
{State , Reply , Effects ++ [{release_cursor , IncomingRaftIdx , State }]};
1849
- undefined ->
1850
- {State0 , Reply , Effects };
1851
+ % undefined ->
1852
+ % {State0, Reply, Effects};
1851
1853
Smallest when is_integer (Smallest ) ->
1852
1854
case find_next_cursor (Smallest , Cursors0 ) of
1853
1855
empty ->
@@ -2077,7 +2079,7 @@ take_next_msg(#?STATE{returns = Returns0,
2077
2079
case rabbit_fifo_q :out (Messages0 ) of
2078
2080
{empty , _ } ->
2079
2081
empty ;
2080
- {{ value , ? MSG (RaftIdx , _ ) = Msg } , Messages } ->
2082
+ {_P , ? MSG (RaftIdx , _ ) = Msg , Messages } ->
2081
2083
% % add index here
2082
2084
Indexes = rabbit_fifo_index :append (RaftIdx , Indexes0 ),
2083
2085
{Msg , State #? STATE {messages = Messages ,
@@ -2418,7 +2420,8 @@ normalize(#?STATE{ra_indexes = _Indexes,
2418
2420
release_cursors = Cursors ,
2419
2421
dlx = DlxState } = State ) ->
2420
2422
State #? STATE {returns = lqueue :from_list (lqueue :to_list (Returns )),
2421
- messages = rabbit_fifo_q :from_lqueue (Messages ),
2423
+ messages = rabbit_fifo_q :normalize (Messages ,
2424
+ rabbit_fifo_q :new ()),
2422
2425
release_cursors = lqueue :from_list (lqueue :to_list (Cursors )),
2423
2426
dlx = rabbit_fifo_dlx :normalize (DlxState )}.
2424
2427
@@ -2528,9 +2531,6 @@ add_bytes_return(Header,
2528
2531
State #? STATE {msg_bytes_checkout = Checkout - Size ,
2529
2532
msg_bytes_enqueue = Enqueue + Size }.
2530
2533
2531
- message_size (# basic_message {content = Content }) ->
2532
- # content {payload_fragments_rev = PFR } = Content ,
2533
- iolist_size (PFR );
2534
2534
message_size (B ) when is_binary (B ) ->
2535
2535
byte_size (B );
2536
2536
message_size (Msg ) ->
@@ -2652,12 +2652,7 @@ smallest_raft_index(#?STATE{messages = Messages,
2652
2652
ra_indexes = Indexes ,
2653
2653
dlx = DlxState }) ->
2654
2654
SmallestDlxRaIdx = rabbit_fifo_dlx :smallest_raft_index (DlxState ),
2655
- SmallestMsgsRaIdx = case rabbit_fifo_q :get (Messages ) of
2656
- ? MSG (I , _ ) when is_integer (I ) ->
2657
- I ;
2658
- _ ->
2659
- undefined
2660
- end ,
2655
+ SmallestMsgsRaIdx = rabbit_fifo_q :get_lowest_index (Messages ),
2661
2656
SmallestRaIdx = rabbit_fifo_index :smallest (Indexes ),
2662
2657
lists :min ([SmallestDlxRaIdx , SmallestMsgsRaIdx , SmallestRaIdx ]).
2663
2658
0 commit comments