Skip to content

Commit 59cf23f

Browse files
Merge pull request #2728 from rabbitmq/qq-bug-fix-service-queue-conv
Fix crash bug in QQ state conversion (cherry picked from commit 9ec4983)
1 parent 7a7eaf0 commit 59cf23f

File tree

2 files changed

+31
-1
lines changed

2 files changed

+31
-1
lines changed

deps/rabbit/src/rabbit_fifo.erl

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -512,6 +512,10 @@ apply(Meta, #update_config{config = Conf}, State) ->
512512
checkout(Meta, State, update_config(Conf, State), []);
513513
apply(_Meta, {machine_version, 0, 1}, V0State) ->
514514
State = convert_v0_to_v1(V0State),
515+
{State, ok, []};
516+
apply(_Meta, Cmd, State) ->
517+
%% handle unhandled commands gracefully
518+
rabbit_log:debug("rabbit_fifo: unhandled command ~W", [Cmd, 10]),
515519
{State, ok, []}.
516520

517521
convert_v0_to_v1(V0State0) ->
@@ -532,7 +536,7 @@ convert_v0_to_v1(V0State0) ->
532536
list_to_tuple(tuple_to_list(C0) ++ [0])
533537
end, V0Cons),
534538
V0SQ = rabbit_fifo_v0:get_field(service_queue, V0State),
535-
V1SQ = priority_queue:from_list(queue:to_list(V0SQ)),
539+
V1SQ = priority_queue:from_list([{0, C} || C <- queue:to_list(V0SQ)]),
536540
Cfg = #cfg{name = rabbit_fifo_v0:get_cfg_field(name, V0State),
537541
resource = rabbit_fifo_v0:get_cfg_field(resource, V0State),
538542
release_cursor_interval = rabbit_fifo_v0:get_cfg_field(release_cursor_interval, V0State),

deps/rabbit/test/rabbit_fifo_SUITE.erl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1524,6 +1524,32 @@ machine_version_test(_) ->
15241524
?assert(priority_queue:is_queue(S)),
15251525
ok.
15261526

1527+
machine_version_waiting_consumer_test(_) ->
1528+
V0 = rabbit_fifo_v0,
1529+
S0 = V0:init(#{name => ?FUNCTION_NAME,
1530+
queue_resource => rabbit_misc:r(<<"/">>, queue, <<"test">>)}),
1531+
Idx = 1,
1532+
{#rabbit_fifo{}, ok, []} = apply(meta(Idx), {machine_version, 0, 1}, S0),
1533+
1534+
Cid = {atom_to_binary(?FUNCTION_NAME, utf8), self()},
1535+
Entries = [
1536+
{1, rabbit_fifo_v0:make_enqueue(self(), 1, banana)},
1537+
{2, rabbit_fifo_v0:make_enqueue(self(), 2, apple)},
1538+
{3, rabbit_fifo_v0:make_checkout(Cid, {auto, 5, unsettled}, #{})}
1539+
],
1540+
{S1, _Effects} = rabbit_fifo_v0_SUITE:run_log(S0, Entries),
1541+
Self = self(),
1542+
{#rabbit_fifo{enqueuers = #{Self := #enqueuer{}},
1543+
consumers = #{Cid := #consumer{priority = 0}},
1544+
service_queue = S,
1545+
messages = Msgs}, ok, []} = apply(meta(Idx),
1546+
{machine_version, 0, 1}, S1),
1547+
%% validate message conversion to lqueue
1548+
?assertEqual(0, lqueue:len(Msgs)),
1549+
?assert(priority_queue:is_queue(S)),
1550+
?assertEqual(1, priority_queue:len(S)),
1551+
ok.
1552+
15271553
queue_ttl_test(_) ->
15281554
QName = rabbit_misc:r(<<"/">>, queue, <<"test">>),
15291555
Conf = #{name => ?FUNCTION_NAME,

0 commit comments

Comments
 (0)