summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Klishin <michael@clojurewerkz.org>2020-10-19 19:47:05 +0300
committerMichael Klishin <michael@clojurewerkz.org>2020-10-19 19:47:05 +0300
commit76255ef5daa6dc89f42f562f29eca1d7bd8aa377 (patch)
tree672a7a73d263997674e87fba623adf679adc18ac
parentbfe9eebc635d7a1b13981bf66995279d7d4c48c0 (diff)
downloadrabbitmq-server-git-76255ef5daa6dc89f42f562f29eca1d7bd8aa377.tar.gz
Stop local quorum queue followers after transferring leadershiprabbitmq-server-2474
This way the shutdown of a node that's been put into maintenance mode won't have any further effects on the quorum (or rather, the effects will be "frontloaded" which is the goal of maintenance mode). Closes #2474.
-rw-r--r--src/rabbit_maintenance.erl23
1 files changed, 23 insertions, 0 deletions
diff --git a/src/rabbit_maintenance.erl b/src/rabbit_maintenance.erl
index 004f8b4cea..039d125b13 100644
--- a/src/rabbit_maintenance.erl
+++ b/src/rabbit_maintenance.erl
@@ -89,6 +89,7 @@ do_drain() ->
[length(TransferCandidates), ReadableCandidates]),
transfer_leadership_of_classic_mirrored_queues(TransferCandidates),
transfer_leadership_of_quorum_queues(TransferCandidates),
+ stop_local_quorum_queue_followers(),
%% allow plugins to react
rabbit_event:notify(maintenance_draining, #{
@@ -276,6 +277,28 @@ transfer_leadership_of_classic_mirrored_queues(TransferCandidates) ->
end || Q <- Queues],
rabbit_log:info("Leadership transfer for local classic mirrored queues is complete").
+-spec stop_local_quorum_queue_followers() -> ok.
+stop_local_quorum_queue_followers() ->
+ Queues = rabbit_amqqueue:list_local_followers(),
+ rabbit_log:info("Will stop local follower replicas of ~b quorum queues on this node",
+ [length(Queues)]),
+ [begin
+ Name = amqqueue:get_name(Q),
+ rabbit_log:debug("Will stop a local follower replica of quorum queue ~s",
+ [rabbit_misc:rs(Name)]),
+ %% shut down Ra nodes so that they are not considered for leader election
+ {RegisteredName, _LeaderNode} = amqqueue:get_pid(Q),
+ RaNode = {RegisteredName, node()},
+ rabbit_log:debug("Will stop Ra server ~p", [RaNode]),
+ case ra:stop_server(RaNode) of
+ ok ->
+ rabbit_log:debug("Successfully stopped Ra server ~p", [RaNode]);
+ {error, nodedown} ->
+ rabbit_log:error("Failed to stop Ra server ~p: target node was reported as down")
+ end
+ end || Q <- Queues],
+ rabbit_log:info("Stopped all local replicas of quorum queues hosted on this node").
+
-spec primary_replica_transfer_candidate_nodes() -> [node()].
primary_replica_transfer_candidate_nodes() ->
filter_out_drained_nodes_consistent_read(rabbit_nodes:all_running() -- [node()]).