diff --git a/deps/rabbit/src/rabbit_core_ff.erl b/deps/rabbit/src/rabbit_core_ff.erl index fd750b7d0f51..3d00e4a3980b 100644 --- a/deps/rabbit/src/rabbit_core_ff.erl +++ b/deps/rabbit/src/rabbit_core_ff.erl @@ -205,8 +205,12 @@ mds_phase1_migration_post_enable(#{feature_name := FeatureName}) -> mds_migration_post_enable(FeatureName, Tables). mds_migration_enable(FeatureName, TablesAndOwners) -> - ok = ensure_khepri_cluster_matches_mnesia(FeatureName), - mds_migrate_tables_to_khepri(FeatureName, TablesAndOwners). + case ensure_khepri_cluster_matches_mnesia(FeatureName) of + ok -> + mds_migrate_tables_to_khepri(FeatureName, TablesAndOwners); + Error -> + Error + end. mds_migration_post_enable(FeatureName, TablesAndOwners) -> ?assert(rabbit_khepri:is_enabled(non_blocking)), @@ -221,7 +225,12 @@ ensure_khepri_cluster_matches_mnesia(FeatureName) -> "Feature flag `~s`: updating the Khepri cluster to match " "the Mnesia cluster", [FeatureName]), - rabbit_khepri:init_cluster(). + try + rabbit_khepri:init_cluster() + catch + error:{khepri_mnesia_migration_ex, _, _} = Reason -> + {error, Reason} + end. mds_plugin_migration_enable(FeatureName, TablesAndOwners) -> global:set_lock({FeatureName, self()}), diff --git a/deps/rabbit/src/rabbit_khepri.erl b/deps/rabbit/src/rabbit_khepri.erl index a09f14fd3031..91f3d5b441b0 100644 --- a/deps/rabbit/src/rabbit_khepri.erl +++ b/deps/rabbit/src/rabbit_khepri.erl @@ -472,9 +472,9 @@ get_sys_status(Proc) -> cli_cluster_status() -> case rabbit:is_running() of true -> - Nodes = nodes(), - [{nodes, [{disc, [N || N <- Nodes, rabbit_nodes:is_running(N)]}]}, - {running_nodes, Nodes}, + Nodes = locally_known_nodes(), + [{nodes, [{disc, Nodes}]}, + {running_nodes, [N || N <- Nodes, rabbit_nodes:is_running(N)]}, {cluster_name, rabbit_nodes:cluster_name()}]; false -> [] @@ -498,6 +498,9 @@ init_cluster() -> _ = application:ensure_all_started(khepri_mnesia_migration), rabbit_log:debug("Khepri clustering: syncing cluster membership"), mnesia_to_khepri:sync_cluster_membership(?STORE_ID) + catch + error:{khepri_mnesia_migration_ex, _, _} = Reason -> + {error, Reason} after case IsRunning of true -> ok; diff --git a/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/join_cluster_command.ex b/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/join_cluster_command.ex index 11b9695ac508..809c0ee095eb 100644 --- a/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/join_cluster_command.ex +++ b/deps/rabbitmq_cli/lib/rabbitmq/cli/ctl/commands/join_cluster_command.ex @@ -78,6 +78,16 @@ defmodule RabbitMQ.CLI.Ctl.Commands.JoinClusterCommand do "Error: cannot cluster node with itself: #{node_name}"} end + def output( + {:error, + {:khepri_mnesia_migration_ex, :all_mnesia_nodes_must_run, + %{all_nodes: nodes, running_nodes: running}}}, + _opts + ) do + {:error, RabbitMQ.CLI.Core.ExitCodes.exit_software(), + "Error: all mnesia nodes must run to join the cluster, mnesia nodes: #{inspect(nodes)}, running nodes: #{inspect(running)}"} + end + use RabbitMQ.CLI.DefaultOutput def banner([target_node], %{node: node_name}) do