diff options
| -rw-r--r-- | src/rabbit_definitions.erl | 13 | ||||
| -rw-r--r-- | src/rabbit_nodes.erl | 43 | ||||
| -rw-r--r-- | test/clustering_management_SUITE.erl | 19 |
3 files changed, 64 insertions, 11 deletions
diff --git a/src/rabbit_definitions.erl b/src/rabbit_definitions.erl index 8c70b5aa6c..1923e2947e 100644 --- a/src/rabbit_definitions.erl +++ b/src/rabbit_definitions.erl @@ -27,7 +27,8 @@ -export([ list_users/0, list_vhosts/0, list_permissions/0, list_topic_permissions/0, list_runtime_parameters/0, list_global_runtime_parameters/0, list_policies/0, - list_exchanges/0, list_queues/0, list_bindings/0 + list_exchanges/0, list_queues/0, list_bindings/0, + is_internal_parameter/1 ]). -export([decode/1, decode/2, args/1]). @@ -677,12 +678,20 @@ runtime_parameter_definition(Param) -> }. list_global_runtime_parameters() -> - [global_runtime_parameter_definition(P) || P <- rabbit_runtime_parameters:list_global()]. + [global_runtime_parameter_definition(P) || P <- rabbit_runtime_parameters:list_global(), not is_internal_parameter(P)]. global_runtime_parameter_definition(P0) -> P = [{rabbit_data_coercion:to_binary(K), V} || {K, V} <- P0], maps:from_list(P). +-define(INTERNAL_GLOBAL_PARAM_PREFIX, "internal"). + +is_internal_parameter(Param) -> + Name = rabbit_data_coercion:to_list(pget(name, Param)), + %% if global parameter name starts with an "internal", consider it to be internal + %% and exclude it from definition export + string:left(Name, length(?INTERNAL_GLOBAL_PARAM_PREFIX)) =:= ?INTERNAL_GLOBAL_PARAM_PREFIX. + list_policies() -> [policy_definition(P) || P <- rabbit_policy:list()]. diff --git a/src/rabbit_nodes.erl b/src/rabbit_nodes.erl index 3d499c8a0b..eb582c69f5 100644 --- a/src/rabbit_nodes.erl +++ b/src/rabbit_nodes.erl @@ -23,23 +23,22 @@ all_running/0, name_type/0, running_count/0, await_running_count/2, boot/0]). +-export([persistent_cluster_id/0, seed_internal_cluster_id/0, seed_user_provided_cluster_name/0]). -include_lib("kernel/include/inet.hrl"). -include_lib("rabbit_common/include/rabbit.hrl"). -define(SAMPLING_INTERVAL, 1000). +-define(INTERNAL_CLUSTER_ID_PARAM_NAME, internal_cluster_id). + %%---------------------------------------------------------------------------- %% API %%---------------------------------------------------------------------------- boot() -> - case application:get_env(rabbit, cluster_name) of - undefined -> ok; - {ok, Name} -> - rabbit_log:info("Setting cluster name to '~s' as configured", [Name]), - set_cluster_name(rabbit_data_coercion:to_binary(Name)) - end. + seed_internal_cluster_id(), + seed_user_provided_cluster_name(). name_type() -> case os:getenv("RABBITMQ_USE_LONGNAME") of @@ -90,6 +89,38 @@ cluster_name_default() -> FQDN = rabbit_net:hostname(), list_to_binary(atom_to_list(make({ID, FQDN}))). +-spec persistent_cluster_id() -> binary(). +persistent_cluster_id() -> + case rabbit_runtime_parameters:lookup_global(?INTERNAL_CLUSTER_ID_PARAM_NAME) of + not_found -> + seed_internal_cluster_id(), + persistent_cluster_id(); + Param -> + #{value := Val, name := ?INTERNAL_CLUSTER_ID_PARAM_NAME} = maps:from_list(Param), + Val + end. + +-spec seed_internal_cluster_id() -> binary(). +seed_internal_cluster_id() -> + case rabbit_runtime_parameters:lookup_global(?INTERNAL_CLUSTER_ID_PARAM_NAME) of + not_found -> + Id = rabbit_guid:binary(rabbit_guid:gen(), "rabbitmq-cluster-id"), + rabbit_log:info("Initialising internal cluster ID to '~s'", [Id]), + rabbit_runtime_parameters:set_global(?INTERNAL_CLUSTER_ID_PARAM_NAME, Id, ?INTERNAL_USER), + Id; + Param -> + #{value := Val, name := ?INTERNAL_CLUSTER_ID_PARAM_NAME} = maps:from_list(Param), + Val + end. + +seed_user_provided_cluster_name() -> + case application:get_env(rabbit, cluster_name) of + undefined -> ok; + {ok, Name} -> + rabbit_log:info("Setting cluster name to '~s' as configured", [Name]), + set_cluster_name(rabbit_data_coercion:to_binary(Name)) + end. + -spec set_cluster_name(binary()) -> 'ok'. set_cluster_name(Name) -> diff --git a/test/clustering_management_SUITE.erl b/test/clustering_management_SUITE.erl index 8566b23130..43029153b0 100644 --- a/test/clustering_management_SUITE.erl +++ b/test/clustering_management_SUITE.erl @@ -56,7 +56,8 @@ groups() -> status_with_alarm, pid_file_and_await_node_startup, await_running_count, - start_with_invalid_schema_in_path + start_with_invalid_schema_in_path, + persistent_cluster_id ]}, {cluster_size_4, [], [ forget_promotes_offline_slave @@ -120,10 +121,9 @@ end_per_testcase(Testcase, Config) -> rabbit_ct_helpers:testcase_finished(Config1, Testcase). %% ------------------------------------------------------------------- -%% Testcases. +%% Test cases %% ------------------------------------------------------------------- - start_with_invalid_schema_in_path(Config) -> [Rabbit, Hare] = cluster_members(Config), stop_app(Rabbit), @@ -137,6 +137,19 @@ start_with_invalid_schema_in_path(Config) -> ErrRabbit -> error({unable_to_start_with_bad_schema_in_work_dir, ErrRabbit}) end. +persistent_cluster_id(Config) -> + [Rabbit, Hare] = cluster_members(Config), + ClusterIDA1 = rpc:call(Rabbit, rabbit_nodes, persistent_cluster_id, []), + ClusterIDB1 = rpc:call(Hare, rabbit_nodes, persistent_cluster_id, []), + ?assertEqual(ClusterIDA1, ClusterIDB1), + + rabbit_ct_broker_helpers:restart_node(Config, Rabbit), + ClusterIDA2 = rpc:call(Rabbit, rabbit_nodes, persistent_cluster_id, []), + rabbit_ct_broker_helpers:restart_node(Config, Hare), + ClusterIDB2 = rpc:call(Hare, rabbit_nodes, persistent_cluster_id, []), + ?assertEqual(ClusterIDA1, ClusterIDA2), + ?assertEqual(ClusterIDA2, ClusterIDB2). + create_bad_schema(Rabbit, Hare, Config) -> {ok, RabbitMnesiaDir} = rpc:call(Rabbit, application, get_env, [mnesia, dir]), |
