Skip to content

Commit 6b08300

Browse files
Merge pull request #4569 from rabbitmq/mergify/bp/v3.9.x/pr-4568
Make await_online_synchronized_mirror no-op in single-node clusters (backport #4567) (backport #4568)
2 parents 5721e8a + 4df11f5 commit 6b08300

File tree

1 file changed

+26
-6
lines changed

1 file changed

+26
-6
lines changed

deps/rabbitmq_cli/lib/rabbitmq/cli/upgrade/commands/await_online_synchronized_mirror_command.ex

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
defmodule RabbitMQ.CLI.Upgrade.Commands.AwaitOnlineSynchronizedMirrorCommand do
88
alias RabbitMQ.CLI.Core.DocGuide
9+
import RabbitMQ.CLI.Core.Config, only: [output_less?: 1]
910

1011
@behaviour RabbitMQ.CLI.CommandBehaviour
1112

@@ -28,19 +29,38 @@ defmodule RabbitMQ.CLI.Upgrade.Commands.AwaitOnlineSynchronizedMirrorCommand do
2829

2930
def run([], %{node: node_name, timeout: timeout}) do
3031
rpc_timeout = timeout + 500
31-
case :rabbit_misc.rpc_call(node_name, :rabbit_upgrade_preparation, :await_online_synchronised_mirrors, [timeout], rpc_timeout) do
32-
{:error, _} = err -> err
33-
{:error, _, _} = err -> err
34-
{:badrpc, _} = err -> err
32+
case :rabbit_misc.rpc_call(node_name, :rabbit_nodes, :is_single_node_cluster, [], rpc_timeout) do
33+
# if target node is the only one in the cluster, the command makes little sense
34+
# and false positives can be misleading
35+
true -> {:ok, :single_node_cluster}
36+
false ->
37+
case :rabbit_misc.rpc_call(node_name, :rabbit_upgrade_preparation, :await_online_synchronised_mirrors, [timeout], rpc_timeout) do
38+
{:error, _} = err -> err
39+
{:error, _, _} = err -> err
40+
{:badrpc, _} = err -> err
3541

36-
true -> :ok
37-
false -> {:error, "time is up, no synchronised mirror came online for at least some classic mirrored queues"}
42+
true -> :ok
43+
false -> {:error, "time is up, no synchronised mirror came online for at least some classic mirrored queues"}
44+
end
45+
other -> other
3846
end
3947
end
4048

49+
def output({:ok, :single_node_cluster}, %{formatter: "json"}) do
50+
{:ok, %{
51+
"result" => "ok",
52+
"message" => "Target node seems to be the only one in a single node cluster, the check does not apply"
53+
}}
54+
end
4155
def output({:error, msg}, %{node: node_name, formatter: "json"}) do
4256
{:error, %{"result" => "error", "node" => node_name, "message" => msg}}
4357
end
58+
def output({:ok, :single_node_cluster}, opts) do
59+
case output_less?(opts) do
60+
true -> :ok;
61+
false -> {:ok, "Target node seems to be the only one in a single node cluster, the command does not apply"}
62+
end
63+
end
4464
use RabbitMQ.CLI.DefaultOutput
4565

4666
def usage, do: "await_online_synchronized_mirror"

0 commit comments

Comments
 (0)