Skip to content

Commit

Permalink
Merge pull request #8479 from rabbitmq/mergify/bp/v3.12.x/pr-8477
Browse files Browse the repository at this point in the history
rabbit_feature_flags: Use cluster members hint for cluster sync (backport #8477)
  • Loading branch information
dumbbell committed Jun 6, 2023
2 parents 1e90fd1 + a4bde35 commit ef64f51
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 9 deletions.
9 changes: 7 additions & 2 deletions deps/rabbit/src/rabbit_feature_flags.erl
Original file line number Diff line number Diff line change
Expand Up @@ -1149,8 +1149,13 @@ sync_feature_flags_with_cluster([] = _Nodes, true = _NodeIsVirgin) ->
rabbit_ff_controller:enable_default();
sync_feature_flags_with_cluster([] = _Nodes, false = _NodeIsVirgin) ->
ok;
sync_feature_flags_with_cluster(_Nodes, _NodeIsVirgin) ->
rabbit_ff_controller:sync_cluster().
sync_feature_flags_with_cluster(Nodes, _NodeIsVirgin) ->
%% We don't use `rabbit_nodes:filter_running()' here because the given
%% `Nodes' list may contain nodes which are not members yet (the cluster
%% could be being created or expanded).
Nodes1 = [N || N <- Nodes, rabbit:is_running(N)],
Nodes2 = lists:usort([node() | Nodes1]),
rabbit_ff_controller:sync_cluster(Nodes2).

-spec refresh_feature_flags_after_app_load() ->
ok | {error, any()} | no_return().
Expand Down
22 changes: 15 additions & 7 deletions deps/rabbit/src/rabbit_ff_controller.erl
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
enable/1,
enable_default/0,
check_node_compatibility/1,
sync_cluster/0,
sync_cluster/1,
refresh_after_app_load/0,
get_forced_feature_flag_names/0]).

Expand Down Expand Up @@ -134,21 +134,21 @@ check_node_compatibility(RemoteNode) ->
%% feature flags.
check_node_compatibility_task(ThisNode, RemoteNode).

sync_cluster() ->
sync_cluster(Nodes) ->
?LOG_DEBUG(
"Feature flags: SYNCING FEATURE FLAGS in cluster...",
[],
#{domain => ?RMQLOG_DOMAIN_FEAT_FLAGS}),
case erlang:whereis(?LOCAL_NAME) of
Pid when is_pid(Pid) ->
%% The function is called while `rabbit' is running.
gen_statem:call(?LOCAL_NAME, sync_cluster);
gen_statem:call(?LOCAL_NAME, {sync_cluster, Nodes});
undefined ->
%% The function is called while `rabbit' is stopped. We need to
%% start a one-off controller, again to make sure concurrent
%% changes are blocked.
{ok, Pid} = start_link(),
Ret = gen_statem:call(Pid, sync_cluster),
Ret = gen_statem:call(Pid, {sync_cluster, Nodes}),
gen_statem:stop(Pid),
Ret
end.
Expand Down Expand Up @@ -273,8 +273,8 @@ proceed_with_task({enable, FeatureNames}) ->
enable_task(FeatureNames);
proceed_with_task(enable_default) ->
enable_default_task();
proceed_with_task(sync_cluster) ->
sync_cluster_task();
proceed_with_task({sync_cluster, Nodes}) ->
sync_cluster_task(Nodes);
proceed_with_task(refresh_after_app_load) ->
refresh_after_app_load_task().

Expand Down Expand Up @@ -645,6 +645,15 @@ get_forced_feature_flag_names_from_config() ->
Reason :: term().

sync_cluster_task() ->
Nodes = running_nodes(),
sync_cluster_task(Nodes).

-spec sync_cluster_task(Nodes) -> Ret when
Nodes :: [node()],
Ret :: ok | {error, Reason},
Reason :: term().

sync_cluster_task(Nodes) ->
%% We assume that a feature flag can only be enabled, not disabled.
%% Therefore this synchronization searches for feature flags enabled on
%% some nodes but not all, and make sure they are enabled everywhere.
Expand All @@ -657,7 +666,6 @@ sync_cluster_task() ->
%% would make sure a feature flag isn't enabled while there is a network
%% partition. On the other hand, this would require that all nodes are
%% running before we can expand the cluster...
Nodes = running_nodes(),
?LOG_DEBUG(
"Feature flags: synchronizing feature flags on nodes: ~tp",
[Nodes],
Expand Down
1 change: 1 addition & 0 deletions deps/rabbit/test/feature_flags_v2_SUITE.erl
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,7 @@ setup_slave_node(Config) ->
_ = rabbit_ff_registry_factory:initialize_registry(),
ok = start_controller(),
ok = rabbit_feature_flags:enable(feature_flags_v2),
_ = catch rabbit_boot_state:set(ready),
ok.

setup_logger() ->
Expand Down

0 comments on commit ef64f51

Please sign in to comment.