Skip to content

Commit 38f83d7

Browse files
committed
rabbit_quorum_queue: Remove old compatibility code in status/2
The `sys:get_status/1` fallback doesn't work as expected since the changes in Ra for OTP 27: <rabbitmq/ra@ab280c7>. This code is meant for mixed-versions compatibility with nodes that don't have the `rabbit_quorum_queue:key_metrics_rpc/1` function which was added in v3.13.0. Quorum queues with a member down could see a failure of the quorum_status CLI command like so: % rabbitmq rabbitmq-queues quorum_status --vhost / "qq-1" Status of quorum queue qq-1 on node [email protected] ... Error: {{:badmatch, false}, [{:rabbit_quorum_queue, :"-status/2-lc$^0/1-0-", 2, [file: ~c"rabbit_quorum_queue.erl", line: 1287]}, {:rabbit_quorum_queue, :status, 2, []}]} The badmatch comes from this line in `rabbit_quorum_queue:status/2`: {_, M} = lists:keyfind(ra_server_state, 1, Sys), The `Sys` return was `[{data, Sys}]` since the linked change in Ra, so the `keyfind/3` would always return `false`.
1 parent bf71e2e commit 38f83d7

File tree

1 file changed

+16
-48
lines changed

1 file changed

+16
-48
lines changed

deps/rabbit/src/rabbit_quorum_queue.erl

Lines changed: 16 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -1290,43 +1290,22 @@ status(Vhost, QueueName) ->
12901290
{<<"Term">>, <<>>},
12911291
{<<"Machine Version">>, MacVer}
12921292
];
1293-
{error, _} ->
1294-
%% try the old method
1295-
case get_sys_status(ServerId) of
1296-
{ok, Sys} ->
1297-
{_, M} = lists:keyfind(ra_server_state, 1, Sys),
1298-
{_, RaftState} = lists:keyfind(raft_state, 1, Sys),
1299-
#{commit_index := Commit,
1300-
machine_version := MacVer,
1301-
current_term := Term,
1302-
last_applied := LastApplied,
1303-
log := #{last_index := Last,
1304-
last_written_index_term := {LastWritten, _},
1305-
snapshot_index := SnapIdx}} = M,
1306-
[{<<"Node Name">>, N},
1307-
{<<"Raft State">>, RaftState},
1308-
{<<"Membership">>, voter},
1309-
{<<"Last Log Index">>, Last},
1310-
{<<"Last Written">>, LastWritten},
1311-
{<<"Last Applied">>, LastApplied},
1312-
{<<"Commit Index">>, Commit},
1313-
{<<"Snapshot Index">>, SnapIdx},
1314-
{<<"Term">>, Term},
1315-
{<<"Machine Version">>, MacVer}
1316-
];
1317-
{error, Err} ->
1318-
[{<<"Node Name">>, N},
1319-
{<<"Raft State">>, Err},
1320-
{<<"Membership">>, <<>>},
1321-
{<<"Last Log Index">>, <<>>},
1322-
{<<"Last Written">>, <<>>},
1323-
{<<"Last Applied">>, <<>>},
1324-
{<<"Commit Index">>, <<>>},
1325-
{<<"Snapshot Index">>, <<>>},
1326-
{<<"Term">>, <<>>},
1327-
{<<"Machine Version">>, <<>>}
1328-
]
1329-
end
1293+
{error, Reason} ->
1294+
State = case is_atom(Reason) of
1295+
true -> Reason;
1296+
false -> unknown
1297+
end,
1298+
[{<<"Node Name">>, N},
1299+
{<<"Raft State">>, State},
1300+
{<<"Membership">>, <<>>},
1301+
{<<"Last Log Index">>, <<>>},
1302+
{<<"Last Written">>, <<>>},
1303+
{<<"Last Applied">>, <<>>},
1304+
{<<"Commit Index">>, <<>>},
1305+
{<<"Snapshot Index">>, <<>>},
1306+
{<<"Term">>, <<>>},
1307+
{<<"Machine Version">>, <<>>}
1308+
]
13301309
end
13311310
end || N <- Nodes];
13321311
{ok, _Q} ->
@@ -1335,17 +1314,6 @@ status(Vhost, QueueName) ->
13351314
E
13361315
end.
13371316

1338-
get_sys_status(Proc) ->
1339-
try lists:nth(5, element(4, sys:get_status(Proc))) of
1340-
Sys -> {ok, Sys}
1341-
catch
1342-
_:Err when is_tuple(Err) ->
1343-
{error, element(1, Err)};
1344-
_:_ ->
1345-
{error, other}
1346-
1347-
end.
1348-
13491317
add_member(VHost, Name, Node, Membership, Timeout)
13501318
when is_binary(VHost) andalso
13511319
is_binary(Name) andalso

0 commit comments

Comments
 (0)