check_if_node_is_mirror_sync_critical is no-op

Make `check_if_node_is_mirror_sync_critical` a no-op
with a deprecation warning. Since this command is commonly used
as part of the node shutdown process (eg. by Cluster Operator),
making it a no-op instead of removing completly will make the
transition to 4.0 easier for users.
This commit is contained in:
Michal Kuratczyk 2024-07-15 14:09:11 +02:00 committed by Michael Klishin
parent 6b1377163d
commit e1b649c0c6
1 changed files with 9 additions and 81 deletions

View File

@ -6,6 +6,8 @@
defmodule RabbitMQ.CLI.Queues.Commands.CheckIfNodeIsMirrorSyncCriticalCommand do
@moduledoc """
DEPRECATED: this command does nothing in RabbitMQ 4.0 and newer.
Exits with a non-zero code if there are classic mirrored queues that don't
have any in sync mirrors online and would potentially lose data
if the target node is shut down.
@ -25,103 +27,29 @@ defmodule RabbitMQ.CLI.Queues.Commands.CheckIfNodeIsMirrorSyncCriticalCommand do
use RabbitMQ.CLI.Core.RequiresRabbitAppRunning
def run([], %{node: node_name, timeout: timeout}) do
case :rabbit_misc.rpc_call(node_name, :rabbit_nodes, :is_single_node_cluster, [], timeout) do
# if target node is the only one in the cluster, the check makes little sense
# and false positives can be misleading
true ->
{:ok, :single_node_cluster}
false ->
case :rabbit_misc.rpc_call(
node_name,
:rabbit_amqqueue,
:list_local_mirrored_classic_without_synchronised_mirrors_for_cli,
[],
timeout
) do
[] -> {:ok, []}
qs when is_list(qs) -> {:ok, qs}
other -> other
end
other ->
other
end
:ok
end
def output({:ok, :single_node_cluster}, %{formatter: "json"}) do
{:ok,
%{
"result" => "ok",
"message" =>
"Target node seems to be the only one in a single node cluster, the check does not apply"
}}
end
def output({:ok, []}, %{formatter: "json"}) do
def output(:ok, %{formatter: "json"}) do
{:ok, %{"result" => "ok"}}
end
def output({:ok, :single_node_cluster}, %{silent: true}) do
{:ok, :check_passed}
end
def output({:ok, []}, %{silent: true}) do
{:ok, :check_passed}
end
def output({:ok, :single_node_cluster}, %{node: node_name}) do
{:ok,
"Node #{node_name} seems to be the only one in a single node cluster, the check does not apply"}
end
def output({:ok, []}, %{node: node_name}) do
{:ok,
"Node #{node_name} reported no classic mirrored queues without online synchronised mirrors"}
end
def output({:ok, qs}, %{node: node_name, formatter: "json"}) when is_list(qs) do
{:error, :check_failed,
%{
"result" => "error",
"queues" => qs,
"message" =>
"Node #{node_name} reported local classic mirrored queues without online synchronised mirrors"
}}
end
def output({:ok, qs}, %{silent: true}) when is_list(qs) do
{:error, :check_failed}
end
def output({:ok, qs}, %{node: node_name}) when is_list(qs) do
lines = queue_lines(qs, node_name)
{:error, :check_failed, Enum.join(lines, line_separator())}
def output(:ok, %{node: node_name}) do
{:ok, "ok"}
end
use RabbitMQ.CLI.DefaultOutput
def help_section(), do: :observability_and_health_checks
def help_section(), do: :deprecated
def description() do
"Health check that exits with a non-zero code if there are classic mirrored queues " <>
"without online synchronised mirrors (queues that would potentially lose data if the target node is shut down)"
"DEPRECATED. Mirrored queues were removed in RabbitMQ 4.0. This command is a no-op."
end
def usage, do: "check_if_node_is_mirror_sync_critical"
def banner([], %{node: node_name}) do
"Checking if node #{node_name} is critical for data safety of any classic mirrored queues ..."
"This command is DEPRECATED and is a no-op. It will be removed in a future version."
end
#
# Implementation
#
def queue_lines(qs, node_name) do
for q <- qs do
"#{q["readable_name"]} would lose its only synchronised replica (master) if node #{node_name} is stopped"
end
end
end