Skip to content

Commit 10cca06

Browse files
committed
QQ: v9 - module setup.
1 parent a7548a3 commit 10cca06

3 files changed

Lines changed: 4666 additions & 81 deletions

File tree

deps/rabbit/src/rabbit_fifo.erl

Lines changed: 21 additions & 81 deletions
Original file line numberDiff line numberDiff line change
@@ -12,15 +12,15 @@
1212
-compile(inline_list_funcs).
1313
-compile(inline).
1414
-compile({no_auto_import, [apply/3]}).
15-
-dialyzer({nowarn_function, convert_v7_to_v8/2}).
15+
-dialyzer({nowarn_function, convert_v8_to_v9/2}).
1616
-dialyzer(no_improper_lists).
1717

1818
-include("rabbit_queue_type.hrl").
1919
-include("rabbit_fifo.hrl").
2020

2121
-include_lib("kernel/include/logger.hrl").
2222

23-
-define(STATE, ?MODULE).
23+
-define(STATE, rabbit_fifo).
2424
-define(DLX, rabbit_fifo_dlx).
2525

2626
-define(CONSUMER_PID(Pid), #consumer{cfg = #consumer_cfg{pid = Pid}}).
@@ -903,8 +903,8 @@ finalize_ra_seq({SeqAcc, Start, End}) ->
903903
State :: state(),
904904
OldMeta :: ra_snapshot:meta(),
905905
OldState :: state().
906-
snapshot_installed(_Meta, #?MODULE{cfg = #cfg{},
907-
consumers = Consumers} = State,
906+
snapshot_installed(_Meta, #?STATE{cfg = #cfg{},
907+
consumers = Consumers} = State,
908908
_OldMeta, _OldState) ->
909909
%% here we need to redliver all pending consumer messages
910910
%% to local consumers
@@ -931,8 +931,8 @@ snapshot_installed(_Meta, #?MODULE{cfg = #cfg{},
931931
delivery_effects(SendAcc, State) ++
932932
credit_reply_resend_effect(State).
933933

934-
credit_reply_resend_effect(#?MODULE{waiting_consumers = Waiting,
935-
consumers = Consumers} = State) ->
934+
credit_reply_resend_effect(#?STATE{waiting_consumers = Waiting,
935+
consumers = Consumers} = State) ->
936936
Available = messages_ready(State),
937937
maps:fold(
938938
fun(ConsumerKey,
@@ -966,69 +966,9 @@ credit_reply_resend_effect(#?MODULE{waiting_consumers = Waiting,
966966
Acc
967967
end, [], maps:merge(Consumers, maps:from_list(Waiting))).
968968

969-
v7_to_v8_consumer(Con, Timeout) ->
970-
V7Cfg = element(#consumer.cfg, Con),
971-
Status0 = element(#consumer.status, Con),
972-
Ch0 = element(#consumer.checked_out, Con),
973-
Ch = maps:map(fun (_, M) -> ?C_MSG(Timeout, M) end, Ch0),
974-
Cfg = #consumer_cfg{meta = element(#consumer_cfg.meta, V7Cfg),
975-
pid = element(#consumer_cfg.pid, V7Cfg),
976-
tag = element(#consumer_cfg.tag, V7Cfg),
977-
credit_mode = element(#consumer_cfg.credit_mode, V7Cfg),
978-
lifetime = element(#consumer_cfg.lifetime, V7Cfg),
979-
priority = element(#consumer_cfg.priority, V7Cfg),
980-
timeout = ?DEFAULT_CONSUMER_TIMEOUT_MS
981-
},
982-
Status = case Status0 of
983-
suspected_down ->
984-
{suspected_down, up};
985-
_ ->
986-
Status0
987-
end,
988-
#consumer{cfg = Cfg,
989-
status = Status,
990-
next_msg_id = element(#consumer.next_msg_id, Con),
991-
checked_out = Ch,
992-
credit = element(#consumer.credit, Con),
993-
delivery_count = element(#consumer.delivery_count, Con)
994-
}.
995-
996-
convert_v7_to_v8(#{system_time := Ts} = _Meta, StateV7) ->
997-
%% the structure is intact for now
998-
Cons0 = element(#?STATE.consumers, StateV7),
999-
Waiting0 = element(#?STATE.waiting_consumers, StateV7),
1000-
Timeout = Ts + ?DEFAULT_CONSUMER_TIMEOUT_MS,
1001-
Cons = maps:map(
1002-
fun (_CKey, Con) ->
1003-
v7_to_v8_consumer(Con, Timeout)
1004-
end, Cons0),
1005-
Waiting = lists:map(fun({Cid, Con}) ->
1006-
{Cid, v7_to_v8_consumer(Con, Timeout)}
1007-
end, Waiting0),
1008-
1009-
Msgs = element(#?STATE.messages, StateV7),
1010-
Cfg = element(#?STATE.cfg, StateV7),
1011-
{Hi, No} = rabbit_fifo_q:to_queues(Msgs),
1012-
Pq0 = queue:fold(fun (I, Acc) ->
1013-
rabbit_fifo_pq:in(9, I, Acc)
1014-
end, rabbit_fifo_pq:new(), Hi),
1015-
Pq = queue:fold(fun (I, Acc) ->
1016-
rabbit_fifo_pq:in(?DEFAULT_PRIORITY, I, Acc)
1017-
end, Pq0, No),
1018-
Dlx0 = element(#?STATE.dlx, StateV7),
1019-
Dlx = Dlx0#?DLX{unused = ?NIL},
1020-
StateV8 = StateV7,
1021-
StateV8#?STATE{cfg = Cfg#cfg{consumer_disconnected_timeout = 60_000,
1022-
delayed_retry = disabled},
1023-
reclaimable_bytes = 0,
1024-
messages = Pq,
1025-
consumers = Cons,
1026-
waiting_consumers = Waiting,
1027-
next_consumer_timeout = Timeout,
1028-
last_command_time = Ts,
1029-
dlx = Dlx,
1030-
delayed = #delayed{}
1031-
}.
969+
convert_v8_to_v9(#{} = _Meta, StateV8) ->
970+
State = StateV8,
971+
State.
1032972

1033973
purge_node(Meta, Node, State, Effects) ->
1034974
lists:foldl(fun(Pid, {S0, E0}) ->
@@ -1252,7 +1192,7 @@ get_checked_out(CKey, From, To, #?STATE{consumers = Consumers}) ->
12521192
end.
12531193

12541194
-spec version() -> pos_integer().
1255-
version() -> 8.
1195+
version() -> 9.
12561196

12571197
which_module(0) -> rabbit_fifo_v0;
12581198
which_module(1) -> rabbit_fifo_v1;
@@ -1262,7 +1202,8 @@ which_module(4) -> rabbit_fifo_v7;
12621202
which_module(5) -> rabbit_fifo_v7;
12631203
which_module(6) -> rabbit_fifo_v7;
12641204
which_module(7) -> rabbit_fifo_v7;
1265-
which_module(8) -> ?MODULE.
1205+
which_module(8) -> rabbit_fifo_v8;
1206+
which_module(9) -> ?MODULE.
12661207

12671208
-define(AUX, aux_v4).
12681209

@@ -1729,10 +1670,7 @@ query_notify_decorators_info(#?STATE{consumers = Consumers} = State) ->
17291670

17301671
-spec usage(atom()) -> float().
17311672
usage(Name) when is_atom(Name) ->
1732-
case ets:lookup(rabbit_fifo_usage, Name) of
1733-
[] -> 0.0;
1734-
[{_, Use}] -> Use
1735-
end.
1673+
ets:lookup_element(rabbit_fifo_usage, Name, 2, 0.0).
17361674

17371675
%%% Internal
17381676

@@ -3582,7 +3520,9 @@ convert(Meta, 6, To, State) ->
35823520
%% no conversion needed, this version only includes a logic change
35833521
convert(Meta, 7, To, State);
35843522
convert(Meta, 7, To, State) ->
3585-
convert(Meta, 8, To, convert_v7_to_v8(Meta, State)).
3523+
convert(Meta, 8, To, rabbit_fifo_v8:convert_v7_to_v8(Meta, State));
3524+
convert(Meta, 8, To, State) ->
3525+
convert(Meta, 9, To, convert_v8_to_v9(Meta, State)).
35863526

35873527
smallest_raft_index(#?STATE{messages = Messages,
35883528
returns = Returns,
@@ -4266,7 +4206,7 @@ consumer_info(ConsumerKey,
42664206
delivery_count = DeliveryCount,
42674207
next_msg_id = NextMsgId},
42684208
State) ->
4269-
#?MODULE{cfg = #cfg{consumer_strategy = Strat}} = State,
4209+
#?STATE{cfg = #cfg{consumer_strategy = Strat}} = State,
42704210
#{next_msg_id => NextMsgId,
42714211
credit => Credit,
42724212
key => ConsumerKey,
@@ -4277,8 +4217,8 @@ consumer_info(ConsumerKey,
42774217

42784218
handle_waiting_timedout_consumers(Meta, Key, MsgIds, State0) ->
42794219
case State0 of
4280-
#?MODULE{cfg = #cfg{consumer_strategy = single_active},
4281-
waiting_consumers = Waiting0} ->
4220+
#?STATE{cfg = #cfg{consumer_strategy = single_active},
4221+
waiting_consumers = Waiting0} ->
42824222
%% check if consumer key relates to any of the waiting
42834223
%% consumers
42844224
case find_waiting_consumer(Key, Waiting0) of
@@ -4292,12 +4232,12 @@ handle_waiting_timedout_consumers(Meta, Key, MsgIds, State0) ->
42924232
Waiting = add_waiting({CKey, WC}, Waiting0),
42934233
{State, Effects} =
42944234
activate_next_consumer(
4295-
State0#?MODULE{waiting_consumers = Waiting}, []),
4235+
State0#?STATE{waiting_consumers = Waiting}, []),
42964236
checkout(Meta, State0, State, Effects);
42974237
Rem ->
42984238
WC = WC0#consumer{timed_out_msg_ids = Rem},
42994239
Waiting = add_waiting({CKey, WC}, Waiting0),
4300-
{State0#?MODULE{waiting_consumers = Waiting}, ok}
4240+
{State0#?STATE{waiting_consumers = Waiting}, ok}
43014241
end;
43024242
_ ->
43034243
{State0, ok}

0 commit comments

Comments
 (0)