Skip to content

Commit 6b1b2f2

Browse files
committed
Be smarter about when to use all cluster nodes vs just those specified by ha-mode:nodes when picking initial queue master node
1 parent 686d90c commit 6b1b2f2

File tree

3 files changed

+22
-8
lines changed

3 files changed

+22
-8
lines changed

src/rabbit_mirror_queue_misc.erl

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,8 @@
2020
-export([remove_from_queue/3, on_node_up/0, add_mirrors/3,
2121
report_deaths/4, store_updated_slaves/1,
2222
initial_queue_node/2, suggested_queue_nodes/1, actual_queue_nodes/1,
23-
is_mirrored/1, update_mirrors/2, update_mirrors/1, validate_policy/1,
23+
is_mirrored/1, is_mirrored_ha_nodes/1,
24+
update_mirrors/2, update_mirrors/1, validate_policy/1,
2425
maybe_auto_sync/1, maybe_drop_master_after_sync/1,
2526
sync_batch_size/1, log_info/3, log_warning/3]).
2627

@@ -31,6 +32,8 @@
3132

3233
-include("rabbit.hrl").
3334

35+
-define(HA_NODES_MODULE, rabbit_mirror_queue_mode_nodes).
36+
3437
-rabbit_boot_step(
3538
{?MODULE,
3639
[{description, "HA policy validation"},
@@ -355,6 +358,12 @@ is_mirrored(Q) ->
355358
_ -> false
356359
end.
357360

361+
is_mirrored_ha_nodes(Q) ->
362+
case module(Q) of
363+
{ok, ?HA_NODES_MODULE} -> true;
364+
_ -> false
365+
end.
366+
358367
actual_queue_nodes(#amqqueue{pid = MPid,
359368
slave_pids = SPids,
360369
sync_slave_pids = SSPids}) ->

src/rabbit_queue_master_location_misc.erl

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,16 @@ get_location_mod_by_config(#amqqueue{}) ->
9393
end.
9494

9595
all_nodes(Queue = #amqqueue{}) ->
96+
handle_is_mirrored_ha_nodes(rabbit_mirror_queue_misc:is_mirrored_ha_nodes(Queue), Queue).
97+
98+
handle_is_mirrored_ha_nodes(false, _Queue) ->
99+
% Note: ha-mode is NOT 'nodes' - it is either exactly or all, which means
100+
% that any node in the cluster is eligible to be the new queue master node
101+
rabbit_nodes:all_running();
102+
handle_is_mirrored_ha_nodes(true, Queue) ->
103+
% Note: ha-mode is 'nodes', which explicitly specifies allowed nodes.
104+
% We must use suggested_queue_nodes to get that list of nodes as the
105+
% starting point for finding the queue master location
96106
handle_suggested_queue_nodes(rabbit_mirror_queue_misc:suggested_queue_nodes(Queue)).
97107

98108
handle_suggested_queue_nodes({_MNode, []}) ->

test/queue_master_location_SUITE.erl

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -186,13 +186,8 @@ declare_policy_exactly(Config) ->
186186
rabbit_queue_master_location_misc,
187187
lookup_master, [Q, ?DEFAULT_VHOST_PATH]),
188188
?assertEqual(MNode0, MNode1),
189-
MIdx = rabbit_ct_broker_helpers:nodename_to_index(Config, MNode1),
190-
SIdx = rabbit_ct_broker_helpers:nodename_to_index(Config, SNode),
191-
% Note:
192-
% We know that the nodes are indexed in the configuration in such a way
193-
% that higher indexes have fewer queues assigned to them
194-
% Node0 has 15 queues, Node1 has 8 and Node2 has 1
195-
?assert(MIdx > SIdx).
189+
Node2 = rabbit_ct_broker_helpers:get_node_config(Config, 2, nodename),
190+
?assertEqual(MNode1, Node2).
196191

197192
declare_config(Config) ->
198193
setup_test_environment(Config),

0 commit comments

Comments
 (0)