Skip to content

Commit d0dc951

Browse files
Merge pull request #7058 from rabbitmq/add-node-lists-functions-to-clarify-intent
rabbit_nodes: Add list functions to clarify which nodes we are interested in
2 parents 054381a + d656371 commit d0dc951

40 files changed

+498
-116
lines changed

deps/rabbit/src/rabbit_amqqueue.erl

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -371,7 +371,7 @@ rebalance(Type, VhostSpec, QueueSpec) ->
371371
maybe_rebalance({true, Id}, Type, VhostSpec, QueueSpec) ->
372372
rabbit_log:info("Starting queue rebalance operation: '~ts' for vhosts matching '~ts' and queues matching '~ts'",
373373
[Type, VhostSpec, QueueSpec]),
374-
Running = rabbit_maintenance:filter_out_drained_nodes_consistent_read(rabbit_nodes:all_running()),
374+
Running = rabbit_maintenance:filter_out_drained_nodes_consistent_read(rabbit_nodes:list_running()),
375375
NumRunning = length(Running),
376376
ToRebalance = [Q || Q <- rabbit_amqqueue:list(),
377377
filter_per_type(Type, Q),
@@ -1048,7 +1048,7 @@ check_queue_type(_Val, _Args) ->
10481048

10491049
list() ->
10501050
All = rabbit_db_queue:get_all(),
1051-
NodesRunning = rabbit_nodes:all_running(),
1051+
NodesRunning = rabbit_nodes:list_running(),
10521052
lists:filter(fun (Q) ->
10531053
Pid = amqqueue:get_pid(Q),
10541054
St = amqqueue:get_state(Q),
@@ -1230,7 +1230,7 @@ is_in_virtual_host(Q, VHostName) ->
12301230
-spec list(vhost:name()) -> [amqqueue:amqqueue()].
12311231
list(VHostPath) ->
12321232
All = rabbit_db_queue:get_all(VHostPath),
1233-
NodesRunning = rabbit_nodes:all_running(),
1233+
NodesRunning = rabbit_nodes:list_running(),
12341234
lists:filter(fun (Q) ->
12351235
Pid = amqqueue:get_pid(Q),
12361236
St = amqqueue:get_state(Q),
@@ -1244,7 +1244,7 @@ list_down(VHostPath) ->
12441244
false -> [];
12451245
true ->
12461246
Alive = sets:from_list([amqqueue:get_name(Q) || Q <- list(VHostPath)]),
1247-
NodesRunning = rabbit_nodes:all_running(),
1247+
NodesRunning = rabbit_nodes:list_running(),
12481248
rabbit_db_queue:filter_all_durable(
12491249
fun (Q) ->
12501250
N = amqqueue:get_name(Q),
@@ -1348,7 +1348,7 @@ emit_info_all(Nodes, VHostPath, Items, Ref, AggregatorPid) ->
13481348
rabbit_control_misc:await_emitters_termination(Pids).
13491349

13501350
collect_info_all(VHostPath, Items) ->
1351-
Nodes = rabbit_nodes:all_running(),
1351+
Nodes = rabbit_nodes:list_running(),
13521352
Ref = make_ref(),
13531353
Pids = [ spawn_link(Node, rabbit_amqqueue, emit_info_local, [VHostPath, Items, Ref, self()]) || Node <- Nodes ],
13541354
rabbit_control_misc:await_emitters_termination(Pids),
@@ -1736,10 +1736,8 @@ forget_node_for_queue(DeadNode, [H|T], Q) when ?is_amqqueue(Q) ->
17361736
node_permits_offline_promotion(Node) ->
17371737
case node() of
17381738
Node -> not rabbit:is_running(); %% [1]
1739-
_ -> All = rabbit_nodes:all(),
1740-
Running = rabbit_nodes:all_running(),
1741-
lists:member(Node, All) andalso
1742-
not lists:member(Node, Running) %% [2]
1739+
_ -> NotRunning = rabbit_nodes:list_not_running(),
1740+
lists:member(Node, NotRunning) %% [2]
17431741
end.
17441742
%% [1] In this case if we are a real running node (i.e. rabbitmqctl
17451743
%% has RPCed into us) then we cannot allow promotion. If on the other

deps/rabbit/src/rabbit_autoheal.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ enabled() ->
145145
end.
146146

147147
leader() ->
148-
[Leader | _] = lists:usort(rabbit_nodes:all()),
148+
[Leader | _] = lists:usort(rabbit_nodes:list_members()),
149149
Leader.
150150

151151
%% This is the winner receiving its last notification that a node has
@@ -411,7 +411,7 @@ partition_value(Partition) ->
411411
%% only know which nodes we have been partitioned from, not which
412412
%% nodes are partitioned from each other.
413413
check_other_nodes(LocalPartitions) ->
414-
Nodes = rabbit_nodes:all(),
414+
Nodes = rabbit_nodes:list_members(),
415415
{Results, Bad} = rabbit_node_monitor:status(Nodes -- [node()]),
416416
RemotePartitions = [{Node, proplists:get_value(partitions, Res)}
417417
|| {Node, Res} <- Results],

deps/rabbit/src/rabbit_channel.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -369,7 +369,7 @@ send_drained(Pid, CTagCredit) ->
369369
-spec list() -> [pid()].
370370

371371
list() ->
372-
Nodes = rabbit_nodes:all_running(),
372+
Nodes = rabbit_nodes:list_running(),
373373
rabbit_misc:append_rpc_all_nodes(Nodes, rabbit_channel, list_local, [], ?RPC_TIMEOUT).
374374

375375
-spec list_local() -> [pid()].

deps/rabbit/src/rabbit_channel_tracking.erl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -262,7 +262,7 @@ list() ->
262262
lists:foldl(
263263
fun (Node, Acc) ->
264264
Acc ++ list_on_node(Node)
265-
end, [], rabbit_nodes:all_running()).
265+
end, [], rabbit_nodes:list_running()).
266266

267267
-spec list_of_user(rabbit_types:username()) -> [rabbit_types:tracked_channel()].
268268

@@ -307,7 +307,7 @@ list_on_node_mnesia(Node) ->
307307
#tracked_channel{_ = '_'})
308308
catch exit:{aborted, {no_exists, _}} ->
309309
%% The table might not exist yet (or is already gone)
310-
%% between the time rabbit_nodes:all_running() runs and
310+
%% between the time rabbit_nodes:list_running() runs and
311311
%% returns a specific node, and
312312
%% mnesia:dirty_match_object() is called for that node's
313313
%% table.

deps/rabbit/src/rabbit_connection_tracking.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,7 +433,7 @@ get_all_tracked_connection_table_names_for_node(Node) ->
433433
-spec lookup(rabbit_types:connection_name()) -> rabbit_types:tracked_connection() | 'not_found'.
434434

435435
lookup(Name) ->
436-
Nodes = rabbit_nodes:all_running(),
436+
Nodes = rabbit_nodes:list_running(),
437437
lookup(Name, Nodes).
438438

439439
lookup(_, []) ->
@@ -468,15 +468,15 @@ list() ->
468468
lists:foldl(
469469
fun (Node, Acc) ->
470470
Acc ++ list_on_node(Node)
471-
end, [], rabbit_nodes:all_running()).
471+
end, [], rabbit_nodes:list_running()).
472472

473473
-spec count() -> non_neg_integer().
474474

475475
count() ->
476476
lists:foldl(
477477
fun (Node, Acc) ->
478478
count_on_node(Node) + Acc
479-
end, 0, rabbit_nodes:all_running()).
479+
end, 0, rabbit_nodes:list_running()).
480480

481481
count_on_node(Node) ->
482482
case rabbit_feature_flags:is_enabled(tracking_records_in_ets) of
@@ -549,7 +549,7 @@ list_on_node_mnesia(Node) ->
549549
#tracked_connection{_ = '_'})
550550
catch exit:{aborted, {no_exists, _}} ->
551551
%% The table might not exist yet (or is already gone)
552-
%% between the time rabbit_nodes:all_running() runs and
552+
%% between the time rabbit_nodes:list_running() runs and
553553
%% returns a specific node, and
554554
%% mnesia:dirty_match_object() is called for that node's
555555
%% table.

deps/rabbit/src/rabbit_core_metrics_gc.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ gc_exchanges() ->
102102
gc_process_and_entity(channel_exchange_metrics, GbSet).
103103

104104
gc_nodes() ->
105-
Nodes = rabbit_nodes:all(),
105+
Nodes = rabbit_nodes:list_members(),
106106
GbSet = gb_sets:from_list(Nodes),
107107
gc_entity(node_node_metrics, GbSet).
108108

deps/rabbit/src/rabbit_direct.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ list_local() ->
4444
-spec list() -> [pid()].
4545

4646
list() ->
47-
Nodes = rabbit_nodes:all_running(),
47+
Nodes = rabbit_nodes:list_running(),
4848
rabbit_misc:append_rpc_all_nodes(Nodes, rabbit_direct, list_local, [], ?RPC_TIMEOUT).
4949

5050
%%----------------------------------------------------------------------------

deps/rabbit/src/rabbit_ff_controller.erl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -914,21 +914,21 @@ post_enable(#{states_per_node := _}, FeatureName, Nodes) ->
914914

915915
-ifndef(TEST).
916916
all_nodes() ->
917-
lists:usort([node() | mnesia:system_info(db_nodes)]).
917+
lists:usort([node() | rabbit_nodes:list_members()]).
918918

919919
running_nodes() ->
920-
lists:usort([node() | mnesia:system_info(running_db_nodes)]).
920+
lists:usort([node() | rabbit_nodes:list_running()]).
921921
-else.
922922
all_nodes() ->
923923
RemoteNodes = case rabbit_feature_flags:get_overriden_nodes() of
924-
undefined -> mnesia:system_info(db_nodes);
924+
undefined -> rabbit_nodes:list_members();
925925
Nodes -> Nodes
926926
end,
927927
lists:usort([node() | RemoteNodes]).
928928

929929
running_nodes() ->
930930
RemoteNodes = case rabbit_feature_flags:get_overriden_running_nodes() of
931-
undefined -> mnesia:system_info(running_db_nodes);
931+
undefined -> rabbit_nodes:list_running();
932932
Nodes -> Nodes
933933
end,
934934
lists:usort([node() | RemoteNodes]).

deps/rabbit/src/rabbit_maintenance.erl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,7 @@ stop_local_quorum_queue_followers() ->
290290

291291
-spec primary_replica_transfer_candidate_nodes() -> [node()].
292292
primary_replica_transfer_candidate_nodes() ->
293-
filter_out_drained_nodes_consistent_read(rabbit_nodes:all_running() -- [node()]).
293+
filter_out_drained_nodes_consistent_read(rabbit_nodes:list_running() -- [node()]).
294294

295295
-spec random_primary_replica_transfer_candidate_node([node()], [node()]) -> {ok, node()} | undefined.
296296
random_primary_replica_transfer_candidate_node([], _Preferred) ->

deps/rabbit/src/rabbit_mirror_queue_misc.erl

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ remove_from_queue(QueueName, Self, DeadGMPids) ->
154154
slaves_to_start_on_failure(Q, DeadGMPids) ->
155155
%% In case Mnesia has not caught up yet, filter out nodes we know
156156
%% to be dead..
157-
ClusterNodes = rabbit_nodes:all_running() --
157+
ClusterNodes = rabbit_nodes:list_running() --
158158
[node(P) || P <- DeadGMPids],
159159
{_, OldNodes, _} = actual_queue_nodes(Q),
160160
{_, NewNodes} = suggested_queue_nodes(Q, ClusterNodes),
@@ -321,7 +321,7 @@ store_updated_slaves(Q0) when ?is_amqqueue(Q0) ->
321321
%% a long time without being removed.
322322
update_recoverable(SPids, RS) ->
323323
SNodes = [node(SPid) || SPid <- SPids],
324-
RunningNodes = rabbit_nodes:all_running(),
324+
RunningNodes = rabbit_nodes:list_running(),
325325
AddNodes = SNodes -- RS,
326326
DelNodes = RunningNodes -- SNodes, %% i.e. running with no slave
327327
(RS -- DelNodes) ++ AddNodes.
@@ -375,17 +375,17 @@ promote_slave([SPid | SPids]) ->
375375
-spec initial_queue_node(amqqueue:amqqueue(), node()) -> node().
376376

377377
initial_queue_node(Q, DefNode) ->
378-
{MNode, _SNodes} = suggested_queue_nodes(Q, DefNode, rabbit_nodes:all_running()),
378+
{MNode, _SNodes} = suggested_queue_nodes(Q, DefNode, rabbit_nodes:list_running()),
379379
MNode.
380380

381381
-spec suggested_queue_nodes(amqqueue:amqqueue()) ->
382382
{node(), [node()]}.
383383

384-
suggested_queue_nodes(Q) -> suggested_queue_nodes(Q, rabbit_nodes:all_running()).
384+
suggested_queue_nodes(Q) -> suggested_queue_nodes(Q, rabbit_nodes:list_running()).
385385
suggested_queue_nodes(Q, All) -> suggested_queue_nodes(Q, node(), All).
386386

387387
%% The third argument exists so we can pull a call to
388-
%% rabbit_nodes:all_running() out of a loop or transaction
388+
%% rabbit_nodes:list_running() out of a loop or transaction
389389
%% or both.
390390
suggested_queue_nodes(Q, DefNode, All) when ?is_amqqueue(Q) ->
391391
Owner = amqqueue:get_exclusive_owner(Q),

0 commit comments

Comments
 (0)