Skip to content

Commit

Permalink
Fix cluster status command and join_cluster error formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dcorbacho committed May 11, 2023
1 parent 41d89e5 commit e5cc386
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 6 deletions.
15 changes: 12 additions & 3 deletions deps/rabbit/src/rabbit_core_ff.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand All @@ -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()}),
Expand Down
9 changes: 6 additions & 3 deletions deps/rabbit/src/rabbit_khepri.erl
Original file line number Diff line number Diff line change
Expand Up @@ -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 ->
[]
Expand All @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit e5cc386

Please sign in to comment.