Skip to content

Commit 214b7f1

Browse files
committed
QQ: fix effects ordering
Not really a problem but effects passed to checkout/4 would be reversed which could potentially cause future confusion.
1 parent ebc1155 commit 214b7f1

File tree

2 files changed

+34
-27
lines changed

2 files changed

+34
-27
lines changed

deps/rabbit/src/rabbit_fifo.erl

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ apply_(_Meta, #register_enqueuer{pid = Pid},
272272
end,
273273
{State, Res, [{monitor, process, Pid}]};
274274
apply_(Meta, #settle{msg_ids = MsgIds,
275-
consumer_key = Key},
275+
consumer_key = Key},
276276
#?STATE{consumers = Consumers} = State) ->
277277
case find_consumer(Key, Consumers) of
278278
{ConsumerKey, Con0} ->
@@ -284,7 +284,7 @@ apply_(Meta, #settle{msg_ids = MsgIds,
284284
{State, ok}
285285
end;
286286
apply_(Meta, #discard{consumer_key = ConsumerKey,
287-
msg_ids = MsgIds},
287+
msg_ids = MsgIds},
288288
#?STATE{consumers = Consumers } = State0) ->
289289
case find_consumer(ConsumerKey, Consumers) of
290290
{ActualConsumerKey, #consumer{} = Con} ->
@@ -293,8 +293,8 @@ apply_(Meta, #discard{consumer_key = ConsumerKey,
293293
{State0, ok}
294294
end;
295295
apply_(Meta, #return{consumer_key = ConsumerKey,
296-
msg_ids = MsgIds},
297-
#?STATE{consumers = Cons} = State) ->
296+
msg_ids = MsgIds},
297+
#?STATE{consumers = Cons} = State) ->
298298
case find_consumer(ConsumerKey, Cons) of
299299
{ActualConsumerKey, #consumer{checked_out = Checked}} ->
300300
return(Meta, ActualConsumerKey, MsgIds, false,
@@ -303,11 +303,11 @@ apply_(Meta, #return{consumer_key = ConsumerKey,
303303
{State, ok}
304304
end;
305305
apply_(Meta, #modify{consumer_key = ConsumerKey,
306-
delivery_failed = DelFailed,
307-
undeliverable_here = Undel,
308-
annotations = Anns,
309-
msg_ids = MsgIds},
310-
#?STATE{consumers = Cons} = State) ->
306+
delivery_failed = DelFailed,
307+
undeliverable_here = Undel,
308+
annotations = Anns,
309+
msg_ids = MsgIds},
310+
#?STATE{consumers = Cons} = State) ->
311311
case find_consumer(ConsumerKey, Cons) of
312312
{ActualConsumerKey, #consumer{checked_out = Checked}}
313313
when Undel == false ->
@@ -1988,8 +1988,8 @@ checkout0(Meta, {success, ConsumerKey, MsgId,
19881988
end,
19891989
checkout0(Meta, checkout_one(Meta, ExpiredMsg, State, Effects), SendAcc);
19901990
checkout0(_Meta, {_Activity, ExpiredMsg, State0, Effects0}, SendAcc) ->
1991-
Effects = add_delivery_effects(Effects0, SendAcc, State0),
1992-
{State0, ExpiredMsg, lists:reverse(Effects)}.
1991+
Effects = add_delivery_effects([], SendAcc, State0),
1992+
{State0, ExpiredMsg, Effects0 ++ lists:reverse(Effects)}.
19931993

19941994
evaluate_limit(_Index, Result,
19951995
#?STATE{cfg = #cfg{max_length = undefined,
@@ -2983,14 +2983,24 @@ do_snapshot(MacVer, Ts, #snapshot{index = _ChIdx,
29832983
RaAux, DiscardedBytes, Force)
29842984
when is_integer(MacVer) andalso MacVer >= 8 ->
29852985
LastAppliedIdx = ra_aux:last_applied(RaAux),
2986-
#?STATE{} = MacState = ra_aux:machine_state(RaAux),
2986+
#?STATE{consumers = Consumers,
2987+
enqueuers = Enqueuers} = MacState = ra_aux:machine_state(RaAux),
29872988
TimeSince = Ts - SnapTime,
29882989
MsgsTot = messages_total(MacState),
29892990
%% if the approximate snapshot size * 2 can be reclaimed it is worth
29902991
%% taking a snapshot
2991-
%% TODO: take number of enqueues and consumers into account
2992-
ApproxSnapSize = 4096 + (32 * MsgsTot),
2993-
EnoughDataRemoved = DiscardedBytes - LastDiscardedBytes > (ApproxSnapSize * 2),
2992+
%% take number of enqueues and consumers into account
2993+
%% message: 32 bytes
2994+
%% enqueuer: 96 bytes
2995+
%% consumer: 256 bytes
2996+
NumEnqueuers = map_size(Enqueuers),
2997+
NumConsumers = map_size(Consumers),
2998+
ApproxSnapSize = 4096 +
2999+
(MsgsTot * 32) +
3000+
(NumEnqueuers * 96) +
3001+
(NumConsumers * 256),
3002+
3003+
EnoughDataRemoved = DiscardedBytes - LastDiscardedBytes > (ApproxSnapSize * 3),
29943004

29953005
{CheckMinInterval, _CheckMinIndexes, _CheckMaxIndexes} =
29963006
persistent_term:get(quorum_queue_checkpoint_config,

deps/rabbit/test/rabbit_fifo_SUITE.erl

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,6 @@ untracked_enq_deq_test(Config) ->
585585
State0),
586586
{_State2, _, Effs} =
587587
apply(meta(Config, 3), make_checkout(Cid, {dequeue, settled}, #{}), State1),
588-
ct:pal("Effs ~p", [State1]),
589588
?ASSERT_EFF({log, [1], _}, Effs),
590589
ok.
591590

@@ -821,7 +820,6 @@ requeue_test(Config) ->
821820
[_Monitor, {log_ext, [1], _Fun, _}]} = checkout(Config, ?LINE, Cid, 1, State0),
822821

823822
[{MsgId, {H1, _}}] = rabbit_fifo:get_checked_out(CKey, MsgId, MsgId, State1),
824-
ct:pal("query consumers ~p", [rabbit_fifo:query_consumers(State1)]),
825823

826824
[{append, Requeue, _}] = rabbit_fifo:make_requeue(CKey, {notify, 1, self()},
827825
[{MsgId, 1, H1, Msg1}], []),
@@ -1940,18 +1938,18 @@ single_active_consumer_priority_test(Config) ->
19401938
],
19411939
{#rabbit_fifo{ cfg = #cfg{resource = Resource}}, StateMachineEvents} = run_log(Config, S0, Entries, fun single_active_invariant/1),
19421940
ModCalls = [ S || S = {mod_call, rabbit_quorum_queue, update_consumer_handler, _} <- StateMachineEvents ],
1943-
1944-
%% C1 should be added as single_active
1941+
1942+
%% C1 should be added as single_active
19451943
assert_update_consumer_handler_state_transition(C1, Resource, true, single_active, lists:nth(1, ModCalls)),
1946-
%% C1 should transition to waiting because ...
1947-
assert_update_consumer_handler_state_transition(C1, Resource, false, waiting, lists:nth(2, ModCalls)),
19481944
%% C2 should become single_active
1949-
assert_update_consumer_handler_state_transition(C2, Resource, true, single_active, lists:nth(3, ModCalls)),
1950-
%% C2 should transition as waiting because ...
1951-
assert_update_consumer_handler_state_transition(C2, Resource, false, waiting, lists:nth(4, ModCalls)),
1945+
assert_update_consumer_handler_state_transition(C2, Resource, true, single_active, lists:nth(2, ModCalls)),
1946+
%% C1 should transition to waiting
1947+
assert_update_consumer_handler_state_transition(C1, Resource, false, waiting, lists:nth(3, ModCalls)),
19521948
%% C3 is added as single_active
1953-
assert_update_consumer_handler_state_transition(C3, Resource, true, single_active, lists:nth(5, ModCalls)),
1954-
1949+
assert_update_consumer_handler_state_transition(C3, Resource, true, single_active, lists:nth(4, ModCalls)),
1950+
%% C2 should transition as waiting
1951+
assert_update_consumer_handler_state_transition(C2, Resource, false, waiting, lists:nth(5, ModCalls)),
1952+
19551953
ok.
19561954

19571955
assert_update_consumer_handler_state_transition(ConsumerId, Resource, IsActive, UpdatedState, ModCall) ->
@@ -2405,7 +2403,6 @@ reject_publish_purge_test(Config) ->
24052403
rabbit_fifo:make_enqueue(Pid1, 2, two), State2),
24062404
{State4, ok, Efx} = apply(meta(Config, 4, ?LINE, {notify, 2, Pid1}),
24072405
rabbit_fifo:make_enqueue(Pid1, 3, three), State3),
2408-
% ct:pal("Efx ~tp", [Efx]),
24092406
?ASSERT_EFF({send_msg, P, {queue_status, reject_publish}, [ra_event]}, P == Pid1, Efx),
24102407
{_State5, {purge, 3}, Efx1} = apply(meta(Config, 5), rabbit_fifo:make_purge(), State4),
24112408
?ASSERT_EFF({send_msg, P, {queue_status, go}, [ra_event]}, P == Pid1, Efx1),

0 commit comments

Comments
 (0)