Skip to content

Commit b35f7c8

Browse files
committed
add --offline-members flag to control including down members in rabbitmq-queues member_with_highest_index command
1 parent 98edd02 commit b35f7c8

File tree

4 files changed

+38
-16
lines changed

4 files changed

+38
-16
lines changed

deps/rabbit/src/rabbit_quorum_queue.erl

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@
6868
notify_decorators/3,
6969
spawn_notify_decorators/3]).
7070

71-
-export([get_member_with_highest_index/3]).
71+
-export([get_member_with_highest_index/4]).
7272

7373
-export([is_enabled/0,
7474
is_compatible/3,
@@ -1337,9 +1337,9 @@ get_sys_status(Proc) ->
13371337

13381338
end.
13391339

1340-
-spec get_member_with_highest_index(rabbit_types:vhost(), rabbit_misc:resource_name(), atom()) ->
1340+
-spec get_member_with_highest_index(rabbit_types:vhost(), rabbit_misc:resource_name(), atom(), boolean()) ->
13411341
[[{binary(), term()}]] | {error, term()}.
1342-
get_member_with_highest_index(Vhost, QueueName, IndexName) ->
1342+
get_member_with_highest_index(Vhost, QueueName, IndexName, IncludeOfflineMembers) ->
13431343
case ?MODULE:status(Vhost, QueueName) of
13441344
Status when is_list(Status) ->
13451345
IndexNameInternal = rabbit_data_coercion:to_atom(IndexName),
@@ -1348,9 +1348,14 @@ get_member_with_highest_index(Vhost, QueueName, IndexName) ->
13481348
{_HighestIndexValue, HighestEntry} =
13491349
lists:foldl(
13501350
fun(Entry, {PreviousIndexValue, _PreviousEntry} = Acc) ->
1351-
case rabbit_misc:pget(Key, Entry) of
1352-
CurrentIndexValue when is_integer(CurrentIndexValue),
1353-
CurrentIndexValue > PreviousIndexValue ->
1351+
State = rabbit_misc:pget(<<"Raft State">>, Entry),
1352+
case {rabbit_misc:pget(Key, Entry), IncludeOfflineMembers} of
1353+
{CurrentIndexValue, false} when is_integer(CurrentIndexValue),
1354+
CurrentIndexValue > PreviousIndexValue,
1355+
State /= noproc ->
1356+
{CurrentIndexValue, Entry};
1357+
{CurrentIndexValue, true} when is_integer(CurrentIndexValue),
1358+
CurrentIndexValue > PreviousIndexValue ->
13541359
{CurrentIndexValue, Entry};
13551360
_ ->
13561361
Acc

deps/rabbit/test/quorum_queue_SUITE.erl

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4591,8 +4591,8 @@ get_member_with_highest_index(Config) ->
45914591
[{Node1, leader, 1015, 1010, 1010}, %% highest SnapshotIdx
45924592
{Node2, follower, 1015, 1010, 1010}, %% highest SnapshotIdx (duplicate)
45934593
{Node3, follower, 1013, 1013, 1009}, %% highest CommitIdx
4594-
{Node4, follower, 1016, 1009, 1008}, %% highest LogIdx
4595-
{Node5, follower, 1013, 1012, undefined}],
4594+
{Node4, follower, 1016, 1009, undefined}, %% highest LogIdx
4595+
{Node5, noproc, 1050, 1050, 1050}], %% highest but noproc
45964596

45974597
Term = 1,
45984598
MachineVersion = 7,
@@ -4622,7 +4622,7 @@ get_member_with_highest_index(Config) ->
46224622
{<<"Last Written">>,1016},
46234623
{<<"Last Applied">>,1016},
46244624
{<<"Commit Index">>, 1009},
4625-
{<<"Snapshot Index">>, 1008},
4625+
{<<"Snapshot Index">>, undefined},
46264626
{<<"Term">>, Term},
46274627
{<<"Machine Version">>, MachineVersion}]],
46284628

@@ -4667,6 +4667,21 @@ get_member_with_highest_index(Config) ->
46674667
[?assertEqual(ExpectedHighestSnapshotIdx,
46684668
rabbit_quorum_queue:get_member_with_highest_index(VHost, Q, I)) || I <- [snapshot, snapshot_index]],
46694669

4670+
ExpectedHighestIdxForAll =
4671+
[[{<<"Node Name">>, Node5},
4672+
{<<"Raft State">>, noproc},
4673+
{<<"Last Log Index">>, 1050},
4674+
{<<"Last Written">>,1050},
4675+
{<<"Last Applied">>,1050},
4676+
{<<"Commit Index">>, 1050},
4677+
{<<"Snapshot Index">>, 1050},
4678+
{<<"Term">>, Term},
4679+
{<<"Machine Version">>, MachineVersion}]],
4680+
4681+
[?assertEqual(ExpectedHighestIdxForAll,
4682+
rabbit_quorum_queue:get_member_with_highest_index(VHost, Q, I, true))
4683+
|| I <- [log, log_index, commit, commit_index, snapshot, snapshot_index]],
4684+
46704685
ok.
46714686

46724687
leader_locator_client_local(Config) ->

deps/rabbitmq_cli/lib/rabbitmq/cli/queues/commands/member_with_highest_index.ex

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,18 +13,19 @@ defmodule RabbitMQ.CLI.Queues.Commands.MemberWithHighestIndexCommand do
1313
use RabbitMQ.CLI.Core.AcceptsOnePositionalArgument
1414
use RabbitMQ.CLI.Core.RequiresRabbitAppRunning
1515

16-
def switches(), do: [index: :string, timeout: :integer]
17-
def aliases(), do: [i: :index, t: :timeout]
16+
def switches(), do: [offline_members: :boolean, index: :string, timeout: :integer]
17+
def aliases(), do: [o: :offline_members, i: :index, t: :timeout]
1818

1919
def merge_defaults(args, opts) do
20-
{args, Map.merge(%{vhost: "/", index: "commit"}, opts)}
20+
{args, Map.merge(%{vhost: "/", index: "commit", offline_members: true}, opts)}
2121
end
2222

23-
def run([name] = _args, %{vhost: vhost, index: index, node: node_name}) do
23+
def run([name] = _args, %{vhost: vhost, index: index, node: node_name, offline_members: offline_members}) do
2424
case :rabbit_misc.rpc_call(node_name, :rabbit_quorum_queue, :get_member_with_highest_index, [
2525
vhost,
2626
name,
27-
to_atom(String.downcase(index))
27+
to_atom(String.downcase(index)),
28+
offline_members
2829
]) do
2930
{:error, :classic_queue_not_supported} ->
3031
index = format_index(String.downcase(index))
@@ -42,11 +43,12 @@ defmodule RabbitMQ.CLI.Queues.Commands.MemberWithHighestIndexCommand do
4243

4344
def formatter(), do: RabbitMQ.CLI.Formatters.PrettyTable
4445

45-
def usage, do: "member_with_highest_index <queue> [--vhost <vhost>] [--index <commit|commit_index|log|log_index|snapshot|snapshot_index>]"
46+
def usage, do: "member_with_highest_index <queue> [--vhost <vhost>] [--offline-members] [--index <commit|commit_index|log|log_index|snapshot|snapshot_index>]"
4647

4748
def usage_additional do
4849
[
4950
["<queue>", "quorum queue name"],
51+
["--offline-members", "include members which are down (in noproc state)"],
5052
["--index <commit|commit_index|log|log_index|snapshot|snapshot_index>", "name of the index to use to lookup highest member"]
5153
]
5254
end

deps/rabbitmq_cli/test/queues/member_with_highest_index_test.exs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ defmodule RabbitMQ.CLI.Queues.Commands.MemberWithHighestIndexCommandTest do
4848
{:badrpc, _},
4949
@command.run(
5050
["quorum-queue-a"],
51-
%{node: :jake@thedog, vhost: "/", index: "log", timeout: 200}
51+
%{node: :jake@thedog, vhost: "/", index: "log", offline_members: true, timeout: 200}
5252
)
5353
)
5454
end

0 commit comments

Comments
 (0)