Skip to content

Commit 167c376

Browse files
Merge pull request #2397 from rabbitmq/rabbitmq-cli-432
Introduce a way to check if a node is the only cluster member
2 parents 24fa7e1 + 8fa9c3c commit 167c376

File tree

2 files changed

+13
-9
lines changed

2 files changed

+13
-9
lines changed

src/rabbit_amqqueue.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1105,10 +1105,10 @@ list_local_mirrored_classic_without_synchronised_mirrors_for_cli() ->
11051105
[begin
11061106
#resource{name = Name} = amqqueue:get_name(Q),
11071107
#{
1108-
<<"readable_name">> => rabbit_misc:rs(amqqueue:get_name(Q)),
1109-
<<"name">> => Name,
1110-
<<"virtual_host">> => amqqueue:get_vhost(Q),
1111-
<<"type">> => <<"quorum">>
1108+
<<"readable_name">> => rabbit_data_coercion:to_binary(rabbit_misc:rs(amqqueue:get_name(Q))),
1109+
<<"name">> => Name,
1110+
<<"virtual_host">> => amqqueue:get_vhost(Q),
1111+
<<"type">> => <<"classic">>
11121112
}
11131113
end || Q <- ClassicQs].
11141114

src/rabbit_nodes.erl

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@
2020
-export([names/1, diagnostics/1, make/1, make/2, parts/1, cookie_hash/0,
2121
is_running/2, is_process_running/2,
2222
cluster_name/0, set_cluster_name/1, set_cluster_name/2, ensure_epmd/0,
23-
all_running/0, name_type/0, running_count/0,
24-
await_running_count/2,
23+
all_running/0, name_type/0, running_count/0, total_count/0,
24+
await_running_count/2, is_single_node_cluster/0,
2525
boot/0]).
2626
-export([persistent_cluster_id/0, seed_internal_cluster_id/0, seed_user_provided_cluster_name/0]).
2727

@@ -138,15 +138,19 @@ ensure_epmd() ->
138138
rabbit_nodes_common:ensure_epmd().
139139

140140
-spec all_running() -> [node()].
141-
142141
all_running() -> rabbit_mnesia:cluster_nodes(running).
143142

144143
-spec running_count() -> integer().
145-
146144
running_count() -> length(all_running()).
147145

148-
-spec await_running_count(integer(), integer()) -> 'ok' | {'error', atom()}.
146+
-spec total_count() -> integer().
147+
total_count() -> length(rabbit_mnesia:cluster_nodes(all)).
149148

149+
-spec is_single_node_cluster() -> boolean().
150+
is_single_node_cluster() ->
151+
total_count() =:= 1.
152+
153+
-spec await_running_count(integer(), integer()) -> 'ok' | {'error', atom()}.
150154
await_running_count(TargetCount, Timeout) ->
151155
Retries = round(Timeout/?SAMPLING_INTERVAL),
152156
await_running_count_with_retries(TargetCount, Retries).

0 commit comments

Comments
 (0)